Typesets rich HTML from a CMS, Markdown, or user content.
Prose renders the core .prose class, which styles the
bare headings, paragraphs, lists, tables, code, quotes, rules, figures, and keys
inside it. It sets the rhythm, a 65ch measure, and every colour from Roadie
tokens.
import { Prose } from '@oztix/roadie-components/prose'
sm sets 14px body text, headings one step below the UI heading styles, and
a tighter rhythm, for dense content such as an FAQ or a sidebar. md is the
default, with the UI heading styles, for content inside a page such as an
event description. lg sets larger body text with the prose heading styles,
for editorial pages.
Each size only sets --prose-* variables, so a class such as
[--prose-flow:2em] on Prose adjusts it further. The
variables table lists them all.
Use render to draw Prose as a semantic element. The deprecated as prop
still works the same way.
Prose wraps each bare table in a .prose-scroll, which scrolls sideways
instead of overflowing. Each column stays at least 9em wide, so a table that
can't fit scrolls rather than squeezing its text. While a table overflows, its
scroller is a named region in the tab order, so a keyboard user can reach it
with Tab and scroll it with the arrow keys.
Prose finds the tables written as elements in its children, and the tables in HTML it renders, such as CMS output:
<Prose dangerouslySetInnerHTML={{ __html: page.body }} />
A table a component renders inside Prose isn't wrapped, because React owns it.
Wrap that table in .prose-scroll yourself, and Prose still makes the scroller
a region. A table already in .prose-scroll, .not-prose, or
data-not-prose stays as it is.
Add .not-prose or data-not-prose to an element inside Prose to keep the
styles away from it and everything inside it. The
prose foundation covers how an escaped child
keeps its place in the rhythm.
A button or link button that renders an <a> inside Prose gets the prose
underline. Wrap it in .not-prose to keep its own styles.
.not-prose element stays unstyled, so put the escape
around the parts that need it, not around a region that also holds Prose.render rather than as to set the element; as is removed in v3.id, so its
region has a name that says what the table holds.tabIndex={0} and role="region" only while the
table overflows, and Prose checks again whenever its size changes. A table
that fits adds no tab stop.aria-labelledby at the nearest heading before it that has an id. A
later table under the same heading is named "Set times, table 2", and a
table with no heading before it is "Table", then "Table 2".is-focusable ring.import { useScrollRegion } from '@oztix/roadie-components/scroll-region'function useScrollRegion(ref: RefObject<HTMLElement | null>): void
Gives a scroll container outside Prose the same keyboard access as a Prose
table. Put the ref on the element that scrolls, and add is-focusable for the
ring.
It returns nothing, and sets these attributes while the content overflows:
| Attribute | Value |
|---|---|
tabindex | 0, unless the element already has a tabindex |
role | region, unless the element already has a role |
aria-label or aria-labelledby | The name Prose would give, unless the element already has one |
Prose container for long-form/rich content (CMS output, markdown, user HTML). Renders the core `.prose` class, which styles the nested HTML. Wraps each bare table in a `.prose-scroll`, which keyboard users can reach and scroll while the table overflows.
Deprecated: Use `render` instead. `as` will be removed in v3.0.0.
Swaps the underlying element with full control over its shape, such as `render={<article />}`.
Body size and heading scale. `sm` sets headings one step below the UI heading styles, for dense content such as an FAQ; `md` uses the UI heading styles; `lg` uses the prose heading styles, for editorial pages.
Defaults to 'md'.