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

@fatqianqian/cabbage-package

v1.0.21

Published

A collection of advanced and customizable React components built on top of Chakra UI. Starting with a rich data table component offering built-in pagination, theming options, and flexible row customization, this package aims to enhance your Chakra UI expe

Downloads

7

Readme

Table of Contents

Installation

Use npm to install the package:

npm install @fatqianqian/cabbage-package

And make sure ChakraProvider is set up in your app:

import { ChakraProvider } from '@chakra-ui/react';

const App = () => (
  <ChakraProvider>
    {/* ... */}
  </ChakraProvider>
);

Basic Usage

Here's how to use the DataTable component in a React component:

import { DataTable } from '@fatqianqian/cabbage-package';

const App = () => {
  const columns = [
    { header: 'Code', accessorKey: 'code' },
    { header: 'Name', accessorKey: 'name' },
    { header: 'Action', accessorKey: 'action', render: (rowData) => (<Button>{rowData.action}</Button>)}
    // ... more columns
  ];

  const data = [
    { id: 1, code: 'A1', name: 'Apple', action: 'Button 1' },
    { id: 2, code: 'B1', name: 'Banana', action: 'Button 2' },
    // ... more data
  ];

  return (
    <DataTable
      columns={columns}
      data={data}
    />
  );
};

Props

columns (required)

An array of column objects specifying the header label and the key for data accessor. If you want to render a custom component in the column, you can also provide a render function that takes the row data as the argument and returns the component to be rendered.

  • Type: Array

  • Example:

    const columns = [
      { header: 'Code', accessorKey: 'code' },
      { header: 'Name', accessorKey: 'name' },
      { header: 'Action', accessorKey: 'action', render: (rowData) => (<Button>{rowData.action}</Button>)}
    ];

data (required)

An array of objects to be displayed in the table. Each object should have the same keys as the accessor keys specified in the columns prop.

  • Type: Array

  • Example:

    const data = [
      { id: 1, code: 'A1', name: 'Apple', action: 'Button 1' },
      { id: 2, code: 'B1', name: 'Banana', action: 'Button 2' },
    ];

selectedRows

An array of objects to be selected in the table. Each object should have the same keys as the accessor keys specified in the columns prop.

  • Type: Array
  • Default: []

onRowSelectionChange

A function that will be called when the selected rows change.

  • Type: Function
  • Default: () => {}

hasCaption

A boolean flag that enables or disables the table caption.

  • Type: Boolean
  • Default: false

caption

A string that is used as the table caption if hasCaption is set to true.

  • Type: String
  • Default: ''

tableStyle

Allows you to provide additional styles for the table.

  • Type: Object

  • Default:

    {
        textAlign: "center",
        size: "sm",
        border: "1px",
        borderColor: "blackAlpha.900",
    }
  • Type: Object

enablePagination

A boolean flag that enables or disables pagination for the table.

  • Type: Boolean
  • Default: false

enableRowDoubleClick

A boolean flag that enables or disables double click for the table row, if enabled, if enabled, rowDoubleClickHandler will be called when double click on the row.

  • Type: Boolean
  • Default: false

rowDoubleClickHandler(rowData)

Double click handler for the table row, if enableRowDoubleClick is set to true, this handler will be called when double click on the row.

  • Type: Function
  • Default: () => {}
  • Usage:
    <DataTable
      ...
      rowDoubleClickHandler = (row) => {alert(`Double Clicked Row ${row.id}`)},
      ...
    />

enableFilter

A boolean flag that enables or disables filter for the table.

  • Type: Boolean
  • Default: false

enableMultiSelect

A boolean flag that enables or disables multi select for the table.

  • Type: Boolean
  • Default: false

enableFixedHeader

A boolean flag that enables or disables fixed header for the table. maxH will be set to 100% if enableFixedHeader is set to true.

  • Type: Boolean
  • Default: false

Example Usage with All Props

<DataTable
  columns={columns}
  data={data}
  selectedRows={[1, 2]}
  onRowSelectionChange={(selectedRows) => { console.log(selectedRows) }}
  hasCaption={true}
  caption="Sample Caption"
  tableStyle={{ textAlign: 'center' }}
  enablePagination={true}
  enableRowDoubleClick={true}
  rowDoubleClickHandler={(row) => { console.log(row) }}
/>