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

@seij/yagrid

v0.1.22

Published

Yet another grid. A tool for building dynamic tables and grids with built-in editor and type registry. Targeted to management software.

Downloads

14

Readme

yagrid

Yet another grid. A tool for building dynamic tables and grids with built-in editor and type registry. Targeted to management software.

heavy development production ready

test and build

Installation

Using yarn yarn add @seij/yagrid or npm npm i @seij/yagrid.

YAGrid depends on React that shall already be installed in your project as it comes as a peer-dependency. Your React version must support hooks.

We export this component as

Typescript

  • YAGrid is build with Typescript. You get native typings. All imports shall be resolved to @seij/yagrid. Do not import from submodules event if you can reach them.

Build yourself and examples

After cloning use the classic npm install and npm run build commands to build. Build is taken care of by Rollup.

To launch the Storybook interface, use npm run storybook.

Launch npm run test for unit tests.

Known issues

  • @rollup/plugin-typescript doesn't generate Typescript definition files
  • Unfortunatly a bug with @rollup/plugin-typescript doesn't generate Typescript definition files

Datatypes

Datatypes add rendering features to types. Each grid can use a registry of data types to customize globally the rendering of known types.

It is possible to build a type registry outside the scope of a particular grid, and pass the type registry as grid properties.

You can also have as many as registries as you want and reuse them across grids of your app.

An important point is that you CAN NOT provide column definitions with types unknown by the registry of the displayed grid.

Default minimalist registry

If no type registry is given, a default one will be used with the following known types: string, boolean, int, decimal, percent. All data will render toString(). Nullish values will render as empty text.

Custom registry

To create a custom registry, use the TypesRegistryBuilder and add your types. Each type must come with a renderer that accepts the data and possiblty nullish values (null, undefined). It MUST return a string (even if empty)

Each type registred will be added to the default registry. If one of your types overlap with the default registry (like percent in following example), your type wins.

You can combine your type registry with custom renderer for columns. If a renderer had been provided for a column, it wins over the registry.

To be clear, when data must be displayed, we use the first found in this order : column renderer, custom type renderer, default type renderer.

If you ask yourself how to manage i18n issues, here we are. You get a precise control on how data is displayed. Up to you. An advice would be to have a "ready-to-go" registry at start of your app, immutable, and then pass it to all your grids. This way, your collegues won't have to be bothered about formatting in your app anymore.

 const customTypes = new TypesRegistryBuilder()
    .add("percent", data => data==null ? "" : ""+(data * 100)+"%")
    .add("monetaryAmountInt", data => ""+(data || 0))
    .add("monetaryAmountDecimal", function(data){
        return new Intl.NumberFormat(undefined, { minimumFractionDigits: 2, style: "decimal" })
            .format(data||0)
    })
    .build()

const gridProps: GridProps<S> = {
    //... other props like columns, plugins, etc.
    types: customTypes
}

 return <Grid {...gridProps} />

Note that in this example nullish data are handled differently depending on the type. This is useful in many cases. For example, on one table you don't want "0" numbers to appear, on others you want them whatever.

Provided plugins

Currently provided plugins

| Name | Description | |------|-------------| | item-add | Provides a toolbar button to add an item. When user clicks, an editable row opens to edit the item. Provides confirm, cancel button and a temporary item to be able to cancel. | | item-edit | Provides row editing features. A button triggers row editing, then user can validate or cancel the row. Also manages a temporary item to be able to cancel. | | item-delete | Provides row button to delete item, confirm and cancel buttons. | | empty-message | Displays a custom empty message or component if data is empty | table-footer | Displays a custom component in table footer (tfoot) area | table-classnames | Using table layout, adjusts the classnames based in displayed item, column, etc.

Each plugin comes with its own documentation. Be sure to take a look at it

Plugin development

Naming

Internal plugins as well a third-party plugins shall expose a Config object and a create(cfg:Config) function.

The goal is to provide an unified naming for importing and instanciating plugins.

// Could be third party plugins
import { EditItem, DeleteItem, AddItem } from "@seij/yagrid";
// When creating the grid
const props: GridProps<ItemType> = {
    // ...
    plugins: [
        EditItem.create({ /** edit item config */ }),
        DeleteItem.create({ /** edit item config */ }),
        AddItem.create({ /** edit item config */ }),
        // ...
    ]
}
return <Grid {...props} />