Repository navigation
feat(lab): add composable RichTextEditorToolbar - #4551
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsIcon (@astryxdesign/core) · View in Storybook
RichTextEditor (@astryxdesign/lab) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 3 accessibility violation(s) found — 1 critical, 2 serious. Icon - 1 issue(s)
RichTextEditor - 2 issue(s)
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"> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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-inIconNameunion (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:*.
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.
25de205 to
568a816
Compare
…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.
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.
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.
… 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]>
What
Adds a composable
RichTextEditorToolbarto@astryxdesign/lab— a formatting toolbar for the experimentalRichTextEditor. 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
Toolbar(withrole="toolbar", aria-label, size coordination) +ToggleButton(pressed state, icon-only) +Divider. No new visual code, no new icon dependency (inline 16px SVGs).SELECTION_CHANGE_COMMAND+registerUpdateListenerto keep active states in sync, and dispatches the standard Lexical commands. Also tracks the editor's editable state (disables controls when read-only).pluginsslot; inject product-specific controls (mentions, AI, etc.) via theendContentprop — this is the extension seam EPS/XDS adapters need.Controls (MVP set — intersection of the playground, EPS, and XDS toolbars):
headingLevels, default h1–h3) + quote ($setBlocksType)CAN_UNDO/CAN_REDO)Usage
Dependencies
@lexical/selectionas a new optional peer dependency (used for$setBlocksType), matching the other@lexical/*peers. Its lockfile entry already existed transitively, so only thepackages/labimporter declaration was needed.@lexical/rich-text,@lexical/list,@lexical/utils,lexical) is already a peer dep.Docs / stories / tests (SYNC contract)
RichTextEditorToolbar+RichTextEditorToolbarPropsfromRichTextEditor/index.tsand the@astryxdesign/labbarrel.RichTextEditor.doc.mjs— added a usage note.RichTextEditor.stories.tsx— added aWithToolbarstory.RichTextEditor.test.tsx— 5 tests: renders the control set, heading-level config, custom accessible label,endContentcomposition, 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
main.