@@ -14,6 +14,18 @@ const isOnMobile = (element: HTMLDivElement) => {
1414const CSidebar = defineComponent ( {
1515 name : 'CSidebar' ,
1616 props : {
17+ /**
18+ * Sets if the color of text should be colored for a light or dark dark background.
19+ *
20+ * @values 'dark', light'
21+ */
22+ colorScheme : {
23+ type : String ,
24+ default : undefined ,
25+ validator : ( value : string ) => {
26+ return [ 'dark' , 'light' ] . includes ( value )
27+ } ,
28+ } ,
1729 /**
1830 * Make sidebar narrow.
1931 */
@@ -22,6 +34,17 @@ const CSidebar = defineComponent({
2234 * Set sidebar to overlaid variant.
2335 */
2436 overlaid : Boolean ,
37+ /**
38+ * Components placement, there’s no default placement.
39+ * @values 'start', 'end'
40+ */
41+ placement : {
42+ type : String ,
43+ default : undefined ,
44+ validator : ( value : string ) => {
45+ return [ 'start' , 'end' ] . includes ( value )
46+ } ,
47+ } ,
2548 /**
2649 * Place sidebar in non-static positions.
2750 */
@@ -64,10 +87,16 @@ const CSidebar = defineComponent({
6487 'visible-change' ,
6588 ] ,
6689 setup ( props , { attrs, slots, emit } ) {
67- const mobile = ref ( )
68- const inViewport = ref ( )
6990 const sidebarRef = ref ( )
70- const visible = ref ( props . visible )
91+
92+ const inViewport = ref ( )
93+ const mobile = ref ( )
94+ const visibleMobile = ref ( false )
95+ const visibleDesktop = ref (
96+ props . visible !== undefined ? props . visible : props . overlaid ? false : true ,
97+ )
98+
99+ // const visible = ref(props.visible)
71100
72101 watch ( inViewport , ( ) => {
73102 emit ( 'visible-change' , inViewport . value )
@@ -76,11 +105,14 @@ const CSidebar = defineComponent({
76105
77106 watch (
78107 ( ) => props . visible ,
79- ( ) => ( visible . value = props . visible ) ,
108+ ( ) => props . visible !== undefined && handleVisibleChange ( props . visible ) ,
80109 )
81110
82111 watch ( mobile , ( ) => {
83- if ( mobile . value && visible . value ) visible . value = false
112+ if ( mobile . value ) {
113+ console . log ( 'mobile' )
114+ visibleMobile . value = false
115+ }
84116 } )
85117
86118 onMounted ( ( ) => {
@@ -109,8 +141,17 @@ const CSidebar = defineComponent({
109141 } )
110142 } )
111143
144+ const handleVisibleChange = ( visible : boolean ) => {
145+ if ( mobile . value ) {
146+ visibleMobile . value = visible
147+ return
148+ }
149+
150+ visibleDesktop . value = visible
151+ }
152+
112153 const handleHide = ( ) => {
113- visible . value = false
154+ handleVisibleChange ( false )
114155 emit ( 'visible-change' , false )
115156 }
116157
@@ -146,13 +187,15 @@ const CSidebar = defineComponent({
146187 class : [
147188 'sidebar' ,
148189 {
190+ [ `sidebar-${ props . colorScheme } ` ] : props . colorScheme ,
149191 'sidebar-narrow' : props . narrow ,
150192 'sidebar-overlaid' : props . overlaid ,
193+ [ `sidebar-${ props . placement } ` ] : props . placement ,
151194 [ `sidebar-${ props . position } ` ] : props . position ,
152195 [ `sidebar-${ props . size } ` ] : props . size ,
153196 'sidebar-narrow-unfoldable' : props . unfoldable ,
154- show : visible . value === true && mobile . value ,
155- hide : visible . value === false && ! mobile . value ,
197+ show : ( mobile . value && visibleMobile . value ) || ( props . overlaid && visibleDesktop . value ) ,
198+ hide : visibleDesktop . value === false && ! mobile . value && ! props . overlaid ,
156199 } ,
157200 attrs . class ,
158201 ] ,
@@ -163,7 +206,7 @@ const CSidebar = defineComponent({
163206 mobile . value &&
164207 h ( CBackdrop , {
165208 class : 'sidebar-backdrop' ,
166- visible : props . visible ,
209+ visible : visibleMobile . value ,
167210 onClick : ( ) => handleHide ( ) ,
168211 } ) ,
169212 ]
0 commit comments