1
1
import React , { memo , useCallback } from 'react'
2
2
import get from 'lodash/get'
3
3
import snakeCase from 'lodash/snakeCase'
4
- import { ArrayControl } from './ArrayControl'
5
- import { ObjectControl } from './ObjectControl'
6
- import { SwitchControl } from './SwitchControl'
7
- import { SwitchableRangeControl } from './SwitchableRangeControl'
8
- import { ColorsControl } from './ColorsControl'
9
- import { QuantizeColorsControl } from './QuantizeColorsControl'
10
- import { ColorPickerControl } from './ColorPickerControl'
11
- import { TextControl } from './TextControl'
12
- import { RadioControl } from './RadioControl'
13
- import { RangeControl } from './RangeControl'
14
- import { ChoicesControl } from './ChoicesControl'
15
- import { BoxAnchorControl } from './BoxAnchorControl'
16
- import { MarginControl } from './MarginControl'
17
- import { OpacityControl } from './OpacityControl'
18
- import { LineWidthControl } from './LineWidthControl'
19
- import { MotionConfigControl } from './MotionConfigControl'
20
- import { NumberArrayControl } from './NumberArrayControl'
21
- import { AngleControl } from './AngleControl'
22
- import { OrdinalColorsControl } from './OrdinalColorsControl'
23
- import { InheritedColorControl } from './InheritedColorControl'
24
- import { BlendModeControl } from './BlendModeControl'
25
- import PropertyDocumentation from './PropertyDocumentation'
26
- import { ValueFormatControl } from './ValueFormatControl'
27
- import { AnnotationsControl } from './AnnotationsControl'
28
4
import { ChartProperty , Flavor } from '../../types'
5
+ import { ControlContext } from './types'
6
+ import {
7
+ ArrayControl ,
8
+ ObjectControl ,
9
+ SwitchControl ,
10
+ SwitchableRangeControl ,
11
+ TextControl ,
12
+ RadioControl ,
13
+ RangeControl ,
14
+ ChoicesControl ,
15
+ NumberArrayControl ,
16
+ PropertyDocumentation ,
17
+ } from './generics'
18
+ import {
19
+ BoxAnchorControl ,
20
+ MarginControl ,
21
+ LineWidthControl ,
22
+ MotionConfigControl ,
23
+ AngleControl ,
24
+ ValueFormatControl ,
25
+ AnnotationsControl ,
26
+ } from './specialized'
27
+ import {
28
+ BlendModeControl ,
29
+ ContinuousColorsControl ,
30
+ ColorPickerControl ,
31
+ ColorsControl ,
32
+ OrdinalColorsControl ,
33
+ OpacityControl ,
34
+ InheritedColorControl ,
35
+ QuantizeColorsControl ,
36
+ } from './colors'
29
37
30
38
export const shouldRenderProperty = ( property : ChartProperty , currentSettings : any ) => {
31
39
if ( typeof property . when !== 'function' ) return true
@@ -39,7 +47,7 @@ interface ControlSwitcherProps {
39
47
currentFlavor : Flavor
40
48
settings : any
41
49
onChange : any
42
- context : any
50
+ context ?: ControlContext
43
51
}
44
52
45
53
const ControlSwitcher = memo (
@@ -88,6 +96,7 @@ const ControlSwitcher = memo(
88
96
property = { property }
89
97
flavors = { flavors }
90
98
currentFlavor = { currentFlavor }
99
+ context = { context }
91
100
/>
92
101
)
93
102
}
@@ -175,6 +184,7 @@ const ControlSwitcher = memo(
175
184
flavors = { flavors }
176
185
currentFlavor = { currentFlavor }
177
186
value = { value }
187
+ context = { context }
178
188
onChange = { handleChange }
179
189
/>
180
190
)
@@ -417,6 +427,20 @@ const ControlSwitcher = memo(
417
427
/>
418
428
)
419
429
430
+ case 'continuous_colors' :
431
+ return (
432
+ < ContinuousColorsControl
433
+ id = { id }
434
+ property = { property }
435
+ flavors = { flavors }
436
+ currentFlavor = { currentFlavor }
437
+ config = { controlConfig }
438
+ value = { value }
439
+ context = { context }
440
+ onChange = { handleChange }
441
+ />
442
+ )
443
+
420
444
default :
421
445
throw new Error (
422
446
`invalid control type: ${ controlConfig ! . type } for property: ${ property . name } `
@@ -432,7 +456,7 @@ interface ControlsGroupProps {
432
456
controls : ChartProperty [ ]
433
457
settings : any
434
458
onChange : any
435
- context ?: any
459
+ context ?: ControlContext
436
460
}
437
461
438
462
export const ControlsGroup = ( {
@@ -445,9 +469,9 @@ export const ControlsGroup = ({
445
469
context,
446
470
} : ControlsGroupProps ) => (
447
471
< >
448
- { controls . map ( control => (
472
+ { controls . map ( ( control , index ) => (
449
473
< ControlSwitcher
450
- key = { control . name }
474
+ key = { ` ${ control . name } . ${ index } ` }
451
475
groupName = { name }
452
476
flavors = { flavors }
453
477
currentFlavor = { currentFlavor }
0 commit comments