-
Notifications
You must be signed in to change notification settings - Fork 21
feat(admin-ui): implement bottom navigation bar for the mobile view (#2917) #2918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
admin-ui/app/components/MobileBottomNav/MobileBottomNav.style.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { makeStyles } from 'tss-react/mui' | ||
| import { hexToRgb } from '@/customColors' | ||
| import { fontFamily, fontWeights, fontSizes } from '@/styles/fonts' | ||
| import { BOTTOM_NAV } from './constants' | ||
| import { SHEET } from './sheetConstants' | ||
| import type { MobileBottomNavThemeColors } from './types' | ||
|
|
||
| const useStyles = makeStyles<{ colors: MobileBottomNavThemeColors }>()((_theme, { colors }) => ({ | ||
| root: { | ||
| position: 'fixed', | ||
| left: 0, | ||
| right: 0, | ||
| bottom: 0, | ||
| zIndex: BOTTOM_NAV.Z_ROOT, | ||
| display: 'flex', | ||
| alignItems: 'stretch', | ||
| height: BOTTOM_NAV.HEIGHT, | ||
| padding: `0 ${BOTTOM_NAV.PADDING_X}px`, | ||
| backgroundColor: colors.background, | ||
| borderTop: `1px solid ${colors.border}`, | ||
| boxShadow: `0px ${BOTTOM_NAV.SHADOW_OFFSET_Y}px ${BOTTOM_NAV.SHADOW_BLUR}px 0px rgba(${hexToRgb(colors.shadow)}, ${BOTTOM_NAV.SHADOW_OPACITY})`, | ||
| paddingBottom: 'env(safe-area-inset-bottom)', | ||
| boxSizing: 'border-box', | ||
| }, | ||
| rootElevated: { | ||
| zIndex: SHEET.Z_BAR_ELEVATED, | ||
| boxShadow: 'none', | ||
| }, | ||
| tab: { | ||
| flex: 1, | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| gap: BOTTOM_NAV.TAB_GAP, | ||
| minWidth: 0, | ||
| padding: 0, | ||
| border: 'none', | ||
| background: 'transparent', | ||
| cursor: 'pointer', | ||
| position: 'relative', | ||
| color: colors.inactive, | ||
| minHeight: BOTTOM_NAV.TAB_MIN_HEIGHT, | ||
| }, | ||
| tabActive: { | ||
| color: colors.active, | ||
| }, | ||
| iconWrap: { | ||
| 'display': 'flex', | ||
| 'alignItems': 'center', | ||
| 'justifyContent': 'center', | ||
| 'width': BOTTOM_NAV.ICON_SIZE, | ||
| 'height': BOTTOM_NAV.ICON_SIZE, | ||
| '& svg': { | ||
| width: BOTTOM_NAV.ICON_SIZE, | ||
| height: BOTTOM_NAV.ICON_SIZE, | ||
| }, | ||
| }, | ||
| label: { | ||
| fontFamily, | ||
| fontSize: fontSizes.xs, | ||
| fontWeight: fontWeights.medium, | ||
| lineHeight: 1, | ||
| whiteSpace: 'nowrap', | ||
| overflow: 'hidden', | ||
| textOverflow: 'ellipsis', | ||
| maxWidth: '100%', | ||
| }, | ||
| activeIndicator: { | ||
| position: 'absolute', | ||
| bottom: 0, | ||
| width: BOTTOM_NAV.ACTIVE_INDICATOR_WIDTH, | ||
| height: BOTTOM_NAV.ACTIVE_INDICATOR_HEIGHT, | ||
| borderRadius: BOTTOM_NAV.ACTIVE_INDICATOR_HEIGHT, | ||
| backgroundColor: colors.active, | ||
| }, | ||
| })) | ||
|
|
||
| export { useStyles } |
123 changes: 123 additions & 0 deletions
123
admin-ui/app/components/MobileBottomNav/MobileBottomNav.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { useCallback, useMemo, useState, type JSX } from 'react' | ||
| import { useTranslation } from 'react-i18next' | ||
| import { useLocation } from 'react-router-dom' | ||
| import useMediaQuery from '@mui/material/useMediaQuery' | ||
| import MoreVertIcon from '@mui/icons-material/MoreVert' | ||
| import { useAppNavigation } from '@/helpers/navigation' | ||
| import customColors from '@/customColors' | ||
| import { useTheme } from '@/context/theme/themeContext' | ||
| import getThemeColor from '@/context/theme/config' | ||
| import { THEME_LIGHT } from '@/context/theme/constants' | ||
| import { useStyles } from './MobileBottomNav.style' | ||
| import { MOBILE_MEDIA_QUERY, PRIMARY_TAB_DEFS, MORE_TAB_KEY } from './constants' | ||
| import MobileNavSheet from './MobileNavSheet' | ||
| import { PRIMARY_ICON_BY_KEY } from './sheetIcons' | ||
| import { isMoreMenuPath, type SheetItem, type SheetKey } from './sheetConstants' | ||
| import type { MobileNavTab, MobileBottomNavThemeColors } from './types' | ||
|
|
||
| const MobileBottomNav = (): JSX.Element | null => { | ||
| const isMobile = useMediaQuery(MOBILE_MEDIA_QUERY) | ||
| const { t } = useTranslation() | ||
| const { navigateToRoute } = useAppNavigation() | ||
| const location = useLocation() | ||
| const { state } = useTheme() | ||
| const [openSheet, setOpenSheet] = useState<SheetKey | null>(null) | ||
|
|
||
| const themeColors = useMemo((): MobileBottomNavThemeColors => { | ||
| const isLight = state.theme === THEME_LIGHT | ||
| const theme = getThemeColor(state.theme) | ||
| return { | ||
| background: isLight ? customColors.white : theme.navbar.background, | ||
| shadow: customColors.black, | ||
| border: theme.navbar.border, | ||
| active: customColors.mobileNavActive, | ||
| inactive: isLight ? customColors.mobileNavInactiveLight : customColors.mobileNavInactiveDark, | ||
| } | ||
| }, [state.theme]) | ||
|
|
||
| const { classes, cx } = useStyles({ colors: themeColors }) | ||
|
|
||
| const tabs = useMemo((): MobileNavTab[] => { | ||
| const primary: MobileNavTab[] = PRIMARY_TAB_DEFS.map((def) => ({ | ||
| key: def.key, | ||
| titleKey: def.titleKey, | ||
| path: def.path, | ||
| basePath: def.basePath, | ||
| directNav: 'directNav' in def ? def.directNav : undefined, | ||
| icon: PRIMARY_ICON_BY_KEY[def.iconKey], | ||
| })) | ||
| return [ | ||
| ...primary, | ||
| { | ||
| key: MORE_TAB_KEY, | ||
| titleKey: 'menus.more', | ||
| isMore: true, | ||
| icon: <MoreVertIcon />, | ||
| }, | ||
| ] | ||
| }, []) | ||
|
|
||
| const isTabActive = (tab: MobileNavTab): boolean => { | ||
| if (openSheet) return openSheet === tab.key | ||
| if (isMoreMenuPath(location.pathname)) return tab.isMore === true | ||
| if (tab.isMore) return false | ||
| const matchPath = tab.basePath ?? tab.path | ||
| if (!matchPath) return false | ||
| return location.pathname === matchPath || location.pathname.startsWith(`${matchPath}/`) | ||
| } | ||
|
|
||
| const handleTabClick = (tab: MobileNavTab): void => { | ||
| if (tab.directNav && tab.path) { | ||
| setOpenSheet(null) | ||
| navigateToRoute(tab.path) | ||
| return | ||
| } | ||
| setOpenSheet((current) => (current === tab.key ? null : (tab.key as SheetKey))) | ||
| } | ||
|
|
||
| const handleSheetClose = useCallback((): void => { | ||
| setOpenSheet(null) | ||
| }, []) | ||
|
|
||
| const handleSheetSelect = useCallback( | ||
| (item: SheetItem): void => { | ||
| if (!item.path) return | ||
| setOpenSheet(null) | ||
| navigateToRoute(item.path) | ||
| }, | ||
| [navigateToRoute], | ||
| ) | ||
|
|
||
| if (!isMobile) return null | ||
|
|
||
| return ( | ||
| <> | ||
| <nav | ||
| className={cx(classes.root, openSheet && classes.rootElevated)} | ||
| aria-label={t('menus.mobileNavigation')} | ||
| data-testid="mobile-bottom-nav" | ||
| > | ||
|
faisalsiddique4400 marked this conversation as resolved.
|
||
| {tabs.map((tab) => { | ||
| const active = isTabActive(tab) | ||
| return ( | ||
| <button | ||
| key={tab.key} | ||
| type="button" | ||
| className={cx(classes.tab, active && classes.tabActive)} | ||
| aria-current={active ? 'page' : undefined} | ||
| aria-label={t(tab.titleKey)} | ||
| onClick={() => handleTabClick(tab)} | ||
| > | ||
| <span className={classes.iconWrap}>{tab.icon}</span> | ||
| <span className={classes.label}>{t(tab.titleKey)}</span> | ||
| {active ? <span className={classes.activeIndicator} /> : null} | ||
| </button> | ||
| ) | ||
| })} | ||
| </nav> | ||
| <MobileNavSheet openKey={openSheet} onClose={handleSheetClose} onSelect={handleSheetSelect} /> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default MobileBottomNav | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.