@wordpress/block-library
Version:
Block library for the WordPress editor.
117 lines (112 loc) • 4.02 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 _element = require("@wordpress/element");
var _i18n = require("@wordpress/i18n");
var _useDeprecatedOpacity = _interopRequireDefault(require("./use-deprecated-opacity"));
var _hooks = require("../utils/hooks");
var _jsxRuntime = require("react/jsx-runtime");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const HtmlElementControl = ({
tagName,
setAttributes
}) => {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.SelectControl, {
label: (0, _i18n.__)('HTML element'),
value: tagName,
onChange: newValue => setAttributes({
tagName: newValue
}),
options: [{
label: (0, _i18n.__)('Default (<hr>)'),
value: 'hr'
}, {
label: '<div>',
value: 'div'
}],
help: tagName === 'hr' ? (0, _i18n.__)('Only select <hr> if the separator conveys important information and should be announced by screen readers.') : (0, _i18n.__)('The <div> element should only be used if the block is a design element with no semantic meaning.'),
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true
});
};
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;
const dropdownMenuProps = (0, _hooks.useToolsPanelDropdownMenuProps)();
(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, {
children: _element.Platform.isNative ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.PanelBody, {
title: (0, _i18n.__)('Settings'),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HtmlElementControl, {
tagName: tagName,
setAttributes: setAttributes
})
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanel, {
label: (0, _i18n.__)('Settings'),
resetAll: () => {
setAttributes({
tagName: 'hr'
});
},
dropdownMenuProps: dropdownMenuProps,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanelItem, {
hasValue: () => tagName !== 'hr',
label: (0, _i18n.__)('HTML element'),
onDeselect: () => setAttributes({
tagName: 'hr'
}),
isShownByDefault: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HtmlElementControl, {
tagName: tagName,
setAttributes: setAttributes
})
})
})
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapper, {
...(0, _blockEditor.useBlockProps)({
className,
style: hasCustomColor ? styles : undefined
})
})]
});
}
//# sourceMappingURL=edit.js.map
;