From 7b0264fc500d904bde5f534bb8a01aa1a237c374 Mon Sep 17 00:00:00 2001 From: Tal Leibman Date: Fri, 14 Feb 2020 12:18:00 +0200 Subject: [PATCH] Widgets: ColorPicker --- src/widgets/ColorPicker.tsx | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/widgets/ColorPicker.tsx diff --git a/src/widgets/ColorPicker.tsx b/src/widgets/ColorPicker.tsx new file mode 100644 index 0000000..190c610 --- /dev/null +++ b/src/widgets/ColorPicker.tsx @@ -0,0 +1,69 @@ +import * as React from 'react'; + +import ColorBox from './ColorBox'; +import { colorHtmlToInt } from '../journal-processors'; +import { TextField, ButtonBase } from '@material-ui/core'; + +interface PropsType { + color: string; + defaultColor: string; + label?: string; + placeholder?: string; + error?: string; + onChange: (color: string) => void; +} + + +export default function ColorPicker(props: PropsType) { + const colors = [ + [ + '#F44336', + '#E91E63', + '#673AB7', + '#3F51B5', + '#2196F3', + ], + [ + '#03A9F4', + '#4CAF50', + '#8BC34A', + '#FFEB3B', + '#FF9800', + ], + ]; + const color = props.color; + + return ( +
+ {colors.map((colorGroup, idx) => ( +
+ {colorGroup.map((colorOption) => ( + props.onChange(colorOption)} + > + + + ))} +
+ ))} +
+ + ) => props.onChange(event.currentTarget.value)} + placeholder={props.placeholder ?? 'E.g. #aabbcc'} + label={props.label ?? 'Color'} + value={color} + helperText={props.error} + /> +
+
+ ); +} \ No newline at end of file