@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
70 lines (69 loc) • 2.37 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_components = require("@wordpress/components");
let react_jsx_runtime = require("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 } = (0, _wordpress_components.useBaseControlProps)(props);
const { value, onChange, fallbackValue, disabled, label } = props;
const units = (0, _wordpress_components.__experimentalUseCustomUnits)({ availableUnits: DEFAULT_UNITS });
const [valueQuantity, valueUnit = "px"] = (0, _wordpress_components.__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__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.BaseControl, {
...baseControlProps,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.Flex, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.FlexItem, {
isBlock: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalUnitControl, {
label,
hideLabelFromVision: true,
value,
onChange: handleUnitControlChange,
units,
min: 0,
disabled
})
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.FlexItem, {
isBlock: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalSpacer, {
marginX: 2,
marginBottom: 0,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.RangeControl, {
label,
hideLabelFromVision: true,
value: valueQuantity,
initialPosition: fallbackValue,
withInputField: false,
onChange: handleRangeControlChange,
min: 0,
max: isValueUnitRelative ? 10 : 100,
step: isValueUnitRelative ? .1 : 1,
disabled
})
})
})] })
});
}
exports.SizeControl = SizeControl;
//# sourceMappingURL=index.cjs.map