From 12d829491601eeff07fc1e7a8c122bcf56578130 Mon Sep 17 00:00:00 2001 From: Gina A <70909035+gndz07@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:56:06 +0100 Subject: [PATCH] feat: navigation tree item subtitle and default expanded state --- .../NavigationTree/NavigationTree.stories.tsx | 35 +++++++++++++++++-- .../NavigationTreeItem.stories.tsx | 2 +- .../NavigationTree/NavigationTreeItem.tsx | 22 ++++++++++-- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/components/NavigationTree/NavigationTree.stories.tsx b/components/NavigationTree/NavigationTree.stories.tsx index cdf2f40d..b01b6796 100644 --- a/components/NavigationTree/NavigationTree.stories.tsx +++ b/components/NavigationTree/NavigationTree.stories.tsx @@ -45,8 +45,13 @@ const Template: ComponentStory = (args) => { return ( - - + + = (args) => { /> - + + + + } + label="Two.Two.One" + /> + + + ); diff --git a/components/NavigationTree/NavigationTreeItem.stories.tsx b/components/NavigationTree/NavigationTreeItem.stories.tsx index 0be74f1c..fe88f50d 100644 --- a/components/NavigationTree/NavigationTreeItem.stories.tsx +++ b/components/NavigationTree/NavigationTreeItem.stories.tsx @@ -94,7 +94,7 @@ const Template: ComponentStory = (args) => { defaultCollapseIcon={args.defaultCollapseIcon} defaultExpandIcon={args.defaultExpandIcon} > - + void; defaultExpandIcon?: React.ReactNode; defaultCollapseIcon?: React.ReactNode; @@ -15,15 +19,17 @@ export interface NavigationTreeItemProps { export const NavigationTreeItem = ({ label, + subtitle, children, onClick, + defaultExpanded = false, defaultCollapseIcon, defaultExpandIcon, customCollapseIcon, customExpandIcon, ...props }: NavigationTreeItemProps & NavigationItemProps) => { - const [isExpanded, setIsExpanded] = useState(false); + const [isExpanded, setIsExpanded] = useState(defaultExpanded); const isExpandable = useMemo(() => React.Children.count(children) > 0, [children]); const hasStartAdornment = useMemo(() => !!props.startAdornment, [props.startAdornment]); const usedStartAdornment = useMemo( @@ -55,7 +61,19 @@ export const NavigationTreeItem = ({ startAdornment={usedStartAdornment} onClick={isExpandable ? () => setIsExpanded(!isExpanded) : onClick} > - {label} + + {label} + {subtitle && ( + + {subtitle} + + )} + {isExpanded && (