import React from "react";
import clsx from "clsx";
import { SketchPicker } from "react-color";
import { FabricButton } from "@gland/react/button";
import { Callout } from "@gland/react/popover";
import { icons } from "../../icons";
import { toolClasses as classes } from "../style";
import { BtnTip } from "./widget";
import { ToolAttr } from "../utils";
export function TextColor(props) {
const tip = props.attr.lang.tip;
return (
);
}
export function BackgroundColor(props) {
const tip = props.attr.lang.tip;
return (
);
}
function ColorSelectBtn(props: { tip?: string; attr?: ToolAttr; children?; type? }) {
const [show, setShow] = React.useState(false);
const [color, setColor] = React.useState(null);
const btnAttr = React.useRef({} as { root; editState; hasBlur }).current;
const toolAttr = props.attr;
const autoColor = props.type === "bg" ? toolAttr.defaultBgColor : toolAttr.defaultTextColor;
const curColor = color || autoColor || "currentcolor";
const colorList = props.type === "bg" ? toolAttr.bgColors : toolAttr.textColors;
return (
(btnAttr.root = r)}>
{
setShow(false);
toolAttr.event.emit(props.type === "bg" ? toolAttr.editEvent.bgColor : toolAttr.editEvent.color, color);
}}
>
{
if (show) {
setShow(false);
} else {
setShow(true);
}
}}
>
{
if (type === "click" && !isTarget) {
setShow(false);
}
}}
onMouseDown={(e) => {
const target: HTMLInputElement = e.target;
if (target.tagName !== "INPUT") {
e.preventDefault();
}
}}
>
{
setShow(false);
setColor(c);
toolAttr.event.emit(props.type === "bg" ? toolAttr.editEvent.bgColor : toolAttr.editEvent.color, c);
}}
lang={toolAttr.lang}
/>
);
}
function ColorPicker(props) {
const [state, setState] = React.useState({
color: props.color || props.autoColor || "#0078d4",
isAuto: !props.color,
});
return (
{
setState({ color: c.hex, isAuto: false });
}}
/>
{
setState(
Object.assign({}, state, {
isAuto: !state.isAuto,
})
);
}}
>
{props.lang.base.auto}
{
props.onChange && props.onChange(state.isAuto ? undefined : state.color);
}}
>
{props.lang.base.confirm}
);
}