A rich text editor whose value is Markdown.
Installation#
bunx --bun fabricator-ui@latest add editor
Usage#
import {
Editor,
EditorBubbleMenu,
EditorContent,
EditorFooter,
EditorKeyboardBar,
EditorLinkPopover,
EditorToolbar,
EditorWordCount,
} from "@/components/ui/editor"
import { Markdown } from "@/components/ui/markdown"
import { Text } from "@/components/ui/text"
import { Editor, EditorContent } from "@/components/ui/editor"<Editor defaultValue={notes} className="w-full">
<EditorToolbar />
<EditorContent />
<EditorBubbleMenu />
<EditorLinkPopover />
<EditorKeyboardBar />
<EditorFooter>
<EditorWordCount />
</EditorFooter>
</Editor>Composition#
EditorEditorBlockTypeMenuEditorBubbleMenuEditorContentEditorFooterEditorKeyboardBarEditorKitEditorKitRuntimeEditorLinkPopoverEditorToolbarEditorToolbarButtonEditorToolbarGroupEditorToolbarSeparatorEditorWordCount
Examples#
import * as React from "react"
import { View } from "react-native"
import {
Editor,
EditorBubbleMenu,
EditorContent,
EditorFooter,
EditorKeyboardBar,
EditorLinkPopover,
EditorToolbar,
EditorWordCount,
} from "@/components/ui/editor"
import { Markdown } from "@/components/ui/markdown"
import { Text } from "@/components/ui/text"
const notes = `# Release notes
Write here. Select text to **format** it, or type Markdown: \`# \` for a heading, \`- \` for a list, \`[] \` for a task.
## Headings
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
## Inline formatting
Text can be **bold**, *italic*, ***both***, ~~struck through~~ or \`inline code\`, and links go to the [changelog](https://fabricator-ui.vercel.app/docs/changelog).
## Lists
- Markdown preview
- Rich text editor
- Web
- iOS
1. Parse the file
2. Edit it
3. Save only what changed
- [x] Parser and serializer
- [x] Web editor
- [ ] Android editor
## Quote
> Unedited blocks save byte for byte.
## Code
\`\`\`tsx
import { Editor, EditorContent } from "@/components/ui/editor"
export function Notes() {
return <Editor defaultValue="# Hello" />
}
\`\`\`
---
## Table
| Platform | Editor | Preview |
| :------- | :----: | ------: |
| Web | Yes | Yes |
| iOS | Yes | Yes |
| Android | Soon | Yes |
`
const review = `## Review
Ship it once **design** signs off. Questions to [Gabs](mailto:gabs@fabricator.dev).
`
const initial = `## Weekly sync
Review the *editor* with **design** on Friday.
1. Typography
2. Keyboard bar
`
function EditorExample() {
const [value, setValue] = React.useState(initial)
return (
<ExampleWrapper>
<Example title="Default" framed={false}>
<Editor defaultValue={notes} className="w-full">
<EditorToolbar />
<EditorContent />
<EditorBubbleMenu />
<EditorLinkPopover />
<EditorKeyboardBar />
<EditorFooter>
<EditorWordCount />
</EditorFooter>
</Editor>
</Example>
<Example title="Placeholder" framed={false}>
<Editor placeholder="Write something" className="w-full">
<EditorContent size="sm" />
<EditorKeyboardBar />
</Editor>
</Example>
<Example title="Read-only" framed={false}>
<Editor defaultValue={review} readOnly className="w-full">
<EditorToolbar />
<EditorContent size="sm" />
</Editor>
</Example>
<Example title="Controlled, with its Markdown" framed={false}>
<Editor value={value} onValueChange={setValue} className="w-full">
<EditorToolbar />
<EditorContent size="sm" />
<EditorLinkPopover />
<EditorKeyboardBar />
</Editor>
<View className="w-full gap-3">
<Text
selectable
className="rounded-xl bg-muted p-4 font-mono text-xs text-muted-foreground"
>
{value}
</Text>
<Markdown size="sm">{value}</Markdown>
</View>
</Example>
<Example title="Size lg, scrolling in its own height" framed={false}>
<Editor defaultValue={notes} className="h-80 w-full">
<EditorContent size="lg" scrollEnabled />
<EditorKeyboardBar />
</Editor>
</Example>
</ExampleWrapper>
)
}
export { EditorExample }API reference#
Props it adds to what it wraps: autoFocus, command, defaultValue, kits, onValueChange, placeholder, readOnly, scrollEnabled, size, syntax, value.
Differences from web#
New engine. The surface is our own native text view (@fabricator-ui/editor-native, one UITextView holding the whole document), driven by the same store and rules as the website. iOS only for now: on Android the content shows the document read-only until the Android view lands, and the app needs a development build, not Expo Go. There's no selection bar on touch, so EditorBubbleMenu renders nothing and the keyboard bar carries the marks. There is no slash menu: formatting comes from the toolbar, the keyboard bar, Markdown shortcuts and a hardware keyboard's shortcuts. The link editor is a dialog. Tables draw as the Markdown preview's grid in the text view and edit in a sheet on phones and tablets (a tap on the table opens it): a grid of cell fields, rows and columns added and removed at the focused cell, the focused column's alignment, Cancel and Done, where the website edits them in place. Code blocks wrap their lines instead of scrolling sideways (one text view can't scroll a paragraph on its own); their language and Copy are drawn in the block's strip, and a tap on the language opens a sheet to pick another. While the editor has focus, EditorKeyboardBar takes the bottom of the screen from the App Shell's bottom nav (through the bottom-bar slot): a floating capsule in the bottom nav's place, docked full width on top of the on-screen keyboard while that's up, with Done giving the bottom nav back. It needs KeyboardProvider from react-native-keyboard-controller at the app's root.
Accessibility#
Parts set role="group", role="radio", role="radiogroup", role="separator", role="toolbar", read by VoiceOver and TalkBack. Give a control with no text an accessibilityLabel.