|
| 1 | +import { |
| 2 | + ActionIcon, |
| 3 | + Box, |
| 4 | + Code, |
| 5 | + Group, |
| 6 | + Text, |
| 7 | + TextInput, |
| 8 | + Tooltip, |
| 9 | + UnstyledButton, |
| 10 | + rem, |
| 11 | + MantineTheme, |
| 12 | +} from '@mantine/core'; |
| 13 | + |
| 14 | +const collections = [ |
| 15 | + { emoji: '👍', label: 'Sales' }, |
| 16 | + { emoji: '🚚', label: 'Deliveries' }, |
| 17 | + { emoji: '💸', label: 'Discounts' }, |
| 18 | + { emoji: '💰', label: 'Profits' }, |
| 19 | + { emoji: '✨', label: 'Reports' }, |
| 20 | + { emoji: '🛒', label: 'Orders' }, |
| 21 | + { emoji: '📅', label: 'Events' }, |
| 22 | + { emoji: '🙈', label: 'Debts' }, |
| 23 | + { emoji: '💁♀️', label: 'Customers' }, |
| 24 | +]; |
| 25 | + |
| 26 | +// --- Sub-component: UserButton --- |
| 27 | +function UserButton() { |
| 28 | + return ( |
| 29 | + <UnstyledButton |
| 30 | + p="md" |
| 31 | + style={(theme: MantineTheme) => ({ |
| 32 | + display: 'block', |
| 33 | + width: '100%', |
| 34 | + borderRadius: theme.radius.sm, |
| 35 | + })} |
| 36 | + > |
| 37 | + <Group> |
| 38 | + <Box style={{ flex: 1 }}> |
| 39 | + <Text size="sm" fw={500}> |
| 40 | + Rohit Handique |
| 41 | + </Text> |
| 42 | + <Text c="dimmed" size="xs"> |
| 43 | + rohit.handique@gmail.com |
| 44 | + </Text> |
| 45 | + </Box> |
| 46 | + </Group> |
| 47 | + </UnstyledButton> |
| 48 | + ); |
| 49 | +} |
| 50 | + |
| 51 | +// --- Main Component --- |
| 52 | +export function Sidebar() { |
| 53 | + const collectionLinks = collections.map((collection) => ( |
| 54 | + <Box |
| 55 | + component="a" |
| 56 | + href="#" |
| 57 | + key={collection.label} |
| 58 | + onClick={(event) => event.preventDefault()} |
| 59 | + style={(theme: MantineTheme) => ({ |
| 60 | + display: 'block', |
| 61 | + padding: `${rem(8)} ${theme.spacing.xs}`, |
| 62 | + textDecoration: 'none', |
| 63 | + borderRadius: theme.radius.sm, |
| 64 | + fontSize: theme.fontSizes.xs, |
| 65 | + lineHeight: 1, |
| 66 | + fontWeight: 500, |
| 67 | + color: |
| 68 | + 'light-dark(var(--mantine-color-gray-7), var(--mantine-color-dark-0))', |
| 69 | + })} |
| 70 | + > |
| 71 | + <Box component="span" mr={9} fz={16}> |
| 72 | + {collection.emoji} |
| 73 | + </Box> |
| 74 | + {collection.label} |
| 75 | + </Box> |
| 76 | + )); |
| 77 | + |
| 78 | + return ( |
| 79 | + <Box |
| 80 | + component="nav" |
| 81 | + style={(theme: MantineTheme) => ({ |
| 82 | + backgroundColor: 'var(--mantine-color-body)', |
| 83 | + height: '100%', |
| 84 | + width: rem(300), |
| 85 | + padding: theme.spacing.md, |
| 86 | + display: 'flex', |
| 87 | + flexDirection: 'column', |
| 88 | + borderRight: `1px solid light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4))`, |
| 89 | + })} |
| 90 | + > |
| 91 | + <Box style={{ height: `calc(100vh - ${rem(140)})` }}> |
| 92 | + <TextInput |
| 93 | + placeholder="Search" |
| 94 | + size="xs" |
| 95 | + rightSectionWidth={70} |
| 96 | + rightSection={ |
| 97 | + <Code style={{ fontSize: rem(10), fontWeight: 700 }}>Ctrl + K</Code> |
| 98 | + } |
| 99 | + styles={{ section: { pointerEvents: 'none' } }} |
| 100 | + mb="sm" |
| 101 | + /> |
| 102 | + |
| 103 | + <Box |
| 104 | + pt="md" |
| 105 | + style={{ |
| 106 | + borderTop: |
| 107 | + '1px solid light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4))', |
| 108 | + }} |
| 109 | + > |
| 110 | + <Group justify="space-between" mb={5} px="xs"> |
| 111 | + <Text size="xs" fw={500} c="dimmed"> |
| 112 | + Collections |
| 113 | + </Text> |
| 114 | + <Tooltip label="Create collection" withArrow position="right"> |
| 115 | + <ActionIcon variant="default" size={18}></ActionIcon> |
| 116 | + </Tooltip> |
| 117 | + </Group> |
| 118 | + <Box>{collectionLinks}</Box> |
| 119 | + </Box> |
| 120 | + </Box> |
| 121 | + <Box |
| 122 | + mx={`calc(var(--mantine-spacing-md) * -1)`} |
| 123 | + mb="md" |
| 124 | + style={{ |
| 125 | + borderTop: |
| 126 | + '1px solid light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4))', |
| 127 | + }} |
| 128 | + h={rem(70)} |
| 129 | + > |
| 130 | + <UserButton /> |
| 131 | + </Box> |
| 132 | + </Box> |
| 133 | + ); |
| 134 | +} |
0 commit comments