@wordpress/block-library
Version:
Block library for the WordPress editor.
101 lines (86 loc) • 2.88 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SpacerControls;
var _element = require("@wordpress/element");
var _i18n = require("@wordpress/i18n");
var _blockEditor = require("@wordpress/block-editor");
var _components = require("@wordpress/components");
var _compose = require("@wordpress/compose");
var _constants = require("./constants");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function DimensionInput(_ref) {
var _ref2;
let {
label,
onChange,
isResizing,
value = ''
} = _ref;
const inputId = (0, _compose.useInstanceId)(_components.__experimentalUnitControl, 'block-spacer-height-input'); // In most contexts the spacer size cannot meaningfully be set to a
// percentage, since this is relative to the parent container. This
// unit is disabled from the UI.
const availableUnitSettings = (_ref2 = (0, _blockEditor.useSetting)('spacing.units') || undefined) === null || _ref2 === void 0 ? void 0 : _ref2.filter(availableUnit => availableUnit !== '%');
const units = (0, _components.__experimentalUseCustomUnits)({
availableUnits: availableUnitSettings || ['px', 'em', 'rem', 'vw', 'vh'],
defaultValues: {
px: 100,
em: 10,
rem: 10,
vw: 10,
vh: 25
}
});
const handleOnChange = unprocessedValue => {
onChange(unprocessedValue);
}; // Force the unit to update to `px` when the Spacer is being resized.
const [parsedQuantity, parsedUnit] = (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(value);
const computedValue = [parsedQuantity, isResizing ? 'px' : parsedUnit].join('');
return (0, _element.createElement)(_components.BaseControl, {
label: label,
id: inputId
}, (0, _element.createElement)(_components.__experimentalUnitControl, {
id: inputId,
isResetValueOnUnitChange: true,
min: _constants.MIN_SPACER_SIZE,
onChange: handleOnChange,
style: {
maxWidth: 80
},
value: computedValue,
units: units
}));
}
function SpacerControls(_ref3) {
let {
setAttributes,
orientation,
height,
width,
isResizing
} = _ref3;
return (0, _element.createElement)(_blockEditor.InspectorControls, null, (0, _element.createElement)(_components.PanelBody, {
title: (0, _i18n.__)('Settings')
}, orientation === 'horizontal' && (0, _element.createElement)(DimensionInput, {
label: (0, _i18n.__)('Width'),
value: width,
onChange: nextWidth => setAttributes({
width: nextWidth
}),
isResizing: isResizing
}), orientation !== 'horizontal' && (0, _element.createElement)(DimensionInput, {
label: (0, _i18n.__)('Height'),
value: height,
onChange: nextHeight => setAttributes({
height: nextHeight
}),
isResizing: isResizing
})));
}
//# sourceMappingURL=controls.js.map
;