UI kit & theming
@nextgensoftwares/folio-react ships two levels of UI:
<FolioApp>, a complete editor app you drop in with a few lines;- the parts it is made of (
FolioView,FolioToolbar, menus, the bubble bar, inspector controls,SlotTabs,ZoomControl,FolioReaderBar…), for hosts that build their own layout.
Both share one design language driven by --folio-* CSS variables.
<FolioApp>
import { createFolioApp, FolioApp, FolioStyles } from '@nextgensoftwares/folio-react';
const app = createFolioApp({ doc, measurer: fonts, plugins: [calloutPlugin(), mathPlugin({ katex })] });
export function Editor() {
const [title, setTitle] = useState('Quarterly report');
return (
<>
<FolioStyles />
<FolioApp app={app} title={title} onTitleChange={setTitle} status="saved" style={{ height: '100vh' }} />
</>
);
}createFolioApp(options) composes the plugins once, wires incremental layout (a LayoutCache and the previous layout on every call) and creates the FolioEditor. It returns { editor, composed, metrics, renderMath, bodySize, layouts, theme, familyFor }; you can also skip it and pass editor, composed, metrics to <FolioApp> yourself.
The toolbar and the phone bar show the font and size the text is laid out with, resolved by layout's resolveTextStyle from the print theme. A heading shows its level's size, a paragraph the body font, inline code the mono family, and Arabic text the family that renders it (familyFor). A mixed selection leaves the field empty (labelled "Mixed"). A family with no glyphs for the text shows with a "shown in …" hint. Hosts that assemble their own toolbar pass theme and familyFor to FolioToolbar (or call effectiveTextStyle(state, theme, familyFor)).
createFolioApp option | |
|---|---|
doc | the document (ProseMirror-shaped JSON) |
measurer | a FontEngine (its metrics also aligns painted baselines) |
plugins | FolioPlugin[], composed in order |
schema | base schema (default standardSchema) |
layout | extra LayoutOptions (theme, math, header/footer…) |
renderMath | KaTeX (or other) renderer for math painters |
reflow | 'auto' (default: phones reflow the text to the screen, Word's mobile view), 'print' (always pages) or false (no layout switch) |
Regions
┌ app bar ─ [◧] mark Title ● Saved ···· people · appbar slot · actions · ☀ · credit · [◨] ┐
├ toolbar (FolioToolbar) ───────────────────────────────────────────────────────────────┤
│ left panel │ page canvas (FolioView) │ right panel │
│ "navigation" │ │ "sidebar" │
│ slot as tabs │ │ tabs + Settings │
├ status bar: page · words · "statusbar" slot ······························ zoom ───────┤| Prop | What it does |
|---|---|
app | createFolioApp(...)'s result (or editor + composed + metrics + renderMath + bodySize) |
layout | shown read-only when there's no editor |
title, onTitleChange, titlePlaceholder | the app-bar title; editable when onTitleChange is given (Enter or blur commits, Escape reverts) |
status | 'saved' | 'saving' | 'unsaved' | 'offline' | 'error' or { label, tone, title } (tone: muted, busy, good, warn, bad) |
brand | logo at the start of the bar (default the Folio mark; false hides it) |
people | AppPerson[] ({ name, color?, image?, status? }, shown with <FolioAvatars>) or any node |
actions | buttons at the end of the bar; use FolioAppButton (icon) or the folio-app-cta class (primary). Toolbar items routed to the appbar surface (ui: { route: { export: ['appbar'] } }) also show here as labelled buttons, collapsed into one menu on narrow bars |
left, right | { slot?, label?, width?, minWidth?, maxWidth?, resizable?, defaultOpen? } or false. Defaults: navigation / 288 px and sidebar / 320 px ; see Resizing panels |
onPanelResize, panelStorageKey | the user resized a side panel: (side, width) to persist it (pass it back as that panel's width), or remember it in localStorage under <key>:left / <key>:right |
settings | slot whose items become collapsible sections of a Settings tab in the right panel (default settings) |
statusbar | status-bar slot (default statusbar), false hides the bar |
appBar, appBarTarget | appBar={false} leaves out the app bar; appBarTarget={el} renders it into an element of yours (your header) instead, see Embedding the app bar |
credit, creditPlacement | the "Made with Folio" credit: 'appBar' (default, the bar's end, as in the reader) or 'statusBar'; always shown (the credit) |
dock | { title, open, onClose, children, width? }: an extra panel docked after the right one (the playground's Developer panel) |
slotProps | extra props for every slot component (they also get editor and item) |
theme, onThemeChange, themeToggle | light / dark / system; uncontrolled by default with a button in the bar |
focusButton | where focus mode's button goes: 'appbar' (default), 'statusbar' (after zoom) or false (none; the key still works), see Focus mode |
zoom, onZoomChange, defaultZoom, onTwoPages | zoom (default 100 %, shrinking to fit narrow screens) |
toolbar | FolioToolbar props (fonts, defaultFontSize, contextBar…) or false |
fonts | families for the toolbar's font picker and the phone bar |
banner | anything under the toolbar (progress, read-only notices) |
view | every other FolioView prop (rulers, reader display, page access, pageComponent…) |
viewRef | receives the FolioViewHandle |
wrapCanvas | wraps the view (e.g. <FolioProtect>) |
canvas, viewHandle | replace the canvas entirely (two panes side by side) and tell the status bar which view to follow |
tooltips | styled tooltips for every title inside the app (default true) |
Actions that don't fit
actions never clip: whatever doesn't fit the bar moves, from the end, into a "⋯ More actions" menu. There your controls read as menu rows: full width, the same height, on one surface (your buttons' own fill, border and width drop; the boxes around groups go). An icon-only control shows its aria-label (or title) as its text, so give every icon button a name. The controls stay yours and keep working:
- a control that opens its own dialog (a Radix
<Dialog>inside the button) closes the menu, and the dialog stays open: the menu's items stay mounted while it's closed; - a control that opens a menu of its own (
aria-haspopup="menu", your own "⋯") keeps the menu open beside it; choosing in it closes both.
To keep a control in the bar whatever its width, give it data-folio-pin (<MoreMenu data-folio-pin />, <button data-folio-pin>Send</button>; the attribute is read from the element you pass, so your component doesn't have to forward it). Pinned controls never fold: they sit at the bar's inline end, after "⋯", and the others fold around them. Pin your own dropdown so it doesn't open as a menu in a menu, and the primary action so it stays one click away. With too little room for the pinned controls themselves the bar clips rather than folding them, so pin few. OverflowRow (@nextgensoftwares/folio-react) does the same for your own rows.
Items as data instead of nodes: give a plugin ui.items with defaultSurfaces: ['appbar'] ({ id, label, icon, kind: 'action', run, children? }; children make a dropdown). They're Folio buttons with labels, and on a narrow bar they fold into one menu of rows, submenus included. Keep a dialog's state outside the item and open it from run.
const hostActions = { name: 'host-actions', ui: { items: [
{ id: 'host.import', label: 'Import', icon: 'upload', kind: 'action', run: () => setImportOpen(true), defaultSurfaces: ['appbar'] },
{ id: 'host.more', label: 'More', icon: 'moreVertical', kind: 'action', run: () => {}, defaultSurfaces: ['appbar'],
children: [{ id: 'host.versions', label: 'Versions', kind: 'action', run: () => setVersionsOpen(true) }] },
] } };Embedding the app bar
Inside a host page that already has a header, the app's own bar can read as a second one. Two props change that (FolioApp, FolioBookApp and SlidesApp):
appBar={false}leaves it out: no title, panel toggles, actions, theme or focus button (the panels still open on wide screens; on narrow ones they are drawers with no toggle, so keep the bar or bring your own toggles).appBarTarget={el}renders the same bar intoel, an element of your header, through a React portal: it keeps the app's state (panel toggles, title editing, actions, theme, focus mode) and comes in a.folio-uibox (.folio-app-bar-host) so Folio's tokens and styles apply there, with no background or border of its own, so it blends into your header. Passnullwhile your element mounts (nothing renders until it's there).
const [header, setHeader] = useState<HTMLElement | null>(null);
<header className="site-header">…<div ref={setHeader} style={{ flex: 1 }} /></header>
<FolioApp app={app} appBarTarget={header} />The "Made with Folio" credit doesn't travel into your header by default: with appBarTarget it stays in Folio's own status bar (or the slim credit bar when the status bar is off, phones included). Only an explicit creditPlacement="appBar" puts it at the end of the portaled bar. With no app bar it is in the status bar (or that slim bar) too.
When your header already names the document, title={false} leaves the title out of the bar: no heading, no "Untitled document" placeholder, no title field.
Resizing panels
A docked side panel's inner edge (the left panel's inline end, the right panel's inline start; mirrored in right-to-left) resizes it:
- drag it (the page follows each frame; the width is committed on release), or focus it (a
role="separator"witharia-valuenow,-min,-max) and use ← / → (16 px, Shift 64 px), Home / End (its min and max); double-click goes back to the panel'swidth; - the range is
minWidth…maxWidth(default 200…640 px, widened to includewidth), and never so wide that the page area drops underMIN_MAINbeside the other open panel and the dock. A remembered width that no longer fits a narrower window gives up what's above the panel's default, never the default itself; drawers (narrow screens, focus mode) don't resize; onPanelResize(side, width)reports each change (and a reset, with the default) so the host can persist it;panelStorageKeykeeps it in localStorage instead;resizable: falseturns a panel's edge off.
A side panel's tab can ask for more room: a slot item's panelWidth: 380 makes the docked panel that wide while the tab shows, back to the panel's width for other tabs. A width the user picked wins over it.
Responsive behaviour
<FolioApp> measures its own box, not the window, so an embedded app (like the examples in these docs) adapts to its container:
- panels dock while the page area keeps at least
MIN_MAIN(820 px, so print layout stays above the 720 px reflow breakpoint); past that they become drawers that slide over the page (Escape or the scrim closes them). The dock docks first, then the right panel, then the left one; - under 600 px (
data-size="phone") the status bar, brand and avatars hide, and in reflow layout the formatting toolbar becomes the phone bar above the keyboard (FolioView'smobileBar); data-size(wide,medium,narrow,phone) is on the root for your own CSS;useAppWidth,appSizeandusePanelsare exported for custom shells.
Slots
Every region is a slot, so a plugin's UI appears without host code:
| Slot | Where <FolioApp> renders it | Component props |
|---|---|---|
navigation | left panel, one tab per item | slotProps + editor, item |
sidebar | right panel, one tab per item | same |
settings | right panel's Settings tab, one collapsible section per item (open: false starts collapsed) | same |
statusbar | status bar cells, after the built-in app.page and app.words | AppStatusProps (layout, view) + slotProps |
appbar | app bar, before actions | slotProps |
toolbar, overlay, reader | as in any host (Customizing the UI) |
A panel whose slot is empty hides itself and its toggle. Built-in cells are slot items: hide one with hide: ['statusbar:app.words'] or replace it by id.
app.words counts as Word does (countWords of @nextgensoftwares/folio-model): words split on whitespace only ("a/b", "self-management" and URLs are one word), each East Asian ideograph is a word, text boxes and shapes count, headers, footers, list numbers and suggested deletions don't.
const notesPlugin: FolioPlugin = {
name: 'notes',
ui: {
slots: [
{ id: 'notes', slot: 'navigation', label: 'Notes', icon: 'bookmark', component: NotesPanel },
{ id: 'notes.count', slot: 'statusbar', label: 'Notes', order: 20, component: NoteCount },
{ id: 'notes.share', slot: 'appbar', component: ShareButton },
],
},
};Theming tokens
All styling reads CSS variables declared on .folio-ui (the app root, the toolbar, popovers and menus all carry that class). Light is the default; dark applies under [data-folio-theme=dark] (set by setFolioTheme('dark') or the theme prop), and system follows the OS.
| Token | Role |
|---|---|
--folio-bg, --folio-bg-2, --folio-chrome | surfaces: panels and popovers, subtle fills, app bar / toolbar / status bar |
--folio-canvas | the desk behind the pages |
--folio-text, --folio-muted | text, secondary text and icons |
--folio-border, --folio-border-strong | hairlines, input borders |
--folio-hover, --folio-press | hover and pressed / selected fills |
--folio-accent, --folio-accent-fg, --folio-focus | primary actions, focus rings |
--folio-on-bg, --folio-on-fg | active toggles (bold on, current option) |
--folio-danger, --folio-success, --folio-warning | status colours |
--folio-shadow-sm, --folio-pop-shadow, --folio-shadow-lg, --folio-scrim | elevation: cards, popovers and menus, drawers, the drawer scrim |
--folio-page-bg, --folio-page-shadow, --folio-page-radius | the paper |
--folio-selection, --folio-caret | selection and caret on the page |
--folio-radius-sm, --folio-radius, --folio-radius-lg | 6 / 8 / 10 px: controls, cards, popovers |
--folio-control-h | button and input height (30 px) |
--folio-text-xs … --folio-text-lg | 11 / 12 / 13 / 15 px type scale |
--folio-nav-text | navigation lists: contents chapters (14 px), headings a pixel under |
--folio-space-1 … --folio-space-5 | 4 / 8 / 12 / 16 / 24 px spacing |
--folio-font, --folio-font-mono, --folio-ease | UI font stacks, motion curve |
Override them on .folio-ui (every Folio element carries the class, so a selector on an ancestor alone is not enough):
.folio-ui {
--folio-accent: #0f766e;
--folio-focus: rgba(15, 118, 110, 0.4);
--folio-on-bg: #ccfbf1;
--folio-on-fg: #115e59;
--folio-font: 'IBM Plex Sans', system-ui, sans-serif;
--folio-radius-sm: 4px;
}
[data-folio-theme='dark'] .folio-ui { --folio-accent: #5eead4; --folio-accent-fg: #042f2e; }Plugins' own UI (comment cards, the import dialog, the equation editor, callout bars) reads the same tokens, so one override restyles everything.
Floating layers and your dialogs
The selection bubble bar (formatting, a picture's or shape's Format bar) and popovers (menus, pickers) float in portals on the page. Their stacking order is a token, set on :root or body (the layers are portalled outside .folio-ui parents):
| Token | Default | Layer |
|---|---|---|
--folio-z-bubble | 900 | bubble bars |
--folio-z-popover | 1000 | popovers and menus |
They also step aside on their own while your app shows a modal dialog (aria-modal="true", or a <dialog> opened with showModal()) that opened after them and doesn't contain the editor, or while the editor is inside an inert subtree: hidden until the dialog closes, never drawn over it. A menu opened from inside your dialog (Folio embedded in a modal) stays.
While keyboard focus is in your app's own UI (a side panel's control, a field, or a press on something that takes no focus), the bubble bar and a selected object's handles step aside too; the selection stays, and they come back as soon as the editor has focus again. Folio's toolbars, its floating layers and panels marked data-folio-editing (a shape's Format panel, the Selection pane, the slides ribbon and inspector; FolioAppPanel's editing) count as the editor's. A deferred focusEditor never pulls focus back from where the user went in the meantime.
To take a host design system's tokens wholesale (shadcn/ui or your own), use hostThemeCss / <FolioHostTheme>; see Embedding Folio in your app.
Overriding styles
- Class hooks. Every part has a stable
folio-*class:folio-app-bar,folio-app-title,folio-app-panel(+folio-app-left/-right/-dock,[data-drawer],[data-open]),folio-app-tabs,folio-app-statusbar,folio-app-cell[data-id],folio-btn,folio-popover,folio-menu-item,folio-bubble,folio-tooltip,folio-c-*(inspector controls). PassclassNameto<FolioApp>to scope overrides. - Without the injected CSS. Import
@nextgensoftwares/folio-react/styles.cssinstead of<FolioStyles />, or ship your own stylesheet built fromfolioCss. - Replace pieces.
brand,actions,people,bannerandcanvastake any node; slots take any component;FolioAppBar,FolioAppPanel,FolioAppStatusBar,FolioAvatars,SaveIndicatorandFolioTooltipsare exported to assemble a different shell from the same parts.
Component set
One set of primitives covers every surface, so plugins look native:
| Need | Use |
|---|---|
| icon button | ToolButton (toolbars), FolioAppButton (app bar) |
| menu or picker | Dropdown + OptionList, Menu, Popover |
| settings form | Field, Section, Select, Switch, Segmented, Slider, NumberInput, CommitInput, ColorInput, Button, FileButton |
| tabs of plugin panels | SlotTabs |
| tooltip | any title inside .folio-ui (with <FolioTooltips> mounted, which <FolioApp> does) |
| toast, dialog | the folio-clip-toast and folio-popover cards (role="dialog"), as the clipboard, import and equation UIs do |
The playground is built on <FolioApp>; its engine internals live in a Developer panel passed as dock.