@wordpress/block-library
Version:
Block library for the WordPress editor.
64 lines (63 loc) • 1.96 kB
JavaScript
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { jsx as _jsx } from "react/jsx-runtime";
const preventDefault = event => event.preventDefault();
export default function HomeEdit({
attributes,
setAttributes,
context
}) {
var _attributes$label;
const homeUrl = useSelect(select => {
// Site index.
return select(coreStore).getEntityRecord('root', '__unstableBase')?.home;
}, []);
const {
textColor,
backgroundColor,
style
} = context;
const blockProps = useBlockProps({
className: clsx('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__*/_jsx("div", {
...blockProps,
children: /*#__PURE__*/_jsx("a", {
className: "wp-block-home-link__content wp-block-navigation-item__content",
href: homeUrl,
onClick: preventDefault,
children: /*#__PURE__*/_jsx(RichText, {
identifier: "label",
className: "wp-block-home-link__label",
value: (_attributes$label = attributes.label) !== null && _attributes$label !== void 0 ? _attributes$label : __('Home'),
onChange: labelValue => {
setAttributes({
label: labelValue
});
},
"aria-label": __('Home link text'),
placeholder: __('Add home link'),
withoutInteractiveFormatting: true
})
})
});
}
//# sourceMappingURL=edit.js.map