UNPKG

@wordpress/block-library

Version:
157 lines (155 loc) 5.86 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-library/src/navigation/edit/responsive-wrapper.js var responsive_wrapper_exports = {}; __export(responsive_wrapper_exports, { default: () => ResponsiveWrapper }); module.exports = __toCommonJS(responsive_wrapper_exports); var import_clsx = __toESM(require("clsx")); var import_icons = require("@wordpress/icons"); var import_components = require("@wordpress/components"); var import_i18n = require("@wordpress/i18n"); var import_block_editor = require("@wordpress/block-editor"); var import_overlay_menu_icon = __toESM(require("./overlay-menu-icon")); var import_jsx_runtime = require("react/jsx-runtime"); function ResponsiveWrapper({ children, id, isOpen, isResponsive, onToggle, isHiddenByDefault, overlayBackgroundColor, overlayTextColor, hasIcon, icon, overlay, onNavigateToEntityRecord }) { if (!isResponsive) { return children; } const responsiveContainerClasses = (0, import_clsx.default)( "wp-block-navigation__responsive-container", { "has-text-color": !!overlayTextColor.color || !!overlayTextColor?.class, [(0, import_block_editor.getColorClassName)("color", overlayTextColor?.slug)]: !!overlayTextColor?.slug, "has-background": !!overlayBackgroundColor.color || overlayBackgroundColor?.class, [(0, import_block_editor.getColorClassName)( "background-color", overlayBackgroundColor?.slug )]: !!overlayBackgroundColor?.slug, "is-menu-open": isOpen, "hidden-by-default": isHiddenByDefault } ); const styles = { color: !overlayTextColor?.slug && overlayTextColor?.color, backgroundColor: !overlayBackgroundColor?.slug && overlayBackgroundColor?.color && overlayBackgroundColor.color }; const openButtonClasses = (0, import_clsx.default)( "wp-block-navigation__responsive-container-open", { "always-shown": isHiddenByDefault } ); const modalId = `${id}-modal`; const dialogProps = { className: "wp-block-navigation__responsive-dialog", ...isOpen && { role: "dialog", "aria-modal": true, "aria-label": (0, import_i18n.__)("Menu") } }; const handleToggleClick = () => { if (overlay && onNavigateToEntityRecord) { onNavigateToEntityRecord({ postId: overlay, postType: "wp_template_part" }); return; } onToggle(true); }; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ !isOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_components.Button, { __next40pxDefaultSize: true, "aria-haspopup": "true", "aria-label": hasIcon && (0, import_i18n.__)("Open menu"), className: openButtonClasses, onClick: handleToggleClick, children: [ hasIcon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_overlay_menu_icon.default, { icon }), !hasIcon && (0, import_i18n.__)("Menu") ] } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { className: responsiveContainerClasses, style: styles, id: modalId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { className: "wp-block-navigation__responsive-close", tabIndex: "-1", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...dialogProps, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_components.Button, { __next40pxDefaultSize: true, className: "wp-block-navigation__responsive-container-close", "aria-label": hasIcon && (0, import_i18n.__)("Close menu"), onClick: () => onToggle(false), children: [ hasIcon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon: import_icons.close }), !hasIcon && (0, import_i18n.__)("Close") ] } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { className: "wp-block-navigation__responsive-container-content", id: `${modalId}-content`, children } ) ] }) } ) } ) ] }); } //# sourceMappingURL=responsive-wrapper.js.map