forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colorpicker.tsx
35 lines (30 loc) · 983 Bytes
/
Colorpicker.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
import * as React from "react"
import { action } from "mobx"
import { SketchPicker } from "react-color"
import { lastOfNonEmptyArray } from "../clientUtils/Util"
import { ColorSchemes } from "../grapher/color/ColorSchemes"
interface ColorpickerProps {
color?: string
onColor: (color: string | undefined) => void
}
export class Colorpicker extends React.Component<ColorpickerProps> {
@action.bound onColor(color: string) {
if (color === "") {
this.props.onColor(undefined)
} else {
this.props.onColor(color)
}
}
render() {
const scheme = ColorSchemes["owid-distinct"]
const availableColors: string[] = lastOfNonEmptyArray(scheme.colorSets)
return (
<SketchPicker
disableAlpha
presetColors={availableColors}
color={this.props.color}
onChange={(color) => this.onColor(color.hex)}
/>
)
}
}