Skip to content

feat(lab): add composable RichTextEditorToolbar - #4551

Merged
potatowagon merged 4 commits into
meta:mainfrom
potatowagon:navi/feat/richtext-toolbar
Aug 3, 2026
Merged

potatowagon merged 4 commits into
meta:mainfrom
potatowagon:navi/feat/richtext-toolbar

Conversation

@potatowagon

Copy link
Copy Markdown
Contributor

What

Adds a composable RichTextEditorToolbar to @astryxdesign/lab — a formatting toolbar for the experimental RichTextEditor. It's built entirely from Astryx primitives (Toolbar, ToggleButton, Divider), so it inherits the active theme with no bespoke styling.

This is the first piece of the "toolbar phase" for the OSS Lexical editor — the piece that unblocks EPS RichTextArea → Astryx parity for toolbar-based formatting.

Design

  • Themed, not hand-rolled. Composes the existing Toolbar (with role="toolbar", aria-label, size coordination) + ToggleButton (pressed state, icon-only) + Divider. No new visual code, no new icon dependency (inline 16px SVGs).
  • Behavior mirrors the Lexical playground toolbar. Reads the current selection on SELECTION_CHANGE_COMMAND + registerUpdateListener to keep active states in sync, and dispatches the standard Lexical commands. Also tracks the editor's editable state (disables controls when read-only).
  • Composable. Render it in the editor's plugins slot; inject product-specific controls (mentions, AI, etc.) via the endContent prop — this is the extension seam EPS/XDS adapters need.

Controls (MVP set — intersection of the playground, EPS, and XDS toolbars):

  • Inline: bold, italic, underline, strikethrough, inline code
  • Blocks: heading (configurable headingLevels, default h1–h3) + quote ($setBlocksType)
  • Lists: bulleted / numbered
  • History: undo / redo (gated on CAN_UNDO/CAN_REDO)

Usage

import {RichTextEditor, RichTextEditorToolbar} from '@astryxdesign/lab';

<RichTextEditor label="Notes" plugins={<RichTextEditorToolbar />} />

Dependencies

  • Adds @lexical/selection as a new optional peer dependency (used for $setBlocksType), matching the other @lexical/* peers. Its lockfile entry already existed transitively, so only the packages/lab importer declaration was needed.
  • Everything else (@lexical/rich-text, @lexical/list, @lexical/utils, lexical) is already a peer dep.

Docs / stories / tests (SYNC contract)

  • Exported RichTextEditorToolbar + RichTextEditorToolbarProps from RichTextEditor/index.ts and the @astryxdesign/lab barrel.
  • RichTextEditor.doc.mjs — added a usage note.
  • RichTextEditor.stories.tsx — added a WithToolbar story.
  • RichTextEditor.test.tsx — 5 tests: renders the control set, heading-level config, custom accessible label, endContent composition, and read-only disabling.

Testing

CI runs the full build/typecheck/lint/test. (Authored on a devserver without a local pnpm toolchain, so relying on CI.)

Notes

@vercel

vercel Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 3, 2026 4:03am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 30, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Icon (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 547 -
Complexity N/A High (28) -
RichTextEditor (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1295 -
Complexity N/A Very High (75) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.3KB
@astryxdesign/lab N/A 3.4KB 1.4KB

Accessibility Audit

Status: 3 accessibility violation(s) found — 1 critical, 2 serious.

Icon - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/18 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
RichTextEditor - 2 issue(s)
  • 🟠 serious: Ensure every ARIA input field has an accessible name
    • Rule: aria-input-field-name · Affects 12/12 stories · Learn more
    • WCAG: 4.1.2 (Level A)
  • 🔴 critical: Ensure every form element has a label
    • Rule: label · Affects 1/12 stories · Learn more
    • WCAG: 4.1.2 (Level A)

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

/** 16px inline icons — no external icon dependency. */
const icons: Record<string, ReactNode> = {
bold: (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since they're hardcoded here they won't be themeable. Are there entries to the icon map for these? I think one thing we might want is some way for libraries to augment the icon map with new keys so people can fill in the map with their icons for their theme.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — fixed in 25de205. You're right that the inline SVGs weren't themeable, and there was no seam for a library to contribute new keys. Addressed both:

1. The toolbar now resolves every glyph through the icon registry. Each control looks up a stable richtext:* key (exported as RICHTEXT_ICON_KEYS), with the inline SVGs as the default fallback. So a theme can restyle any glyph without forking:

import {registerIcons} from '@astryxdesign/core/Icon';
registerIcons({'richtext:bold': <MyBoldIcon />});

2. The registry can now be augmented with new keys — which is the "way for libraries to fill in the map with their icons" you asked about. Two changes in @astryxdesign/core:

  • registerIcons() now accepts arbitrary extension keys, not just the built-in IconName union (Partial<Record<ExtendedIconName, ReactNode>>).
  • New getExtendedIcon(name, fallback) resolves an extension key, preferring a theme-registered icon and falling back to a library-supplied default. That's the general seam any library can use to make its own icons theme-overridable — the toolbar is just the first consumer.

getIconRegistry() still returns only the built-in IconName snapshot, so extension keys don't leak into the typed core set.

Added test coverage for both (registry extension-key resolution + a theme-override render test on the Bold control), plus doc notes on Icon and RichTextEditor. Let me know if you'd rather namespace the keys differently than richtext:*.

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 31, 2026
Adds a formatting toolbar for the experimental RichTextEditor, built entirely
from Astryx primitives (Toolbar, ToggleButton, Divider) so it inherits the
active theme with no bespoke styling.

Behavior mirrors the Lexical playground toolbar: it reads the current selection
(SELECTION_CHANGE_COMMAND + registerUpdateListener) to keep active states in
sync, and dispatches the standard Lexical commands. Covers:
  - inline: bold, italic, underline, strikethrough, inline code
  - blocks: paragraph/heading (configurable levels) + quote via $setBlocksType
  - lists: bulleted / numbered (INSERT_*_LIST_COMMAND / REMOVE_LIST_COMMAND)
  - history: undo / redo (with CAN_UNDO/REDO gating)
It also tracks the editor's editable state and disables controls when read-only.

Composable: render it in the editor's `plugins` slot; pass extra controls via
the `endContent` prop (e.g. product-specific mentions/AI buttons). Icons are
inline SVGs — no new icon dependency.

- Added @lexical/selection as a new optional peer dep (used for $setBlocksType);
  its lockfile entry already existed transitively, so only the importer +
  package.json declarations were needed.
- Exported RichTextEditorToolbar + props from index.ts and the lab barrel.
- Updated doc.mjs usage notes; added a WithToolbar storybook story.
- Added 5 unit tests (renders controls, heading-level config, custom label,
  endContent composition, read-only disabling).
The sandbox/docsite Next build resolves deps via the `source` export
condition, so `source`-shipping deps imported from an Astryx package
(e.g. lexical / @lexical/*, pulled in by the lab RichTextEditor) are fed
their untranspiled .ts to Next's Babel. Lexical's source uses `declare`
class fields, which next/babel's preset-typescript rejects unless
allowDeclareFields is set — breaking build-sandbox.

Enable allowDeclareFields on the TypeScript preset. This is correct TS
semantics (declare fields are type-only, dropped from output) and safe
for all files, fixing the build for lexical and any future source-shipping
dependency.
…table icon registry

Toolbar glyphs were hardcoded inline SVGs and weren't themeable. Now each
control resolves its icon through the core icon registry under a stable
richtext:* key, falling back to the bundled inline SVG, so a theme can
override any glyph with registerIcons().

core:
- registerIcons() accepts arbitrary extension keys (not just built-in
  IconName), so libraries can augment the icon map with their own keys.
- Add getExtendedIcon(name, fallback) resolves an extension key, preferring
  a theme-registered icon and falling back to a caller-supplied default.
- Add ExtendedIconName type. getIconRegistry() snapshot stays scoped to the
  built-in IconName set (extension keys don't leak in).

lab:
- RichTextEditorToolbar resolves every glyph via getExtendedIcon under
  RICHTEXT_ICON_KEYS; inline SVGs become defaults. Export RICHTEXT_ICON_KEYS.
- Tests: registry extension-key coverage + a theme-override render test.
@potatowagon
potatowagon force-pushed the navi/feat/richtext-toolbar branch from 25de205 to 568a816 Compare August 2, 2026 16:56
github-actions Bot added a commit that referenced this pull request Aug 2, 2026
…ditor With Toolbar story

The new 'With Toolbar' story surfaces the same pre-existing
aria-input-field-name violation already baselined for all other
RichTextEditor stories (Default, With Description, etc.). axe cannot
resolve the contenteditable's aria-labelledby reference inside the
isolated story iframe; the label association is correct in real usage.
Baseline this instance to match its 11 sibling stories.
@potatowagon
potatowagon merged commit e424a04 into meta:main Aug 3, 2026
19 checks passed
github-actions Bot added a commit that referenced this pull request Aug 3, 2026
josephfarina added a commit that referenced this pull request Aug 4, 2026
The English Icon docs gained a best-practices bullet in #4551 covering
registerIcons/getExtendedIcon for library icon augmentation, but the
docsDense overlay was not updated to match. Because the dense overlay
merges by count and position, the missing bullet caused a silent 11-vs-10
parity gap: the dense CLI output dropped the augmentation guidance.

Add the compressed dense bullet at the matching position so
`astryx component Icon --lang dense` renders all 11 best practices with
the same guidance flags as English. Also straighten one em dash in the
English bullet to a colon per the doc prose style.

Found during Night Watch doc review.
josephfarina added a commit that referenced this pull request Aug 6, 2026
The English Icon docs gained a best-practices bullet in #4551 covering
registerIcons/getExtendedIcon for library icon augmentation, but the
docsDense overlay was not updated to match. Because the dense overlay
merges by count and position, the missing bullet caused a silent 11-vs-10
parity gap: the dense CLI output dropped the augmentation guidance.

Add the compressed dense bullet at the matching position so
`astryx component Icon --lang dense` renders all 11 best practices with
the same guidance flags as English. Also straighten one em dash in the
English bullet to a colon per the doc prose style.

Found during Night Watch doc review.
josephfarina added a commit that referenced this pull request Aug 7, 2026
… bullets (#4676)

* docs(icon): restore dropped dense best practice and straighten em dash

The English Icon docs gained a best-practices bullet in #4551 covering
registerIcons/getExtendedIcon for library icon augmentation, but the
docsDense overlay was not updated to match. Because the dense overlay
merges by count and position, the missing bullet caused a silent 11-vs-10
parity gap: the dense CLI output dropped the augmentation guidance.

Add the compressed dense bullet at the matching position so
`astryx component Icon --lang dense` renders all 11 best practices with
the same guidance flags as English. Also straighten one em dash in the
English bullet to a colon per the doc prose style.

Found during Night Watch doc review.

* docs(carousel): restore dropped dense/zh best practice bullets

The English bestPractices gained a hasLoop bullet in #4629 but neither
docsDense nor docsZh was updated, so both overlays fell one bullet short
and the CLI silently dropped the hasLoop guidance under --lang dense/zh.
Also backfill the pre-existing missing built-in-navigation bullet in the
zh overlay. Both overlays now match the English bullet count and per-position
guidance flags (8: 5 do, 3 don't).

Found during Night Watch doc review.

* docs(icon): recommend theme icon overrides over the global registry

registerIcons() warns at runtime that defineTheme({icons}) is the
theme-scoped way to swap a glyph, so documenting the global registry as
the seam for library icons contradicted the library's own guidance.
Point both the English and dense best practices at the theme, and keep
registerIcons framed as an app-bootstrap escape hatch.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: Cursor <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 6c507823 Deployed Aug 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants