|
1 | | -import { AppBar, AppBarProps, Collapse, Drawer, List, ListItemButton, ListItemIcon, ListItemText, Paper, Stack, Theme, Toolbar, Typography, useTheme } from '@mui/material'; |
| 1 | +import { AppBar, AppBarProps, Drawer, List, Stack, Toolbar } from '@mui/material'; |
2 | 2 | import useMediaQuery from '@mui/material/useMediaQuery'; |
3 | | -import { PropsWithChildren, ReactNode, createContext, useContext } from 'react'; |
| 3 | +import { ReactNode } from 'react'; |
4 | 4 | import { useControllableState } from '@enterwell/react-hooks'; |
5 | | -import { AddOutlined, RemoveOutlined } from '@mui/icons-material'; |
6 | | - |
7 | | -const itemOpacity = 0.7; |
8 | | -const itemHoverOpacity = 0.9; |
9 | | - |
10 | | -function itemBackgroundImageHighlight(theme: Theme, amount = 0.05) { |
11 | | - return theme.palette.mode === "dark" |
12 | | - ? `linear-gradient(180deg, rgba(255,255,255,${amount}) 0%, rgba(255,255,255,${amount}) 100%)` |
13 | | - : `linear-gradient(180deg, rgba(0,0,0,${amount}) 0%, rgba(0,0,0,${amount}) 100%)`; |
14 | | -} |
15 | 5 |
|
16 | 6 | /** |
17 | 7 | * The props for the SideNav component |
@@ -42,8 +32,7 @@ export type SideNavProps = AppBarProps & { |
42 | 32 | */ |
43 | 33 | export function SideNav({ children, sx, width = 230, headerHeight = 65, header, endAdorner, ...rest }: SideNavProps) { |
44 | 34 | const [navOpen, setNavOpen] = useControllableState(false); |
45 | | - const theme = useTheme(); |
46 | | - const isMobile = useMediaQuery(theme.breakpoints.down('md')); |
| 35 | + const isMobile = useMediaQuery((theme) => theme.breakpoints.down('md')); |
47 | 36 |
|
48 | 37 | const handleClose = () => setNavOpen(false); |
49 | 38 |
|
@@ -118,158 +107,3 @@ export function SideNav({ children, sx, width = 230, headerHeight = 65, header, |
118 | 107 | </> |
119 | 108 | ); |
120 | 109 | }; |
121 | | - |
122 | | -/** |
123 | | - * The SideNavItemGroup component props. |
124 | | - * @public |
125 | | - */ |
126 | | -type SideNavItemGroupProps = PropsWithChildren<{ |
127 | | - label: string; |
128 | | - expanded?: boolean; |
129 | | - defaultExpanded?: boolean; |
130 | | -}>; |
131 | | - |
132 | | -const SideNavItemGroupContext = createContext({ inGroup: false }); |
133 | | - |
134 | | -/** |
135 | | - * The SideNavItemGroup component. |
136 | | - * |
137 | | - * @param props - The component props. |
138 | | - * @returns The react function component. |
139 | | - * @public |
140 | | - */ |
141 | | -export function SideNavItemGroup({ children, label, expanded: controlledExpanded, defaultExpanded }: SideNavItemGroupProps) { |
142 | | - const [expanded, setExpanded] = useControllableState(controlledExpanded, defaultExpanded ?? false); |
143 | | - const handleToggleExpand = () => setExpanded(!expanded); |
144 | | - const theme = useTheme(); |
145 | | - |
146 | | - const contextValue = { |
147 | | - inGroup: true |
148 | | - }; |
149 | | - |
150 | | - return ( |
151 | | - <> |
152 | | - <ListItemButton |
153 | | - sx={{ |
154 | | - alignItems: 'center', |
155 | | - justifyContent: 'space-between', |
156 | | - padding: '12px 10px', |
157 | | - fontWeight: 600, |
158 | | - opacity: itemOpacity, |
159 | | - '&:hover': { |
160 | | - bgcolor: 'transparent', |
161 | | - opacity: itemHoverOpacity |
162 | | - } |
163 | | - }} |
164 | | - onClick={handleToggleExpand} |
165 | | - > |
166 | | - <ListItemText> |
167 | | - <Typography variant='body2' textTransform="uppercase" fontWeight={600}> |
168 | | - {label} |
169 | | - </Typography> |
170 | | - </ListItemText> |
171 | | - {expanded |
172 | | - ? ( |
173 | | - <RemoveOutlined |
174 | | - color="primary" |
175 | | - sx={{ fontSize: 20 }} |
176 | | - /> |
177 | | - ) : ( |
178 | | - <AddOutlined |
179 | | - color="primary" |
180 | | - sx={{ fontSize: 20 }} |
181 | | - /> |
182 | | - )} |
183 | | - </ListItemButton> |
184 | | - <Collapse |
185 | | - in={expanded} |
186 | | - sx={{ width: '100%' }} |
187 | | - > |
188 | | - <SideNavItemGroupContext.Provider value={contextValue}> |
189 | | - <List |
190 | | - disablePadding |
191 | | - sx={{ |
192 | | - backgroundImage: itemBackgroundImageHighlight(theme), |
193 | | - borderRadius: '4px' |
194 | | - }} |
195 | | - > |
196 | | - {children} |
197 | | - </List> |
198 | | - </SideNavItemGroupContext.Provider> |
199 | | - </Collapse> |
200 | | - </> |
201 | | - ); |
202 | | -} |
203 | | - |
204 | | -/** |
205 | | - * The SideNavItem component props. |
206 | | - * @public |
207 | | - */ |
208 | | -export type SideNavItemProps = PropsWithChildren<{ |
209 | | - href: string; |
210 | | - icon?: ReactNode; |
211 | | - selected?: boolean; |
212 | | -}>; |
213 | | - |
214 | | -/** |
215 | | - * The SideNavItem component |
216 | | - * @param props - The component props |
217 | | - * @returns The react function component. |
218 | | - * @public |
219 | | - */ |
220 | | -export function SideNavItem({ children, href, selected, icon }: SideNavItemProps) { |
221 | | - const groupContext = useContext(SideNavItemGroupContext); |
222 | | - const child = groupContext?.inGroup; |
223 | | - const theme = useTheme(); |
224 | | - |
225 | | - return ( |
226 | | - <ListItemButton |
227 | | - href={href} |
228 | | - selected={selected} |
229 | | - sx={{ |
230 | | - paddingX: 1.25, |
231 | | - paddingY: 1.5, |
232 | | - borderRadius: 1, |
233 | | - fontWeight: 600, |
234 | | - gap: 1, |
235 | | - "&.Mui-selected": { |
236 | | - color: 'primary.main', |
237 | | - fill: 'primary.main', |
238 | | - backgroundColor: 'transparent', |
239 | | - backgroundImage: child && selected ? itemBackgroundImageHighlight(theme) : 'none', |
240 | | - "&:hover": { |
241 | | - backgroundColor: 'transparent', |
242 | | - backgroundImage: child ? itemBackgroundImageHighlight(theme) : 'none', |
243 | | - } |
244 | | - }, |
245 | | - opacity: child ? itemHoverOpacity : itemOpacity, |
246 | | - ':hover': { |
247 | | - opacity: itemHoverOpacity, |
248 | | - backgroundColor: child ? itemBackgroundImageHighlight(theme) : 'transparent' |
249 | | - } |
250 | | - }}> |
251 | | - {icon && ( |
252 | | - <ListItemIcon |
253 | | - sx={{ |
254 | | - minWidth: 'auto', |
255 | | - // '& > svg': { fill: selected ? 'primaryBase' : 'white' } |
256 | | - }} |
257 | | - > |
258 | | - {icon} |
259 | | - </ListItemIcon> |
260 | | - )} |
261 | | - <ListItemText> |
262 | | - <Typography |
263 | | - variant='body2' |
264 | | - textTransform="uppercase" |
265 | | - fontWeight={600} |
266 | | - sx={{ |
267 | | - // color: child && !selected ? whiteBase : 'inherit' |
268 | | - }} |
269 | | - > |
270 | | - {children} |
271 | | - </Typography> |
272 | | - </ListItemText> |
273 | | - </ListItemButton> |
274 | | - ); |
275 | | -}; |
0 commit comments