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

@kobra-dev/better-react-spreadsheet

v0.2.0

Published

A better spreadsheet widget for React (currently in active development, but probably stable enough to use)

Downloads

2

Readme

Better React Spreadsheet

A better spreadsheet widget for React (currently in active development, but probably stable enough to use)

Project goals:

  • [x] ⚡ Fully virtualized (rows and columns)
  • [x] ⌨️ Same key shortcuts as industry standard spreadsheet software (Google Docs, Excel, etc)
  • [x] 🏢 Modern architecture (React function components)
  • [ ] 📊 Easy dataset creation and editing
    • [x] Selection of multiple cells
    • [x] Insert rows
    • [x] Copy, cut, paste (for single cells or multiple cells)
    • [x] Paste data from other spreadsheet programs
    • [ ] Insert columns
    • [ ] Drag-to-autocomplete like in a spreadsheet
  • [x] 📁 Internally and externally, data is just a 2D array, so interop with file formats like CSV is really easy

Usage

import React, { useState } from "react";
import Spreadsheet from "@kobra-dev/better-react-spreadsheet";

function MyComponent() {
    const [data, setData] = useState([
        [1, 2, 3, 4, 5],
        [6, 7, 8, 9, 10],
        [11, 12, 13, 14, 15]
    ]);

    return (
        <Spreadsheet data={data} onChange={setData}/>
    );
}

If you have data where different rows have different numbers of cells, you'll need to pass it to normalizeRows first:

const newData = normalizeRows(data, /* minWidth */ 20, /* minHeight */ 20);

This will also make sure that the array is at least 20 columns by 20 rows by adding empty cells to any row that is less than the minimum, and adding empty rows until the number of rows is equal to the minimum specified. If you don't want any minimum width or height, just set both to 0.

Be warned that normalizeRows mutates the data array that is passed to it as a parameter. If you do not want this behavior, use the cloneDataArray function:

const newData = normalizeRows(cloneDataArray(data), 20, 20);

Props

  • data: string[][]: Source for data, formatted as a 2D array of strings
  • onChange(newData: string[][]): void: Function to call to update data array
  • className?: string: Optional class name to apply to the outermost div element of the spreadsheet

Working with CSVs

To load a CSV, use the parseCSV function (a wrapper around Papa Parse):

const parseResult = parseCSV(csv);
if(parseResult.errors.length > 0) {
    // Handle errors
}
const data = normalizeRows(parseResult.data, 20, 20);

You can also convert a data array back to a CSV string:

const csv = dataToCSV(data, /* trim */ true);

If the trim parameter is set to true, all empty cells at the end of each row will be removed in the resulting CSV.

Customizing theme

Better React Spreadsheet uses Material-UI internally, so you can use a ThemeProvider to change the color scheme of the table (for example, to add dark mode):

import { createMuiTheme, ThemeProvider } from "@material-ui/core";


// Kobra's MUI theme
const getMuiTheme = (isDark: boolean) =>
    createMuiTheme({
        palette: {
            type: isDark ? "dark" : "light",
            primary: { main: "#42ad66", contrastText: "#ffffff" },
            secondary: { main: "#76e094", contrastText: "#000000" }
        }
    });

export default function App() {
    const isDark = /* get dark theme status */;

    return (
        <ThemeProvider theme={getMuiTheme(isDark)}>
            {/* the rest of your app */}
        </ThemeProvider>
    );
}

Development

We use TSDX for scaffolding the library. For information about how to get started, check out the TSDX default README.

TLDR: run yarn start in one terminal, then run yarn storybook to run Storybook (although just running yarn storybook has worked fine for me).

Showcase

  • Kobra (integrated into the dataset manager): Screenshot of edit dataset dialog in Kobra, powered by Better React Spreadsheet

If you develop (or know of) a project using Better React Spreadsheet, feel free to submit an issue or PR and we'll add you to this section.