@@ -77,27 +77,15 @@ const formPlugins: Array<Plugin<PluginProps>> = [
77
77
} ) ,
78
78
] ;
79
79
80
- const hypertextStyles : ComponentStyles < HypertextClassNameContract , undefined > = {
81
- hypertext : {
82
- margin : "0 8px" ,
83
- display : "inline-block" ,
84
- lineHeight : "1" ,
85
- whiteSpace : "nowrap" ,
86
- } ,
87
- } ;
88
-
89
80
enum ThemeName {
90
81
dark = "dark" ,
91
82
light = "light" ,
92
83
custom = "custom" ,
93
84
}
94
85
95
86
export interface AppState extends ColorConfig {
96
- accentPalette : string [ ] ;
97
- neutralPalette : string [ ] ;
98
87
theme : ThemeName ;
99
- direction : Direction ;
100
- density : DensityOffset ;
88
+ designSystem : DesignSystem ;
101
89
}
102
90
103
91
export default class App extends React . Component < { } , AppState > {
@@ -120,12 +108,15 @@ export default class App extends React.Component<{}, AppState> {
120
108
121
109
this . state = {
122
110
accentColor : accent ,
123
- accentPalette : this . createColorPalette ( parseColor ( accent ) ) ,
124
- neutralPalette : this . createColorPalette ( new ColorRGBA64 ( 0.5 , 0.5 , 0.5 , 1 ) ) ,
125
- direction : Direction . ltr ,
111
+ designSystem : Object . assign ( { } , DesignSystemDefaults , {
112
+ accentPalette : this . createColorPalette ( parseColor ( accent ) ) ,
113
+ neutralPalette : this . createColorPalette (
114
+ new ColorRGBA64 ( 0.5 , 0.5 , 0.5 , 1 )
115
+ ) ,
116
+ direction : Direction . ltr ,
117
+ } ) ,
126
118
backgroundColor : DesignSystemDefaults . backgroundColor ,
127
119
theme : ThemeName . light ,
128
- density : DesignSystemDefaults . density ,
129
120
} ;
130
121
}
131
122
@@ -141,8 +132,9 @@ export default class App extends React.Component<{}, AppState> {
141
132
showTransparencyToggle = { true }
142
133
styleEditing = { true }
143
134
designSystemEditing = { {
144
- data : DesignSystemDefaults ,
135
+ data : this . state . designSystem ,
145
136
schema : designSystemSchema ,
137
+ designSystemOnChange : this . handleDesignSystemUpdate ,
146
138
} }
147
139
>
148
140
< SiteTitle slot = { "title" } >
@@ -158,11 +150,7 @@ export default class App extends React.Component<{}, AppState> {
158
150
</ SiteCategoryIcon >
159
151
</ SiteCategory >
160
152
< SiteCategory slot = { "category" } name = { "Components" } >
161
- { this . sortExamples (
162
- componentFactory ( examples , {
163
- ...this . generateDesignSystem ( ) ,
164
- } )
165
- ) }
153
+ { this . sortExamples ( componentFactory ( examples ) ) }
166
154
</ SiteCategory >
167
155
< div slot = { ShellSlot . infoBar } >
168
156
< div
@@ -176,7 +164,7 @@ export default class App extends React.Component<{}, AppState> {
176
164
< input
177
165
type = "range"
178
166
name = "density"
179
- defaultValue = "0"
167
+ value = { this . state . designSystem . density }
180
168
min = "-3"
181
169
max = "3"
182
170
onChange = { this . handleDensityUpdate }
@@ -200,45 +188,60 @@ export default class App extends React.Component<{}, AppState> {
200
188
) ;
201
189
}
202
190
203
- private generateDesignSystem ( ) : DesignSystem {
204
- const designSystem : Partial < DesignSystem > = {
205
- accentPalette : this . state . accentPalette ,
206
- neutralPalette : this . state . neutralPalette ,
207
- direction : this . state . direction ,
208
- backgroundColor : this . state . backgroundColor ,
209
- density : this . state . density ,
210
- } ;
211
-
212
- return Object . assign ( { } , DesignSystemDefaults , designSystem ) ;
213
- }
214
-
215
191
private handleUpdateDirection = ( direction : Direction ) : void => {
216
192
const newDir : Direction =
217
- this . state . direction === Direction . ltr ? Direction . rtl : Direction . ltr ;
193
+ direction === Direction . ltr ? Direction . rtl : Direction . ltr ;
218
194
219
- if ( this . state . direction === newDir ) {
195
+ if ( this . state . designSystem . direction === newDir ) {
220
196
return ;
221
197
}
222
198
223
199
this . setState ( {
224
- direction : newDir ,
200
+ designSystem : Object . assign ( { } , this . state . designSystem , {
201
+ direction : newDir ,
202
+ } ) ,
225
203
} ) ;
226
204
} ;
227
205
206
+ private getNeutralPallete ( colorSource : string ) : string [ ] {
207
+ const color : ColorRGBA64 = parseColor ( colorSource ) ;
208
+ const hslColor : ColorHSL = rgbToHSL ( color ) ;
209
+ const augmentedHSLColor : ColorHSL = ColorHSL . fromObject ( {
210
+ h : hslColor . h ,
211
+ s : hslColor . s ,
212
+ l : 0.5 ,
213
+ } ) ;
214
+ return this . createColorPalette ( hslToRGB ( augmentedHSLColor ) ) ;
215
+ }
216
+
228
217
private handleUpdateTheme = ( theme : ThemeName ) : void => {
229
218
if ( theme !== ThemeName . custom ) {
230
219
this . setState ( {
231
220
theme,
232
221
backgroundColor : theme === ThemeName . dark ? dark : light ,
222
+ designSystem : Object . assign ( { } , this . state . designSystem , {
223
+ backgroundColor : theme === ThemeName . dark ? dark : light ,
224
+ neutralPalette : this . getNeutralPallete (
225
+ theme === ThemeName . dark ? dark : light
226
+ ) ,
227
+ } ) ,
233
228
} ) ;
234
229
} else {
235
- this . setCustomThemeBackground ( this . state . backgroundColor ) ;
230
+ this . setCustomThemeBackground ( this . state . designSystem . backgroundColor ) ;
236
231
this . setState ( {
237
232
theme,
238
233
} ) ;
239
234
}
240
235
} ;
241
236
237
+ private handleDesignSystemUpdate = ( data : any ) : void => {
238
+ if ( data !== this . state . designSystem ) {
239
+ this . setState ( {
240
+ designSystem : data ,
241
+ } ) ;
242
+ }
243
+ } ;
244
+
242
245
/**
243
246
* Handles any changes made by the user to the color picker inputs
244
247
*/
@@ -251,20 +254,16 @@ export default class App extends React.Component<{}, AppState> {
251
254
updates . theme = ThemeName . custom ;
252
255
}
253
256
254
- const color : ColorRGBA64 = parseColor ( config . backgroundColor ) ;
255
- const hslColor : ColorHSL = rgbToHSL ( color ) ;
256
- const augmentedHSLColor : ColorHSL = ColorHSL . fromObject ( {
257
- h : hslColor . h ,
258
- s : hslColor . s ,
259
- l : 0.5 ,
257
+ updates . designSystem = Object . assign ( { } , this . state . designSystem , {
258
+ neutralPalette : this . getNeutralPallete ( config . backgroundColor ) ,
260
259
} ) ;
261
- updates . neutralPalette = this . createColorPalette ( hslToRGB ( augmentedHSLColor ) ) ;
260
+ updates . designSystem . backgroundColor = config . backgroundColor ;
262
261
}
263
262
264
263
if ( config . accentColor !== this . state . accentColor ) {
265
- updates . accentPalette = this . createColorPalette (
266
- parseColor ( config . accentColor )
267
- ) ;
264
+ updates . designSystem = Object . assign ( { } , this . state . designSystem , {
265
+ accentPalette : this . createColorPalette ( parseColor ( config . accentColor ) ) ,
266
+ } ) ;
268
267
}
269
268
270
269
this . setState ( updates as AppState ) ;
@@ -281,7 +280,9 @@ export default class App extends React.Component<{}, AppState> {
281
280
282
281
private handleDensityUpdate = ( e : React . ChangeEvent < HTMLInputElement > ) : void => {
283
282
this . setState ( {
284
- density : parseInt ( e . target . value , 10 ) as DensityOffset ,
283
+ designSystem : Object . assign ( { } , this . state . designSystem , {
284
+ density : parseInt ( e . target . value , 10 ) as DensityOffset ,
285
+ } ) ,
285
286
} ) ;
286
287
} ;
287
288
/**
0 commit comments