|
| 1 | +import * as DropdownMenuPrimitive from '@rn-primitives/dropdown-menu'; |
| 2 | +import React, { ReactNode, useState } from 'react'; |
| 3 | +import { View } from 'react-native'; |
| 4 | + |
| 5 | +import { Atoms, useTheme } from '../theme'; |
| 6 | + |
| 7 | +function DropdownMenuContent({ |
| 8 | + style, |
| 9 | + ...props |
| 10 | +}: DropdownMenuPrimitive.ContentProps & |
| 11 | + React.RefAttributes<DropdownMenuPrimitive.ContentRef>) { |
| 12 | + const { theme } = useTheme(); |
| 13 | + |
| 14 | + return ( |
| 15 | + <DropdownMenuPrimitive.Portal> |
| 16 | + <DropdownMenuPrimitive.Overlay> |
| 17 | + <DropdownMenuPrimitive.Content |
| 18 | + style={(state) => [ |
| 19 | + { borderWidth: 1, borderColor: theme.palette.neutral_50 }, |
| 20 | + Atoms.rounded_lg, |
| 21 | + { minWidth: 256 }, |
| 22 | + //Atoms.outline_none, |
| 23 | + { backgroundColor: theme.palette.neutral_25 }, |
| 24 | + Atoms.overflow_hidden, |
| 25 | + typeof style === 'function' ? style(state) : style, |
| 26 | + ]} |
| 27 | + {...props} |
| 28 | + /> |
| 29 | + </DropdownMenuPrimitive.Overlay> |
| 30 | + </DropdownMenuPrimitive.Portal> |
| 31 | + ); |
| 32 | +} |
| 33 | + |
| 34 | +function DropdownMenuItem({ |
| 35 | + style, |
| 36 | + children, |
| 37 | + ...props |
| 38 | +}: DropdownMenuPrimitive.ItemProps & { children: ReactNode }) { |
| 39 | + const { theme } = useTheme(); |
| 40 | + const [hovered, setHovering] = useState(false); |
| 41 | + |
| 42 | + return ( |
| 43 | + <DropdownMenuPrimitive.Item |
| 44 | + style={{ outline: 'none' }} |
| 45 | + onHoverIn={() => setHovering(true)} |
| 46 | + onHoverOut={() => setHovering(false)} |
| 47 | + {...props} |
| 48 | + > |
| 49 | + <View |
| 50 | + style={[ |
| 51 | + Atoms.py_md, |
| 52 | + Atoms.px_lg, |
| 53 | + hovered && { backgroundColor: theme.palette.neutral_50 }, |
| 54 | + Atoms.flex_row, |
| 55 | + Atoms.align_center, |
| 56 | + Atoms.gap_lg, |
| 57 | + ]} |
| 58 | + > |
| 59 | + {children} |
| 60 | + </View> |
| 61 | + </DropdownMenuPrimitive.Item> |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +function DropdownMenu({ children }: { children: ReactNode }) { |
| 66 | + return <DropdownMenuPrimitive.Root>{children}</DropdownMenuPrimitive.Root>; |
| 67 | +} |
| 68 | +DropdownMenu.Trigger = DropdownMenuPrimitive.Trigger; |
| 69 | +DropdownMenu.Content = DropdownMenuContent; |
| 70 | +DropdownMenu.Item = DropdownMenuItem; |
| 71 | + |
| 72 | +export default DropdownMenu; |
0 commit comments