import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; import { Icon, IconButton } from '@edx/paragon'; import { ArrowBackIos, Close } from '@edx/paragon/icons'; import classNames from 'classnames'; import PropTypes from 'prop-types'; import React, { useCallback, useContext } from 'react'; import { useEventListener } from '../../../../generic/hooks'; import messages from '../../messages'; import SidebarContext from '../SidebarContext'; const SidebarBase = ({ intl, title, ariaLabel, sidebarId, className, children, showTitleBar, width, }) => { const { toggleSidebar, shouldDisplayFullScreen, currentSidebar, } = useContext(SidebarContext); const receiveMessage = useCallback(({ data }) => { const { type } = data; if (type === 'learning.events.sidebar.close') { toggleSidebar(null); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [sidebarId, toggleSidebar]); useEventListener('message', receiveMessage); return currentSidebar === sidebarId && (
{shouldDisplayFullScreen ? (
toggleSidebar(null)} onKeyDown={() => toggleSidebar(null)} role="button" tabIndex="0" alt={intl.formatMessage(messages.responsiveCloseNotificationTray)} > {intl.formatMessage(messages.responsiveCloseNotificationTray)}
) : null} {showTitleBar && ( <>
{title} {shouldDisplayFullScreen ? null : (
toggleSidebar(null)} variant="primary" alt={intl.formatMessage(messages.closeNotificationTrigger)} />
)}
)} {children}
); }; SidebarBase.propTypes = { intl: intlShape.isRequired, title: PropTypes.string.isRequired, ariaLabel: PropTypes.string.isRequired, sidebarId: PropTypes.string.isRequired, className: PropTypes.string, children: PropTypes.element.isRequired, showTitleBar: PropTypes.bool, width: PropTypes.string, }; SidebarBase.defaultProps = { width: '31rem', showTitleBar: true, className: '', }; export default injectIntl(SidebarBase);