|
| 1 | +import { ChevronLeft } from 'lucide-react'; |
| 2 | +import { CSSProperties, ReactNode, memo } from 'react'; |
| 3 | +import { Flexbox } from 'react-layout-kit'; |
| 4 | + |
| 5 | +import ActionIcon from '@/ActionIcon'; |
| 6 | +import MobileSafeArea from '@/MobileSafeArea'; |
| 7 | + |
| 8 | +import { useStyles } from './style'; |
| 9 | + |
| 10 | +export interface MobileNavBarProps { |
| 11 | + center?: ReactNode; |
| 12 | + className?: string; |
| 13 | + classNames?: { |
| 14 | + center?: string; |
| 15 | + left?: string; |
| 16 | + right?: string; |
| 17 | + }; |
| 18 | + contentStyles?: { |
| 19 | + center?: CSSProperties; |
| 20 | + left?: CSSProperties; |
| 21 | + right?: CSSProperties; |
| 22 | + }; |
| 23 | + gap?: { |
| 24 | + center?: number; |
| 25 | + left?: number; |
| 26 | + right?: number; |
| 27 | + }; |
| 28 | + left?: ReactNode; |
| 29 | + onBackClick?: () => void; |
| 30 | + right?: ReactNode; |
| 31 | + safeArea?: boolean; |
| 32 | + showBackButton?: boolean; |
| 33 | + style?: CSSProperties; |
| 34 | +} |
| 35 | + |
| 36 | +const MobileNavBar = memo<MobileNavBarProps>( |
| 37 | + ({ |
| 38 | + className, |
| 39 | + safeArea = true, |
| 40 | + style, |
| 41 | + center, |
| 42 | + left, |
| 43 | + right, |
| 44 | + gap, |
| 45 | + classNames, |
| 46 | + onBackClick, |
| 47 | + showBackButton, |
| 48 | + contentStyles, |
| 49 | + }) => { |
| 50 | + const { styles, cx } = useStyles(); |
| 51 | + |
| 52 | + return ( |
| 53 | + <Flexbox className={cx(styles.container, className)} style={style}> |
| 54 | + {safeArea && <MobileSafeArea position={'bottom'} />} |
| 55 | + <Flexbox |
| 56 | + align={'center'} |
| 57 | + className={styles.inner} |
| 58 | + flex={1} |
| 59 | + horizontal |
| 60 | + justify={'space-between'} |
| 61 | + > |
| 62 | + <Flexbox |
| 63 | + align={'center'} |
| 64 | + className={cx(styles.left, classNames?.left)} |
| 65 | + flex={1} |
| 66 | + gap={gap?.left} |
| 67 | + horizontal |
| 68 | + style={contentStyles?.left} |
| 69 | + > |
| 70 | + {showBackButton && ( |
| 71 | + <ActionIcon |
| 72 | + icon={ChevronLeft} |
| 73 | + onClick={() => onBackClick?.()} |
| 74 | + size={{ fontSize: 24 }} |
| 75 | + /> |
| 76 | + )} |
| 77 | + {left} |
| 78 | + </Flexbox> |
| 79 | + <Flexbox |
| 80 | + align={'center'} |
| 81 | + className={cx(styles.center, classNames?.center)} |
| 82 | + flex={1} |
| 83 | + gap={gap?.center} |
| 84 | + horizontal |
| 85 | + justify={'center'} |
| 86 | + style={contentStyles?.center} |
| 87 | + > |
| 88 | + {center} |
| 89 | + </Flexbox> |
| 90 | + <Flexbox |
| 91 | + align={'center'} |
| 92 | + className={cx(styles.right, classNames?.right)} |
| 93 | + flex={1} |
| 94 | + gap={gap?.right} |
| 95 | + horizontal |
| 96 | + style={contentStyles?.right} |
| 97 | + > |
| 98 | + {right} |
| 99 | + </Flexbox> |
| 100 | + </Flexbox> |
| 101 | + </Flexbox> |
| 102 | + ); |
| 103 | + }, |
| 104 | +); |
| 105 | + |
| 106 | +export default MobileNavBar; |
0 commit comments