import { useIntl } from '@edx/frontend-platform/i18n'; import { Icon, IconButton } from '@openedx/paragon'; import { ArrowBackIos, Close } from '@openedx/paragon/icons'; import classNames from 'classnames'; import PropTypes from 'prop-types'; import { useCallback, useContext } from 'react'; import { useEventListener } from '@src/generic/hooks'; import messages from '../../messages'; import SidebarContext from '../SidebarContext'; const SidebarBase = ({ title, ariaLabel, sidebarId, className, children, showTitleBar, width, }) => { const intl = useIntl(); 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 (
{shouldDisplayFullScreen ? (
toggleSidebar(null)} onKeyDown={() => toggleSidebar(null)} role="button" tabIndex="0" > {intl.formatMessage(messages.responsiveCloseNotificationTray)}
) : null} {showTitleBar && ( <>
{title} {shouldDisplayFullScreen ? null : (
toggleSidebar(null)} variant="primary" alt={intl.formatMessage(messages.closeNotificationTrigger)} />
)}
)} {children}
); }; SidebarBase.propTypes = { title: PropTypes.string.isRequired, ariaLabel: PropTypes.string.isRequired, sidebarId: PropTypes.string.isRequired, className: PropTypes.string.isRequired, children: PropTypes.element.isRequired, showTitleBar: PropTypes.bool, width: PropTypes.string, }; SidebarBase.defaultProps = { width: '31rem', showTitleBar: true, }; export default SidebarBase;