@wordpress/block-library
Version:
Block library for the WordPress editor.
91 lines (86 loc) • 3.7 kB
JavaScript
import { createElement, Fragment } from "@wordpress/element";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { close, Icon } from '@wordpress/icons';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { getColorClassName } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import OverlayMenuIcon from './overlay-menu-icon';
export default function ResponsiveWrapper(_ref) {
let {
children,
id,
isOpen,
isResponsive,
onToggle,
isHiddenByDefault,
overlayBackgroundColor,
overlayTextColor,
hasIcon,
icon
} = _ref;
if (!isResponsive) {
return children;
}
const responsiveContainerClasses = classnames('wp-block-navigation__responsive-container', {
'has-text-color': !!overlayTextColor.color || !!(overlayTextColor !== null && overlayTextColor !== void 0 && overlayTextColor.class),
[getColorClassName('color', overlayTextColor === null || overlayTextColor === void 0 ? void 0 : overlayTextColor.slug)]: !!(overlayTextColor !== null && overlayTextColor !== void 0 && overlayTextColor.slug),
'has-background': !!overlayBackgroundColor.color || (overlayBackgroundColor === null || overlayBackgroundColor === void 0 ? void 0 : overlayBackgroundColor.class),
[getColorClassName('background-color', overlayBackgroundColor === null || overlayBackgroundColor === void 0 ? void 0 : overlayBackgroundColor.slug)]: !!(overlayBackgroundColor !== null && overlayBackgroundColor !== void 0 && overlayBackgroundColor.slug),
'is-menu-open': isOpen,
'hidden-by-default': isHiddenByDefault
});
const styles = {
color: !(overlayTextColor !== null && overlayTextColor !== void 0 && overlayTextColor.slug) && (overlayTextColor === null || overlayTextColor === void 0 ? void 0 : overlayTextColor.color),
backgroundColor: !(overlayBackgroundColor !== null && overlayBackgroundColor !== void 0 && overlayBackgroundColor.slug) && (overlayBackgroundColor === null || overlayBackgroundColor === void 0 ? void 0 : overlayBackgroundColor.color) && overlayBackgroundColor.color
};
const openButtonClasses = classnames('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': __('Menu')
})
};
return createElement(Fragment, null, !isOpen && createElement(Button, {
"aria-haspopup": "true",
"aria-label": hasIcon && __('Open menu'),
className: openButtonClasses,
onClick: () => onToggle(true)
}, hasIcon && createElement(OverlayMenuIcon, {
icon: icon
}), !hasIcon && createElement("span", {
className: "wp-block-navigation__toggle_button_label"
}, __('Menu'))), createElement("div", {
className: responsiveContainerClasses,
style: styles,
id: modalId
}, createElement("div", {
className: "wp-block-navigation__responsive-close",
tabIndex: "-1"
}, createElement("div", dialogProps, createElement(Button, {
className: "wp-block-navigation__responsive-container-close",
"aria-label": hasIcon && __('Close menu'),
onClick: () => onToggle(false)
}, hasIcon && createElement(Icon, {
icon: close
}), !hasIcon && createElement("span", {
className: "wp-block-navigation__toggle_button_label"
}, __('Close'))), createElement("div", {
className: "wp-block-navigation__responsive-container-content",
id: `${modalId}-content`
}, children)))));
}
//# sourceMappingURL=responsive-wrapper.js.map