/
ColorPickerControl.tsx
52 lines (49 loc) · 1.32 KB
/
ColorPickerControl.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { useCallback } from 'react'
import { Control } from './Control'
import { PropertyHeader } from './PropertyHeader'
import { Help } from './Help'
import { Flavor } from '../../types'
import { ColorPickerControlConfig } from './types'
interface ColorPickerControlProps {
id: string
property: any
flavors: Flavor[]
currentFlavor: Flavor
config: ColorPickerControlConfig
value: string
onChange: (value: string) => void
context: any
}
export const ColorPickerControl = ({
id,
property,
flavors,
currentFlavor,
value,
context,
onChange,
}: ColorPickerControlProps) => {
const handleChange = useCallback(
e => {
onChange(e.target.value)
},
[onChange]
)
return (
<Control
id={id}
description={property.description}
flavors={flavors}
currentFlavor={currentFlavor}
supportedFlavors={property.flavors}
>
<PropertyHeader id={id} {...property} context={context} />
<div>
<input type="color" id={id} onChange={handleChange} value={value} />
<code className="code code-string">{value}</code>
</div>
<Help>{property.help}</Help>
</Control>
)
}