@@ -19,20 +19,23 @@ export default meta;
1919const  createMockBridge  =  ( 
2020  fontSize : 'xs'  |  'sm'  |  'lg'  |  'xl' , 
2121  setFontSize : ( size : 'xs'  |  'sm'  |  'lg'  |  'xl' )  =>  void , 
22+   colorPalette : 'default'  |  string , 
23+   setColorPalette : ( palette : 'default'  |  string )  =>  void , 
2224  widgets : DashboardLayout [ 'widgets' ]  =  [ ] 
2325) : DashboardBridge  =>  ( { 
2426  reloadDashboard : ( )  =>  { 
2527    // noop 
2628  } , 
2729  saveDashboard : ( dashboard : DashboardLayout )  =>  { 
28-     // Update the font size in the dashboard 
30+     // Update the font size and color palette  in the dashboard 
2931    setFontSize ( dashboard . generalSettings ?. fontSize  ||  'sm' ) ; 
32+     setColorPalette ( dashboard . generalSettings ?. colorPalette   ||  'default' ) ; 
3033  } , 
3134  dashboardUpdated : ( callback )  =>  { 
32-     // Initialize with current font size 
35+     // Initialize with current font size and color palette  
3336    callback ( { 
3437      widgets, 
35-       generalSettings : {  fontSize } , 
38+       generalSettings : {  fontSize,  colorPalette  } , 
3639    } ) ; 
3740    return  ( )  =>  { 
3841      // noop 
@@ -49,13 +52,14 @@ const createMockBridge = (
4952  resetDashboard : ( )  => 
5053    Promise . resolve ( { 
5154      widgets : [ ] , 
52-       generalSettings : {  fontSize } , 
55+       generalSettings : {  fontSize,  colorPalette  } , 
5356    } ) , 
5457} ) ; 
5558
56- // Helper function to create font size buttons 
57- const  createFontSizeButtons  =  ( 
59+ // Helper function to create theme controls ( font size buttons and color palette dropdown)  
60+ const  createThemeControls  =  ( 
5861  fontSize : 'xs'  |  'sm'  |  'lg'  |  'xl' , 
62+   colorPalette : 'default'  |  string , 
5963  mockBridge : DashboardBridge 
6064)  =>  { 
6165  const  getButtonClass  =  ( size : 'xs'  |  'sm'  |  'lg'  |  'xl' )  =>  { 
@@ -66,51 +70,72 @@ const createFontSizeButtons = (
6670  } ; 
6771
6872  return  ( 
69-     < div  className = "flex gap-2" > 
70-       < button 
71-         className = { getButtonClass ( 'xs' ) } 
72-         onClick = { ( )  => 
73-           mockBridge . saveDashboard ( { 
74-             widgets : [ ] , 
75-             generalSettings : {  fontSize : 'xs'  } , 
76-           } ) 
77-         } 
78-       > 
79-         Extra Small
80-       </ button > 
81-       < button 
82-         className = { getButtonClass ( 'sm' ) } 
83-         onClick = { ( )  => 
84-           mockBridge . saveDashboard ( { 
85-             widgets : [ ] , 
86-             generalSettings : {  fontSize : 'sm'  } , 
87-           } ) 
88-         } 
89-       > 
90-         Small
91-       </ button > 
92-       < button 
93-         className = { getButtonClass ( 'lg' ) } 
94-         onClick = { ( )  => 
95-           mockBridge . saveDashboard ( { 
96-             widgets : [ ] , 
97-             generalSettings : {  fontSize : 'lg'  } , 
98-           } ) 
99-         } 
100-       > 
101-         Large
102-       </ button > 
103-       < button 
104-         className = { getButtonClass ( 'xl' ) } 
105-         onClick = { ( )  => 
106-           mockBridge . saveDashboard ( { 
107-             widgets : [ ] , 
108-             generalSettings : {  fontSize : 'xl'  } , 
109-           } ) 
110-         } 
111-       > 
112-         Extra Large
113-       </ button > 
73+     < div  className = "flex flex-col gap-4" > 
74+       < div  className = "flex gap-2" > 
75+         < button 
76+           className = { getButtonClass ( 'xs' ) } 
77+           onClick = { ( )  => 
78+             mockBridge . saveDashboard ( { 
79+               widgets : [ ] , 
80+               generalSettings : {  fontSize : 'xs' ,  colorPalette } , 
81+             } ) 
82+           } 
83+         > 
84+           Extra Small
85+         </ button > 
86+         < button 
87+           className = { getButtonClass ( 'sm' ) } 
88+           onClick = { ( )  => 
89+             mockBridge . saveDashboard ( { 
90+               widgets : [ ] , 
91+               generalSettings : {  fontSize : 'sm' ,  colorPalette } , 
92+             } ) 
93+           } 
94+         > 
95+           Small
96+         </ button > 
97+         < button 
98+           className = { getButtonClass ( 'lg' ) } 
99+           onClick = { ( )  => 
100+             mockBridge . saveDashboard ( { 
101+               widgets : [ ] , 
102+               generalSettings : {  fontSize : 'lg' ,  colorPalette } , 
103+             } ) 
104+           } 
105+         > 
106+           Large
107+         </ button > 
108+         < button 
109+           className = { getButtonClass ( 'xl' ) } 
110+           onClick = { ( )  => 
111+             mockBridge . saveDashboard ( { 
112+               widgets : [ ] , 
113+               generalSettings : {  fontSize : 'xl' ,  colorPalette } , 
114+             } ) 
115+           } 
116+         > 
117+           Extra Large
118+         </ button > 
119+       </ div > 
120+       < div  className = "flex items-center gap-2" > 
121+         < label  htmlFor = "colorPalette"  className = "text-[12px]" > 
122+           Color Palette:
123+         </ label > 
124+         < select 
125+           id = "colorPalette" 
126+           value = { colorPalette } 
127+           onChange = { ( e )  => 
128+             mockBridge . saveDashboard ( { 
129+               widgets : [ ] , 
130+               generalSettings : {  fontSize,  colorPalette : e . target . value  as  'default'  |  string  } , 
131+             } ) 
132+           } 
133+           className = "px-2 py-1 rounded border text-[12px]" 
134+         > 
135+           < option  value = "default" > Default</ option > 
136+           < option  value = "black" > Black</ option > 
137+         </ select > 
138+       </ div > 
114139    </ div > 
115140  ) ; 
116141} ; 
@@ -143,15 +168,16 @@ export const Primary = {
143168export  const  WithFontSizeControls  =  { 
144169  render : ( )  =>  { 
145170    const  [ fontSize ,  setFontSize ]  =  useState < 'xs'  |  'sm'  |  'lg'  |  'xl' > ( 'sm' ) ; 
146-     const  mockBridge  =  createMockBridge ( fontSize ,  setFontSize ) ; 
171+     const  [ colorPalette ,  setColorPalette ]  =  useState < 'default'  |  string > ( 'default' ) ; 
172+     const  mockBridge  =  createMockBridge ( fontSize ,  setFontSize ,  colorPalette ,  setColorPalette ) ; 
147173
148174    return  ( 
149175      < DashboardProvider  bridge = { mockBridge } > 
150176        < MemoryRouter  initialEntries = { [ '/' ] } > 
151177          < ThemeManager > 
152178            < div  className = "p-4 space-y-4" > 
153-               { createFontSizeButtons ( fontSize ,  mockBridge ) } 
154-               < div  className = "space-y-2" > 
179+               { createThemeControls ( fontSize ,   colorPalette ,  mockBridge ) } 
180+               < div  className = "space-y-2 bg-slate-800/25 rounded-sm p-2 " > 
155181                < div  className = "text-xs" > This is extra small text</ div > 
156182                < div  className = "text-sm" > This is small text</ div > 
157183                < div  className = "text-base" > This is base text</ div > 
@@ -169,14 +195,15 @@ export const WithFontSizeControls = {
169195export  const  WithAllAvailableWidgets  =  { 
170196  render : ( )  =>  { 
171197    const  [ fontSize ,  setFontSize ]  =  useState < 'xs'  |  'sm'  |  'lg'  |  'xl' > ( 'sm' ) ; 
172-     const  mockBridge  =  createMockBridge ( fontSize ,  setFontSize ,  defaultDashboard . widgets ) ; 
198+     const  [ colorPalette ,  setColorPalette ]  =  useState < 'default'  |  string > ( 'default' ) ; 
199+     const  mockBridge  =  createMockBridge ( fontSize ,  setFontSize ,  colorPalette ,  setColorPalette ,  defaultDashboard . widgets ) ; 
173200
174201    return  ( 
175202      < DashboardProvider  bridge = { mockBridge } > 
176203        < MemoryRouter  initialEntries = { [ '/' ] } > 
177204          < ThemeManager > 
178205            < div  className = "p-4 space-y-4" > 
179-               { createFontSizeButtons ( fontSize ,  mockBridge ) } 
206+               { createThemeControls ( fontSize ,   colorPalette ,  mockBridge ) } 
180207            </ div > 
181208            < hr  className = "my-4"  /> 
182209            < Routes > 
0 commit comments