Ir al contenido

CellEditor

Un valor que se cambia en su sitio, fuera de una tabla: en una lista, una tarjeta o una página de detalles. La DataTable usa el mismo comportamiento en sus celdas.

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

En esta página
  1. Detalles de un producto
  2. Cuándo usarlo
  3. Para todos
  4. Props

Detalles de un producto

Prueba un precio menor que cero: el servidor lo rechaza.

Name
Price
Category
SKU
Created
Código
import { CellEditor, KeyValue } from '@sypnia/ui/react';

// Press a value to change it. Enter saves, Escape puts the old value back. A price below zero is refused by the
// server: the old value comes back and the reason is said in words.
const save = (v: string) => new Promise<void>((ok, fail) => setTimeout(() => (Number(v) < 0 ? fail(new Error('A price cannot be below zero.')) : ok()), 700));
export default function Prices() {
  return (
    <KeyValue items={[
      ['Name', <CellEditor key="n" label="Name" value="Sourdough loaf" onCommit={save} />],
      ['Price', <CellEditor key="p" label="Price" editor="number" value={6.5} onCommit={save} render={(v) => `$${Number(v).toFixed(2)}`} />],
      ['Category', <CellEditor key="c" label="Category" editor="select" value="Bread" options={['Bread', 'Pastry', 'Drinks']} onCommit={save} />],
      ['SKU', <CellEditor key="s" label="SKU" machine value="BRD-0042" onCommit={save} />],
      ['Created', <CellEditor key="d" label="Created" value="2026-03-04" disabled onCommit={save} />],
    ]} />
  );
}

Cuándo usarlo

Úsalo cuando

  • Páginas de detalle donde uno o dos valores cambian a menudo: un precio, un nombre.
  • onCommit guarda; lanza un Error con un mensaje para decir por qué no se guardó.

No lo uses cuando

  • Formularios de varios campos que se guardan juntos: usa un Form con una SaveBar.
  • Valores que necesitan una explicación larga para cambiarse: usa un Dialog.

Para todos

  • El valor es un botón llamado «Editar Precio: 12».
  • Enter guarda, Escape devuelve el valor anterior y el foco vuelve al valor.
  • Un guardado fallido se anuncia, con la razón en palabras.

Props

CellEditorTipoPor defecto
labelobligatorio

What the value is: «Price». It names the button and the field.

string
onCommitobligatorio

Saves the new value. Throw an Error with a message to say why it was not saved.

(value: string) => void | Promise<void>
valueobligatorio string | number | null
disabled boolean
editor "number" | "text" | "select" text
machine

Machine text (ids, keys): set in the mono face.

boolean
options DataOption[]
render

How the value is drawn when it is not being edited.

((value: string | number | null) => ReactNode)
  1. Detalles de un producto
  2. Cuándo usarlo
  3. Para todos
  4. Props

    Busca páginas, secciones y términos