@wordpress/block-library
Version:
Block library for the WordPress editor.
72 lines (69 loc) • 2.29 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = HomeEdit;
var _clsx = _interopRequireDefault(require("clsx"));
var _blockEditor = require("@wordpress/block-editor");
var _i18n = require("@wordpress/i18n");
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _jsxRuntime = require("react/jsx-runtime");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
const preventDefault = event => event.preventDefault();
function HomeEdit({
attributes,
setAttributes,
context
}) {
var _attributes$label;
const homeUrl = (0, _data.useSelect)(select => {
// Site index.
return select(_coreData.store).getEntityRecord('root', '__unstableBase')?.home;
}, []);
const {
textColor,
backgroundColor,
style
} = context;
const blockProps = (0, _blockEditor.useBlockProps)({
className: (0, _clsx.default)('wp-block-navigation-item', {
'has-text-color': !!textColor || !!style?.color?.text,
[`has-${textColor}-color`]: !!textColor,
'has-background': !!backgroundColor || !!style?.color?.background,
[`has-${backgroundColor}-background-color`]: !!backgroundColor
}),
style: {
color: style?.color?.text,
backgroundColor: style?.color?.background
}
});
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
...blockProps,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
className: "wp-block-home-link__content wp-block-navigation-item__content",
href: homeUrl,
onClick: preventDefault,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.RichText, {
identifier: "label",
className: "wp-block-home-link__label",
value: (_attributes$label = attributes.label) !== null && _attributes$label !== void 0 ? _attributes$label : (0, _i18n.__)('Home'),
onChange: labelValue => {
setAttributes({
label: labelValue
});
},
"aria-label": (0, _i18n.__)('Home link text'),
placeholder: (0, _i18n.__)('Add home link'),
withoutInteractiveFormatting: true
})
})
});
}
//# sourceMappingURL=edit.js.map
;