diff --git a/packages/ui/src/button.tsx b/packages/ui/src/button.tsx index 6f5c3c695..787548dfc 100644 --- a/packages/ui/src/button.tsx +++ b/packages/ui/src/button.tsx @@ -1,5 +1,5 @@ import type { VariantProps } from "class-variance-authority"; -import * as React from "react"; +import type { ComponentProps } from "react"; import { Slot } from "@radix-ui/react-slot"; import { cva } from "class-variance-authority"; @@ -36,23 +36,25 @@ const buttonVariants = cva( ); interface ButtonProps - extends React.ButtonHTMLAttributes, + extends ComponentProps<"button">, VariantProps { asChild?: boolean; } -const Button = React.forwardRef( - ({ className, variant, size, asChild = false, ...props }, ref) => { - const Comp = asChild ? Slot : "button"; - return ( - - ); - }, -); -Button.displayName = "Button"; +function Button({ + className, + variant, + size, + asChild = false, + ...props +}: ButtonProps) { + const Comp = asChild ? Slot : "button"; + return ( + + ); +} export { Button, buttonVariants }; diff --git a/packages/ui/src/dropdown-menu.tsx b/packages/ui/src/dropdown-menu.tsx index ecca776cc..0b6e349c2 100644 --- a/packages/ui/src/dropdown-menu.tsx +++ b/packages/ui/src/dropdown-menu.tsx @@ -1,6 +1,4 @@ -"use client"; - -import * as React from "react"; +import type { ComponentProps } from "react"; import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"; import { CheckIcon, @@ -17,169 +15,168 @@ const DropdownMenuPortal = DropdownMenuPrimitive.Portal; const DropdownMenuSub = DropdownMenuPrimitive.Sub; const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup; -const DropdownMenuSubTrigger = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef & { - inset?: boolean; - } ->(({ className, inset, children, ...props }, ref) => ( - - {children} - - -)); -DropdownMenuSubTrigger.displayName = - DropdownMenuPrimitive.SubTrigger.displayName; - -const DropdownMenuSubContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -DropdownMenuSubContent.displayName = - DropdownMenuPrimitive.SubContent.displayName; +function DropdownMenuSubTrigger({ + className, + inset, + children, + ...props +}: ComponentProps & { + inset?: boolean; +}) { + return ( + + {children} + + + ); +} -const DropdownMenuContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, sideOffset = 4, ...props }, ref) => ( - - ) { + return ( + - -)); -DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName; + ); +} -const DropdownMenuItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef & { - inset?: boolean; - } ->(({ className, inset, ...props }, ref) => ( - -)); -DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName; +function DropdownMenuContent({ + className, + sideOffset = 4, + ...props +}: ComponentProps) { + return ( + + + + ); +} -const DropdownMenuCheckboxItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, children, checked, ...props }, ref) => ( - - - - - - - {children} - -)); -DropdownMenuCheckboxItem.displayName = - DropdownMenuPrimitive.CheckboxItem.displayName; +function DropdownMenuItem({ + className, + inset, + ...props +}: ComponentProps & { + inset?: boolean; +}) { + return ( + + ); +} -const DropdownMenuRadioItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, children, ...props }, ref) => ( - - - - - - - {children} - -)); -DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName; +function DropdownMenuCheckboxItem({ + className, + children, + ...props +}: ComponentProps) { + return ( + + + + + + + {children} + + ); +} -const DropdownMenuLabel = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef & { - inset?: boolean; - } ->(({ className, inset, ...props }, ref) => ( - -)); -DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName; +function DropdownMenuRadioItem({ + className, + children, + ...props +}: ComponentProps) { + return ( + + + + + + + {children} + + ); +} -const DropdownMenuSeparator = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName; +function DropdownMenuLabel({ + className, + inset, + ...props +}: ComponentProps & { + inset?: boolean; +}) { + return ( + + ); +} -const DropdownMenuShortcut = ({ +function DropdownMenuSeparator({ className, ...props -}: React.HTMLAttributes) => { +}: ComponentProps) { + return ( + + ); +} + +function DropdownMenuShortcut({ className, ...props }: ComponentProps<"span">) { return ( ); -}; -DropdownMenuShortcut.displayName = "DropdownMenuShortcut"; +} export { DropdownMenu, diff --git a/packages/ui/src/form.tsx b/packages/ui/src/form.tsx index ac0c191ab..43ca1f52f 100644 --- a/packages/ui/src/form.tsx +++ b/packages/ui/src/form.tsx @@ -1,6 +1,6 @@ "use client"; -import type * as LabelPrimitive from "@radix-ui/react-label"; +import type { ComponentProps } from "react"; import type { ControllerProps, FieldPath, @@ -8,13 +8,12 @@ import type { UseFormProps, } from "react-hook-form"; import type { ZodType, ZodTypeDef } from "zod"; -import * as React from "react"; +import { createContext, use, useId } from "react"; import { zodResolver } from "@hookform/resolvers/zod"; import { Slot } from "@radix-ui/react-slot"; import { useForm as __useForm, Controller, - FormProvider, useFormContext, } from "react-hook-form"; @@ -22,7 +21,7 @@ import { cn } from "@acme/ui"; import { Label } from "./label"; -const useForm = < +function useForm< TOut extends FieldValues, TDef extends ZodTypeDef, TIn extends FieldValues, @@ -30,16 +29,14 @@ const useForm = < props: Omit, "resolver"> & { schema: ZodType; }, -) => { +) { const form = __useForm({ ...props, resolver: zodResolver(props.schema, undefined), }); return form; -}; - -const Form = FormProvider; +} interface FormFieldContextValue< TFieldValues extends FieldValues = FieldValues, @@ -48,33 +45,29 @@ interface FormFieldContextValue< name: TName; } -const FormFieldContext = React.createContext( - null, -); +const FormFieldContext = createContext(null); -const FormField = < +function FormField< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath, ->({ - ...props -}: ControllerProps) => { +>({ ...props }: ControllerProps) { return ( ); -}; +} -const useFormField = () => { - const fieldContext = React.useContext(FormFieldContext); - const itemContext = React.useContext(FormItemContext); +function useFormField() { const { getFieldState, formState } = useFormContext(); + const fieldContext = use(FormFieldContext); if (!fieldContext) { throw new Error("useFormField should be used within "); } const fieldState = getFieldState(fieldContext.name, formState); + const itemContext = use(FormItemContext); const { id } = itemContext; return { @@ -85,57 +78,44 @@ const useFormField = () => { formMessageId: `${id}-form-item-message`, ...fieldState, }; -}; +} interface FormItemContextValue { id: string; } -const FormItemContext = React.createContext( +const FormItemContext = createContext( {} as FormItemContextValue, ); -const FormItem = React.forwardRef< - HTMLDivElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => { - const id = React.useId(); +function FormItem({ className, ...props }: ComponentProps<"div">) { + const id = useId(); return ( -
+
); -}); -FormItem.displayName = "FormItem"; +} -const FormLabel = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => { +function FormLabel({ className, ...props }: ComponentProps) { const { error, formItemId } = useFormField(); return (