import { Meta } from '@storybook/react'; import React from 'react'; import { longTree } from 'demodata'; import { UncontrolledTreeEnvironment } from '../uncontrolledEnvironment/UncontrolledTreeEnvironment'; import { StaticTreeDataProvider } from '../uncontrolledEnvironment/StaticTreeDataProvider'; import { Tree } from '../tree/Tree'; export default { title: 'Core/Search Configurability', } as Meta; export const SearchByStartTyping = () => ( dataProvider={new StaticTreeDataProvider(longTree.items)} getItemTitle={item => item.data} canSearchByStartingTyping viewState={{ 'tree-1': { expandedItems: [ 'Fruit', 'Meals', 'America', 'Europe', 'Asia', 'Desserts', ], }, }} > ); export const SearchOnlyWithHotkey = () => ( dataProvider={new StaticTreeDataProvider(longTree.items)} getItemTitle={item => item.data} canSearchByStartingTyping={false} keyboardBindings={{ startSearch: ['f1'], // TODO hotkeys do not overwrite browser default because preventDefault is called on keyup, not keydown // TODO fix by checking whether hotkey is already fulfilled during keydown }} viewState={{ 'tree-1': { expandedItems: [ 'Fruit', 'Meals', 'America', 'Europe', 'Asia', 'Desserts', ], }, }} > ); export const NoSearch = () => ( dataProvider={new StaticTreeDataProvider(longTree.items)} getItemTitle={item => item.data} canSearch={false} viewState={{ 'tree-1': { expandedItems: [ 'Fruit', 'Meals', 'America', 'Europe', 'Asia', 'Desserts', ], }, }} > ); export const CustomSearchEvaluation = () => ( <>

In the following example, the search evaluates only the children of an item, not the items title itself. This means that searching for "Orange" will match its parent "Fruit".

dataProvider={new StaticTreeDataProvider(longTree.items)} getItemTitle={item => item.data} doesSearchMatchItem={(search, item) => !!item.children?.join(' ').toLowerCase().includes(search.toLowerCase()) } renderItemTitle={props => props.info.isSearching && props.context.isSearchMatching ? ( {props.title} ) : ( props.title ) } viewState={{ 'tree-1': { expandedItems: [ 'Fruit', 'Meals', 'America', 'Europe', 'Asia', 'Desserts', ], }, }} > );