1.0.1 • Published 2 years ago

@ohaidukova/react-tree-list v1.0.1

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

react-tree-list

react-tree-list is a lightweight react library for big lists and big tree lists

Table

Demo

https://ohaidukova.github.io/react-tree-list/

Installation

npm i @ohaidukova/react-tree-list

Example

import { List, IRowRenderer, TDataBase } from '@ohaidukova/react-tree-list';
import { treeData } from '../data';

interface IData extends TDataBase<'id'> {
    deep: string;
    name: string;
    type: string;
    count: number;
    children?: IData[];
}

const rowRenderer: IRowRenderer<IData> = ({ rowData, style }) => {
    return (
        <div
            style={{
                ...style,
                paddingTop: '5px',
                paddingBottom: '5px',
                borderBottom: '2px solid gray',
                width: '100%',
            }}
        >
            <span
                style={{ padding: '0 10px' }}
            >{`${rowData.name}, ${rowData.id}`}</span>
        </div>
    );
};

export const App = () => {
    return (
        <div
            style={{ height: '100%', display: 'flex', flexDirection: 'column' }}
        >
            <div style={{ padding: '50px' }}>React tree data</div>
            <div style={{ flex: 'auto' }}>
                <List<'id', IData>
                    data={treeData}
                    height={500}
                    rowHeight={30}
                    rowRenderer={rowRenderer}
                    uniqueFieldName="id"
                    childrenFieldName="children"
                />
            </div>
        </div>
    );
};

API

PropertyTypeRequiredDescription
dataarray+Array of objects with a unique field name, interface IData extends TDataBase<'id'>
heightnumber+Height of the block for the table
rowHeightnumber+Height of the row
overscanRowCountnumberHow many rows we need to render below the visible area, by default 10
uniqueFieldNamestring+Name of the field with unique data
childrenFieldNamestring+Name of the field with nested data
rowRendererfunction+Function for displaying rows, interface IRowRenderer
expandedDataobjectObject with data of expanded rows, interface IExpandedChildrenData