npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-spreadsheets

v1.0.0

Published

A lightweight, fully customizable, feature rich spreadsheet component for React

Downloads

15

Readme

react-spreadsheets

A lightweight, fully customizable, feature rich spreadsheet component for React

Installation

$ npm i react-spreadsheets
# or
$ yarn add react-spreadsheets

Screenshot

Screenshot

Features

  • Straight and simple APIs
  • Keyboard friendly
  • Allows easy transfer of data using drag & drop
  • Readonly cells are allowed
  • Inbuilt search and sort functionalities
  • Accepts custom filters
  • Allows custom data formators
  • Accepts name, text and select fields

Usage

Example

import { SpreadSheet } from 'react-spreadsheets';
import { addCountryCode } from './utils';

const App = () => {
  const tableSchema = [
    { id: 'name', name: 'Name', searchable: true },
    { id: 'age', name: 'Age', type: 'number' },
    {
      id: 'foodPreference',
      name: 'Food Perference',
      options: [
        { value: '', label: '' },
        { value: 'vegan', label: 'Vegan' },
        { value: 'veg', label: 'Veg' },
        { value: 'non-veg', label: 'Non-Veg' }
      ]
    },
    {
      id: 'ph',
      name: 'Phone Number',
      type: 'number',
      searchable: true,
      dataFormator: data => addCountryCode(data)
    }
  ];

  return (
    <div className='App'>
      <SpreadSheet tableSchema={tableSchema} />
    </div>
  );
};

Example: Add 2 numbers

import { SpreadSheet } from 'react-spreadsheets';
import { addCountryCode } from './utils';

const App = () => {
  const tableSchema = [
    { id: 'user', name: 'User', type: 'text' },
    { id: 'num1', name: 'Number 1', type: 'number' },
    { id: 'num2', name: 'Number 2', type: 'number' },
    {
      id: 'sum',
      name: 'Sum',
      readOnly: true,
      getRow: ({ num1, num2 }) => {
        const sum = +num1 + +num2;
        if (isNaN(sum)) return '';
        return sum;
      }
    }
  ];

  return (
    <div className='App'>
      <SpreadSheet tableSchema={tableSchema} />
    </div>
  );
};

SpreadSheet Props

tableSchema: (type: TableSchema[]);

This is the most important and only required prop. Defines the schema of the SpreadSheet.

  type TableSchema = {
    id: string;
    name: string;
    readOnly?: boolean;
    getRow?: (row: { [key: string]: any }) => any;
    } & (
    | {
        type?: 'text';
        dataFormator?: (data: string) => string;
        searchable?: boolean;
      }
    | {
        type: 'number';
        dataFormator?: (data: number) => number;
        searchable?: boolean;
      }
    | { type: 'select'; options: OptionHTMLAttributes<any>[] }
  ); 

initialTableData?: (type: TableSchema[]);

Holds the initial data for the SpreadSheet. Can be helpful in persisting the table state.

getTableData?: (type: (data: TableSchema[]) => any);

Subscribe to table data changes using getTableData. This contains the unaltered table data and doesn't get affected by sorting, searching or other custom filters.

getDraftTableData?: (type: (data: TableSchema[]) => any);

Subscribe to filtered table data changes using getDraftTableData.

onFilter?: (type: (data: TableSchema[]) => TableSchema[]);

Pass custom filters using onFilter.

searchableValue?: (type: string);

Searchable value searches the searchable columns passed through tableSchema.

autoGrow?: (type: boolean; default: true);

Decides if the SpreadSheet is allowed to automatically grow.

sortable?: (type: boolean; default: false);

If true, allows sorting the SpreadSheet by column

rowNum?: (type: number; default: 1);

Number of rows in the SpreadSheet

classes?: (type: ClassNames)

  type ClassNames = {
    table?: string;
    tableHead?: string;
    tableHeadRow?: string;
    tableHeadCell?: string;
    tableBody?: string;
    tableBodyRow?: string;
    tableBodyCell?: string;
    tableBodyCellSelect?: string;
    tableBodyCellSelected?: string;
  }

styles?: (type: InlineStyles)

  type InlineStyles = {
    table?: React.CSSProperties;
    tableHead?: React.CSSProperties;
    tableHeadRow?: React.CSSProperties;
    tableHeadCell?: React.CSSProperties;
    tableBody?: React.CSSProperties;
    tableBodyRow?: React.CSSProperties;
    tableBodyCell?: React.CSSProperties;
    tableBodyCellSelect?: React.CSSProperties;
    tableBodyCellSelected?: React.CSSProperties;
  }

Keyboard Shortcuts

  • Ctrl + C -> Copy
  • Ctrl + V -> Paste
  • Backspace / Delete -> Delete
  • Enter -> Edit and move down
  • Shift + Enter -> Edit and move up
  • Tab -> Move right
  • Shift + Tab -> Move left
  • ArrowUp -> Move up
  • ArrowDown -> Move down
  • ArrowLeft -> Move left
  • ArrowRight -> Move right