UNPKG

@wordpress/block-library

Version:
53 lines (52 loc) 1.84 kB
// packages/block-library/src/home-link/edit.js import clsx from "clsx"; 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 } from "react/jsx-runtime"; var preventDefault = (event) => event.preventDefault(); function HomeEdit({ attributes, setAttributes, context }) { const homeUrl = useSelect((select) => { 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 ?? __("Home"), onChange: (labelValue) => { setAttributes({ label: labelValue }); }, "aria-label": __("Home link text"), placeholder: __("Add home link"), withoutInteractiveFormatting: true } ) } ) }); } export { HomeEdit as default }; //# sourceMappingURL=edit.js.map