@@ -13,6 +13,12 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
13
13
* A string of all className you want applied to the component.
14
14
*/
15
15
className ?: string
16
+ /**
17
+ * Sets if the color of text should be colored for a light or dark dark background.
18
+ *
19
+ * @type 'dark' | 'light'
20
+ */
21
+ colorScheme ?: 'dark' | 'light'
16
22
/**
17
23
* Make sidebar narrow.
18
24
*/
@@ -33,6 +39,11 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
33
39
* Set sidebar to overlaid variant.
34
40
*/
35
41
overlaid ?: boolean
42
+ /**
43
+ * Components placement, there’s no default placement.
44
+ * @type 'start' | 'end'
45
+ */
46
+ placement ?: 'start' | 'end'
36
47
/**
37
48
* Place sidebar in non-static positions.
38
49
*/
@@ -59,11 +70,13 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
59
70
{
60
71
children,
61
72
className,
73
+ colorScheme,
62
74
narrow,
63
75
onHide,
64
76
onShow,
65
77
onVisibleChange,
66
78
overlaid,
79
+ placement,
67
80
position,
68
81
size,
69
82
unfoldable,
@@ -77,18 +90,16 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
77
90
78
91
const [ inViewport , setInViewport ] = useState < boolean > ( )
79
92
const [ mobile , setMobile ] = useState ( false )
80
- const [ visibleMobile , setVisibleMobile ] = useState ( false )
81
- const [ visibleDesktop , setVisibleDesktop ] = useState ( true )
93
+ const [ visibleMobile , setVisibleMobile ] = useState < boolean > ( false )
94
+ const [ visibleDesktop , setVisibleDesktop ] = useState < boolean > (
95
+ visible !== undefined ? visible : overlaid ? false : true ,
96
+ )
82
97
83
98
useEffect ( ( ) => {
84
99
sidebarRef . current && setMobile ( isOnMobile ( sidebarRef . current ) )
85
- if ( visible !== undefined ) {
86
- handleVisibleChange ( visible )
87
- }
100
+ visible !== undefined && handleVisibleChange ( visible )
88
101
} , [ visible ] )
89
102
90
-
91
-
92
103
useEffect ( ( ) => {
93
104
inViewport !== undefined && onVisibleChange && onVisibleChange ( inViewport )
94
105
! inViewport && onHide && onHide ( )
@@ -176,13 +187,15 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
176
187
className = { classNames (
177
188
'sidebar' ,
178
189
{
190
+ [ `sidebar-${ colorScheme } ` ] : colorScheme ,
179
191
'sidebar-narrow' : narrow ,
180
192
'sidebar-overlaid' : overlaid ,
193
+ [ `sidebar-${ placement } ` ] : placement ,
181
194
[ `sidebar-${ position } ` ] : position ,
182
195
[ `sidebar-${ size } ` ] : size ,
183
196
'sidebar-narrow-unfoldable' : unfoldable ,
184
197
show : ( mobile && visibleMobile ) || ( overlaid && visibleDesktop ) ,
185
- hide : ! visibleDesktop && ! mobile ,
198
+ hide : visibleDesktop === false && ! mobile && ! overlaid ,
186
199
} ,
187
200
className ,
188
201
) }
@@ -205,11 +218,13 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
205
218
CSidebar . propTypes = {
206
219
children : PropTypes . node ,
207
220
className : PropTypes . string ,
221
+ colorScheme : PropTypes . oneOf ( [ 'dark' , 'light' ] ) ,
208
222
narrow : PropTypes . bool ,
209
223
onHide : PropTypes . func ,
210
224
onShow : PropTypes . func ,
211
225
onVisibleChange : PropTypes . func ,
212
226
overlaid : PropTypes . bool ,
227
+ placement : PropTypes . oneOf ( [ 'start' , 'end' ] ) ,
213
228
position : PropTypes . oneOf ( [ 'fixed' , 'sticky' ] ) ,
214
229
size : PropTypes . oneOf ( [ 'sm' , 'lg' , 'xl' ] ) ,
215
230
unfoldable : PropTypes . bool ,
0 commit comments