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