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/
161 lines
4.5 KiB
TypeScript
161 lines
4.5 KiB
TypeScript
/* eslint-disable react/no-children-prop */
|
|
"use client"
|
|
|
|
import { useForm } from "@tanstack/react-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,
|
|
FieldContent,
|
|
FieldDescription,
|
|
FieldError,
|
|
FieldGroup,
|
|
FieldLabel,
|
|
FieldLegend,
|
|
FieldSet,
|
|
FieldTitle,
|
|
} from "@/registry/new-york-v4/ui/field"
|
|
import {
|
|
RadioGroup,
|
|
RadioGroupItem,
|
|
} from "@/registry/new-york-v4/ui/radio-group"
|
|
|
|
const plans = [
|
|
{
|
|
id: "starter",
|
|
title: "Starter (100K tokens/month)",
|
|
description: "For everyday use with basic features.",
|
|
},
|
|
{
|
|
id: "pro",
|
|
title: "Pro (1M tokens/month)",
|
|
description: "For advanced AI usage with more features.",
|
|
},
|
|
{
|
|
id: "enterprise",
|
|
title: "Enterprise (Unlimited tokens)",
|
|
description: "For large teams and heavy usage.",
|
|
},
|
|
] as const
|
|
|
|
const formSchema = z.object({
|
|
plan: z.string().min(1, "You must select a subscription plan to continue."),
|
|
})
|
|
|
|
export default function FormTanstackRadioGroup() {
|
|
const form = useForm({
|
|
defaultValues: {
|
|
plan: "",
|
|
},
|
|
validators: {
|
|
onSubmit: formSchema,
|
|
},
|
|
onSubmit: async ({ value }) => {
|
|
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(value, 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>Subscription Plan</CardTitle>
|
|
<CardDescription>
|
|
See pricing and features for each plan.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form
|
|
id="form-tanstack-radiogroup"
|
|
onSubmit={(e) => {
|
|
e.preventDefault()
|
|
form.handleSubmit()
|
|
}}
|
|
>
|
|
<FieldGroup>
|
|
<form.Field
|
|
name="plan"
|
|
children={(field) => {
|
|
const isInvalid =
|
|
field.state.meta.isTouched && !field.state.meta.isValid
|
|
return (
|
|
<FieldSet>
|
|
<FieldLegend>Plan</FieldLegend>
|
|
<FieldDescription>
|
|
You can upgrade or downgrade your plan at any time.
|
|
</FieldDescription>
|
|
<RadioGroup
|
|
name={field.name}
|
|
value={field.state.value}
|
|
onValueChange={field.handleChange}
|
|
>
|
|
{plans.map((plan) => (
|
|
<FieldLabel
|
|
key={plan.id}
|
|
htmlFor={`form-tanstack-radiogroup-${plan.id}`}
|
|
>
|
|
<Field
|
|
orientation="horizontal"
|
|
data-invalid={isInvalid}
|
|
>
|
|
<FieldContent>
|
|
<FieldTitle>{plan.title}</FieldTitle>
|
|
<FieldDescription>
|
|
{plan.description}
|
|
</FieldDescription>
|
|
</FieldContent>
|
|
<RadioGroupItem
|
|
value={plan.id}
|
|
id={`form-tanstack-radiogroup-${plan.id}`}
|
|
aria-invalid={isInvalid}
|
|
/>
|
|
</Field>
|
|
</FieldLabel>
|
|
))}
|
|
</RadioGroup>
|
|
{isInvalid && (
|
|
<FieldError errors={field.state.meta.errors} />
|
|
)}
|
|
</FieldSet>
|
|
)
|
|
}}
|
|
/>
|
|
</FieldGroup>
|
|
</form>
|
|
</CardContent>
|
|
<CardFooter>
|
|
<Field orientation="horizontal">
|
|
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
Reset
|
|
</Button>
|
|
<Button type="submit" form="form-tanstack-radiogroup">
|
|
Save
|
|
</Button>
|
|
</Field>
|
|
</CardFooter>
|
|
</Card>
|
|
)
|
|
}
|