返回 oh-my-ppt
Select.tsx
根目录 / src / renderer / src / components / ui / Select.tsx
1 import * as React from 'react'
2 import * as SelectPrimitive from '@radix-ui/react-select'
3 import { ChevronDown, ChevronUp } from 'lucide-react'
4 import { cn } from '@renderer/lib/utils'
5
6 export const Select = SelectPrimitive.Root
7 export const SelectGroup = SelectPrimitive.Group
8 export const SelectValue = SelectPrimitive.Value
9
10 export const SelectTrigger = React.forwardRef<
11 React.ElementRef<typeof SelectPrimitive.Trigger>,
12 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
13 >(({ className, children, ...props }, ref) => (
14 <SelectPrimitive.Trigger
15 ref={ref}
16 className={cn(
17 'flex h-11 w-full items-center justify-between gap-2 rounded-lg border border-[#d8ccb5]/80 bg-[#fff9ef]/86 px-3 py-2 text-sm text-foreground shadow-[inset_0_1px_2px_rgba(77,63,46,0.08)] focus:outline-none focus:ring-2 focus:ring-[#8fbc8f] disabled:cursor-not-allowed disabled:opacity-50',
18 '[&>span]:min-w-0 [&>span]:truncate [&>span]:whitespace-nowrap',
19 className
20 )}
21 {...props}
22 >
23 {children}
24 <ChevronDown className="h-4 w-4 shrink-0 opacity-50" />
25 </SelectPrimitive.Trigger>
26 ))
27 SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
28
29 export const SelectContent = React.forwardRef<
30 React.ElementRef<typeof SelectPrimitive.Content>,
31 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
32 >(({ className, children, position = 'popper', ...props }, ref) => (
33 <SelectPrimitive.Portal>
34 <SelectPrimitive.Content
35 ref={ref}
36 className={cn(
37 'relative z-50 min-w-[8rem] max-h-64 overflow-hidden rounded-lg border border-[#d8ccb5]/85 bg-[#fff9ef] text-foreground shadow-[0_12px_28px_rgba(88,72,54,0.18)]',
38 position === 'popper' && 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
39 className
40 )}
41 position={position}
42 {...props}
43 >
44 <SelectScrollUpButton />
45 <SelectPrimitive.Viewport
46 className={cn(
47 'p-1',
48 position === 'popper' &&
49 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'
50 )}
51 >
52 {children}
53 </SelectPrimitive.Viewport>
54 <SelectScrollDownButton />
55 </SelectPrimitive.Content>
56 </SelectPrimitive.Portal>
57 ))
58 SelectContent.displayName = SelectPrimitive.Content.displayName
59
60 export const SelectLabel = React.forwardRef<
61 React.ElementRef<typeof SelectPrimitive.Label>,
62 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
63 >(({ className, ...props }, ref) => (
64 <SelectPrimitive.Label
65 ref={ref}
66 className={cn('px-3 py-2 text-xs font-medium uppercase tracking-wider text-muted-foreground', className)}
67 {...props}
68 />
69 ))
70 SelectLabel.displayName = SelectPrimitive.Label.displayName
71
72 export const SelectItem = React.forwardRef<
73 React.ElementRef<typeof SelectPrimitive.Item>,
74 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
75 >(({ className, children, ...props }, ref) => (
76 <SelectPrimitive.Item
77 ref={ref}
78 className={cn(
79 'relative flex w-full cursor-default select-none items-center rounded-md px-3 py-2 text-sm outline-none focus:bg-[#efe5d3]/70 data-[state=checked]:bg-[#dbe7ca] data-[state=checked]:text-[#2f3b28]',
80 '[&>span]:min-w-0 [&>span]:truncate [&>span]:whitespace-nowrap',
81 className
82 )}
83 {...props}
84 >
85 <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
86 </SelectPrimitive.Item>
87 ))
88 SelectItem.displayName = SelectPrimitive.Item.displayName
89
90 export const SelectScrollUpButton = React.forwardRef<
91 React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
92 React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
93 >(({ className, ...props }, ref) => (
94 <SelectPrimitive.ScrollUpButton
95 ref={ref}
96 className={cn('flex cursor-default items-center justify-center py-1', className)}
97 {...props}
98 >
99 <ChevronUp className="h-4 w-4" />
100 </SelectPrimitive.ScrollUpButton>
101 ))
102 SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName
103
104 export const SelectScrollDownButton = React.forwardRef<
105 React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
106 React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
107 >(({ className, ...props }, ref) => (
108 <SelectPrimitive.ScrollDownButton
109 ref={ref}
110 className={cn('flex cursor-default items-center justify-center py-1', className)}
111 {...props}
112 >
113 <ChevronDown className="h-4 w-4" />
114 </SelectPrimitive.ScrollDownButton>
115 ))
116 SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName
117
117 lines Plain Text