UNPKG

@wordpress/block-library

Version:
103 lines (88 loc) 3.26 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = HomeEdit; var _element = require("@wordpress/element"); var _classnames = _interopRequireDefault(require("classnames")); var _blockEditor = require("@wordpress/block-editor"); var _i18n = require("@wordpress/i18n"); var _data = require("@wordpress/data"); var _coreData = require("@wordpress/core-data"); /** * External dependencies */ /** * WordPress dependencies */ const preventDefault = event => event.preventDefault(); function HomeEdit(_ref) { var _style$color, _style$color2, _style$color3, _style$color4; let { attributes, setAttributes, context } = _ref; const { homeUrl } = (0, _data.useSelect)(select => { var _getUnstableBase; const { getUnstableBase // Site index. } = select(_coreData.store); return { homeUrl: (_getUnstableBase = getUnstableBase()) === null || _getUnstableBase === void 0 ? void 0 : _getUnstableBase.home }; }, []); const { __unstableMarkNextChangeAsNotPersistent } = (0, _data.useDispatch)(_blockEditor.store); const { textColor, backgroundColor, style } = context; const blockProps = (0, _blockEditor.useBlockProps)({ className: (0, _classnames.default)('wp-block-navigation-item', { 'has-text-color': !!textColor || !!(style !== null && style !== void 0 && (_style$color = style.color) !== null && _style$color !== void 0 && _style$color.text), [`has-${textColor}-color`]: !!textColor, 'has-background': !!backgroundColor || !!(style !== null && style !== void 0 && (_style$color2 = style.color) !== null && _style$color2 !== void 0 && _style$color2.background), [`has-${backgroundColor}-background-color`]: !!backgroundColor }), style: { color: style === null || style === void 0 ? void 0 : (_style$color3 = style.color) === null || _style$color3 === void 0 ? void 0 : _style$color3.text, backgroundColor: style === null || style === void 0 ? void 0 : (_style$color4 = style.color) === null || _style$color4 === void 0 ? void 0 : _style$color4.background } }); const { label } = attributes; (0, _element.useEffect)(() => { if (label === undefined) { __unstableMarkNextChangeAsNotPersistent(); setAttributes({ label: (0, _i18n.__)('Home') }); } }, [label]); return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("div", blockProps, (0, _element.createElement)("a", { className: "wp-block-home-link__content wp-block-navigation-item__content", href: homeUrl, onClick: preventDefault }, (0, _element.createElement)(_blockEditor.RichText, { identifier: "label", className: "wp-block-home-link__label", value: label, onChange: labelValue => { setAttributes({ label: labelValue }); }, "aria-label": (0, _i18n.__)('Home link text'), placeholder: (0, _i18n.__)('Add home link'), withoutInteractiveFormatting: true, allowedFormats: ['core/bold', 'core/italic', 'core/image', 'core/strikethrough'] })))); } //# sourceMappingURL=edit.js.map