@@ -11,8 +11,11 @@ import {
11
11
Icon ,
12
12
Button ,
13
13
TextField ,
14
- Incubator
14
+ Incubator ,
15
+ ColorPalette ,
16
+ ColorPickerDialog
15
17
} from 'react-native-ui-lib' ;
18
+ import { renderBooleanOption } from '../ExampleScreenPresenter' ;
16
19
17
20
const { Toast} = Incubator ;
18
21
@@ -42,7 +45,14 @@ class ColorsScreen extends Component {
42
45
searchValue : '' ,
43
46
filteredTokens : [ ] ,
44
47
showToast : false ,
45
- message : undefined
48
+ message : undefined ,
49
+ currentColor : Colors . $textPrimary ,
50
+ showPicker : false ,
51
+ isDefaultOptions : false ,
52
+ adjustLightness : false ,
53
+ adjustSaturation : false ,
54
+ addDarkestTints : true ,
55
+ avoidReverseOnDark : true
46
56
} ;
47
57
48
58
scrollViewRef = React . createRef ( ) ;
@@ -281,13 +291,102 @@ class ColorsScreen extends Component {
281
291
) ;
282
292
}
283
293
294
+ /** Color Palette */
295
+
296
+ showColorPicker = ( ) => {
297
+ this . setState ( { showPicker : true } ) ;
298
+ } ;
299
+
300
+ onValueChange = ( color ) => {
301
+ this . setState ( { currentColor : color } ) ;
302
+ } ;
303
+
304
+ onSubmit = ( color ) => {
305
+ this . setState ( { currentColor : color } ) ;
306
+ } ;
307
+
308
+ onDismiss = ( ) => {
309
+ this . setState ( { showPicker : false } ) ;
310
+ } ;
311
+
312
+ setDefaultOptions = ( ) => {
313
+ const designKitsOptions = { adjustLightness : false , adjustSaturation : false , addDarkestTints : true , avoidReverseOnDark : true } ;
314
+ const defaultOptions = { adjustLightness : true , adjustSaturation : true , addDarkestTints : false , avoidReverseOnDark : false } ;
315
+ if ( this . state . isDefaultOptions ) {
316
+ this . setState ( { ...designKitsOptions , isDefaultOptions : false } ) ;
317
+ } else {
318
+ this . setState ( { ...defaultOptions , isDefaultOptions : true } ) ;
319
+ }
320
+ } ;
321
+
322
+ renderColorPicker = ( ) => {
323
+ const { showPicker, currentColor} = this . state ;
324
+ return (
325
+ < ColorPickerDialog
326
+ visible = { showPicker }
327
+ initialColor = { currentColor }
328
+ key = { currentColor }
329
+ onDismiss = { this . onDismiss }
330
+ onSubmit = { this . onSubmit }
331
+ />
332
+ ) ;
333
+ } ;
334
+
335
+ renderOptions = ( ) => {
336
+ return (
337
+ < View padding-20 >
338
+ { renderBooleanOption . call ( this , 'adjustLightness' , 'adjustLightness' ) }
339
+ { renderBooleanOption . call ( this , 'adjustSaturation' , 'adjustSaturation' ) }
340
+ { renderBooleanOption . call ( this , 'addDarkestTints' , 'addDarkestTints' ) }
341
+ { renderBooleanOption . call ( this , 'avoidReverseOnDark' , 'avoidReverseOnDark' ) }
342
+ < Button label = { this . state . isDefaultOptions ? 'Reset example' : 'Set defaults' } onPress = { this . setDefaultOptions } />
343
+ </ View >
344
+ ) ;
345
+ } ;
346
+
347
+ renderColorPalette = ( ) => {
348
+ const { currentColor, adjustLightness, adjustSaturation, addDarkestTints, avoidReverseOnDark} = this . state ;
349
+ const paletteOptions = { adjustLightness, adjustSaturation, addDarkestTints, avoidReverseOnDark} ;
350
+ const palette = Colors . generateColorPalette ( currentColor , paletteOptions ) ;
351
+ return (
352
+ < View margin-12 br40 style = { { borderWidth : 1 } } >
353
+ { this . renderOptions ( ) }
354
+ < View center row >
355
+ < TouchableOpacity
356
+ marginH-10
357
+ style = { [ styles . colorBox , { backgroundColor : currentColor } ] }
358
+ onPress = { this . showColorPicker }
359
+ />
360
+ < ColorPalette
361
+ colors = { palette }
362
+ value = { currentColor }
363
+ swatchStyle = { styles . swatchStyle }
364
+ containerStyle = { { marginLeft : - 10 } }
365
+ onValueChange = { this . onValueChange }
366
+ />
367
+ </ View >
368
+ </ View >
369
+ ) ;
370
+ } ;
371
+
372
+ renderColorPaletteExample = ( ) => {
373
+ return (
374
+ < >
375
+ < Text text50 marginL-20 > Generate Color Palette</ Text >
376
+ { this . renderColorPalette ( ) }
377
+ { this . renderColorPicker ( ) }
378
+ </ >
379
+ ) ;
380
+ } ;
381
+
284
382
render ( ) {
285
383
return (
286
384
< >
287
385
{ this . renderSearch ( ) }
288
386
< ScrollView ref = { this . scrollViewRef } >
289
387
{ this . renderDesignTokens ( ) }
290
388
{ this . renderColors ( SYSTEM_COLORS , 'SYSTEM COLORS' ) }
389
+ { this . renderColorPaletteExample ( ) }
291
390
</ ScrollView >
292
391
{ this . renderToast ( ) }
293
392
</ >
@@ -303,6 +402,19 @@ const styles = StyleSheet.create({
303
402
searchField : {
304
403
padding : Spacings . s3 ,
305
404
borderRadius : 8
405
+ } ,
406
+ colorBox : {
407
+ width : 60 ,
408
+ height : 60 ,
409
+ borderWidth : 1 ,
410
+ borderRadius : 30
411
+ } ,
412
+ swatchStyle : {
413
+ width : 18 ,
414
+ height : 40 ,
415
+ borderRadius : 10 ,
416
+ marginLeft : 4 ,
417
+ marginRight : 4
306
418
}
307
419
} ) ;
308
420
0 commit comments