import React, { useCallback, useContext } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { useIntl } from '@edx/frontend-platform/i18n'; import { Icon, IconButton } from '@openedx/paragon'; import { ArrowBackIos, Close } from '@openedx/paragon/icons'; import { useEventListener } from '../../../../generic/hooks'; import WIDGETS from '../constants'; import messages from '../messages'; import SidebarContext from '../SidebarContext'; const SidebarBase = ({ title, ariaLabel, sidebarId, className, children, showTitleBar, width, allowFullHeight, showBorder, }) => { const intl = useIntl(); const { toggleSidebar, shouldDisplayFullScreen, currentSidebar, } = useContext(SidebarContext); const receiveMessage = useCallback(({ data }) => { const { type } = data; if (type === 'learning.events.sidebar.close') { toggleSidebar(currentSidebar, WIDGETS.DISCUSSIONS); } }, [toggleSidebar]); useEventListener('message', receiveMessage); return (
{shouldDisplayFullScreen && (
toggleSidebar(null)} onKeyDown={() => toggleSidebar(null)} role="button" tabIndex="0" alt={intl.formatMessage(messages.responsiveCloseSidebarTray)} > {intl.formatMessage(messages.responsiveCloseSidebarTray)}
)} {showTitleBar && ( <>
{title}
toggleSidebar(sidebarId)} alt={intl.formatMessage(messages.closeTrigger)} className="icon-hover" />
)} {children}
); }; SidebarBase.propTypes = { title: PropTypes.string, ariaLabel: PropTypes.string.isRequired, sidebarId: PropTypes.string.isRequired, className: PropTypes.string, children: PropTypes.element.isRequired, showTitleBar: PropTypes.bool, width: PropTypes.string, allowFullHeight: PropTypes.bool, showBorder: PropTypes.bool, }; SidebarBase.defaultProps = { title: '', width: '50rem', allowFullHeight: false, showTitleBar: true, className: '', showBorder: true, }; export default SidebarBase;