4.1.1 • Published 9 months ago

@tabula/ui-checkbox-tree v4.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

@tabula/ui-checkbox-tree

Allows to select items in the tree.

Installation

Use the package manager pnpm to install @tabula/ui-checkbox-tree.

pnpm add @tabula/ui-checkbox-tree

You can use npm or yarn too.

Usage

Usage of the UiCheckboxTree is simple:

import { FC } from 'react';

import { UiCheckboxTree, Tree as BaseTree } from '@tabula/ui-checkbox-tree';

type Data = {
  name: string;
};

type Tree = BaseTree<number, Data>;

const labelOf = ({ name }: Data) => name;

type Props = {
  tree: Tree;
};

export const Tree: FC<Props> = ({ tree }) => {
  const [selected, setSelected] = useState<Set<number>>(new Set());

  return (
    <UiCheckboxTree labelOf={labelOf} onChange={setSelected} selected={selected} tree={tree} />
  );
};

Options

tree

The tree property contains a tree data to render. You can define type of ids, and data which expected in the tree structure.

Ids of items must be unique and has type number or string.

See typings for more information.

labelOf

Function which will be called to get label of node.

selected

Set of leaf's ids which is checked.

onChange

Handler which accepts a set of checked leaf's ids.

The UiCheckboxTree always calls this callback with full set of checked ids, not only ids which checked after the latest user's action.

pattern and match

This is a pair of properties.

The pattern is string value which contains a pattern which will be provided to the match function.

The match function is predicated, which takes node and pattern, and returns boolean flag.

If one of them will not be provided, or the pattern will be is an empty string, then search will be ignored completely.

className

You can provide custom CSS class which will be assigned to the root element.

testId

We allow to assign test ID for the root element.

Empty Branches

If branch is empty then it's disabled and have no toggle button.

Disabled State

Each item can have isDisabled property:

  • if all items are disabled, then the Select All is disabled too;
  • if branch is disabled, then all children is disabled too;
  • if branch's children are disabled, then branch is disabled too;
  • if user toggle branch or Select All when disabled items is presented, then disabled items aren't changed.

License

This project is ISC licensed.

4.1.1

9 months ago

4.1.0

10 months ago

4.1.0-next.0

10 months ago

4.0.3

10 months ago

4.0.2

10 months ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

3.0.1

12 months ago

3.0.0

1 year ago

1.1.3

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

4.0.1

11 months ago

4.0.0

11 months ago

4.0.0-next.0

11 months ago

2.0.0-next.0

1 year ago

2.0.0

1 year ago

0.1.0

1 year ago