Ir al contenido

FormSection

Divide un formulario largo en partes, con un título y una frase que dice para qué son los campos. El título va a la izquierda en pantallas anchas y arriba en tabletas y celulares.

import { FormSection, Field } from '@sypnia/ui/react'

En esta página
  1. Una página de ajustes en dos partes
  2. Skeleton
  3. Cuándo usarlo
  4. Para todos
  5. Props

Una página de ajustes en dos partes

Angosta la ventana: por debajo del ancho de una tableta el título pasa arriba.

General

How the project is called and where its data lives.

It cannot be changed after the project is created.

Backups

Copies of the database, kept for the days you choose.

Código
import { Field, FormSection, Input, NativeSelect, Switch } from '@sypnia/ui/react';

// A long form in parts: each section says what its fields are for. On tablets and phones the title goes on top.
export default function Settings() {
  return (
    <div className="sy-form">
      <FormSection title="General" description="How the project is called and where its data lives.">
        <Field label="Project name"><Input defaultValue="Storefront" /></Field>
        <Field label="Region" hint="It cannot be changed after the project is created.">
          <NativeSelect defaultValue="eu" disabled><option value="eu">Frankfurt</option></NativeSelect>
        </Field>
      </FormSection>
      <FormSection title="Backups" description="Copies of the database, kept for the days you choose.">
        <Switch label="Daily backup" description="Runs at 03:00 in the project's time zone." defaultChecked />
        <Field label="Keep for (days)"><Input defaultValue="7" inputMode="numeric" /></Field>
      </FormSection>
    </div>
  );
}

Skeleton

La pieza real y su skeleton: la misma caja, así nada se mueve cuando llegan los datos.

General

How the project is called.

Backups

Copies of the database, kept for the days you choose.

Código
import { Field, FormSection, FormSectionSkeleton, Input } from '@sypnia/ui/react';

// With `loading` the title stays and the fields wait; FormSectionSkeleton is for when nothing is known yet.
export default function Skeleton() {
  return (
    <div className="sy-form">
      <FormSection title="General" description="How the project is called."><Field label="Project name"><Input defaultValue="Storefront" /></Field></FormSection>
      <FormSection title="Backups" description="Copies of the database, kept for the days you choose." loading fields={1} />
      <FormSectionSkeleton fields={1} />
    </div>
  );
}

Cuándo usarlo

Úsalo cuando

  • Páginas de ajustes y formularios largos con grupos de campos que van juntos.
  • Escribe la descripción como lo que la persona obtiene, no como lo que son los campos: «Copias de la base de datos, guardadas los días que elijas».

No lo uses cuando

  • Formularios de tres o cuatro campos: un título por campo es ruido.
  • Agrupar opciones que responden una sola pregunta: eso es un Fieldset con su leyenda.

Para todos

  • Cada sección es una región nombrada por su título, así se llega a ella desde la lista de regiones.
  • El título es un encabezado de nivel 2; pon el título de la página en un PageHeader encima.

Props

FormSectionTipoPor defecto
titleobligatorio ReactNode
className string
description ReactNode
fields

How many field skeletons to show while loading.

number 2
loading

The values are on their way: the title stays and the fields are skeletons.

boolean
FieldTipoPor defecto
labelobligatorio ReactNode
className string
error

What is wrong and how to fix it. Its presence marks the control as invalid.

ReactNode
hint

Help that is always visible: what to write, in what format.

ReactNode
optional

Adds «optional» beside the label. Required is the default and is not marked.

boolean
wide

Spans both columns of a FormGrid.

boolean
  1. Una página de ajustes en dos partes
  2. Skeleton
  3. Cuándo usarlo
  4. Para todos
  5. Props

    Busca páginas, secciones y términos