|
| 1 | +import { useState } from 'react'; |
| 2 | +import { |
| 3 | + IconButton, |
| 4 | + IconButtonToggle, |
| 5 | + Stack, |
| 6 | + breakpoints, |
| 7 | +} from '@openedx/paragon'; |
| 8 | +import { Close, Help, Info } from '@openedx/paragon/icons'; |
| 9 | +import { useMediaQuery } from 'react-responsive'; |
| 10 | + |
| 11 | +import { useWaffleFlags } from '@src/data/apiHooks'; |
| 12 | + |
| 13 | +import OutlineHelpSidebar from './OutlineHelpSidebar'; |
| 14 | +import OutlineInfoSidebar from './OutlineInfoSidebar'; |
| 15 | + |
| 16 | +interface OutlineSideBarProps { |
| 17 | + courseId: string; |
| 18 | +} |
| 19 | + |
| 20 | +const COMPONENTS = { |
| 21 | + help: OutlineHelpSidebar, |
| 22 | + info: OutlineInfoSidebar, |
| 23 | +}; |
| 24 | + |
| 25 | +const OutlineSideBar = ({ courseId }: OutlineSideBarProps) => { |
| 26 | + const { tempWaffleFlag } = useWaffleFlags(); |
| 27 | + const [currentTab, setCurrentTab] = useState('info'); |
| 28 | + const isMedium = useMediaQuery({ maxWidth: breakpoints.medium.maxWidth }); |
| 29 | + |
| 30 | + // Returns the previous help sidebar component if the waffle flag is disabled |
| 31 | + if (!tempWaffleFlag) { |
| 32 | + // On screens smaller than medium, the help sidebar is shown below the course outline |
| 33 | + const colSpan = isMedium ? 'col-12' : 'col-3'; |
| 34 | + return ( |
| 35 | + <div className={colSpan}> |
| 36 | + <OutlineHelpSidebar courseId={courseId} /> |
| 37 | + </div> |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + const SidebarComponent = COMPONENTS[currentTab]; |
| 42 | + |
| 43 | + return ( |
| 44 | + <Stack direction="horizontal" className="align-items-baseline px-3"> |
| 45 | + {!!currentTab && ( |
| 46 | + <div className="mw-300px"> |
| 47 | + <SidebarComponent courseId={courseId} /> |
| 48 | + </div> |
| 49 | + )} |
| 50 | + <div className="sidebar-toggle"> |
| 51 | + <IconButtonToggle |
| 52 | + activeValue={currentTab} |
| 53 | + onChange={setCurrentTab} |
| 54 | + > |
| 55 | + <IconButton src={Close} alt="Close" /> |
| 56 | + <IconButton value="info" src={Info} alt="Help" /> |
| 57 | + <IconButton value="help" src={Help} alt="Help" /> |
| 58 | + </IconButtonToggle> |
| 59 | + </div> |
| 60 | + </Stack> |
| 61 | + ); |
| 62 | +}; |
| 63 | + |
| 64 | +export default OutlineSideBar; |
0 commit comments