Обзор
Компоненты
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Auth Surface
- Avatar
- Badge
- Browse Catalog Dialog
- Button
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Connector Setup Dialog
- Cookie Banner
- Dialog
- Directory Card
- Directory Detail
- Directory Skeleton
- DrawerНовое
- Token Parts Input
- Empty
- Field
- Fieldset
- File Preview Modal
- File Preview Skeleton
- Form
- Frame
- Group
- Icon
- Input
- Input Group
- Kbd
- Label
- Legal Shell
- Menu
- Mermaid Diagram
- Mind Map Diagram
- Not Found Screen
- Onboarding Frame
- Popover
- PDF Thumbnail
- Personalization Landing
- Preview Card
- Pricing Page
- Progress
- Radio Group
- Ring Spinner
- Scroll Area
- Select
- Separator
- Settings Page
- Settings Skills
- Settings Connectors
- Settings Capabilities
- Settings Usage
- Settings Account
- Settings Billing
- Sheet
- Sidebar
- Skeleton
- Skill Create Dialog
- Slider
- Spinner
- Stat
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Tooltip
AI-компоненты
- Компоненты AI
- Chat Conversation
- Chat Message
- Chat Response
- Chat Suggestion
- Chat Prompt Input
- Slash Highlighted Textarea
- Chat Search Dialog
- Chat Skill Doc
- Chat Connector Detail
- Chat Attachments
- Chat File Card
- Chat Token Chip
- Chat Code Block
- Chat Image
- Chat Inline Citation
- Chat Sources
- Chat Web Search
- Chat Research
- Chat Source
- Chat Actions
- Chat Context
- Chat Loader
- Chat Compaction
- Chat Timeline
- Chat Snippet
- Chat Terminal
- Chat Stack Trace
- Chat Test Results
- Chat File Tree
- Chat Environment Variables
- Chat Audio Player
- Chat Transcription
- Chat Speech Input
- Chat Mic Selector
- Chat Voice Selector
- Chat Agent
- Chat Persona
- Chat Connection
- Chat Connector Suggestion
- Chat Queue
- Chat Checkpoint
- Chat Confirmation
- Chat Artifact
- Chat JSX Preview
- Chat Schema Display
- Chat Package Info
- Chat Commit
- Chat Plan
- Chat Open In Chat
- Chat Sandbox
- Chat Model Selector
- Chat Canvas
- Chat Node
- Chat Edge
Ресурсы
Form
Компонент-обёртка для формы, упрощающий валидацию и отправку.
"use client";
import type { FormEvent } from "react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
export default function Particle() {
const [loading, setLoading] = useState(false);
const onSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
setLoading(true);
await new Promise((r) => setTimeout(r, 800));
setLoading(false);
alert(`Эл. почта: ${formData.get("email") || ""}`);
};
return (
<Form className="flex w-full max-w-64 flex-col gap-4" onSubmit={onSubmit}>
<Field name="email">
<FieldLabel>Эл. почта</FieldLabel>
<Input placeholder="you@example.com" required type="email" />
<FieldError>Введите корректный адрес эл. почты.</FieldError>
</Field>
<Button loading={loading} type="submit">
Отправить
</Button>
</Form>
);
}
Установка
pnpm dlx shadcn@latest add @oracul/form
Использование
import {
Field,
FieldError,
FieldLabel,
} from "@/components/ui/field"
import { Form } from "@/components/ui/form"
import { Input } from "@/components/ui/input"<Form
className="flex w-full flex-col gap-4"
onSubmit={(e) => {
/* handle submit */
}}
>
<Field>
<FieldLabel>Email</FieldLabel>
<Input name="email" type="email" required />
<FieldError>Please enter a valid email.</FieldError>
</Field>
</Form>Справочник API
Form
Тонкая обёртка вокруг Form из Base UI без компоновки по умолчанию. Передайте className для отступов и структуры (например, flex w-full flex-col gap-4 для вертикального стека полей).
Dialog, sheet, drawer: Размещайте DialogHeader (или заголовок sheet/drawer) вне формы. Оборачивайте в <Form className="contents"> (или <form className="contents">) только DialogPanel и DialogFooter. Значение свойства display contents позволяет панели и подвалу корректно участвовать во flex-компоновке всплывающего окна, не вкладывая заголовок внутрь <form>.
Примеры
Использование с Zod
"use client";
import type { FormEvent } from "react";
import { useState } from "react";
import { z } from "zod";
import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
const schema = z.object({
age: z.coerce
.number({ message: "Введите число." })
.positive({ message: "Число должно быть положительным." }),
name: z.string().min(1, { message: "Введите имя." }),
});
type Errors = Record<string, string | string[]>;
async function submitForm(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const result = schema.safeParse(Object.fromEntries(formData));
if (!result.success) {
const { fieldErrors } = z.flattenError(result.error);
return { errors: fieldErrors as Errors };
}
return {
errors: {} as Errors,
};
}
export default function Particle() {
const [loading, setLoading] = useState(false);
const [errors, setErrors] = useState<Errors>({});
const onSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
setLoading(true);
const response = await submitForm(event);
await new Promise((r) => setTimeout(r, 800));
setErrors(response.errors);
setLoading(false);
if (Object.keys(response.errors).length === 0) {
alert(
`Имя: ${String(formData.get("name") || "")}\nВозраст: ${String(
formData.get("age") || "",
)}`,
);
}
};
return (
<Form
className="flex w-full max-w-64 flex-col gap-4"
errors={errors}
onSubmit={onSubmit}
>
<Field name="name">
<FieldLabel>Имя</FieldLabel>
<Input placeholder="Введите имя" />
<FieldError />
</Field>
<Field name="age">
<FieldLabel>Возраст</FieldLabel>
<Input placeholder="Введите возраст" />
<FieldError />
</Field>
<Button loading={loading} type="submit">
Отправить
</Button>
</Form>
);
}
История изменений
- 17 апреля 2026 —
Formбольше не применяет классы компоновки по умолчанию; передавайтеclassNameдля стека полей (flex w-full flex-col gap-4); для оверлеев оборачивайте панель + подвал вForm className="contents", оставляя заголовок снаружи.