All components (244)
Rich text editor
Fields · RichTextEditor
What it is and when to use it
An own rich text editor with no dependencies at all: it is imported from @amset/ui/rich-text and only loaded where it is used. Write with the toolbar or with the keyboard (Markdown shortcuts work: # , - , 1. , > , **bold**), paste from Word or Google Docs without dragging their junk along, and store JSON (the exact thing) or HTML, as chosen with format.
When to use it
- The long text of a management panel: a product description, a news item, an email template.
- Content that is later shown with
RichTextView, on the server too and withoutdangerouslySetInnerHTML.
When not to
- Text without formatting:
TextArea. Code:CodeField.
Insert and configure: the Insert button in the toolbar opens everything that can go into the document (text, structure, custom blocks and the AMSET UI components by family), with a search box; the same list appears when you type "/". A freshly inserted component comes with its properties open, and they open again with a double click on it, with the right button or with the toolbar button.
Right button: what is underneath (a component: properties, duplicate, move up, move down, delete; an image; a link: edit, open, remove it; a table: rows, columns and cells) and the usual editing (cut, copy, paste, formatting). From the keyboard, the menu key or Shift+F10.
Images: the image panel lets you choose one from this device or paste its address; pasting or dropping a screenshot works too. With onImageUpload it is uploaded wherever the application says; without it, it is embedded in the document. The alternative text is always asked for (or mark it as decorative).
Links: the panel asks for the link text (what is read out), the address and an optional tooltip, and warns when the text does not say where it goes ("here", an address).
Full screen: the browser one; if it is not allowed (an iframe without permission), the top layer, which fills the window even when the editor lives inside something with transform.
Value: format="json" (the default) returns and receives the document; format="html" returns and receives already sanitised HTML text. Controlled with value or free with defaultValue. maxLength is optional: without a value, there is no limit.
Keyboard: Alt+F10 moves to the toolbar and Escape goes back to the text. Tab goes down a level in a list or jumps cell in a table; Mod+Z and Mod+Shift+Z undo and redo; Mod+F finds and replaces.
Accessibility: label is required. The editable area is a multi-line textbox with its name, hint and error linked; the counter announces how many characters are left only when they are few. What is pasted and what is exported goes through a schema that discards everything it does not know: no <script>, no handlers, no javascript:.
Fine styling: --amset-richtext-min-height and --amset-richtext-max-height (also with rows and maxHeight); the typography of the written text is .amset-richtext__content.
What it looks like
import { RichTextEditor } from "@amset/ui/rich-text";
<RichTextEditor
label="Product description"
format="html"
defaultValue={html}
onChange={setHtml}
rows={6}
counter
/>Props
Import it with import { RichTextEditor } from '@amset/ui/rich-text'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
labelrequired | string | Obligatoria: es el nombre del campo para quien no lo ve. |
hiddenLabel | boolean | — |
hint | string | — |
error | string | — |
placeholder | string | — |
rows | number | Lineas que se ven de salida. Al escribir mas, crece. |
maxHeight | string | number | La altura a partir de la cual el area se desplaza en vez de crecer. Sin valor, crece sin limite. |
toolbar | boolean | La barra de herramientas. Por defecto, si. |
shortcuts | RichTextShortcuts | Los atajos que se anuncian en la barra. |
counter | boolean | Enseña cuanto texto lleva (palabras y caracteres) bajo el editor. |
maxLength | number | Limite de caracteres, solo si lo quieres: sin valor no hay limite. Se enseña «123 / 500». |
blocks | RichTextBlocks | Los bloques propios que se pueden insertar y pintar dentro del texto (una tarjeta, una grafica...), por su `kind`. Cada uno sale en el menu «/» y se pinta con su `render`. |
aiCommands | readonly RichTextAiCommand[] | Los comandos del asistente ("Resumir", "Traducir"...): salen en el menu «/» y en la barra flotante. |
onAiCommand | (request: RichTextAiRequest) => void | Se elige un comando del asistente. Lo que pase despues (llamar a un modelo, proponer cambios) es cosa de quien integra el editor. |
bubbleToolbar | boolean | La barra que sale sobre un texto seleccionado. Por defecto, si. |
blockHandles | boolean | El asa para arrastrar bloques de sitio, a la izquierda de cada uno. Por defecto, si. |
accessibilityCheck | boolean | Avisa mientras se escribe de lo que falta para que sea accesible (imagenes sin descripcion, tablas sin cabecera...). Por defecto, si. |
mentions | RichTextMentions | Con esto, escribir «@» y un nombre abre una lista de lo que devuelva `search`; elegir una pone la mencion en el texto. |
onImageUpload | (file: File) => Promise<string> | Uploads a file (an image pasted, dropped or chosen from this device in the image panel) and returns its address. Without it the image is embedded in the document as base64: it works without a server, but it is heavy. |
spellchecker | RichTextSpellchecker | El corrector ortografico: con uno, los fallos se subrayan, el boton derecho (o la tecla de menu) sobre uno ofrece sugerencias, ignorar y, si el corrector lo sabe, añadir al diccionario. Ver `createWordSpellchecker` y `createLanguageToolSpellchecker`. Sin esto se queda el del navegador. |
lang | string | El idioma del texto (`es`, `en-GB`): lo usa el corrector y el atributo `lang` del area editable. |
review | RichTextReview | Comentarios y sugerencias: con esto la barra trae «Comentar», «Sugerir cambios» y la lista de revision. Los hilos los guardas tu (`threads`/`onThreadsChange`); las sugerencias van dentro del documento. |
versions | RichTextVersions | El historial de versiones: la barra trae un boton que abre la lista, deja ver lo que cambio desde cada version y restaurarla (se puede deshacer). Las versiones las guardas tu: `versions`, `load` y, para guardar desde el panel, `onSave`. |
autoFocus | boolean | — |
name | string | Con `name`, el editor lleva un campo oculto con el HTML para que un formulario normal (sin JavaScript) lo envie. |
onFocus | () => void | El foco entra en el area editable o sale de ella: lo que necesita un formulario para saber si se ha tocado. |
onBlur | () => void | — |
className | string | — |
style | CSSProperties | — |
id | string | — |
aria-describedby | string | — |
editorRef | Ref<RichTextEditorHandle> | El manejador para enfocar el editor o leer su documento desde fuera. |
format | 'json' | — |
value | RichDocument | — |
defaultValue | RichDocument | — |
onChange | (value: RichDocument) => void | — |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
In the test bench
Every state and variant, to try one at a time, on its page at ui.amset.tech:
- Interactivo
- Vacío
- Con límite de caracteres
- Con error
- Solo lectura
- Apagado
- Sin barra
- Con altura máxima
- Con valor JSON y vista
- Con menciones
- Con celdas combinadas
- Con Markdown y Word
- Con avisos de accesibilidad
- Con cuadros y desplegables
- Con bloques propios
- Con asistente de IA
- Con componentes de AMSET UI
- Con corrector ortográfico
- Con comentarios y sugerencias
- Con historial de versiones
- Con columnas
- Con fórmulas
