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

carbon-data-table-state-manager

v1.0.3

Published

Sample project for creating fully customized state management of carbon-components-react data table

Downloads

54

Readme

About

This package emerged through the need of a custom state manager for IBMs Carbon Design Data table component. The default behavior of the component (sorting, filtering, searching) can only be overwritten by implementing an own Custom State manager.

Read more about it here: https://github.com/carbon-design-system/carbon/issues/6373#issuecomment-747612917

After implementing this custom state manager, I realized that I need the same code in many projects, so this package was born.

The initial code was taken from the example implementation by IBM: https://github.com/carbon-design-system/carbon/issues/6373#issuecomment-747612917

Features

The package was written with a focus on displaying time series data.

Time

You can supply a column named "time" and an optional Day.js format string. The time column will then be formatted according to this format string (default is YYYY/MM/DD HH:mm). Additionaly if you supply a title prop, the Table will show a description in the form from <start date> till <end date>.

Requirements

Requires Carbon components v10, migration to v11 is coming soon.

"@carbon/icons-react": "10.x",
"carbon-components": "10.x",
"carbon-components-react": "7.x",
"react": ">=16",
"react-dom": ">=16"

Install

yarn add carbon-data-table-state-manager

or

npm i carbon-data-table-state-manager --save

Usage

Example

import { CarbonDataTableStateManager } from "carbon-data-table-state-manager";
import { TABLE_SORT_DIRECTION } from "carbon-data-table-state-manager/misc";

const columns = [
  {
    title: "Time",
    id: "time",
    sortCycle: "tri-states-from-ascending",
  },
  {
    title: "Temperature",
    small: `in °C`,
    id: "temperature",
    sortCycle: "tri-states-from-ascending",
  },
  {
    title: "Humidity",
    small: `in %`,
    id: "humidity",
    sortCycle: "tri-states-from-ascending",
  },
];

const rows = [
  {
    time: 1614927420,
    temperature: -0.7,
    humidity: 93,
  },
  {
    time: 2021-03-05T02:57:00.000Z,
    temperature: 1.2,
    humidity: 77,
  },
];

<CarbonDataTableStateManager
  columns={columns}
  rows={rows}
  start={0}
  pageSize={10}
  pageSizes={[10, 25, 50, 100, 200, 500]}
  sortInfo={{
    columnId: "timeParsed",
    direction: TABLE_SORT_DIRECTION.ASC,
  }}
  size="short"
/>

Storybook

See the Storybook for more examples.

Props

{
  id: string | number;
  title: string;
  sortCycle?: string;
  small?: string;
  tooltip?: string;
}[]
{
  [key: string]: any;
  selected: boolean;
  time?: string | number;
}[]
{
  columnId: string;
  direction: "ASC" | "DESC" | "NONE";
}

Day.js format string for formatting the time column