import { __ } from "@wordpress/i18n"; import { useState, memo } from "@wordpress/element"; import SpColorPicker from "../color/color"; import SPToggleGroupControl from "../toggleGroupControl/toggleGroupControl"; import { DashedStyle, DottedStyle, DoubleStyle, SolidStyle } from "../../icons/icons"; import "./editor.scss"; import Spacing from "../spacing/spacing"; import { useDeviceType } from "../../controls/controls"; const Border = ({ label = "Border", attributes, setAttributes, attributesKey, units = ["px", "%", "em"], btnType = false, defaultValue = {unit: "px", value: { top: 0, right: 0, bottom: 0, left: 0 } }, defaultColor = "#fff", onStateUpdate = false, }) => { const { border, borderWidth } = attributes; const [buttonTab, setButtonTab] = useState("normal"); const deviceType = useDeviceType(); const borderColorOptions = [ { label: "Normal", value: "normal" }, ...(attributes.border.hoverColor || attributes.border.hoverColor === "" || attributes.border.hover || attributes.border.hover === "" ? [{ label: "Hover", value: "hover" }] : []), ...(attributes.border.activeColor || attributes.border.activeColor === "" || attributes.border.active || attributes.border.active === "" ? [{ label: "Active", value: "activeColor" }] : []), ]; const hoverColor = () => { if (border?.hoverColor !== undefined) { return "hoverColor"; } if (border?.hover !== undefined) { return "hover"; } if (border?.activeColor !== undefined) { return "activeColor"; } return "active"; }; const borderStyleString = () => { if (btnType && btnType !== "normal") { return "hoverStyle"; } return "style"; }; const updateBorderWithHandler = (newValue) => { if (onStateUpdate) { onStateUpdate(attributesKey.borderWidth, newValue); } return false; }; const updateSpacingUtilityHandler = (type, newUtility) => { if (onStateUpdate) { onStateUpdate(attributesKey.borderWidth, { ...attributes.borderWidth, [type]: newUtility, }); } else { const updateAttr = type === "allChange" ? { ...attributes.borderWidth, [type]: newUtility } : { ...attributes.borderWidth, [type]: { ...attributes?.borderWidth?.unit, [deviceType]: newUtility }, }; setAttributes({ [attributesKey.borderWidth]: updateAttr }); } }; return ( <>