snapshot of https://github.com/shadcn-ui/ui.git (main, 2026-09-15; blobs > 131072B omitted)
All checks were successful
Release / Create Version PR or Publish Stable Release (push) Has been skipped
Release / Publish Prerelease to NPM (push) Has been skipped
Monitor Registries / Monitor registry health (push) Has been skipped

This commit is contained in:
upstream-mirror
2026-09-15 22:44:43 +05:00
commit 1416db152c
5727 changed files with 630238 additions and 0 deletions

View File

@@ -0,0 +1,117 @@
"use client"
import * as React from "react"
import { Form, Field as FormischField, reset, useForm } from "@formisch/react"
import type { SubmitHandler } from "@formisch/react"
import { toast } from "sonner"
import * as v from "valibot"
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,
} from "@/registry/new-york-v4/ui/field"
import { Switch } from "@/registry/new-york-v4/ui/switch"
const FormSchema = v.object({
twoFactor: v.pipe(
v.boolean(),
v.check(
(value) => value === true,
"It is highly recommended to enable two-factor authentication."
)
),
})
export default function FormFormischSwitch() {
const form = useForm({
schema: FormSchema,
initialInput: {
twoFactor: false,
},
})
const handleSubmit: SubmitHandler<typeof FormSchema> = (output) => {
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(output, 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>Security Settings</CardTitle>
<CardDescription>
Manage your account security preferences.
</CardDescription>
</CardHeader>
<CardContent>
<Form of={form} id="form-formisch-switch" onSubmit={handleSubmit}>
<FieldGroup>
<FormischField of={form} path={["twoFactor"]}>
{(field) => (
<Field
orientation="horizontal"
data-invalid={field.errors !== null}
>
<FieldContent>
<FieldLabel htmlFor="form-formisch-switch-twoFactor">
Multi-factor authentication
</FieldLabel>
<FieldDescription>
Enable multi-factor authentication to secure your account.
</FieldDescription>
{field.errors && (
<FieldError
errors={field.errors.map((message) => ({ message }))}
/>
)}
</FieldContent>
<Switch
id="form-formisch-switch-twoFactor"
checked={field.input ?? false}
onCheckedChange={(checked) => field.onChange(checked)}
aria-invalid={field.errors !== null}
/>
</Field>
)}
</FormischField>
</FieldGroup>
</Form>
</CardContent>
<CardFooter>
<Field orientation="horizontal">
<Button type="button" variant="outline" onClick={() => reset(form)}>
Reset
</Button>
<Button type="submit" form="form-formisch-switch">
Save
</Button>
</Field>
</CardFooter>
</Card>
)
}