mirror of
https://github.com/hanzoai/shadcn.git
synced 2026-11-03 03:18:52 +00:00
Upstream sync from shadcn-ui/ui (1686 commits since last merge base). Key changes: - packages/shadcn upgraded to 4.1.0 (CLI font transformers, scaffold from github, chart colors) - apps/v4 replaces apps/www as the primary docs/registry app - Font system: 25+ heading font registries, font markers utility, @supports override - Chart improvements: recharts v3 compat, radial chart fixes - templates/ updated with monorepo variants (astro, vite, react-router, start) - skills/shadcn AI skill definitions added - deprecated/ removed (auth, auth-firebase, cli, www) Preserved Hanzo-only paths: app/, pkg/, demo/, docs/, template/next/
115 lines
3.2 KiB
TypeScript
115 lines
3.2 KiB
TypeScript
"use client"
|
|
|
|
import { zodResolver } from "@hookform/resolvers/zod"
|
|
import { Controller, useForm } from "react-hook-form"
|
|
import { toast } from "sonner"
|
|
import * as z from "zod"
|
|
|
|
import { Button } from "@/registry/new-york-v4/ui/button"
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardFooter,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from "@/registry/new-york-v4/ui/card"
|
|
import {
|
|
Field,
|
|
FieldDescription,
|
|
FieldError,
|
|
FieldGroup,
|
|
FieldLabel,
|
|
} from "@/registry/new-york-v4/ui/field"
|
|
import { Input } from "@/registry/new-york-v4/ui/input"
|
|
|
|
const formSchema = z.object({
|
|
username: z
|
|
.string()
|
|
.min(3, "Username must be at least 3 characters.")
|
|
.max(10, "Username must be at most 10 characters.")
|
|
.regex(
|
|
/^[a-zA-Z0-9_]+$/,
|
|
"Username can only contain letters, numbers, and underscores."
|
|
),
|
|
})
|
|
|
|
export default function FormRhfInput() {
|
|
const form = useForm<z.infer<typeof formSchema>>({
|
|
resolver: zodResolver(formSchema),
|
|
defaultValues: {
|
|
username: "",
|
|
},
|
|
})
|
|
|
|
function onSubmit(data: z.infer<typeof formSchema>) {
|
|
toast("You submitted the following values:", {
|
|
description: (
|
|
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
<code>{JSON.stringify(data, null, 2)}</code>
|
|
</pre>
|
|
),
|
|
position: "bottom-right",
|
|
classNames: {
|
|
content: "flex flex-col gap-2",
|
|
},
|
|
style: {
|
|
"--border-radius": "calc(var(--radius) + 4px)",
|
|
} as React.CSSProperties,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<Card className="w-full sm:max-w-md">
|
|
<CardHeader>
|
|
<CardTitle>Profile Settings</CardTitle>
|
|
<CardDescription>
|
|
Update your profile information below.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form id="form-rhf-input" onSubmit={form.handleSubmit(onSubmit)}>
|
|
<FieldGroup>
|
|
<Controller
|
|
name="username"
|
|
control={form.control}
|
|
render={({ field, fieldState }) => (
|
|
<Field data-invalid={fieldState.invalid}>
|
|
<FieldLabel htmlFor="form-rhf-input-username">
|
|
Username
|
|
</FieldLabel>
|
|
<Input
|
|
{...field}
|
|
id="form-rhf-input-username"
|
|
aria-invalid={fieldState.invalid}
|
|
placeholder="shadcn"
|
|
autoComplete="username"
|
|
/>
|
|
<FieldDescription>
|
|
This is your public display name. Must be between 3 and 10
|
|
characters. Must only contain letters, numbers, and
|
|
underscores.
|
|
</FieldDescription>
|
|
{fieldState.invalid && (
|
|
<FieldError errors={[fieldState.error]} />
|
|
)}
|
|
</Field>
|
|
)}
|
|
/>
|
|
</FieldGroup>
|
|
</form>
|
|
</CardContent>
|
|
<CardFooter>
|
|
<Field orientation="horizontal">
|
|
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
Reset
|
|
</Button>
|
|
<Button type="submit" form="form-rhf-input">
|
|
Save
|
|
</Button>
|
|
</Field>
|
|
</CardFooter>
|
|
</Card>
|
|
)
|
|
}
|