import * as DropdownMenuPrimitive from '@rn-primitives/dropdown-menu';
import * as React from 'react';
import { Check } from '~/lib/icons/Check';
import { ChevronDown } from '~/lib/icons/ChevronDown';
import { ChevronRight } from '~/lib/icons/ChevronRight';
import { ChevronUp } from '~/lib/icons/ChevronUp';
import { cn } from '~/lib/utils';
import { TextClassContext } from '~/components/ui/text';
const DropdownMenu = DropdownMenuPrimitive.Root;
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
const DropdownMenuGroup = DropdownMenuPrimitive.Group;
const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
const DropdownMenuSub = DropdownMenuPrimitive.Sub;
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
const DropdownMenuSubTrigger = React.forwardRef<
DropdownMenuPrimitive.SubTriggerRef,
DropdownMenuPrimitive.SubTriggerProps & {
>(({ className, inset, children, ...props }, ref) => {
const { open } = DropdownMenuPrimitive.useSubContext();
const Icon = Platform.OS === 'web' ? ChevronRight : open ? ChevronUp : ChevronDown;
<TextClassContext.Provider
'select-none text-sm native:text-lg text-primary',
open && 'native:text-accent-foreground'
<DropdownMenuPrimitive.SubTrigger
'flex flex-row web:cursor-default web:select-none gap-2 items-center web:focus:bg-accent web:hover:bg-accent active:bg-accent rounded-sm px-2 py-1.5 native:py-2 web:outline-none',
<Icon size={18} className='ml-auto text-foreground' />
</DropdownMenuPrimitive.SubTrigger>
</TextClassContext.Provider>
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;
const DropdownMenuSubContent = React.forwardRef<
DropdownMenuPrimitive.SubContentRef,
DropdownMenuPrimitive.SubContentProps
>(({ className, ...props }, ref) => {
const { open } = DropdownMenuPrimitive.useSubContext();
<DropdownMenuPrimitive.SubContent
'z-50 min-w-[8rem] overflow-hidden rounded-md border border-border mt-1 bg-popover p-1 shadow-md shadow-foreground/5 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
? 'web:animate-in web:fade-in-0 web:zoom-in-95'
: 'web:animate-out web:fade-out-0 web:zoom-out ',
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;
const DropdownMenuContent = React.forwardRef<
DropdownMenuPrimitive.ContentRef,
DropdownMenuPrimitive.ContentProps & {
overlayStyle?: StyleProp<ViewStyle>;
overlayClassName?: string;
>(({ className, overlayClassName, overlayStyle, portalHost, ...props }, ref) => {
const { open } = DropdownMenuPrimitive.useRootContext();
<DropdownMenuPrimitive.Portal hostName={portalHost}>
<DropdownMenuPrimitive.Overlay
Platform.OS !== 'web' ? StyleSheet.absoluteFill : undefined,
? StyleSheet.absoluteFill
className={overlayClassName}
<DropdownMenuPrimitive.Content
'z-50 min-w-[8rem] overflow-hidden rounded-md border border-border bg-popover p-1 shadow-md shadow-foreground/5 web:data-[side=bottom]:slide-in-from-top-2 web:data-[side=left]:slide-in-from-right-2 web:data-[side=right]:slide-in-from-left-2 web:data-[side=top]:slide-in-from-bottom-2',
? 'web:animate-in web:fade-in-0 web:zoom-in-95'
: 'web:animate-out web:fade-out-0 web:zoom-out-95',
</DropdownMenuPrimitive.Overlay>
</DropdownMenuPrimitive.Portal>
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
const DropdownMenuItem = React.forwardRef<
DropdownMenuPrimitive.ItemRef,
DropdownMenuPrimitive.ItemProps & {
>(({ className, inset, ...props }, ref) => (
<TextClassContext.Provider value='select-none text-sm native:text-lg text-popover-foreground web:group-focus:text-accent-foreground'>
<DropdownMenuPrimitive.Item
'relative flex flex-row web:cursor-default gap-2 items-center rounded-sm px-2 py-1.5 native:py-2 web:outline-none web:focus:bg-accent active:bg-accent web:hover:bg-accent group',
props.disabled && 'opacity-50 web:pointer-events-none',
</TextClassContext.Provider>
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
const DropdownMenuCheckboxItem = React.forwardRef<
DropdownMenuPrimitive.CheckboxItemRef,
DropdownMenuPrimitive.CheckboxItemProps
>(({ className, children, checked, ...props }, ref) => (
<DropdownMenuPrimitive.CheckboxItem
'relative flex flex-row web:cursor-default items-center web:group rounded-sm py-1.5 native:py-2 pl-8 pr-2 web:outline-none web:focus:bg-accent active:bg-accent',
props.disabled && 'web:pointer-events-none opacity-50',
<View className='absolute left-2 flex h-3.5 w-3.5 items-center justify-center'>
<DropdownMenuPrimitive.ItemIndicator>
<Check size={14} strokeWidth={3} className='text-foreground' />
</DropdownMenuPrimitive.ItemIndicator>
</DropdownMenuPrimitive.CheckboxItem>
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;
const DropdownMenuRadioItem = React.forwardRef<
DropdownMenuPrimitive.RadioItemRef,
DropdownMenuPrimitive.RadioItemProps
>(({ className, children, ...props }, ref) => (
<DropdownMenuPrimitive.RadioItem
'relative flex flex-row web:cursor-default web:group items-center rounded-sm py-1.5 native:py-2 pl-8 pr-2 web:outline-none web:focus:bg-accent active:bg-accent',
props.disabled && 'web:pointer-events-none opacity-50',
<View className='absolute left-2 flex h-3.5 w-3.5 items-center justify-center'>
<DropdownMenuPrimitive.ItemIndicator>
<View className='bg-foreground h-2 w-2 rounded-full' />
</DropdownMenuPrimitive.ItemIndicator>
</DropdownMenuPrimitive.RadioItem>
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
const DropdownMenuLabel = React.forwardRef<
DropdownMenuPrimitive.LabelRef,
DropdownMenuPrimitive.LabelProps & {
>(({ className, inset, ...props }, ref) => (
<DropdownMenuPrimitive.Label
'px-2 py-1.5 text-sm native:text-base font-semibold text-foreground web:cursor-default',
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
const DropdownMenuSeparator = React.forwardRef<
DropdownMenuPrimitive.SeparatorRef,
DropdownMenuPrimitive.SeparatorProps
>(({ className, ...props }, ref) => (
<DropdownMenuPrimitive.Separator
className={cn('-mx-1 my-1 h-px bg-border', className)}
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
const DropdownMenuShortcut = ({ className, ...props }: TextProps) => {
'ml-auto text-xs native:text-sm tracking-widest text-muted-foreground',
DropdownMenuShortcut.displayName = 'DropdownMenuShortcut';
DropdownMenuCheckboxItem,