Textarea
Varias líneas de texto: una descripción, una nota, una regla. Crece a medida que la persona escribe.
import { Textarea } from '@sypnia/ui/react'
Una descripción
Empieza con dos líneas de alto y crece con el texto.
One or two sentences for the people you invite.
Código
import { Field, FormGrid, Textarea } from '@sypnia/ui/react';
// It grows with what is written, and can be dragged taller.
export default function Basic() {
return (
<FormGrid>
<Field label="Description" optional hint="One or two sentences for the people you invite." wide>
<Textarea defaultValue="Orders, customers and products of the online store. The mobile app and the back office both read from here." />
</Field>
</FormGrid>
);
} Texto de máquina
Una condición en SQL, con letra monoespaciada y sin corrector ortográfico.
A condition in SQL. A row is visible when it is true.
Código
import { Field, FormGrid, Textarea } from '@sypnia/ui/react';
export default function Machine() {
return (
<FormGrid>
<Field label="Access rule" hint="A condition in SQL. A row is visible when it is true." wide>
<Textarea machine rows={3} spellCheck={false} defaultValue={"customer_id = auth.user_id()\nand status <> 'draft'"} />
</Field>
</FormGrid>
);
} Límite y desactivado
La pista cuenta caracteres desde el principio; borra algo de texto para quitar el error.
118 of 120 characters
Refunds are closed for this order.
Código
import { useState } from 'react';
import { Field, FormGrid, Textarea } from '@sypnia/ui/react';
export default function States() {
const [note, setNote] = useState('Refund approved by phone. The customer keeps the damaged item and gets a new one on the next shipment, free of charge.');
const max = 120;
return (
<FormGrid>
<Field label="Note for the order" hint={`${note.length} of ${max} characters`}
error={note.length > max ? `Shorten the note: it has ${note.length - max} characters too many.` : undefined}>
<Textarea value={note} onChange={(e) => setNote(e.target.value)} />
</Field>
<Field label="Reason for the refund" hint="Refunds are closed for this order.">
<Textarea disabled defaultValue="Arrived damaged." />
</Field>
</FormGrid>
);
} Cuándo usarlo
Úsalo cuando
- La respuesta puede ocupar más de una línea: descripciones, notas, mensajes.
- Un fragmento corto de código o una condición: agrega
machine.
No lo uses cuando
- Basta con una línea: usa Input.
- Es código de verdad con resaltado, números de línea o muchas líneas: eso es CodeEditor.
- Hay un límite estricto y solo lo dices después de que la persona lo pasa. Di el límite en la pista desde el principio.
Para todos
- Dentro de un Field toma la etiqueta, la pista y el error por sí solo.
- Enter agrega una línea; nunca envía el formulario. Tab sale del campo.
- Se puede arrastrar para hacerlo más alto, y crece con su contenido donde el navegador lo permite.
Props
| Textarea | Tipo | Por defecto |
|---|---|---|
machine | boolean |