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

@invisionag/iris-react-table

v6.6.2

Published

```js import Table, {Column} from '@invisionag/iris-react-table'; ```

Downloads

83

Readme

import Table, {Column} from '@invisionag/iris-react-table';

react-table is a component that exposes multiple building blocks for structured, table-like display of data, while also providing freedom to supply data in a more dynamic and react-oriented way. We also get the freedom to animate row movement freely, without worrying about breaking the <table> markup. The central piece is the Table component, as it provides the basic styles. Instead of using tr for rows, you nest Columns into it to outline a structure. The rows themselves are provided as an Array of objects in the rows prop.

Usage

Basic

Please note, a __props.key attribute is required. Otherwise animations and sorting/searching in the virtualized version of the table will break.

rows = [
  {__props: { key: 1 }, name: 'Superman', morality: 'good'},
  {__props: { key: 2 }, name: 'Joker', morality: 'evil'},
  {__props: { key: 3 }, name: 'Wonder Woman', morality: 'good'},
];
<Table rows={rows}>
  <Column name="name" label="Name" />
  <Column name="morality" label="Morality" />
</Table>

Animation and Virtualization

Animations are enabled by default, you can disable them by setting animation to false. If animations are disabled the table will by virtualized. You should do this if your table needs to handle a lot of rows. It's required to set a height for the virtualized table to render rows.

Custom Column width

For custom column width you can pass a string in the width prop of a column. The string will directly be injected as a css value.

rows = [
  {__props: { key: 1 }, name: 'Superman', morality: 'good' },
  {__props: { key: 2 }, name: 'Joker', morality: 'evil' },
  {__props: { key: 3 }, name: 'Wonder Woman', morality: 'good' },
];
<Table rows={rows}>
  <Column width="10px" name="name" />
  <Column width="20%" name="morality" />
</Table>

Disabled rows

Rows can receive the disabled styling. For that, the row object should contain a true value for its __props.disabled key.

rows = [
  {__props: { key: 1, disabled: true }, name: 'Superman', morality: 'good' },
  {__props: { key: 2, disabled: true }, name: 'Joker', morality: 'evil' },
  {__props: { key: 3, disabled: true }, name: 'Wonder Woman', morality: 'good' },
];
<Table rows={rows}>
  <Column width="10px" name="name" />
  <Column width="20%" name="morality" />
</Table>

Sortable

A table can use the built-in functionality to make columns sortable by providing the sortable prop in the table component.

rows = [
  {__props: { key: 1, disabled: true }, name: 'Superman', morality: 'good' },
  {__props: { key: 1, disabled: true }, name: 'Joker', morality: 'evil' },
  {__props: { key: 1, disabled: true }, name: 'Wonder Woman', morality: 'good' },
];
<Table rows={rows} sortable showHeader>
  <Column width="10px" name="name" />
  <Column width="20%" name="morality" />
</Table>

For more elaborated sorting mechanisms, a valid alternative is providing the sorting functionality in a parent component. Columns can be passed an onClick prop, which will be fired when the header "cell" of this column is clicked. This means that custom sort functionality should only be used in conjunction with showHeader. Example here

Fixed height

For fixed height and any other inline styles you want to put on the table body, you can either pass just pass style object to the Table or use the height prop. If both are specified the height prop will overrule the style object.

const tableStyles = {
  height: '160px',
};

const height = '180px';
rows = [
  {__props: { key: 1, disabled: true }, name: 'Superman', morality: 'good' },
  {__props: { key: 1, disabled: true }, name: 'Joker', morality: 'evil' },
  {__props: { key: 1, disabled: true }, name: 'Wonder Woman', morality: 'good' },
];
<Table rows={rows} style={tableStyles} height={height}>
  <Column name="name" />
  <Column name="morality" />
</Table>

Placeholder

A placeholder can be provided. It will be displayed when the rowGetter doesn't return any elements to show. The placeholder can be either a string, or jsx.

rows = [];
<Table rows={rows} placeholder={<p>There is no data here.</p>}>
  <Column name="name" />
  <Column name="morality" />
</Table>

Custom Column Headings

It is possible to specify custom Column content via render prop. The render prop is expected as a child of column, and it passes along all of the column props.

Column Props:

  • name (string): name passed to the column
  • label (string or React$Node): the label passed to the column,
  • onClick (SyntheticMouseEvent<*> => any): Call to invoke sorting functionality
  • handleClick (SyntheticMouseEvent<*> => any): Call to invoke sorting functionality. Calls preventDefault before executing.
  • sorted ('unsorted' | 'ascending' | 'descending'): Whether the column is currently sorted (and in which direction)
  • className (string): ClassNames of the column
  • width (string): width passed to the column

Example:

rows = [];
<Table rows={rows} placeholder={<p>There is no data here.</p>}>
  <Column name="name" />
    {props => <button onClick={props.onClick}>{props.name}</button>}
  </Column>
</Table>