Ir al contenido

CodeEditor

Unas pocas líneas de código con números de línea. Tab indenta, Shift+Tab quita sangría, Ctrl/⌘+Enter ejecuta. Ligero a propósito: sin resaltado, así carga al instante y funciona con cualquier lector de pantalla.

import { CodeEditor, CodeEditorSkeleton } from '@sypnia/ui/react'

En esta página
  1. Una función
  2. Cuándo usarlo
  3. Para todos
  4. Props

Una función

Código
import { useState } from 'react';
import { CodeEditor, CodeEditorSkeleton, Field } from '@sypnia/ui/react';

// Tab indents and Shift+Tab outdents; the line numbers follow. The skeleton is under it.
export default function Script() {
  const [code, setCode] = useState("export default async (req) => {\n  const user = await req.user();\n  return { hello: user.name };\n};");
  return <div className="sy-stack"><Field label="Function"><CodeEditor value={code} onChange={setCode} language="JavaScript" rows={6} /></Field><CodeEditorSkeleton rows={4} /></div>;
}

Cuándo usarlo

Úsalo cuando

  • Funciones cortas, scripts, plantillas.

No lo uses cuando

  • Archivos completos: enlaza al repositorio o a un editor.

Para todos

  • Es un área de texto donde Tab indenta; pulsa Escape y luego Tab para seguir, así el teclado nunca queda atrapado.

Props

CodeEditorTipoPor defecto
onChangeobligatorio (v: string) => void
valueobligatorio string
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks the value as wrong. Inside a `<Field error>` it is set for you.

boolean
language

The language, said to screen readers and used by SqlEditor and JsonEditor.

string
onRun

Runs with Ctrl/⌘ + Enter.

(() => void)
placeholder string
readOnly boolean
rows

Visible lines before it scrolls.

number 10
CodeEditorSkeletonTipoPor defecto
rows number 10
  1. Una función
  2. Cuándo usarlo
  3. Para todos
  4. Props

    Busca páginas, secciones y términos