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'; const cx = (...classNames: Array) => classNames.filter(cn => !!cn).join(' '); export default { title: 'Core/Custom View State', } as Meta; export const SingleTree = () => ( canDragAndDrop canDropOnFolder canReorderItems dataProvider={ new StaticTreeDataProvider(longTree.items, (item, data) => ({ ...item, data, })) } getItemTitle={item => item.data} renderItem={({ item, depth, children, title, context, arrow }) => { const InteractiveComponent = context.isRenaming ? 'div' : 'button'; const type = context.isRenaming ? undefined : 'button'; return (
  • {arrow} {title} {context.viewStateFlags.activeItems ? ' (marked as active)' : ''}
    {children}
  • ); }} viewState={{ 'tree-1': { expandedItems: [ 'Fruit', 'Meals', 'America', 'Europe', 'Asia', 'Desserts', ], activeItems: ['America', 'Europe'], }, }} > );