Skip to content

Commit b55a07c

Browse files
committed
chore: Formatting
1 parent f0c752a commit b55a07c

File tree

6 files changed

+73
-113
lines changed

6 files changed

+73
-113
lines changed
Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as React from "react"
2-
import { Slot } from "@radix-ui/react-slot"
3-
import { cva, type VariantProps } from "class-variance-authority"
1+
import * as React from "react";
2+
import { Slot } from "@radix-ui/react-slot";
3+
import { cva, type VariantProps } from "class-variance-authority";
44

5-
import { cn } from "@/lib/utils"
5+
import { cn } from "@/lib/utils";
66

77
const buttonVariants = cva(
88
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
@@ -14,10 +14,8 @@ const buttonVariants = cva(
1414
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
1515
outline:
1616
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
17-
secondary:
18-
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
19-
ghost:
20-
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
17+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
18+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
2119
link: "text-primary underline-offset-4 hover:underline",
2220
},
2321
size: {
@@ -34,7 +32,7 @@ const buttonVariants = cva(
3432
size: "default",
3533
},
3634
}
37-
)
35+
);
3836

3937
function Button({
4038
className,
@@ -44,17 +42,11 @@ function Button({
4442
...props
4543
}: React.ComponentProps<"button"> &
4644
VariantProps<typeof buttonVariants> & {
47-
asChild?: boolean
45+
asChild?: boolean;
4846
}) {
49-
const Comp = asChild ? Slot : "button"
47+
const Comp = asChild ? Slot : "button";
5048

51-
return (
52-
<Comp
53-
data-slot="button"
54-
className={cn(buttonVariants({ variant, size, className }))}
55-
{...props}
56-
/>
57-
)
49+
return <Comp data-slot="button" className={cn(buttonVariants({ variant, size, className }))} {...props} />;
5850
}
5951

60-
export { Button, buttonVariants }
52+
export { Button, buttonVariants };
Lines changed: 42 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"use client"
1+
"use client";
22

3-
import * as React from "react"
4-
import * as LabelPrimitive from "@radix-ui/react-label"
5-
import { Slot } from "@radix-ui/react-slot"
3+
import * as React from "react";
4+
import * as LabelPrimitive from "@radix-ui/react-label";
5+
import { Slot } from "@radix-ui/react-slot";
66
import {
77
Controller,
88
FormProvider,
@@ -11,23 +11,21 @@ import {
1111
type ControllerProps,
1212
type FieldPath,
1313
type FieldValues,
14-
} from "react-hook-form"
14+
} from "react-hook-form";
1515

16-
import { cn } from "@/lib/utils"
17-
import { Label } from "@/components/ui/label"
16+
import { cn } from "@/lib/utils";
17+
import { Label } from "@/components/ui/label";
1818

19-
const Form = FormProvider
19+
const Form = FormProvider;
2020

2121
type FormFieldContextValue<
2222
TFieldValues extends FieldValues = FieldValues,
2323
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
2424
> = {
25-
name: TName
26-
}
25+
name: TName;
26+
};
2727

28-
const FormFieldContext = React.createContext<FormFieldContextValue>(
29-
{} as FormFieldContextValue
30-
)
28+
const FormFieldContext = React.createContext<FormFieldContextValue>({} as FormFieldContextValue);
3129

3230
const FormField = <
3331
TFieldValues extends FieldValues = FieldValues,
@@ -39,21 +37,21 @@ const FormField = <
3937
<FormFieldContext.Provider value={{ name: props.name }}>
4038
<Controller {...props} />
4139
</FormFieldContext.Provider>
42-
)
43-
}
40+
);
41+
};
4442

4543
const useFormField = () => {
46-
const fieldContext = React.useContext(FormFieldContext)
47-
const itemContext = React.useContext(FormItemContext)
48-
const { getFieldState } = useFormContext()
49-
const formState = useFormState({ name: fieldContext.name })
50-
const fieldState = getFieldState(fieldContext.name, formState)
44+
const fieldContext = React.useContext(FormFieldContext);
45+
const itemContext = React.useContext(FormItemContext);
46+
const { getFieldState } = useFormContext();
47+
const formState = useFormState({ name: fieldContext.name });
48+
const fieldState = getFieldState(fieldContext.name, formState);
5149

5250
if (!fieldContext) {
53-
throw new Error("useFormField should be used within <FormField>")
51+
throw new Error("useFormField should be used within <FormField>");
5452
}
5553

56-
const { id } = itemContext
54+
const { id } = itemContext;
5755

5856
return {
5957
id,
@@ -62,36 +60,27 @@ const useFormField = () => {
6260
formDescriptionId: `${id}-form-item-description`,
6361
formMessageId: `${id}-form-item-message`,
6462
...fieldState,
65-
}
66-
}
63+
};
64+
};
6765

6866
type FormItemContextValue = {
69-
id: string
70-
}
67+
id: string;
68+
};
7169

72-
const FormItemContext = React.createContext<FormItemContextValue>(
73-
{} as FormItemContextValue
74-
)
70+
const FormItemContext = React.createContext<FormItemContextValue>({} as FormItemContextValue);
7571

7672
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
77-
const id = React.useId()
73+
const id = React.useId();
7874

7975
return (
8076
<FormItemContext.Provider value={{ id }}>
81-
<div
82-
data-slot="form-item"
83-
className={cn("grid gap-2", className)}
84-
{...props}
85-
/>
77+
<div data-slot="form-item" className={cn("grid gap-2", className)} {...props} />
8678
</FormItemContext.Provider>
87-
)
79+
);
8880
}
8981

90-
function FormLabel({
91-
className,
92-
...props
93-
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
94-
const { error, formItemId } = useFormField()
82+
function FormLabel({ className, ...props }: React.ComponentProps<typeof LabelPrimitive.Root>) {
83+
const { error, formItemId } = useFormField();
9584

9685
return (
9786
<Label
@@ -101,29 +90,25 @@ function FormLabel({
10190
htmlFor={formItemId}
10291
{...props}
10392
/>
104-
)
93+
);
10594
}
10695

10796
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
108-
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
97+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
10998

11099
return (
111100
<Slot
112101
data-slot="form-control"
113102
id={formItemId}
114-
aria-describedby={
115-
!error
116-
? `${formDescriptionId}`
117-
: `${formDescriptionId} ${formMessageId}`
118-
}
103+
aria-describedby={!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`}
119104
aria-invalid={!!error}
120105
{...props}
121106
/>
122-
)
107+
);
123108
}
124109

125110
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
126-
const { formDescriptionId } = useFormField()
111+
const { formDescriptionId } = useFormField();
127112

128113
return (
129114
<p
@@ -132,36 +117,22 @@ function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
132117
className={cn("text-muted-foreground text-sm", className)}
133118
{...props}
134119
/>
135-
)
120+
);
136121
}
137122

138123
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
139-
const { error, formMessageId } = useFormField()
140-
const body = error ? String(error?.message ?? "") : props.children
124+
const { error, formMessageId } = useFormField();
125+
const body = error ? String(error?.message ?? "") : props.children;
141126

142127
if (!body) {
143-
return null
128+
return null;
144129
}
145130

146131
return (
147-
<p
148-
data-slot="form-message"
149-
id={formMessageId}
150-
className={cn("text-destructive text-sm", className)}
151-
{...props}
152-
>
132+
<p data-slot="form-message" id={formMessageId} className={cn("text-destructive text-sm", className)} {...props}>
153133
{body}
154134
</p>
155-
)
135+
);
156136
}
157137

158-
export {
159-
useFormField,
160-
Form,
161-
FormItem,
162-
FormLabel,
163-
FormControl,
164-
FormDescription,
165-
FormMessage,
166-
FormField,
167-
}
138+
export { useFormField, Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField };

examples/shadcn/src/components/ui/input.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as React from "react"
1+
import * as React from "react";
22

3-
import { cn } from "@/lib/utils"
3+
import { cn } from "@/lib/utils";
44

55
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
66
return (
@@ -15,7 +15,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
1515
)}
1616
{...props}
1717
/>
18-
)
18+
);
1919
}
2020

21-
export { Input }
21+
export { Input };
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import * as React from "react"
2-
import * as LabelPrimitive from "@radix-ui/react-label"
1+
import * as React from "react";
2+
import * as LabelPrimitive from "@radix-ui/react-label";
33

4-
import { cn } from "@/lib/utils"
4+
import { cn } from "@/lib/utils";
55

6-
function Label({
7-
className,
8-
...props
9-
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
6+
function Label({ className, ...props }: React.ComponentProps<typeof LabelPrimitive.Root>) {
107
return (
118
<LabelPrimitive.Root
129
data-slot="label"
@@ -16,7 +13,7 @@ function Label({
1613
)}
1714
{...props}
1815
/>
19-
)
16+
);
2017
}
2118

22-
export { Label }
19+
export { Label };

examples/shadcn/src/lib/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { clsx, type ClassValue } from "clsx"
2-
import { twMerge } from "tailwind-merge"
1+
import { clsx, type ClassValue } from "clsx";
2+
import { twMerge } from "tailwind-merge";
33

44
export function cn(...inputs: ClassValue[]) {
5-
return twMerge(clsx(inputs))
5+
return twMerge(clsx(inputs));
66
}

examples/shadcn/src/main.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { StrictMode } from 'react'
2-
import { createRoot } from 'react-dom/client'
3-
import './index.css'
4-
import App from './App.tsx'
1+
import { StrictMode } from "react";
2+
import { createRoot } from "react-dom/client";
3+
import "./index.css";
4+
import App from "./App.tsx";
55

6-
createRoot(document.getElementById('root')!).render(
6+
createRoot(document.getElementById("root")!).render(
77
<StrictMode>
88
<App />
9-
</StrictMode>,
10-
)
9+
</StrictMode>
10+
);

0 commit comments

Comments
 (0)