Ir al contenido

Label

El nombre de un control, para cuando un control necesita su propio diseño. Dentro de un Field apunta solo al control del Field; fuera, dale htmlFor.

import { Label } from '@sypnia/ui/react'

En esta página
  1. Una etiqueta con contador
  2. Opcional
  3. Cuándo usarlo
  4. Para todos
  5. Props

Una etiqueta con contador

Escribe en el campo: el contador lo sigue.

33 / 120

People who see the key in the list read this to know whether they can delete it.

Código
import { useState } from 'react';
import { Hint, Label, Textarea } from '@sypnia/ui/react';

// When a control needs its own layout, such as a count written beside the label, use the parts on their own.
export default function Custom() {
  const [text, setText] = useState('Nightly copy of the orders table.');
  return (
    <div className="sy-field">
      <div className="sy-row sy-row--between">
        <Label htmlFor="purpose">What this key is for</Label>
        <output htmlFor="purpose" className="sy-text--muted">{text.length} / 120</output>
      </div>
      <Textarea id="purpose" maxLength={120} value={text} onChange={(e) => setText(e.target.value)} aria-describedby="purpose-hint" />
      <Hint id="purpose-hint">People who see the key in the list read this to know whether they can delete it.</Hint>
    </div>
  );
}

Opcional

Código
import { Label } from '@sypnia/ui/react';

// Mark what can be left empty, not what is required: most fields in a good form are required.
export default function Optional() {
  return (
    <div className="sy-stack">
      <div className="sy-field"><Label htmlFor="org">Organization name</Label><input id="org" className="sy-input" defaultValue="Northwind" /></div>
      <div className="sy-field"><Label htmlFor="vat" optional>Tax number</Label><input id="vat" className="sy-input sy-input--machine" /></div>
    </div>
  );
}

Cuándo usarlo

Úsalo cuando

  • Una etiqueta con algo al lado, como un contador o un enlace.
  • Marca con optional los campos que se pueden dejar vacíos.

No lo uses cuando

  • Campos comunes: un Field escribe por ti la etiqueta, la ayuda y el error.
  • Textos de ejemplo en vez de etiquetas: desaparecen en cuanto alguien escribe.

Para todos

  • Cada control tiene una etiqueta visible unida con for.
  • «opcional» es parte de la etiqueta, así se lee con ella.

Props

LabelTipoPor defecto
htmlFor string
optional boolean
  1. Una etiqueta con contador
  2. Opcional
  3. Cuándo usarlo
  4. Para todos
  5. Props

    Busca páginas, secciones y términos