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({
|
|
|
|
color,
|
|
|
|
onChange
|
|
|
|
}: {
|
|
|
|
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
|
|
|
|
colors={[
|
|
|
|
"#000000",
|
|
|
|
"#ABB8C3",
|
|
|
|
"#FFFFFF",
|
|
|
|
"#FF6900",
|
|
|
|
"#FCB900",
|
|
|
|
"#00D084",
|
|
|
|
"#8ED1FC",
|
|
|
|
"#0693E3",
|
|
|
|
"#EB144C",
|
|
|
|
"#F78DA7",
|
|
|
|
"#9900EF"
|
|
|
|
]}
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|