UNPKG

@wordpress/global-styles-ui

Version:
65 lines (64 loc) • 2 kB
import { BaseControl, Flex, FlexItem, RangeControl, __experimentalParseQuantityAndUnitFromRawValue, __experimentalSpacer, __experimentalUnitControl, __experimentalUseCustomUnits, useBaseControlProps } from "@wordpress/components"; import { jsx, jsxs } from "react/jsx-runtime"; // packages/global-styles-ui/src/size-control/index.tsx const DEFAULT_UNITS = [ "px", "em", "rem", "vw", "vh" ]; function SizeControl(props) { const { baseControlProps } = useBaseControlProps(props); const { value, onChange, fallbackValue, disabled, label } = props; const units = __experimentalUseCustomUnits({ availableUnits: DEFAULT_UNITS }); const [valueQuantity, valueUnit = "px"] = __experimentalParseQuantityAndUnitFromRawValue(value, units); const isValueUnitRelative = !!valueUnit && [ "em", "rem", "vw", "vh" ].includes(valueUnit); const handleUnitControlChange = (newValue) => { onChange?.(newValue); }; const handleRangeControlChange = (newValue) => { if (newValue !== void 0) onChange?.(newValue + valueUnit); else onChange?.(void 0); }; return /* @__PURE__ */ jsx(BaseControl, { ...baseControlProps, children: /* @__PURE__ */ jsxs(Flex, { children: [/* @__PURE__ */ jsx(FlexItem, { isBlock: true, children: /* @__PURE__ */ jsx(__experimentalUnitControl, { label, hideLabelFromVision: true, value, onChange: handleUnitControlChange, units, min: 0, disabled }) }), /* @__PURE__ */ jsx(FlexItem, { isBlock: true, children: /* @__PURE__ */ jsx(__experimentalSpacer, { marginX: 2, marginBottom: 0, children: /* @__PURE__ */ jsx(RangeControl, { label, hideLabelFromVision: true, value: valueQuantity, initialPosition: fallbackValue, withInputField: false, onChange: handleRangeControlChange, min: 0, max: isValueUnitRelative ? 10 : 100, step: isValueUnitRelative ? .1 : 1, disabled }) }) })] }) }); } export { SizeControl }; //# sourceMappingURL=index.mjs.map