2020-01-07 23:37:22 +05:00
|
|
|
import React, { lazy } from "react";
|
2020-01-07 07:50:59 +05:00
|
|
|
import { Popover } from "./Popover";
|
2020-01-06 21:29:44 +04:00
|
|
|
|
2020-01-07 23:37:22 +05:00
|
|
|
const TwitterPicker = lazy(() =>
|
|
|
|
import(
|
|
|
|
/* webpackPrefetch: true */ "react-color/lib/components/twitter/Twitter"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-01-06 21:29:44 +04:00
|
|
|
export function ColorPicker({
|
2020-01-11 23:58:44 +01:00
|
|
|
type,
|
2020-01-06 21:29:44 +04:00
|
|
|
color,
|
|
|
|
onChange
|
|
|
|
}: {
|
2020-01-11 23:58:44 +01:00
|
|
|
type: "canvasBackground" | "elementBackground" | "elementStroke";
|
2020-01-06 21:29:44 +04:00
|
|
|
color: string | null;
|
|
|
|
onChange: (color: string) => void;
|
|
|
|
}) {
|
|
|
|
const [isActive, setActive] = React.useState(false);
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<button
|
|
|
|
className="swatch"
|
|
|
|
style={color ? { backgroundColor: color } : undefined}
|
|
|
|
onClick={() => setActive(!isActive)}
|
|
|
|
/>
|
2020-01-07 23:37:22 +05:00
|
|
|
<React.Suspense fallback="">
|
|
|
|
{isActive ? (
|
|
|
|
<Popover onCloseRequest={() => setActive(false)}>
|
|
|
|
<TwitterPicker
|
2020-01-11 23:58:44 +01:00
|
|
|
colors={colors[type]}
|
2020-01-07 23:37:22 +05:00
|
|
|
width="205px"
|
|
|
|
color={color || undefined}
|
|
|
|
onChange={changedColor => {
|
|
|
|
onChange(changedColor.hex);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Popover>
|
|
|
|
) : null}
|
|
|
|
</React.Suspense>
|
2020-01-06 21:29:44 +04:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
className="swatch-input"
|
|
|
|
value={color || ""}
|
2020-01-06 20:28:14 +01:00
|
|
|
onPaste={e => onChange(e.clipboardData.getData("text"))}
|
2020-01-06 21:29:44 +04:00
|
|
|
onChange={e => onChange(e.target.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-01-11 23:58:44 +01:00
|
|
|
|
|
|
|
const colors = {
|
|
|
|
canvasBackground: [
|
|
|
|
"#DEE6EF",
|
|
|
|
"#FCEAD8",
|
|
|
|
"#F9E0E0",
|
|
|
|
"#E6F1F1",
|
|
|
|
"#E0EDDF",
|
|
|
|
"#FBF5DD",
|
|
|
|
"#F0E6ED",
|
|
|
|
"#FFEDEF",
|
|
|
|
"#EDE5E1",
|
|
|
|
"#F2F0EF",
|
|
|
|
"#FFFFFF"
|
|
|
|
],
|
|
|
|
elementBackground: [
|
|
|
|
"#4E79A7",
|
|
|
|
"#F28E2C",
|
|
|
|
"#E15759",
|
|
|
|
"#76B7B2",
|
|
|
|
"#59A14F",
|
|
|
|
"#EDC949",
|
|
|
|
"#AF7AA1",
|
|
|
|
"#FF9DA7",
|
|
|
|
"#9C755F",
|
|
|
|
"#BAB0AB",
|
|
|
|
"#FFFFFF"
|
|
|
|
],
|
|
|
|
elementStroke: [
|
|
|
|
"#324E6B",
|
|
|
|
"#9B5B1D",
|
|
|
|
"#903839",
|
|
|
|
"#4C7572",
|
|
|
|
"#396733",
|
|
|
|
"#AD9336",
|
|
|
|
"#805976",
|
|
|
|
"#BA737A",
|
|
|
|
"#725646",
|
|
|
|
"#88817D",
|
|
|
|
"#000000"
|
|
|
|
]
|
|
|
|
};
|