1
1
import { styled } from '@mui/material/styles' ;
2
- import { Box , Button , ClickAwayListener , Collapse , Container , InputBase , Paper , TextareaAutosize } from '@mui/material' ;
2
+ import {
3
+ Box ,
4
+ Button ,
5
+ ButtonGroup ,
6
+ ClickAwayListener ,
7
+ Collapse ,
8
+ Container ,
9
+ Divider , Grow , IconButton ,
10
+ InputBase ,
11
+ ListItemIcon ,
12
+ ListItemText ,
13
+ ListSubheader ,
14
+ Menu ,
15
+ MenuItem ,
16
+ Paper ,
17
+ TextareaAutosize , Tooltip , Typography
18
+ } from '@mui/material' ;
3
19
import { useState } from 'react' ;
20
+ import { CampaignRounded , ExpandMoreRounded , GroupsRounded , PersonRounded } from '@mui/icons-material' ;
21
+ import { TaskVisibility } from './types' ;
22
+ import { User } from 'next-auth' ;
4
23
5
24
const StyledAutoresizeTextarea = styled ( TextareaAutosize ) ( ( { theme } ) => ( {
6
25
backgroundColor : 'transparent' ,
@@ -9,35 +28,66 @@ const StyledAutoresizeTextarea = styled(TextareaAutosize)(({ theme }) => ({
9
28
outline : 'none' ,
10
29
border : 'none' ,
11
30
padding : '.75rem 1rem' ,
31
+ margin : 0 ,
12
32
resize : 'none' ,
13
33
...theme . typography . body1 ,
34
+ '&::-webkit-scrollbar' : {
35
+ width : '.5rem' ,
36
+ backgroundColor : 'transparent'
37
+ } ,
38
+ '&::-webkit-scrollbar-thumb' : {
39
+ backgroundColor : theme . palette . divider
40
+ }
14
41
} ) ) ;
15
42
16
43
const TitleInput = styled ( InputBase ) ( ( { theme } ) => ( {
17
44
backgroundColor : 'transparent' ,
18
45
color : theme . palette . text . primary ,
19
46
flexGrow : 1 ,
20
47
width : '100%' ,
21
- padding : '1rem 1rem 0 1rem' ,
48
+ padding : '.8rem 1rem .5rem 1rem' ,
22
49
...theme . typography . h6 ,
23
- '&>input' : {
24
- padding : 0
25
- }
50
+ '&>input' : { padding : 0 }
51
+ } ) ) ;
52
+
53
+ const CreatorContainer = styled ( Paper ) ( ( { theme } ) => ( {
54
+ border : `1px solid ${ theme . palette . divider } ` ,
55
+ margin : '1rem auto' ,
56
+ display : 'flex' ,
57
+ flexDirection : 'column' ,
58
+ borderRadius : 24
59
+ } ) ) ;
60
+
61
+ const MenuHeader = styled ( ListSubheader ) ( ( { theme } ) => ( {
62
+ backgroundColor : 'transparent' ,
63
+ lineHeight : '1em' ,
64
+ margin : '.4rem 0 .6rem' ,
65
+ paddingTop : 8 ,
26
66
} ) ) ;
27
67
28
- export default function TaskCreator ( ) {
68
+ export default function TaskCreator ( props : { isAdmin : boolean , isSuperAdmin : boolean } ) {
29
69
const
30
70
[ inputFocused , setInputFocused ] = useState ( false ) ,
31
71
[ title , setTitle ] = useState ( '' ) ,
32
72
[ content , setContent ] = useState ( '' ) ,
33
- canShrink = title . length === 0 && content . length === 0 && ! inputFocused ;
73
+ [ optAnchor , setOptAnchor ] = useState < null | HTMLElement > ( null ) ,
74
+ [ visibility , setVisibility ] = useState < TaskVisibility > ( TaskVisibility . Private ) ,
75
+ [ optionsExpanded , setOptionsExpanded ] = useState ( false ) ,
76
+ shrunk = title . length === 0 && content . length === 0 && ! inputFocused ;
77
+
78
+ const handleClose = ( op : TaskVisibility | null = null ) => {
79
+ return ( ) => {
80
+ setOptAnchor ( null ) ;
81
+ if ( op ) setVisibility ( op ) ;
82
+ }
83
+ }
34
84
35
85
return < ClickAwayListener onClickAway = { ( ) => setInputFocused ( false ) } >
36
86
< Container maxWidth = { 'sm' } onClick = { ( ) => setInputFocused ( true ) } >
37
- < Paper variant = { 'outlined' }
38
- sx = { { mx : 'auto' , my : 2 , display : 'flex' , flexDirection : 'column' , borderRadius : 2 } } >
39
- < Collapse in = { ! canShrink } >
87
+ < CreatorContainer variant = { shrunk ? 'outlined' : 'elevation' } >
88
+ < Collapse in = { ! shrunk } >
40
89
< TitleInput placeholder = { 'Title' } onChange = { e => setTitle ( e . target . value ) } value = { title } />
90
+ < Divider sx = { { borderStyle : 'dashed' } } />
41
91
</ Collapse >
42
92
43
93
< StyledAutoresizeTextarea
@@ -46,13 +96,72 @@ export default function TaskCreator() {
46
96
onInput = { e => setContent ( e . currentTarget . value ) }
47
97
/>
48
98
49
- < Collapse in = { ! canShrink } >
50
- < Box px = { 1.4 } pb = { 1.25 } display = { 'flex' } >
99
+ < Collapse in = { ! shrunk } >
100
+ < Collapse in = { optionsExpanded } >
101
+ < Divider sx = { { borderStyle : 'dashed' } } />
102
+ < Box px = { 2 } >
103
+ < Typography variant = { 'overline' } > Options</ Typography >
104
+ </ Box >
105
+ </ Collapse >
106
+
107
+ < Divider sx = { { borderStyle : 'dashed' } } />
108
+
109
+ < Box px = { 1.3 } py = { 1.25 } display = { 'flex' } alignItems = { 'center' } gap = { 1 } >
110
+ < IconButton size = { 'small' } onClick = { ( ) => setOptionsExpanded ( ! optionsExpanded ) } >
111
+ < ExpandMoreRounded sx = { {
112
+ transform : `rotate(${ optionsExpanded ? 180 : 0 } deg)` ,
113
+ transition : t => t . transitions . create ( [ 'transform' ] )
114
+ } } />
115
+ </ IconButton >
116
+ < Grow in = { ! optionsExpanded } >
117
+ < Typography variant = { 'caption' } lineHeight = { '1.2em' } > More options</ Typography >
118
+ </ Grow >
119
+
51
120
< Box flexGrow = { 1 } />
52
- < Button size = { 'small' } > Add</ Button >
121
+
122
+ < ButtonGroup variant = { 'contained' } size = { 'small' } >
123
+ < Button > Add</ Button >
124
+ < Button
125
+ sx = { { pl : .3 , pr : .7 , minWidth : '0!important' } }
126
+ aria-haspopup
127
+ aria-controls = { ! ! optAnchor ? 'add-ops' : undefined }
128
+ onClick = { e => setOptAnchor ( e . currentTarget ) }
129
+ > < ExpandMoreRounded /> </ Button >
130
+ </ ButtonGroup >
131
+ < Menu
132
+ id = { 'add-ops' }
133
+ anchorEl = { optAnchor }
134
+ open = { ! ! optAnchor }
135
+ onClose = { handleClose ( ) }
136
+ MenuListProps = { { 'aria-labelledby' : 'basic-button' , dense : true } }
137
+ anchorOrigin = { { vertical : 'bottom' , horizontal : 'right' } }
138
+ transformOrigin = { { vertical : 'top' , horizontal : 'right' } }
139
+ >
140
+ < MenuHeader > Visibility</ MenuHeader >
141
+ < Divider />
142
+ < MenuItem onClick = { handleClose ( TaskVisibility . Private ) }
143
+ selected = { visibility === TaskVisibility . Private } >
144
+ < ListItemIcon > < PersonRounded /> </ ListItemIcon >
145
+ < ListItemText primary = { 'Private' } secondary = { 'Only visible to you' } />
146
+ </ MenuItem >
147
+ {
148
+ props . isAdmin && < MenuItem onClick = { handleClose ( TaskVisibility . Class ) }
149
+ selected = { visibility === TaskVisibility . Class } >
150
+ < ListItemIcon > < GroupsRounded /> </ ListItemIcon >
151
+ < ListItemText primary = { 'Class' } secondary = { 'Visible to class members' } />
152
+ </ MenuItem >
153
+ }
154
+ {
155
+ props . isSuperAdmin && < MenuItem onClick = { handleClose ( TaskVisibility . Announcement ) }
156
+ selected = { visibility === TaskVisibility . Announcement } >
157
+ < ListItemIcon > < CampaignRounded /> </ ListItemIcon >
158
+ < ListItemText primary = { 'Announcement' } secondary = { '' } />
159
+ </ MenuItem >
160
+ }
161
+ </ Menu >
53
162
</ Box >
54
163
</ Collapse >
55
- </ Paper >
164
+ </ CreatorContainer >
56
165
</ Container >
57
166
</ ClickAwayListener > ;
58
167
}
0 commit comments