diff options
| author | MohamedBassem <me@mbassem.com> | 2024-02-08 17:22:31 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-02-08 17:22:31 +0000 |
| commit | bae1bccbd8029db4bacbd8ecc9f668e7119016c8 (patch) | |
| tree | 157b71c6009e3b38a3a94c0cc7d9dda190b72d56 /packages/web/components/ui | |
| parent | 80bb8a108f29331cdb2f2695f6801beee104dc89 (diff) | |
| download | karakeep-bae1bccbd8029db4bacbd8ecc9f668e7119016c8.tar.zst | |
Migrating away from bun to yarn
Diffstat (limited to 'packages/web/components/ui')
| -rw-r--r-- | packages/web/components/ui/form.tsx | 101 | ||||
| -rw-r--r-- | packages/web/components/ui/label.tsx | 20 |
2 files changed, 61 insertions, 60 deletions
diff --git a/packages/web/components/ui/form.tsx b/packages/web/components/ui/form.tsx index 4603f8b3..497718a9 100644 --- a/packages/web/components/ui/form.tsx +++ b/packages/web/components/ui/form.tsx @@ -1,6 +1,6 @@ -import * as React from "react" -import * as LabelPrimitive from "@radix-ui/react-label" -import { Slot } from "@radix-ui/react-slot" +import * as React from "react"; +import * as LabelPrimitive from "@radix-ui/react-label"; +import { Slot } from "@radix-ui/react-slot"; import { Controller, ControllerProps, @@ -8,27 +8,27 @@ import { FieldValues, FormProvider, useFormContext, -} from "react-hook-form" +} from "react-hook-form"; -import { cn } from "@/lib/utils" -import { Label } from "@/components/ui/label" +import { cn } from "@/lib/utils"; +import { Label } from "@/components/ui/label"; -const Form = FormProvider +const Form = FormProvider; type FormFieldContextValue< TFieldValues extends FieldValues = FieldValues, - TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues> + TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, > = { - name: TName -} + name: TName; +}; const FormFieldContext = React.createContext<FormFieldContextValue>( - {} as FormFieldContextValue -) + {} as FormFieldContextValue, +); const FormField = < TFieldValues extends FieldValues = FieldValues, - TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues> + TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, >({ ...props }: ControllerProps<TFieldValues, TName>) => { @@ -36,21 +36,21 @@ const FormField = < <FormFieldContext.Provider value={{ name: props.name }}> <Controller {...props} /> </FormFieldContext.Provider> - ) -} + ); +}; const useFormField = () => { - const fieldContext = React.useContext(FormFieldContext) - const itemContext = React.useContext(FormItemContext) - const { getFieldState, formState } = useFormContext() + const fieldContext = React.useContext(FormFieldContext); + const itemContext = React.useContext(FormItemContext); + const { getFieldState, formState } = useFormContext(); - const fieldState = getFieldState(fieldContext.name, formState) + const fieldState = getFieldState(fieldContext.name, formState); if (!fieldContext) { - throw new Error("useFormField should be used within <FormField>") + throw new Error("useFormField should be used within <FormField>"); } - const { id } = itemContext + const { id } = itemContext; return { id, @@ -59,36 +59,36 @@ const useFormField = () => { formDescriptionId: `${id}-form-item-description`, formMessageId: `${id}-form-item-message`, ...fieldState, - } -} + }; +}; type FormItemContextValue = { - id: string -} + id: string; +}; const FormItemContext = React.createContext<FormItemContextValue>( - {} as FormItemContextValue -) + {} as FormItemContextValue, +); const FormItem = React.forwardRef< HTMLDivElement, React.HTMLAttributes<HTMLDivElement> >(({ className, ...props }, ref) => { - const id = React.useId() + const id = React.useId(); return ( <FormItemContext.Provider value={{ id }}> <div ref={ref} className={cn("space-y-2", className)} {...props} /> </FormItemContext.Provider> - ) -}) -FormItem.displayName = "FormItem" + ); +}); +FormItem.displayName = "FormItem"; const FormLabel = React.forwardRef< React.ElementRef<typeof LabelPrimitive.Root>, React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> >(({ className, ...props }, ref) => { - const { error, formItemId } = useFormField() + const { error, formItemId } = useFormField(); return ( <Label @@ -97,15 +97,16 @@ const FormLabel = React.forwardRef< htmlFor={formItemId} {...props} /> - ) -}) -FormLabel.displayName = "FormLabel" + ); +}); +FormLabel.displayName = "FormLabel"; const FormControl = React.forwardRef< React.ElementRef<typeof Slot>, React.ComponentPropsWithoutRef<typeof Slot> >(({ ...props }, ref) => { - const { error, formItemId, formDescriptionId, formMessageId } = useFormField() + const { error, formItemId, formDescriptionId, formMessageId } = + useFormField(); return ( <Slot @@ -119,15 +120,15 @@ const FormControl = React.forwardRef< aria-invalid={!!error} {...props} /> - ) -}) -FormControl.displayName = "FormControl" + ); +}); +FormControl.displayName = "FormControl"; const FormDescription = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement> >(({ className, ...props }, ref) => { - const { formDescriptionId } = useFormField() + const { formDescriptionId } = useFormField(); return ( <p @@ -136,19 +137,19 @@ const FormDescription = React.forwardRef< className={cn("text-sm text-muted-foreground", className)} {...props} /> - ) -}) -FormDescription.displayName = "FormDescription" + ); +}); +FormDescription.displayName = "FormDescription"; const FormMessage = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement> >(({ className, children, ...props }, ref) => { - const { error, formMessageId } = useFormField() - const body = error ? String(error?.message) : children + const { error, formMessageId } = useFormField(); + const body = error ? String(error?.message) : children; if (!body) { - return null + return null; } return ( @@ -160,9 +161,9 @@ const FormMessage = React.forwardRef< > {body} </p> - ) -}) -FormMessage.displayName = "FormMessage" + ); +}); +FormMessage.displayName = "FormMessage"; export { useFormField, @@ -173,4 +174,4 @@ export { FormDescription, FormMessage, FormField, -} +}; diff --git a/packages/web/components/ui/label.tsx b/packages/web/components/ui/label.tsx index 53418217..84f8b0c7 100644 --- a/packages/web/components/ui/label.tsx +++ b/packages/web/components/ui/label.tsx @@ -1,14 +1,14 @@ -"use client" +"use client"; -import * as React from "react" -import * as LabelPrimitive from "@radix-ui/react-label" -import { cva, type VariantProps } from "class-variance-authority" +import * as React from "react"; +import * as LabelPrimitive from "@radix-ui/react-label"; +import { cva, type VariantProps } from "class-variance-authority"; -import { cn } from "@/lib/utils" +import { cn } from "@/lib/utils"; const labelVariants = cva( - "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" -) + "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", +); const Label = React.forwardRef< React.ElementRef<typeof LabelPrimitive.Root>, @@ -20,7 +20,7 @@ const Label = React.forwardRef< className={cn(labelVariants(), className)} {...props} /> -)) -Label.displayName = LabelPrimitive.Root.displayName +)); +Label.displayName = LabelPrimitive.Root.displayName; -export { Label } +export { Label }; |
