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 (
{unit}
{units?.map((item, i) => ( ))}
); }); export const ResetButton = memo(({ onClick }) => { return ( ); }); export const SpLinkedButton = ({ attributes, attributesKey, setAttributes, Icon, updateAllChange }) => { const linked = attributes?.allChange || false; return (
updateAllChange ? updateAllChange(!linked) : setAttributes({ [attributesKey]: { ...attributes, allChange: !linked }, }) } > {Icon}
); };