@@ -7,8 +7,9 @@ import NavigationTop from '@/components/Navigation/Vertical/Top';
7
7
import NavigationList from '@/components/Navigation/Vertical/List' ;
8
8
import NavigationListItem from '@/components/Navigation/Vertical/ListItem' ;
9
9
import NavigationDivider from '@/components/Navigation/Vertical/Divider' ;
10
- import { useState } from 'react' ;
11
- import { VerticalNavigationScope } from './Vertical/VerticalNavigationScope' ;
10
+ import { useEffect , useState } from 'react' ;
11
+ import { VerticalNavigationScope } from '@/components/Navigation/Vertical/VerticalNavigationScope' ;
12
+ import { NavigationContext } from './Vertical/NavigationContext' ;
12
13
13
14
export interface VerticalNavigationStatics {
14
15
Top : typeof NavigationTop ;
@@ -17,26 +18,51 @@ export interface VerticalNavigationStatics {
17
18
Divider : typeof NavigationDivider ;
18
19
}
19
20
20
- export interface SideNavigationProps extends React . HTMLAttributes < HTMLDivElement > {
21
+ export interface VerticalNavigationProps extends React . HTMLAttributes < HTMLDivElement > {
22
+ /**
23
+ * Variant of the menu. With this prop, the color of the menu can be set.
24
+ */
21
25
variant ?: Variant | string ;
26
+ /**
27
+ * Indicates whether the menu collapse is controllable.
28
+ */
22
29
collapsable ?: boolean ;
30
+ /**
31
+ * Indicating whether the menu is collapsed. Can be used to make the navigation a controllable component
32
+ */
33
+ collapsed ?: boolean ;
34
+ /**
35
+ * Indicates whether a tooltip with the menu text must be shown when menu is collapsed. Default: true
36
+ */
37
+ tooltipsWhenCollapsed ?: boolean ;
38
+ /**
39
+ * Children of the menu. This can be either a React ChildNode or callback function to access various actions
40
+ */
23
41
children : React . ReactNode | ( ( scope : VerticalNavigationScope ) => React . ReactNode ) ;
24
42
}
25
43
26
44
// @ts -ignore
27
- const VerticalNavigation : ForwardComponentWithStatics < HTMLDivElement , SideNavigationProps , VerticalNavigationStatics > =
45
+ const VerticalNavigation : ForwardComponentWithStatics < HTMLDivElement , VerticalNavigationProps , VerticalNavigationStatics > =
28
46
React . forwardRef ( (
29
47
{
30
48
children,
31
49
className,
32
- variant
50
+ variant,
51
+ collapsed,
52
+ tooltipsWhenCollapsed = true
33
53
} ,
34
54
ref
35
55
) : React . ReactElement => {
36
- const [ collapsed , setCollapsed ] = useState < boolean > ( false ) ;
56
+ const [ isCollapsed , setCollapsed ] = useState < boolean > ( false ) ;
57
+
58
+ useEffect ( ( ) => {
59
+ if ( collapsed ) {
60
+ setCollapsed ( collapsed ) ;
61
+ }
62
+ } , [ collapsed ] )
37
63
38
64
const makeScope = ( ) : VerticalNavigationScope => ( {
39
- collapsed,
65
+ collapsed : isCollapsed ,
40
66
collapse : ( ) => setCollapsed ( ! collapsed )
41
67
} ) ;
42
68
@@ -45,25 +71,34 @@ const VerticalNavigation: ForwardComponentWithStatics<HTMLDivElement, SideNaviga
45
71
: children ;
46
72
47
73
return (
48
- < div
49
- ref = { ref }
50
- className = { clsx (
51
- 'vertical-navigation-container' ,
52
- collapsed && 'is-collapsed' ,
53
- variant && `navigation-${ variant } ` ,
54
- className
55
- ) }
74
+ < NavigationContext . Provider
75
+ value = { {
76
+ tooltipsWhenCollapsed : tooltipsWhenCollapsed ,
77
+ collapsed : isCollapsed
78
+ } }
56
79
>
57
- { children }
58
- </ div >
80
+ < div
81
+ ref = { ref }
82
+ className = { clsx (
83
+ 'vertical-navigation-container' ,
84
+ isCollapsed && 'is-collapsed' ,
85
+ variant && `navigation-${ variant } ` ,
86
+ className
87
+ ) }
88
+ >
89
+ { children }
90
+ </ div >
91
+ </ NavigationContext . Provider >
59
92
)
60
93
} ) ;
61
94
62
95
VerticalNavigation . displayName = 'VerticalNavigation' ;
63
96
VerticalNavigation . propTypes = {
64
97
children : PropTypes . node ,
65
98
className : PropTypes . string ,
66
- variant : PropTypes . string
99
+ variant : PropTypes . string ,
100
+ collapsed : PropTypes . bool ,
101
+ tooltipsWhenCollapsed : PropTypes . bool
67
102
}
68
103
69
104
VerticalNavigation . Top = NavigationTop ;
0 commit comments