import React from "react";
import { Popover } from "./Popover";
import "./ColorPicker.css";
// This is a narrow reimplementation of the awesome react-color Twitter component
// https://github.com/casesandberg/react-color/blob/master/src/components/twitter/Twitter.js
const Picker = function({
colors,
color,
onChange
}: {
colors: string[];
color: string | undefined;
onChange: (color: string) => void;
}) {
const [innerValue, setInnerValue] = React.useState(color);
React.useEffect(() => {
setInnerValue(color);
}, [color]);
return (
{colors.map(color => (
{
onChange(color);
}}
title={color}
tabIndex={0}
style={{ backgroundColor: color }}
key={color}
>
{color === "transparent" ? (
) : (
undefined
)}
))}
#
{
const value = e.target.value;
if (value.match(/^([0-9a-f]{3}|[0-9a-f]{6}|transparent)$/)) {
onChange(value === "transparent" ? "transparent" : "#" + value);
}
setInnerValue(value);
}}
value={(innerValue || "").replace(/^#/, "")}
/>
);
};
export function ColorPicker({
type,
color,
onChange
}: {
type: "canvasBackground" | "elementBackground" | "elementStroke";
color: string | null;
onChange: (color: string) => void;
}) {
const [isActive, setActive] = React.useState(false);
return (
);
}
// https://yeun.github.io/open-color/
const colors = {
// Shade 0
canvasBackground: [
"#FFFFFF",
"#F8F9FA",
"#F1F3F5",
"#FFF5F5",
"#FFF0F6",
"#F8F0FC",
"#F3F0FF",
"#EDF2FF",
"#E7F5FF",
"#E3FAFC",
"#E6FCF5",
"#EBFBEE",
"#F4FCE3",
"#FFF9DB",
"#FFF4E6"
],
// Shade 6
elementBackground: [
"transparent",
"#CED4DA",
"#868E96",
"#FA5252",
"#E64980",
"#BE4BDB",
"#7950F2",
"#4C6EF5",
"#228BE6",
"#15AABF",
"#12B886",
"#40C057",
"#82C91E",
"#FAB005",
"#FD7E14"
],
// Shade 9
elementStroke: [
"#000000",
"#343A40",
"#495057",
"#C92A2A",
"#A61E4D",
"#862E9C",
"#5F3DC4",
"#364FC7",
"#1864AB",
"#0B7285",
"#087F5B",
"#2B8A3E",
"#5C940D",
"#E67700",
"#D9480F"
]
};