w6w docs

Editors

One read-only block and three editors. All four are props-only and follow the current theme. CodeBlock’s syntax colors come from the --w6w-code-* tokens. The editors use the general surface tokens (--w6w-panel-2, --w6w-text, --w6w-border, --w6w-accent) with CodeMirror’s light or dark highlighting.

CodeBlock

Read-only, syntax-highlighted code with a copy button. It’s the one component in the lightweight @w6w/ui/code entrypoint, which leaves out the editors and the expression engine. Use that entrypoint, with @w6w/ui/code.css, on a page that only shows code.

PropTypeDefaultWhat it does
codestringRequiredThe source, rendered verbatim.
languageCodeLanguage"plaintext"bash, shell, json, typescript, tsx, javascript, jsx, yaml, sql, markdown, python, go, rust, markup, css or plaintext.
copyablebooleantrueThe copy button. Turn it off when the block is server-rendered and never hydrated, or the button won’t respond.
wrapbooleanfalseSoft-wrap long lines instead of scrolling sideways.
showLineNumbersbooleanfalseA line-number gutter.
maxHeightstringNoneCap the height and scroll, such as "320px".
copiedMsnumber1500How long the copied checkmark shows.
className, aria-labelstringNoneclassName lands on the <pre>. The label defaults to naming the language.
import { CodeBlock } from "@w6w/ui/code";
import "@w6w/ui/code.css";

<CodeBlock language="bash" code={`curl -H "Authorization: Bearer $W6W_TOKEN" https://<your-host>/apps`} />

CodeBlock is exported from the root @w6w/ui too, so you don’t need a second import when you already load the full library.

Every line and every token CodeBlock renders carries an explicit React key, including repeated, blank and whitespace-only lines, so the block raises no key warning. If your console shows a Each child in a list should have a unique "key" prop warning that names Highlight, it is not this component: it comes from a different renderer, either Highlight from prism-react-renderer used directly with the library’s documented spread pattern, or an older copy of CodeBlock. Import CodeBlock from @w6w/ui/code and pin a current commit of w6w-ui.

JsonEditor

A JSON editor with parse errors marked inline.

PropTypeDefaultWhat it does
valuestringRequiredThe text, which may be invalid JSON mid-edit.
onChange(value: string) => voidRequiredEvery edit.
onValidChange(parsed: unknown) => voidNoneFires with the parsed value whenever the text is valid JSON. Never fires while it’s invalid.
onValidityChange({ valid, error? }) => voidNoneFires on every edit, so you can disable a Save button while the JSON is broken.
minHeightstring"240px"
maxHeightstringNoneScroll past this height.
heightstringNoneA fixed height. "100%" fills a flex parent.
copyablebooleanfalseAn in-box copy button.
placeholder, readOnly, theme, aria-label
import { JsonEditor } from "@w6w/ui";

const [text, setText] = useState('{\n  "to": "team@example.com"\n}');
const [valid, setValid] = useState(true);

<JsonEditor value={text} onChange={setText} onValidityChange={(r) => setValid(r.valid)} minHeight="160px" />
<button className="w6w-btn" disabled={!valid} onClick={() => save(JSON.parse(text))}>Save</button>

YamlEditor

The same editor for YAML: value, onChange, placeholder, minHeight (default "240px"), maxHeight, height, readOnly, theme, aria-label and copyable (default off). It has no validity callbacks: parse the text yourself when you need to.

import { YamlEditor } from "@w6w/ui";

<YamlEditor value={yamlText} onChange={setYamlText} minHeight="320px" />

CodeEditor

A plain code editor for script snippets, with optional highlighting.

PropTypeDefaultWhat it does
value, onChangestring, (value) => voidRequired
language"javascript" | "python"NoneHighlighting and language-aware editing. Omit it for plain text.
minHeightstring"160px"
maxHeight, height, placeholder, readOnly, theme, aria-labelAs on JsonEditor.
import { CodeEditor } from "@w6w/ui";

<CodeEditor language="javascript" value={script} onChange={setScript} aria-label="Script" />

Where to next

  • Theming: the color tokens, including --w6w-code-*.
  • Forms: PropertyEntryForm, which pairs fields with a JSON view.