Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 48 additions & 38 deletions packages/components/src/ui/dropdown-menu-select.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { forwardRef, type ElementRef, type ComponentPropsWithoutRef, type ReactNode } from 'react'
// biome-ignore lint/style/noNamespaceImport: from Radix
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
import { type FieldComponents, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "./form"
import { Button } from './button'
import { DropdownMenuContent } from './dropdown-menu'
import type { Control, FieldPath, FieldValues } from "react-hook-form";
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
import { type ComponentPropsWithoutRef, type ElementRef, type ReactNode, forwardRef } from 'react';
import type { Control, FieldPath, FieldValues } from 'react-hook-form';
import { Button } from './button';
import { DropdownMenuContent } from './dropdown-menu';
import {
type FieldComponents,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from './form';

export interface DropdownMenuSelectProps<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> extends Omit<ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Root>, 'onChange' | 'value'> {
control?: Control<TFieldValues>;
name: TName;
Expand All @@ -21,35 +29,37 @@ export interface DropdownMenuSelectProps<
components?: Partial<FieldComponents>;
}

export const DropdownMenuSelect = forwardRef<
ElementRef<typeof DropdownMenuPrimitive.Root>,
DropdownMenuSelectProps
>(({ control, name, label, description, children, className, labelClassName, dropdownClassName, components, ...props }, ref) => {
return (
<FormField
control={control}
name={name}
render={({ field, fieldState }) => (
<FormItem className={className}>
{label && <FormLabel Component={components?.FormLabel} className={labelClassName}>{label}</FormLabel>}
<FormControl>
<DropdownMenuPrimitive.Root {...field} {...props}>
<DropdownMenuPrimitive.Trigger asChild>
<Button className={dropdownClassName}>
{field.value ? field.value : "Select an option"}
</Button>
</DropdownMenuPrimitive.Trigger>
<DropdownMenuContent>
{children}
</DropdownMenuContent>
</DropdownMenuPrimitive.Root>
</FormControl>
{description && <FormDescription Component={components?.FormDescription}>{description}</FormDescription>}
<FormMessage Component={components?.FormMessage}>{fieldState.error?.message}</FormMessage>
</FormItem>
)}
/>
);
});
export const DropdownMenuSelect = forwardRef<ElementRef<typeof DropdownMenuPrimitive.Root>, DropdownMenuSelectProps>(
(
{ control, name, label, description, children, className, labelClassName, dropdownClassName, components, ...props },
ref,
) => {
return (
<FormField
control={control}
name={name}
render={({ field, fieldState }) => (
<FormItem className={className}>
{label && (
<FormLabel Component={components?.FormLabel} className={labelClassName}>
{label}
</FormLabel>
)}
<FormControl>
<DropdownMenuPrimitive.Root {...field} {...props}>
<DropdownMenuPrimitive.Trigger asChild>
<Button className={dropdownClassName}>{field.value ? field.value : 'Select an option'}</Button>
</DropdownMenuPrimitive.Trigger>
<DropdownMenuContent>{children}</DropdownMenuContent>
</DropdownMenuPrimitive.Root>
</FormControl>
{description && <FormDescription Component={components?.FormDescription}>{description}</FormDescription>}
<FormMessage Component={components?.FormMessage}>{fieldState.error?.message}</FormMessage>
</FormItem>
)}
/>
);
},
);

DropdownMenuSelect.displayName = "DropdownMenuSelect";
DropdownMenuSelect.displayName = 'DropdownMenuSelect';
2 changes: 1 addition & 1 deletion packages/components/src/ui/dropdown-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forwardRef, type ElementRef, type ComponentPropsWithoutRef, type HTMLAttributes } from 'react';
// biome-ignore lint/style/noNamespaceImport: from Radix
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
import { Check, ChevronRight, Circle } from 'lucide-react';
import { type ComponentPropsWithoutRef, type ElementRef, type HTMLAttributes, forwardRef } from 'react';

import { cn } from '../../lib/utils';

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/ui/input-otp.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Control, FieldValues } from 'react-hook-form';
import { forwardRef, type ElementRef, type ComponentPropsWithoutRef, useContext } from 'react';
import { OTPInput, OTPInputContext, type OTPInputProps } from 'input-otp';
import { Dot } from 'lucide-react';
import { type ComponentPropsWithoutRef, type ElementRef, forwardRef, useContext } from 'react';
import type { Control, FieldValues } from 'react-hook-form';
import { cn } from '../../lib/utils';
import {
type FieldComponents,
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { type InputHTMLAttributes, forwardRef } from 'react';
import { cn } from '../../lib/utils';

export interface InputProps extends InputHTMLAttributes<HTMLInputElement> { }
export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {}

const Input = forwardRef<HTMLInputElement, InputProps>(({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
'flex h-10 w-full text-base sm:text-sm rounded-md border border-input bg-background px-3 py-2 ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
ref={ref}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forwardRef, type ElementRef, type ComponentPropsWithoutRef } from 'react';
// biome-ignore lint/style/noNamespaceImport: from Radix
import * as LabelPrimitive from '@radix-ui/react-label';
import { type VariantProps, cva } from 'class-variance-authority';
import { type ComponentPropsWithoutRef, type ElementRef, forwardRef } from 'react';

import { cn } from '../../lib/utils';

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/ui/popover.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { forwardRef, type ElementRef, type ComponentPropsWithoutRef } from 'react';
// biome-ignore lint/style/noNamespaceImport: from Radix
import * as PopoverPrimitive from '@radix-ui/react-popover';
import { type ComponentPropsWithoutRef, type ElementRef, forwardRef } from 'react';

import { cn } from '../../lib/utils';

Expand Down
8 changes: 5 additions & 3 deletions packages/components/src/ui/radio-group.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// biome-ignore lint/style/noNamespaceImport: from Radix
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
import { Circle } from 'lucide-react';
import { type ComponentPropsWithoutRef, type ElementRef, forwardRef } from 'react';
import type { Control, FieldPath, FieldValues } from 'react-hook-form';
import { cn } from '../../lib/utils';
import {
type FieldComponents,
Expand All @@ -11,8 +13,6 @@ import {
FormLabel,
FormMessage,
} from './form';
import type { Control, FieldPath, FieldValues } from 'react-hook-form';
import { forwardRef, type ElementRef, type ComponentPropsWithoutRef } from 'react';

const RadioGroup = forwardRef<
ElementRef<typeof RadioGroupPrimitive.Root>,
Expand Down Expand Up @@ -67,7 +67,9 @@ const RadioGroupField = forwardRef<HTMLDivElement, RadioGroupFieldProps>(
<RadioGroup ref={field.ref} onValueChange={field.onChange} defaultValue={field.value} {...props} />
</FormControl>
{description && <FormDescription Component={components?.FormDescription}>{description}</FormDescription>}
{fieldState.error && <FormMessage Component={components?.FormMessage}>{fieldState.error.message}</FormMessage>}
{fieldState.error && (
<FormMessage Component={components?.FormMessage}>{fieldState.error.message}</FormMessage>
)}
</FormItem>
)}
/>
Expand Down
9 changes: 6 additions & 3 deletions packages/components/src/ui/switch.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { forwardRef, type ComponentPropsWithoutRef, type ReactNode } from 'react';
// biome-ignore lint/style/noNamespaceImport: from Radix
import * as SwitchPrimitives from '@radix-ui/react-switch';
import { type ComponentPropsWithoutRef, type ReactNode, forwardRef } from 'react';
import type { Control, FieldPath, FieldValues } from 'react-hook-form';
import { cn } from '../../lib/utils';
import { type FieldComponents, FormControl, FormDescription, FormField, FormItem, FormLabel } from './form';
import type { Control, FieldPath, FieldValues } from 'react-hook-form';

export interface SwitchProps<
TFieldValues extends FieldValues = FieldValues,
Expand All @@ -23,7 +23,10 @@ const Switch = forwardRef<HTMLDivElement, SwitchProps>(
control={control}
name={name}
render={({ field }) => (
<FormItem className={cn('flex flex-row items-center justify-between rounded-lg border p-4', className)} ref={ref}>
<FormItem
className={cn('flex flex-row items-center justify-between rounded-lg border p-4', className)}
ref={ref}
>
<div className="space-y-0.5">
{label && <FormLabel Component={components?.FormLabel}>{label}</FormLabel>}
{description && <FormDescription Component={components?.FormDescription}>{description}</FormDescription>}
Expand Down
18 changes: 14 additions & 4 deletions packages/components/src/ui/textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { type TextareaHTMLAttributes, forwardRef } from 'react';
import type { Control, FieldPath, FieldValues } from 'react-hook-form';
import { cn } from '../../lib/utils';
import { FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, type FieldComponents } from './form';
import type { Control, FieldPath, FieldValues } from "react-hook-form";
import {
type FieldComponents,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from './form';

export interface TextareaProps<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'name'> {
control?: Control<TFieldValues>;
name: TName;
Expand Down Expand Up @@ -35,7 +43,9 @@ export const Textarea = forwardRef<HTMLDivElement, TextareaProps>(
/>
</FormControl>
{description && <FormDescription Component={components?.FormDescription}>{description}</FormDescription>}
{fieldState.error && <FormMessage Component={components?.FormMessage}>{fieldState.error.message}</FormMessage>}
{fieldState.error && (
<FormMessage Component={components?.FormMessage}>{fieldState.error.message}</FormMessage>
)}
</FormItem>
)}
/>
Expand Down
Loading