@idui/react tree select

React TreeSelect Component

Version: 1.0.5 Updated: 04/05/2022

By: id-ui License: MIT

Downloads Last 30 Days: 147

TreeSelect React Component

NPM Size JavaScript Style Guide Coverage Status LICENSE

Install

npm install --save @idui/react-tree-select
yarn add @idui/react-tree-select

See props in Docs

Basic Example

import React from 'react'
import TreeSelect from '@idui/react-tree-select'

const nodes = [
    { label: 'Cake', value: 'cake' },
    { label: 'Coffee', value: 'coffee', children: [
        { label: 'Cappuccino', value: 'cappuccino' },
        { label: 'Latte', value: 'latte' },
        { label: 'Americano', value: 'americano' },
    ]},
]

function Example() {
  return <TreeSelect 
      nodes={nodes}
      valueKey="value"
      labelKey="label"
      canSelectParentNode={false}
      closeOnSelect={true}
      maxTreeHeight="300px"
      hideScrollbar={false}
      searchPlaceholder="Search"
      // searchTreeBottomAddon={<Pagination ... />}
      // searchTreeScrollBottomAddon={<Waypoint ... />}
  />
}

Custom renderers

import React from 'react'
import styled from 'styled-components';
import TreeSelect, { SearchTreeLeaf } from '@idui/react-tree-select'
import { TextInput, SearchInput } from '@idui/react-inputs';

function Example() {
  return <TreeSelect 
            nodes={nodes}
            renderInput={({ value, onClear, placeholder, open, close, toggle, isOpen }) => <Input 
                {...props} 
                readOnly 
                placeholder="Select value" 
                rightAddon={<ArrowDown color={isOpen ? "lightskyblue" : "gray"} />}
                colors={customColors}
            />}
            renderSearchInput={(props) => <StyledSearchTreeInput 
                {...props} 
                autoFocus 
                placeholder="Search"
            />}
            renderLeaf={(props) => <SearchTreeLeaf {...props} />}
        />
}

const Input = styled(TextInput)`
  width: 100%;
`;

const SearchTreeInput = styled(SearchInput)`
  width: 100%;
`;

const StyledSearchTreeInput = styled(SearchTreeLeaf)`
  .highlight {
    background-color: #ffa7a7;
  }
  padding: 5px 10px;
  &:hover {
    background-color: #fafafa;
  }
`

See more details in storybook

License

MIT © [email protected]

Categories: React js