import { memo } from "@wordpress/element"; import { Button } from "@wordpress/components"; import { ResetIcon } from "../../icons/icons"; import { useDeviceType } from "../../controls/controls"; export const Units = memo(({ attributes, setAttributes, attributesKey, units, onUnitChange }) => { const deviceType = useDeviceType(); // Set unit function. const setUnit = (newValue) => { if (onUnitChange) { onUnitChange(newValue); return; } if (attributes.unit?.[deviceType]) { setAttributes({ [attributesKey]: { ...attributes, unit: { ...attributes.unit, [deviceType]: newValue.toLowerCase(), }, }, }); } else { setAttributes({ [attributesKey]: { ...attributes, unit: newValue.toLowerCase(), }, }); } }; const unit = "object" === typeof attributes?.unit ? attributes.unit?.[deviceType] : attributes?.unit; return (