UNPKG

@wordpress/components

Version:
62 lines (52 loc) 1.6 kB
import { createElement } from "@wordpress/element"; /** * External dependencies */ import classnames from 'classnames'; /** * WordPress dependencies */ import { forwardRef } from '@wordpress/element'; import { __, isRTL } from '@wordpress/i18n'; import { Icon, chevronLeft, chevronRight } from '@wordpress/icons'; /** * Internal dependencies */ import { useNavigationContext } from '../context'; import { MenuBackButtonUI } from '../styles/navigation-styles'; function NavigationBackButton({ backButtonLabel, className, href, onClick, parentMenu }, ref) { var _navigationTree$getMe; const { setActiveMenu, navigationTree } = useNavigationContext(); const classes = classnames('components-navigation__back-button', className); const parentMenuTitle = (_navigationTree$getMe = navigationTree.getMenu(parentMenu)) === null || _navigationTree$getMe === void 0 ? void 0 : _navigationTree$getMe.title; const handleOnClick = event => { if (typeof onClick === 'function') { onClick(event); } const animationDirection = isRTL() ? 'left' : 'right'; if (parentMenu && !event.defaultPrevented) { setActiveMenu(parentMenu, animationDirection); } }; const icon = isRTL() ? chevronRight : chevronLeft; return createElement(MenuBackButtonUI, { className: classes, href: href, isTertiary: true, ref: ref, onClick: handleOnClick }, createElement(Icon, { icon: icon }), backButtonLabel || parentMenuTitle || __('Back')); } export default forwardRef(NavigationBackButton); //# sourceMappingURL=index.js.map