@@ -7,6 +7,7 @@ import { Tree } from '../tree/Tree';
77import { StaticTreeDataProvider } from '../uncontrolledEnvironment/StaticTreeDataProvider' ;
88import { UncontrolledTreeEnvironment } from '../uncontrolledEnvironment/UncontrolledTreeEnvironment' ;
99import { buildTestTree } from '../../test/helpers' ;
10+ import { TreeItemIndex } from '../types' ;
1011
1112export default {
1213 title : 'Core/Basic Examples' ,
@@ -556,3 +557,66 @@ export const NavigateAway = () => {
556557 </ UncontrolledTreeEnvironment >
557558 ) ;
558559} ;
560+
561+ export const AnimatedExpandingAndCollapsing = ( ) => {
562+ const [ openingItem , setOpeningItem ] = useState < TreeItemIndex | undefined > ( ) ;
563+ const [ closingItem , setClosingItem ] = useState < TreeItemIndex | undefined > ( ) ;
564+ return (
565+ < UncontrolledTreeEnvironment < string >
566+ dataProvider = {
567+ new StaticTreeDataProvider ( longTree . items , ( item , data ) => ( {
568+ ...item ,
569+ data,
570+ } ) )
571+ }
572+ getItemTitle = { item => item . data }
573+ shouldRenderChildren = { ( item , context ) =>
574+ context . isExpanded ||
575+ closingItem === item . index ||
576+ openingItem === item . index
577+ }
578+ onExpandItem = { item => {
579+ setOpeningItem ( item . index ) ;
580+ setTimeout ( ( ) => {
581+ setOpeningItem ( undefined ) ;
582+ } ) ;
583+ } }
584+ onCollapseItem = { item => {
585+ setClosingItem ( item . index ) ;
586+ setTimeout ( ( ) => {
587+ setClosingItem ( undefined ) ;
588+ } , 500 ) ;
589+ } }
590+ viewState = { {
591+ 'tree-1' : { } ,
592+ } }
593+ renderItemsContainer = { ( { children, containerProps, parentId } ) => (
594+ < div
595+ style = { {
596+ overflow : 'hidden' ,
597+ } }
598+ >
599+ < ul
600+ { ...containerProps }
601+ className = "rct-tree-items-container"
602+ style = { {
603+ transition : 'all 500ms' ,
604+ maxHeight :
605+ parentId === openingItem || parentId === closingItem
606+ ? 0
607+ : '999999px' ,
608+ marginTop :
609+ parentId === closingItem || parentId === openingItem
610+ ? '-100%'
611+ : '0' ,
612+ } }
613+ >
614+ { children }
615+ </ ul >
616+ </ div >
617+ ) }
618+ >
619+ < Tree treeId = "tree-1" rootItem = "root" treeLabel = "Tree Example" />
620+ </ UncontrolledTreeEnvironment >
621+ ) ;
622+ } ;
0 commit comments