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@latest 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-sm text-muted-foreground">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-sm text-muted-foreground">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" context="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 { browser } from "$app/environment"; import * as Form from "$lib/components/ui/form/index.js"; import { Input } from "$lib/components/ui/input/index.js"; import SuperDebug, { type SuperValidated, type Infer, superForm } from "sveltekit-superforms"; import { zodClient } from "sveltekit-superforms/adapters"; import { toast } from "svelte-sonner"; let data: SuperValidated<Infer<FormSchema>>; export { data as form }; 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 let:attrs> <Form.Label>Username</Form.Label> <Input {...attrs} bind:value={$formData.username} /> </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