MCPcopy Create free account
hub / github.com/CloudOrc/SolidUI / InputColor

Function InputColor

solidui-web/src/components/InputColor/InputColor.tsx:35–115  ·  view source on GitHub ↗
({
	prefixCls = "solid",
	className,
	style,
	width = 155,
	value = "#000000",
	onChange,
}: InputColorProps)

Source from the content-addressed store, hash-verified

33}
34
35export default function InputColor({
36 prefixCls = "solid",
37 className,
38 style,
39 width = 155,
40 value = "#000000",
41 onChange,
42}: InputColorProps) {
43 const [displayColorPicker, setDisplayColorPicker] = useState(false);
44 const [stateValue, setStateValue] = useState(value);
45
46 useEffect(() => {
47 setStateValue(value);
48 }, [value]);
49
50 function handleClickColorPicker() {
51 setDisplayColorPicker(!displayColorPicker);
52 }
53
54 function handleCloseColorPicker() {
55 setDisplayColorPicker(false);
56 }
57
58 function handleColorChange(color: any) {
59 const mValue = isString(color) ? color : color.hex;
60 setStateValue(mValue);
61 if (onChange) {
62 onChange(mValue);
63 }
64 }
65
66 function renderColorPicker() {
67 if (!displayColorPicker) return undefined;
68 return (
69 <div className="popover">
70 <div
71 className="cover"
72 onClick={handleCloseColorPicker}
73 onKeyPress={handleCloseColorPicker}
74 role="button"
75 tabIndex={0}
76 />
77 <ColorPicker color={stateValue} onChange={handleColorChange} />
78 </div>
79 );
80 }
81
82 const _style: React.CSSProperties = {
83 display: "flex",
84 justifyContent: "center",
85 alignItems: "center",
86 width: `${width}px`,
87 ...style,
88 };
89
90 return (
91 <div
92 className={classNames(prefixCls, "solid-color", className)}

Callers

nothing calls this directly

Calls 1

renderColorPickerFunction · 0.85

Tested by

no test coverage detected