|
| 1 | +import { |
| 2 | + createStyles, |
| 3 | + Divider, |
| 4 | + Drawer, |
| 5 | + IconButton, |
| 6 | + makeStyles, |
| 7 | + Theme, |
| 8 | + useTheme, |
| 9 | + Typography, |
| 10 | +} from '@material-ui/core'; |
| 11 | +import { Form, Button, NavDropdown } from 'react-bootstrap'; |
| 12 | +import { ChevronLeft, ChevronRight, Menu } from '@material-ui/icons'; |
| 13 | +import clsx from 'clsx'; |
| 14 | +import React from 'react'; |
| 15 | +import { RubricRequirement } from '../../../__generated__/types'; |
| 16 | +import Rubric from './Rubric'; |
| 17 | + |
| 18 | +const useStyles = makeStyles((theme: Theme) => |
| 19 | + createStyles({ |
| 20 | + root: { |
| 21 | + display: 'flex', |
| 22 | + }, |
| 23 | + appBar: { |
| 24 | + transition: theme.transitions.create(['margin', 'width'], { |
| 25 | + easing: theme.transitions.easing.sharp, |
| 26 | + duration: theme.transitions.duration.leavingScreen, |
| 27 | + }), |
| 28 | + }, |
| 29 | + appBarShift: { |
| 30 | + transition: theme.transitions.create(['margin', 'width'], { |
| 31 | + easing: theme.transitions.easing.easeOut, |
| 32 | + duration: theme.transitions.duration.enteringScreen, |
| 33 | + }), |
| 34 | + }, |
| 35 | + title: { |
| 36 | + flexGrow: 1, |
| 37 | + }, |
| 38 | + hide: { |
| 39 | + display: 'none', |
| 40 | + }, |
| 41 | + drawer: { |
| 42 | + flexShrink: 0, |
| 43 | + }, |
| 44 | + drawerPaper: {}, |
| 45 | + drawerHeader: { |
| 46 | + display: 'flex', |
| 47 | + alignItems: 'center', |
| 48 | + padding: theme.spacing(0, 1), |
| 49 | + // necessary for content to be below app bar |
| 50 | + ...theme.mixins.toolbar, |
| 51 | + justifyContent: 'flex-start', |
| 52 | + }, |
| 53 | + content: { |
| 54 | + flexGrow: 1, |
| 55 | + padding: theme.spacing(3), |
| 56 | + transition: theme.transitions.create('margin', { |
| 57 | + easing: theme.transitions.easing.sharp, |
| 58 | + duration: theme.transitions.duration.leavingScreen, |
| 59 | + }), |
| 60 | + }, |
| 61 | + contentShift: { |
| 62 | + transition: theme.transitions.create('margin', { |
| 63 | + easing: theme.transitions.easing.easeOut, |
| 64 | + duration: theme.transitions.duration.enteringScreen, |
| 65 | + }), |
| 66 | + marginRight: 0, |
| 67 | + }, |
| 68 | + }) |
| 69 | +); |
| 70 | + |
| 71 | +function RubricMenu({ requirements }: { requirements: RubricRequirement[] }) { |
| 72 | + const classes = useStyles(); |
| 73 | + const theme = useTheme(); |
| 74 | + const [open, setOpen] = React.useState(false); |
| 75 | + |
| 76 | + const handleDrawerOpen = () => { |
| 77 | + setOpen(true); |
| 78 | + }; |
| 79 | + |
| 80 | + const handleDrawerClose = () => { |
| 81 | + setOpen(false); |
| 82 | + }; |
| 83 | + return ( |
| 84 | + <div> |
| 85 | + <IconButton |
| 86 | + color="inherit" |
| 87 | + aria-label="open drawer" |
| 88 | + edge="end" |
| 89 | + onClick={handleDrawerOpen} |
| 90 | + className={clsx(open && classes.hide)} |
| 91 | + > |
| 92 | + <Menu /> |
| 93 | + <Typography>Task Rubric</Typography> |
| 94 | + </IconButton> |
| 95 | + <Drawer |
| 96 | + className={classes.drawer} |
| 97 | + variant="persistent" |
| 98 | + anchor="right" |
| 99 | + open={open} |
| 100 | + classes={{ |
| 101 | + paper: classes.drawerPaper, |
| 102 | + }} |
| 103 | + > |
| 104 | + <div className={classes.drawerHeader}> |
| 105 | + <IconButton onClick={handleDrawerClose}> |
| 106 | + {theme.direction === 'rtl' ? <ChevronLeft /> : <ChevronRight />} |
| 107 | + </IconButton> |
| 108 | + <Typography>Task Rubric</Typography> |
| 109 | + </div> |
| 110 | + <Divider /> |
| 111 | + <Form> |
| 112 | + {requirements.map((requirement: RubricRequirement) => ( |
| 113 | + <Rubric requirement={requirement} /> |
| 114 | + ))} |
| 115 | + <NavDropdown.Divider /> |
| 116 | + <Button className="mx-auto" type="submit"> |
| 117 | + Submit Task |
| 118 | + </Button> |
| 119 | + </Form> |
| 120 | + </Drawer> |
| 121 | + </div> |
| 122 | + ); |
| 123 | +} |
| 124 | + |
| 125 | +export default RubricMenu; |
0 commit comments