1- import { PlayCircle , StopCircle } from '@mui/icons-material' ;
1+ import {
2+ BarChart ,
3+ Brush ,
4+ MusicNote ,
5+ MusicOff ,
6+ PlayCircle ,
7+ Refresh ,
8+ StopCircle ,
9+ } from '@mui/icons-material' ;
210import {
311 Toolbar ,
412 Button ,
513 FormControlLabel ,
6- Switch ,
714 Typography ,
815 CircularProgress ,
916 IconButton ,
1017 AppBar ,
18+ useTheme ,
19+ useMediaQuery ,
20+ Checkbox ,
21+ Grid2 ,
22+ ButtonProps ,
1123} from '@mui/material' ;
1224import MenuIcon from '@mui/icons-material/Menu' ;
1325import { AppState , SortSettings , SortValue } from './types' ;
1426
27+ type AppBarButtonProps = {
28+ isCompact : boolean ;
29+ text : string ;
30+ icon : React . ReactElement ;
31+ } & ButtonProps ;
32+
33+ const AppBarButton = ( {
34+ isCompact,
35+ icon,
36+ text,
37+ ...props
38+ } : AppBarButtonProps ) => (
39+ < Button
40+ variant = "contained"
41+ color = "secondary"
42+ disableElevation
43+ startIcon = { ! isCompact ? icon : undefined }
44+ { ...props }
45+ >
46+ { ! isCompact ? text : icon }
47+ </ Button >
48+ ) ;
49+
1550interface AppBarProps {
1651 startSorting : ( arr : SortValue [ ] ) => Promise < void > ;
1752 arr : SortValue [ ] ;
@@ -44,70 +79,78 @@ export function SortAppBar({
4479 shouldPlaySound,
4580 } ,
4681} : AppBarProps ) {
82+ const theme = useTheme ( ) ;
83+ const isSm = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
84+ const isM = useMediaQuery ( theme . breakpoints . down ( 'lg' ) ) ;
85+
86+ const sortIcon = ! isSorting ? < PlayCircle /> : < StopCircle /> ;
87+
4788 return (
4889 < AppBar position = "relative" >
49- < Toolbar className = "toolbar" onClick = { onClick } >
90+ < Toolbar variant = "dense" className = "toolbar" onClick = { onClick } >
5091 < div >
51- < Button
52- variant = "contained"
53- color = "secondary"
92+ < AppBarButton
93+ isCompact = { isM }
94+ text = "Sort"
95+ icon = { sortIcon }
5496 onClick = { ( ) => startSorting ( arr ) }
55- disableElevation
56- startIcon = { ! isSorting ? < PlayCircle /> : < StopCircle /> }
57- >
58- Sort
59- </ Button >
97+ />
6098 </ div >
6199 < div >
62- < Button
63- variant = "contained"
64- color = "secondary"
100+ < AppBarButton
101+ isCompact = { isM }
102+ text = "Shuffle"
103+ icon = { < BarChart /> }
65104 onClick = { shuffleAndRedraw }
66- disableElevation
67- >
68- Shuffle
69- </ Button >
105+ />
70106 </ div >
71107 < div >
72- < Button
73- variant = "contained"
74- color = "secondary"
108+ < AppBarButton
109+ isCompact = { isM }
110+ text = "Reset"
111+ icon = { < Refresh /> }
75112 onClick = { resetAndDraw }
76- disableElevation
77- >
78- Reset
79- </ Button >
113+ />
80114 </ div >
81- < div >
115+ < Grid2
116+ container
117+ direction = "row"
118+ sx = { { flexWrap : 'nowrap' , alignItems : 'center' , flexShrink : 0 } }
119+ >
82120 < FormControlLabel
83121 control = {
84- < Switch
122+ < Checkbox
85123 checked = { canDraw }
86124 onChange = { toggleCanDraw }
87125 name = "canDraw"
88126 color = "secondary"
127+ icon = { < Brush /> }
128+ checkedIcon = { < Brush /> }
89129 />
90130 }
91- sx = { { marginRight : '0px' } }
92- label = "Draw Mode"
131+ sx = { { marginRight : isSm ? '0px' : undefined , marginLeft : '0px' } }
132+ label = { ! isSm ? 'Draw Mode' : '' }
133+ slotProps = { { typography : { whiteSpace : 'nowrap' } } }
93134 />
94- </ div >
95- < div >
96135 < FormControlLabel
97136 control = {
98- < Switch
137+ < Checkbox
99138 checked = { shouldPlaySound }
100139 onChange = { togglePlaySound }
101140 name = "shouldPlaySound"
102141 color = "secondary"
142+ icon = { < MusicOff /> }
143+ checkedIcon = { < MusicNote /> }
103144 />
104145 }
105- label = "Play Sound"
146+ sx = { { marginRight : isSm ? '0px' : undefined , marginLeft : '0px' } }
147+ label = { ! isSm ? 'Play Sound' : '' }
148+ slotProps = { { typography : { whiteSpace : 'nowrap' } } }
106149 />
107- </ div >
150+ </ Grid2 >
108151 < div >
109- < Typography className = "counter" align = "left" color = "white" >
110- Swaps:{ ' ' }
152+ < Typography className = "counter" align = "left" color = "white" noWrap >
153+ { ! isM ? ' Swaps:' : 'S:' } { ' ' }
111154 { swapTime || ! isSorting ? (
112155 nbrOfSwaps
113156 ) : (
@@ -121,8 +164,8 @@ export function SortAppBar({
121164 </ Typography >
122165 </ div >
123166 < div >
124- < Typography className = "counter" align = "left" color = "white" >
125- Comparisons:{ ' ' }
167+ < Typography className = "counter" align = "left" color = "white" noWrap >
168+ { ! isM ? ' Comparisons:' : 'C:' } { ' ' }
126169 { compareTime || ! isSorting ? (
127170 nbrOfComparisons
128171 ) : (
@@ -136,8 +179,8 @@ export function SortAppBar({
136179 </ Typography >
137180 </ div >
138181 < div >
139- < Typography className = "counter" align = "left" color = "white" >
140- Aux. writes:{ ' ' }
182+ < Typography className = "counter" align = "left" color = "white" noWrap >
183+ { ! isM ? ' Aux. writes:' : 'AW:' } { ' ' }
141184 { auxWriteTime || ! isSorting ? (
142185 nbrOfAuxWrites
143186 ) : (
0 commit comments