Skip to content

Commit 3b43320

Browse files
committedJan 12, 2022
feat(website): improve and reorganize controls
1 parent 806da06 commit 3b43320

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+521
-258
lines changed
 

‎website/src/components/ThemeSelector.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback, useMemo } from 'react'
22
import styled, { useTheme } from 'styled-components'
33
import { useSetTheme } from '../theming/SwitchableThemeProvider'
4-
import { Switch } from './controls/Switch'
4+
import { Switch } from './controls/ui'
55

66
const ThemeSelector = () => {
77
const theme = useTheme()

‎website/src/components/controls/ControlsGroup.tsx

+52-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
import React, { memo, useCallback } from 'react'
22
import get from 'lodash/get'
33
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'
284
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'
2937

3038
export const shouldRenderProperty = (property: ChartProperty, currentSettings: any) => {
3139
if (typeof property.when !== 'function') return true
@@ -39,7 +47,7 @@ interface ControlSwitcherProps {
3947
currentFlavor: Flavor
4048
settings: any
4149
onChange: any
42-
context: any
50+
context?: ControlContext
4351
}
4452

4553
const ControlSwitcher = memo(
@@ -88,6 +96,7 @@ const ControlSwitcher = memo(
8896
property={property}
8997
flavors={flavors}
9098
currentFlavor={currentFlavor}
99+
context={context}
91100
/>
92101
)
93102
}
@@ -175,6 +184,7 @@ const ControlSwitcher = memo(
175184
flavors={flavors}
176185
currentFlavor={currentFlavor}
177186
value={value}
187+
context={context}
178188
onChange={handleChange}
179189
/>
180190
)
@@ -417,6 +427,20 @@ const ControlSwitcher = memo(
417427
/>
418428
)
419429

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+
420444
default:
421445
throw new Error(
422446
`invalid control type: ${controlConfig!.type} for property: ${property.name}`
@@ -432,7 +456,7 @@ interface ControlsGroupProps {
432456
controls: ChartProperty[]
433457
settings: any
434458
onChange: any
435-
context?: any
459+
context?: ControlContext
436460
}
437461

438462
export const ControlsGroup = ({
@@ -445,9 +469,9 @@ export const ControlsGroup = ({
445469
context,
446470
}: ControlsGroupProps) => (
447471
<>
448-
{controls.map(control => (
472+
{controls.map((control, index) => (
449473
<ControlSwitcher
450-
key={control.name}
474+
key={`${control.name}.${index}`}
451475
groupName={name}
452476
flavors={flavors}
453477
currentFlavor={currentFlavor}

0 commit comments

Comments
 (0)
Please sign in to comment.