본문으로 건너뛰기

예제

폼

접근 가능한 레이블, 검증 상태, 텍스트·날짜·기간 입력, 그룹 선택 컨트롤을 조합합니다.

공개 계약NxCheckboxNxComboboxNxFieldGroupNxFieldLegendNxFieldsetNxFileDropzoneNxFormFieldNxFormSectionNxSearchFieldNxSelectNxTextAreaNxTextInputNxDatePickerNxDateRangePickerNxRadioNxRadioGroupNxLookupFieldNxResourceFormLegalEntityFieldNxLookupDialogNxDocumentDataFieldPicker

실행 미리 보기

실시간

팀원이 알아보기 쉬운 이름을 사용하세요.

알림
검토 주기

복사 가능한 소스

코드 예시
TSX
import { useState } from "react";
import type { DocumentDataCatalogPage, NxLookupRow } from "@nexia/sdk";

import {
    NxButton,
    NxCheckbox,
    NxCombobox,
    NxDatePicker,
    NxDateRangePicker,
    NxFieldGroup,
    NxFieldLegend,
    NxFieldset,
    NxFileDropzone,
    NxFormField,
    NxFormSection,
    NxDocumentDataFieldPicker,
    NxLookupDialog,
    NxLookupField,
    NxResourceFormLegalEntityField,
    NxRadio,
    NxRadioGroup,
    NxSearchField,
    NxSelect,
    NxTextArea,
    NxTextInput,
} from "@nexia/sdk/host";

// Replace with a server-authorized DocumentDataHost catalog request.
const loadDocumentFields = async (): Promise<DocumentDataCatalogPage> => ({
    data: [{ app_key: "workshop", app_name: "Workshop", source_key: "workshop.note",
        source_version: 1, label: "Note", cardinality: "one",
        field: { key: "name", label: "Name", label_key: "sample.name", type: "string", formatters: ["plain"] },
        binding: { app_key: "workshop", source_key: "workshop.note", source_version: 1, field_key: "name" } }],
    next_offset: null,
});

const TEAM_OPTIONS = [
    { value: "operations", label: "Operations" },
    { value: "quality", label: "Quality" },
    { value: "maintenance", label: "Maintenance" },
] as const;

export function FormsExample() {
    const [search, setSearch] = useState("");
    const [legalEntity, setLegalEntity] = useState<string | null>(null);
    const [team, setTeam] = useState<string | null>("operations");
    const [owner, setOwner] = useState<string | null>("min-kim");
    const [reviewer, setReviewer] = useState<string | null>(null);
    const [lookupOpen, setLookupOpen] = useState(false);
    const [documentOpen, setDocumentOpen] = useState(false);
    const [documentField, setDocumentField] = useState("");
    const [lookupSearch, setLookupSearch] = useState("");
    const [lookupSelection, setLookupSelection] = useState<NxLookupRow[]>([]);
    const lookupRows: NxLookupRow[] = ["Min Kim", "Sora Choi"]
        .filter((label) => label.toLowerCase().includes(lookupSearch.toLowerCase()))
        .map((label) => ({ value: label, label, cells: { name: label } }));
    const [fileName, setFileName] = useState<string | null>(null);
    const [cadence, setCadence] = useState("weekly");
    const [reviewDate, setReviewDate] = useState<string | null>("2026-09-15");
    const [reportingPeriod, setReportingPeriod] = useState<{
        start: string | null;
        end: string | null;
    }>({
        start: "2026-09-01",
        end: "2026-09-30",
    });

    return (
        <NxFormSection
            placement="footer"
            spacing="stack"
            actions={<NxButton type="submit">Save</NxButton>}
            onSubmit={(event) => event.preventDefault()}
        >
            <NxFieldGroup className="grid gap-5 lg:grid-cols-2">
                <NxFormField
                    label="Workspace name"
                    help="Use a name your team will recognize."
                    required
                >
                    {({ id, describedBy, invalid }) => (
                        <NxTextInput
                            id={id}
                            aria-describedby={describedBy}
                            invalid={invalid}
                            defaultValue="Operations"
                        />
                    )}
                </NxFormField>
                <NxFormField label="Description">
                    {({ id, describedBy, invalid }) => (
                        <NxTextArea
                            id={id}
                            aria-describedby={describedBy}
                            invalid={invalid}
                            rows={3}
                            defaultValue="Daily production coordination"
                        />
                    )}
                </NxFormField>
                <NxSearchField
                    value={search}
                    onChange={setSearch}
                    placeholder="Search records"
                    aria-label="Search records"
                />
                <NxSelect<string>
                    value={team}
                    options={TEAM_OPTIONS}
                    onChange={setTeam}
                    placeholder="Select a team"
                    ariaLabel="Team"
                    fullWidth
                />
                <NxCombobox<string>
                    value={owner}
                    onChange={setOwner}
                    options={[
                        {
                            value: "min-kim",
                            label: "Min Kim",
                            meta: "Operations",
                        },
                        {
                            value: "sora-choi",
                            label: "Sora Choi",
                            meta: "Quality",
                        },
                    ]}
                    placeholder="Select an owner"
                    ariaLabel="Owner"
                    searchPlaceholder="Search people"
                    fullWidth
                />
                <NxLookupField<string>
                    value={reviewer}
                    onChange={setReviewer}
                    options={[
                        { value: "min-kim", label: "Min Kim" },
                        { value: "sora-choi", label: "Sora Choi" },
                    ]}
                    placeholder="Select a reviewer"
                    ariaLabel="Reviewer"
                />
                <NxFileDropzone
                    accept=".csv"
                    onFile={(file) => setFileName(file.name)}
                    prompt="Drop a CSV file here"
                    browseLabel="Browse"
                    hint="Up to 10 MB"
                    selectedFileName={fileName}
                    inputLabel="Upload CSV"
                />
            </NxFieldGroup>
            {/* Supply only targets authorized for this actor and create operation. */}
            <div>
                <NxButton type="button" variant="secondary" onClick={() => setLookupOpen(true)}>Select reviewers</NxButton>
                <NxLookupDialog
                    open={lookupOpen} onClose={() => setLookupOpen(false)} title="Select reviewers" multiple
                    value={lookupSelection} onApply={setLookupSelection} rows={lookupRows}
                    columns={[{ key: "name", label: "Name" }]}
                    search={lookupSearch} onSearchChange={setLookupSearch}
                    page={1} pageSize={25} total={lookupRows.length} onPageChange={() => {}}
                />
            </div>
            <div>
                <NxButton type="button" variant="secondary" onClick={() => setDocumentOpen(true)}>Choose a document field</NxButton>
                {documentField ? <p role="status">{documentField}</p> : null}
                <NxDocumentDataFieldPicker open={documentOpen} onClose={() => setDocumentOpen(false)}
                    title="Choose a document field" loadPage={loadDocumentFields} onSelect={(field) => {
                        setDocumentField("binding" in field ? field.field?.label ?? "" : field.label);
                        setDocumentOpen(false);
                    }} />
            </div>
            <NxResourceFormLegalEntityField
                mode="create"
                target={{ kind: "select", value: legalEntity, onChange: setLegalEntity,
                    options: [{ value: "seoul", label: "Seoul" }, { value: "busan", label: "Busan" }] }}
            />
            <NxFieldset>
                <NxFieldLegend>Notifications</NxFieldLegend>
                <NxCheckbox
                    label="Email me when provisioning completes"
                    defaultChecked
                />
            </NxFieldset>
            <NxFieldset>
                <NxFieldLegend>Review cadence</NxFieldLegend>
                <NxRadioGroup
                    name="review-cadence"
                    value={cadence}
                    onChange={setCadence}
                    orientation="horizontal"
                    aria-label="Review cadence"
                >
                    <NxRadio value="weekly" label="Weekly" />
                    <NxRadio value="monthly" label="Monthly" />
                </NxRadioGroup>
            </NxFieldset>
            <NxFieldGroup className="grid gap-5 lg:grid-cols-2">
                <NxDatePicker
                    label="Next review"
                    value={reviewDate}
                    onChange={setReviewDate}
                    clearable
                />
                <NxDateRangePicker
                    label="Reporting period"
                    value={reportingPeriod}
                    onChange={setReportingPeriod}
                    clearable
                />
            </NxFieldGroup>
        </NxFormSection>
    );
}
예제 원본: docs/developers/examples/ui/forms.tsx