@wordpress/block-library
Version:
Block library for the WordPress editor.
84 lines (79 loc) • 2.64 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SeparatorEdit;
var _clsx = _interopRequireDefault(require("clsx"));
var _components = require("@wordpress/components");
var _blockEditor = require("@wordpress/block-editor");
var _i18n = require("@wordpress/i18n");
var _useDeprecatedOpacity = _interopRequireDefault(require("./use-deprecated-opacity"));
var _messages = require("../utils/messages");
var _jsxRuntime = require("react/jsx-runtime");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function SeparatorEdit({
attributes,
setAttributes
}) {
const {
backgroundColor,
opacity,
style,
tagName
} = attributes;
const colorProps = (0, _blockEditor.__experimentalUseColorProps)(attributes);
const currentColor = colorProps?.style?.backgroundColor;
const hasCustomColor = !!style?.color?.background;
(0, _useDeprecatedOpacity.default)(opacity, currentColor, setAttributes);
// The dots styles uses text for the dots, to change those dots color is
// using color, not backgroundColor.
const colorClass = (0, _blockEditor.getColorClassName)('color', backgroundColor);
const className = (0, _clsx.default)({
'has-text-color': backgroundColor || currentColor,
[colorClass]: colorClass,
'has-css-opacity': opacity === 'css',
'has-alpha-channel-opacity': opacity === 'alpha-channel'
}, colorProps.className);
const styles = {
color: currentColor,
backgroundColor: currentColor
};
const Wrapper = tagName === 'hr' ? _components.HorizontalRule : tagName;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, {
group: "advanced",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.SelectControl, {
__nextHasNoMarginBottom: true,
__next40pxDefaultSize: true,
label: (0, _i18n.__)('HTML element'),
options: [{
label: (0, _i18n.__)('Default (<hr>)'),
value: 'hr'
}, {
label: '<div>',
value: 'div'
}],
value: tagName,
onChange: value => setAttributes({
tagName: value
}),
help: _messages.htmlElementMessages[tagName]
})
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapper, {
...(0, _blockEditor.useBlockProps)({
className,
style: hasCustomColor ? styles : undefined
})
})]
});
}
//# sourceMappingURL=edit.js.map