1.3.0 • Published 4 years ago

@opuscapita/react-list v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

react-list

Description

Highly configurable react list component

Main features

  • Virtualization with react-infinite
  • Responsive or fixed size
  • Columns with headers
  • Selectable items
  • Drag'n'drop ordering

Installation

npm install @opuscapita/react-list

Demo

View the DEMO

Change log

View the Change log

Migrate guide

View the Migrate guide between major versions

Builds

UMD

The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.

CommonJS/ES Module

You need to configure your module loader to use cjs or es fields of the package.json to use these module types. Also you need to configure sass loader, since all the styles are in sass format.

API

Prop nameTypeDefault / paramsDescription
itemsarray of item objectsrequiredArray of items in the list
idstringoc-react-listComponent base id
classNamestringComponent class
columnsarray of column objects{ valueKey: 'value', title: 'value' }Array of columns in the list
selectedItemsarray of id's[]Array of selected item id's
heightnumber or 'auto''auto'Height of the list in pixels
widthnumber or 'auto''auto'Width of the list in pixels
itemHeightnumber40Height of the item in the list in pixels
columnHeaderHeightnumber40Height of the column header in pixels
dragItemZindexnumber1060draggable items z-index
idKeystring'id'ID key of item data
translationsobject{ search: 'Search', selectAll: 'All', showOnlySelected: 'Show only selected', noResults: 'There are no items to show in this list.' }Translations
customThemeobjectthemeDefaultsOverride theme
highlightedItemsarray[]List of ID keys of items to be highlighted with a grey background color
isSearchablebooleanfalseIs list searchable
isSelectColumnVisiblebooleanfalseIs select column visible
isSelectAllVisiblebooleanfalseIs select all checkbox visible
isShowOnlySelectedVisiblebooleanfalseIs show only selected checkbox visible
isColumnHeaderVisiblebooleanfalseIs column header visible
isIndexColumnVisiblebooleanfalseIs index column visible
isItemBorderVisiblebooleantrueIs border visible between items
isSortablebooleanfalseEnable drag'n'drop sorting
showOnlySelectedInitialValuebooleanfalseShow only selected checkbox initial state
onSelectedChangefunction(selectedIds: array)Callback for selected items change
onShowOnlySelectedChangefunction(showOnlySelected: bool)Callback for Show only selected change
onRowClickfunction(item: object, rowIndex: number)Callback for row click
onRowDoubleClickfunction(item: object, rowIndex: number)Callback for row double click
onRowContextMenufunction(item: object, rowIndex: number)Callback for row context menu (right click)
onSelectAllClickfunctionCallback for select all click
onSortEndfunction({ oldIndex: number, newIndex: number })Callback for sort end

column object attributes

NameTypeDefault / ParametersDescription
valueKeystring'value'Value key in the list
titlearray of strings'Value'Title text to display in column header
widthnumber or 'auto'200Column width in pixels
alignmentstring'flex-start'Value for justify-content CSS rule
renderfunction(item: object, rowIndex: number)Custom renderer function

special item attributes

NameTypeDefault / ParametersDescription
isAlwaysVisiblebooleanundefinedShould this item be always visible even if filters don't match it

Theme

You can use styled-components ThemeProvider to provide theme. If no ThemeProvider is found, default theme object is used. You can always override theme with customTheme prop.

Code example

Simple data

import React from 'react';
import List from '@opuscapita/react-list';

export default class ReactView extends React.Component {
  render() {
    const items = [
      { id: 1, value: 'item 1' },
      { id: 2, value: 'item 2' },
      { id: 3, value: 'item 3' },
    ];
    return (
      <List
        items={items}
      />
    );
  }
}

Column list with custom ID field, column header visible, sorting enabled

import React from 'react';
import List from '@opuscapita/react-list';
import arrayMove from 'array-move';

export default class ReactView extends React.Component {
  state = {
    items: [
      { itemId: 1, name: 'Valve', price: 15.99, tax: 24 },
      { itemId: 2, name: 'Crankshaft', price: 359.99, tax: 24 },
      { itemId: 3, name: 'Carburetor', price: 299.99, tax: 24 },
    ],
  }

  handleSortEnd = ({ oldIndex, newIndex }) => {
    const { items } = this.state;
    this.setState({
      items: arrayMove(items, oldIndex, newIndex),
    });
  };

  render() {
    const columns = [
      { valueKey: 'name', title: 'Item' },
      { valueKey: 'price', title: 'Price' },
      { valueKey: 'tax', title: 'Tax %' },
    ];
    const items = [
      { itemId: 1, name: 'Valve', price: 15.99, tax: 24 },
      { itemId: 2, name: 'Crankshaft', price: 359.99, tax: 24 },
      { itemId: 3, name: 'Carburetor', price: 299.99, tax: 24 },
    ];
    return (
      <List
        columns={columns}
        items={items}
        idKey="itemId"
        isColumnHeaderVisible
        isSortable
        onSortEnd={handleSortEnd}
      />
    );
  }
}
1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.6.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago