UNPKG

@wordpress/block-library

Version:
66 lines (65 loc) • 2.45 kB
import { Button } from "@wordpress/components"; import { __, isRTL } from "@wordpress/i18n"; import { chevronLeftSmall, chevronRightSmall } from "@wordpress/icons"; import { useFocusOnMount, useInstanceId } from "@wordpress/compose"; import { VisuallyHidden } from "@wordpress/ui"; import { jsx, jsxs } from "react/jsx-runtime"; // packages/block-library/src/navigation-link/link-ui/dialog-wrapper.jsx /** * Shared BackButton component for consistent navigation across LinkUI sub-components. * * @param {Object} props Component props. * @param {string} props.className CSS class name for the button. * @param {Function} props.onBack Callback when user wants to go back. */ function BackButton({ className, onBack }) { return /* @__PURE__ */ jsx(Button, { className, icon: isRTL() ? chevronRightSmall : chevronLeftSmall, onClick: (e) => { e.preventDefault(); onBack(); }, size: "small", children: __("Back") }); } /** * Shared DialogWrapper component for consistent dialog structure across LinkUI sub-components. * * @param {Object} props Component props. * @param {string} props.className CSS class name for the dialog container. * @param {string} props.title Dialog title for accessibility. * @param {string} props.description Dialog description for accessibility. * @param {Function} props.onBack Callback when user wants to go back. * @param {Object} props.children Child components to render inside the dialog. */ function DialogWrapper({ className, title, description, onBack, children }) { const dialogTitleId = useInstanceId(DialogWrapper, "link-ui-dialog-title"); const dialogDescriptionId = useInstanceId(DialogWrapper, "link-ui-dialog-description"); const focusOnMountRef = useFocusOnMount("firstElement"); const backButtonClassName = `${className}__back`; return /* @__PURE__ */ jsxs("div", { className, role: "dialog", "aria-labelledby": dialogTitleId, "aria-describedby": dialogDescriptionId, ref: focusOnMountRef, children: [ /* @__PURE__ */ jsxs(VisuallyHidden, { children: [/* @__PURE__ */ jsx("h2", { id: dialogTitleId, children: title }), /* @__PURE__ */ jsx("p", { id: dialogDescriptionId, children: description })] }), /* @__PURE__ */ jsx(BackButton, { className: backButtonClassName, onBack }), children ] }); } export { DialogWrapper as default }; //# sourceMappingURL=dialog-wrapper.mjs.map