|
1 | 1 | import React from 'react'; |
2 | | -import BottomNavigation from '@mui/material/BottomNavigation'; |
3 | | -import BottomNavigationAction from '@mui/material/BottomNavigationAction'; |
4 | | -import Plumbing from '@mui/icons-material/Plumbing'; |
5 | | -import Person from '@mui/icons-material/Person'; |
6 | | -import Brush from '@mui/icons-material/Brush'; |
| 2 | + |
| 3 | +import { AutoFixHighOutlined, Person, PestControlOutlined } from '@mui/icons-material'; |
| 4 | +import { BottomNavigation, BottomNavigationAction } from '@mui/material'; |
| 5 | +import { styled } from '@mui/material/styles'; |
| 6 | +import { appColors } from '@root/src/theme/palette'; |
7 | 7 |
|
8 | 8 | interface BottomNavProps { |
9 | 9 | value: string; |
10 | | - tagIsInstalled: boolean; |
11 | 10 | onChange: (newValue: string) => void; |
12 | 11 | } |
13 | 12 |
|
14 | | -const BottomNav: React.FC<BottomNavProps> = ({ value, tagIsInstalled, onChange }) => { |
| 13 | +interface NavigationSection { |
| 14 | + route: string; |
| 15 | + icon: React.ReactElement; |
| 16 | + ariaLabel: string; |
| 17 | +} |
| 18 | + |
| 19 | +const StyledBottomNavigation = styled(BottomNavigation)(({ theme }) => ({ |
| 20 | + position: 'fixed', |
| 21 | + bottom: 0, |
| 22 | + width: '100%', |
| 23 | + height: 'auto', |
| 24 | + display: 'flex', |
| 25 | + justifyContent: 'space-between', |
| 26 | + padding: theme.spacing(1.5, 2), |
| 27 | + cursor: 'default', |
| 28 | + transition: 'none', |
| 29 | + '&:hover': { |
| 30 | + boxShadow: 'none', |
| 31 | + transform: 'none', |
| 32 | + }, |
| 33 | +})); |
| 34 | + |
| 35 | +const StyledBottomNavigationAction = styled(BottomNavigationAction)<{ |
| 36 | + isSelected: boolean; |
| 37 | +}>(({ theme, isSelected }) => ({ |
| 38 | + flex: 'none', |
| 39 | + minWidth: 0, |
| 40 | + paddingBlock: theme.spacing(1.5), |
| 41 | + backgroundColor: isSelected ? appColors.common.colors.accent : 'transparent', |
| 42 | + borderRadius: theme.spacing(0.5), |
| 43 | + transition: 'none', |
| 44 | + '&.Mui-selected': { |
| 45 | + color: appColors.common.white, |
| 46 | + }, |
| 47 | +})); |
| 48 | + |
| 49 | +const navigationSections: NavigationSection[] = [ |
| 50 | + { |
| 51 | + route: '/', |
| 52 | + icon: <PestControlOutlined />, |
| 53 | + ariaLabel: 'Debug', |
| 54 | + }, |
| 55 | + { |
| 56 | + route: '/profile', |
| 57 | + icon: <Person />, |
| 58 | + ariaLabel: 'Profile', |
| 59 | + }, |
| 60 | + { |
| 61 | + route: '/personalization', |
| 62 | + icon: <AutoFixHighOutlined />, |
| 63 | + ariaLabel: 'Personalization', |
| 64 | + }, |
| 65 | +]; |
| 66 | + |
| 67 | +export const BottomNav = ({ value, onChange }: BottomNavProps): JSX.Element => { |
15 | 68 | return ( |
16 | | - <BottomNavigation |
17 | | - showLabels |
18 | | - value={value} |
19 | | - onChange={(_, newValue) => onChange(newValue)} |
20 | | - sx={{ |
21 | | - position: 'fixed', |
22 | | - bottom: 0, |
23 | | - width: '100%', |
24 | | - }}> |
25 | | - <BottomNavigationAction |
26 | | - label="Debugger" |
27 | | - value="/" |
28 | | - icon={<Plumbing />} |
29 | | - sx={{ |
30 | | - '&.Mui-selected': { |
31 | | - color: 'secondary.main', |
32 | | - }, |
33 | | - }} |
34 | | - /> |
35 | | - <BottomNavigationAction |
36 | | - label="Profile" |
37 | | - value="/profile" |
38 | | - disabled={!tagIsInstalled} |
39 | | - icon={<Person />} |
40 | | - sx={{ |
41 | | - '&.Mui-selected': { |
42 | | - color: 'secondary.main', |
43 | | - }, |
44 | | - }} |
45 | | - /> |
46 | | - <BottomNavigationAction |
47 | | - label="Personalization" |
48 | | - value="/personalization" |
49 | | - disabled={!tagIsInstalled} |
50 | | - icon={<Brush />} |
51 | | - sx={{ |
52 | | - '&.Mui-selected': { |
53 | | - color: 'secondary.main', |
54 | | - }, |
55 | | - }} |
56 | | - /> |
57 | | - </BottomNavigation> |
| 69 | + <StyledBottomNavigation value={value} onChange={(_, newValue) => onChange(newValue)}> |
| 70 | + {navigationSections.map(section => { |
| 71 | + const isSelected = value === section.route; |
| 72 | + return ( |
| 73 | + <StyledBottomNavigationAction |
| 74 | + key={section.route} |
| 75 | + value={section.route} |
| 76 | + icon={section.icon} |
| 77 | + isSelected={isSelected} |
| 78 | + aria-label={section.ariaLabel} |
| 79 | + /> |
| 80 | + ); |
| 81 | + })} |
| 82 | + </StyledBottomNavigation> |
58 | 83 | ); |
59 | 84 | }; |
60 | 85 |
|
|
0 commit comments