-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.tsx
More file actions
52 lines (49 loc) · 1.96 KB
/
select.tsx
File metadata and controls
52 lines (49 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type * as React from 'react';
import { useRemixFormContext } from 'remix-hook-form';
import { FormField, FormItem } from '../ui/form';
import { type SelectUIComponents, Select as UISelect, type SelectProps as UISelectProps } from '../ui/select';
import { FormControl, FormDescription, FormLabel, FormMessage } from './form';
export interface SelectProps extends Omit<UISelectProps, 'value' | 'onValueChange'> {
name: string;
label?: string;
description?: string;
className?: string;
components?: Partial<
{
FormControl: React.ComponentType<React.ComponentProps<typeof FormControl>>;
FormLabel: React.ComponentType<React.ComponentProps<typeof FormLabel>>;
FormDescription: React.ComponentType<React.ComponentProps<typeof FormDescription>>;
FormMessage: React.ComponentType<React.ComponentProps<typeof FormMessage>>;
} & SelectUIComponents
>;
}
export function Select({ name, label, description, className, components, ...props }: SelectProps) {
const { control } = useRemixFormContext();
return (
<FormField
control={control}
name={name}
render={({ field }) => (
<FormItem className={className}>
{label && <FormLabel Component={components?.FormLabel}>{label}</FormLabel>}
<FormControl Component={components?.FormControl}>
<UISelect
{...props}
value={field.value}
onValueChange={field.onChange}
components={{
Trigger: components?.Trigger,
Item: components?.Item,
SearchInput: components?.SearchInput,
CheckIcon: components?.CheckIcon,
ChevronIcon: components?.ChevronIcon,
}}
/>
</FormControl>
{description && <FormDescription Component={components?.FormDescription}>{description}</FormDescription>}
<FormMessage Component={components?.FormMessage} />
</FormItem>
)}
/>
);
}