Displays a form input field or a component that looks like an input field.
<script lang="ts"> import { Input } from "$lib/components/ui/input/index.js"; </script> <Input type="email" placeholder="email" class="max-w-xs" />
npx shadcn-svelte@next add input
<script lang="ts"> import { Input } from "$lib/components/ui/input"; </script> <Input />
<script lang="ts"> import { Input } from "$lib/components/ui/input/index.js"; </script> <Input disabled type="email" placeholder="email" class="max-w-xs" />
<script lang="ts"> import { Input } from "$lib/components/ui/input/index.js"; </script> <Input disabled type="email" placeholder="email" class="max-w-sm" />
<script lang="ts"> import { Input } from "$lib/components/ui/input/index.js"; import { Label } from "$lib/components/ui/label/index.js"; </script> <div class="grid w-full max-w-sm items-center gap-1.5"> <Label for="email">Email</Label> <Input type="email" id="email" placeholder="email" /> </div>
<script lang="ts"> import { Input } from "$lib/components/ui/input/index.js"; import { Label } from "$lib/components/ui/label/index.js"; </script> <div class="flex w-full max-w-sm flex-col gap-1.5"> <Label for="email">Email</Label> <Input type="email" id="email" placeholder="email" /> </div>
<script lang="ts"> import { Input } from "$lib/components/ui/input/index.js"; import { Label } from "$lib/components/ui/label/index.js"; </script> <div class="grid w-full max-w-sm items-center gap-1.5"> <Label for="email-2">Email</Label> <Input type="email" id="email-2" placeholder="Email" /> <p class="text-muted-foreground text-sm">Enter your email address.</p> </div>
<script lang="ts"> import { Input } from "$lib/components/ui/input/index.js"; import { Label } from "$lib/components/ui/label/index.js"; </script> <div class="flex w-full max-w-sm flex-col gap-1.5"> <Label for="email-2">Email</Label> <Input type="email" id="email-2" placeholder="Email" /> <p class="text-muted-foreground text-sm">Enter your email address.</p> </div>
<script lang="ts"> import { Button } from "$lib/components/ui/button/index.js"; import { Input } from "$lib/components/ui/input/index.js"; </script> <form class="flex w-full max-w-sm items-center space-x-2"> <Input type="email" placeholder="email" /> <Button type="submit">Subscribe</Button> </form>
<script lang="ts"> import { Input } from "$lib/components/ui/input/index.js"; import { Label } from "$lib/components/ui/label/index.js"; </script> <div class="grid w-full max-w-sm items-center gap-1.5"> <Label for="picture">Picture</Label> <Input id="picture" type="file" /> </div>
<script lang="ts" module> import { z } from "zod"; export const formSchema = z.object({ username: z.string().min(2).max(50) }); export type FormSchema = typeof formSchema; </script> <script lang="ts"> import SuperDebug, { type Infer, type SuperValidated, superForm } from "sveltekit-superforms"; import { zodClient } from "sveltekit-superforms/adapters"; import { toast } from "svelte-sonner"; import { browser } from "$app/environment"; import * as Form from "$lib/components/ui/form/index.js"; import { Input } from "$lib/components/ui/input/index.js"; import { page } from "$app/stores"; let { form: data = $page.data.form }: { form: SuperValidated<Infer<FormSchema>> } = $props(); const form = superForm(data, { validators: zodClient(formSchema), onUpdated: ({ form: f }) => { if (f.valid) { toast.success(`You submitted ${JSON.stringify(f.data, null, 2)}`); } else { toast.error("Please fix the errors in the form."); } } }); const { form: formData, enhance } = form; </script> <form action="/?/username" method="POST" class="w-2/3 space-y-6" use:enhance> <Form.Field {form} name="username"> <Form.Control> {#snippet children({ props })} <Form.Label>Username</Form.Label> <Input {...props} bind:value={$formData.username} /> {/snippet} </Form.Control> <Form.Description>This is your public display name.</Form.Description> <Form.FieldErrors /> </Form.Field> <Form.Button>Submit</Form.Button> {#if browser} <SuperDebug data={$formData} /> {/if} </form>
<script lang="ts" module> import { z } from "zod"; export const formSchema = z.object({ username: z.string().min(2).max(50) }); export type FormSchema = typeof formSchema; </script> <script lang="ts"> import SuperDebug, { type Infer, type SuperValidated, superForm } from "sveltekit-superforms"; import { zodClient } from "sveltekit-superforms/adapters"; import { toast } from "svelte-sonner"; import { browser } from "$app/environment"; import * as Form from "$lib/components/ui/form/index.js"; import { Input } from "$lib/components/ui/input/index.js"; import { page } from "$app/stores"; let { form: data = $page.data.username }: { form: SuperValidated<Infer<FormSchema>> } = $props(); const form = superForm(data, { validators: zodClient(formSchema), onUpdated: ({ form: f }) => { if (f.valid) { toast.success(`You submitted ${JSON.stringify(f.data, null, 2)}`); } else { toast.error("Please fix the errors in the form."); } } }); const { form: formData, enhance } = form; </script> <form action="/?/username" method="POST" class="w-2/3 space-y-6" use:enhance> <Form.Field {form} name="username"> <Form.Control> {#snippet children({ props })} <Form.Label>Username</Form.Label> <Input {...props} bind:value={$formData.username} /> {/snippet} </Form.Control> <Form.Description>This is your public display name.</Form.Description> <Form.FieldErrors /> </Form.Field> <Form.Button>Submit</Form.Button> {#if browser} <SuperDebug data={$formData} /> {/if} </form>
On This Page