nook
Browse the docs

Components

Rich Text Editor

Native

A small editor for formatted text: headings, lists, quotes and links.

See the prompt

Release notes

Version 2.4 ships saved filters and a faster search.

  • Filters stay after a reload
  • Search answers in under a second
Thanks to everyone who tested the beta.

Installation

npx nook-ui@latest add rich-text-editor

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Rich Text Editor" component to this project, exactly as Nook ships it.

A small editor for formatted text: headings, lists, quotes and links.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add rich-text-editor`. It writes `components/ui/rich-text-editor.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/rich-text-editor.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { Label } from "@/components/ui/label";
import { RichTextEditor } from "@/components/ui/rich-text-editor";

const NOTES = `<h2>Release notes</h2><p>Version 2.4 ships <b>saved filters</b> and a faster <i>search</i>.</p><ul><li>Filters stay after a reload</li><li>Search answers in under a second</li></ul><blockquote>Thanks to everyone who tested the beta.</blockquote>`;

export default function RichTextEditorDefault() {
  return (
    <div className="grid w-full max-w-lg gap-2">
      <Label id="editor-label">Announcement</Label>
      <RichTextEditor aria-labelledby="editor-label" name="announcement" defaultValue={NOTES} placeholder="Write something" />
    </div>
  );
}
```

API
- `RichTextEditor`: The toolbar and the writing area. Pasted content comes in as plain text.
  - `defaultValue` (`string`): The starting content, as HTML you trust.
  - `onValueChange` (`(html: string) => void`): Called with the HTML after every change. Sanitize it before showing it elsewhere.
  - `placeholder` (`string`): Shown while empty.
  - `name` (`string`): Name submitted with a form. The value is the HTML.
  - `disabled` (`boolean`): Prevents editing.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The writing area is a multi-line textbox: name it with `aria-label` or `aria-labelledby`. The toolbar is one Tab stop; arrow keys move between tools and each reports whether it is on. Ctrl or ⌘ with B, I, U and Z work as usual.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { Label } from "@/components/ui/label";
import { RichTextEditor } from "@/components/ui/rich-text-editor";

const NOTES = `<h2>Release notes</h2><p>Version 2.4 ships <b>saved filters</b> and a faster <i>search</i>.</p><ul><li>Filters stay after a reload</li><li>Search answers in under a second</li></ul><blockquote>Thanks to everyone who tested the beta.</blockquote>`;

export default function RichTextEditorDefault() {
  return (
    <div className="grid w-full max-w-lg gap-2">
      <Label id="editor-label">Announcement</Label>
      <RichTextEditor aria-labelledby="editor-label" name="announcement" defaultValue={NOTES} placeholder="Write something" />
    </div>
  );
}

Props

RichTextEditor

The toolbar and the writing area. Pasted content comes in as plain text.

PropTypeDefaultDescription
defaultValuestring–The starting content, as HTML you trust.
onValueChange(html: string) => void–Called with the HTML after every change. Sanitize it before showing it elsewhere.
placeholderstring–Shown while empty.
namestring–Name submitted with a form. The value is the HTML.
disabledboolean–Prevents editing.

Accessibility

The writing area is a multi-line textbox: name it with `aria-label` or `aria-labelledby`. The toolbar is one Tab stop; arrow keys move between tools and each reports whether it is on. Ctrl or ⌘ with B, I, U and Z work as usual.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.