Package Exports
- @idui/react-tree-select
- @idui/react-tree-select/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@idui/react-tree-select) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
TreeSelect React Component
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 © kaprisa57@gmail.com