import { useMemo, FC, Fragment } from 'react'; import { provide, useDependencies } from '@servicetitan/react-ioc'; import { observer } from 'mobx-react'; import { Table, TableColumn, singleSelectColumnMenuFilter } from '../..'; import { TableStore } from './table.store'; import { categories, CategoryCell } from './categories'; import { Banner, BodyText } from '@servicetitan/design-system'; export const SingleSelectDefaultExample: FC = provide({ singletons: [TableStore], })( observer(() => { const [{ tableState, madeInOptions }] = useDependencies(TableStore); const madeInColumnMenu = useMemo( () => singleSelectColumnMenuFilter({ options: madeInOptions }), [madeInOptions] ); const categoryColumnMenu = useMemo( () => singleSelectColumnMenuFilter({ options: categories, renderItem: cat => ( {cat.CategoryName} (#{cat.CategoryID}) ), valueSelector: cat => cat.CategoryID, contentMaxHeight: '200px', }), [] ); return ( Single select filter allows to choose one option from the provided list. You can pass simple options (string or number) or complex objects
Use it when options list is fixed and less than 20 items
); }) ); export const SingleSelectCustomFilterExample: FC = provide({ singletons: [TableStore], })( observer(() => { const [{ tableState }] = useDependencies(TableStore); const productNameCustomFilter = useMemo(() => { const isVowel = (str: string) => /[aeiou]/i.test(str[0]); return singleSelectColumnMenuFilter({ options: [0, 1], renderItem: item => (item ? 'Start with Vowel' : 'Start with Consonants'), filterOperator: (madeIn: string, value: number) => madeIn ? (value ? isVowel(madeIn) : !isVowel(madeIn)) : false, }); }, []); return ( Single select filter allows to choose one option from the provided list. You can pass simple options (string or number) or complex objects
Custom filter allows you to provide custom filtering options
); }) );