Expandable text
ProText cut to a few lines with "See more", shown only when it is cut, that expands it in place: posts, comments, reviews and bios. Not an M3 component (@windmorph/react-pro).
import { ExpandableText } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Props
ExpandableText 12 props
The text, or any inline content (links, mentions). Line breaks in it are kept.
The number of lines shown while collapsed.
Show "See less" while expanded, to collapse it again.
Whether the text is expanded (controlled).
Whether the text starts expanded (uncontrolled).
The element to render:
div, orpfor a paragraph of plain text.The root element (
as).
Text
The buttons' words, so they come from the app's translations. A
LabelsProvidersets them for the whole app.
Classes for the root; consumer classes always win.
Classes for each part, merged after the defaults.
Inline styles for the root, e.g. a
--wm-expandable-text-*token.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Spec status
Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.
| Item | Status | Details |
|---|---|---|
Cut to a number of lines (lines), with "See more" | Built | Configuration · Post |
Collapsible again, with "See less" (collapsible) | Built | Configuration · Collapsible |
Controlled (expanded) | Built | Configuration · Controlled |
Translated buttons (labels) | Built | Configuration · Collapsible |
Cut to a number of lines (
Builtlines), with "See more"Configuration · Post
Collapsible again, with "See less" (
Builtcollapsible)Configuration · Collapsible
Controlled (
Builtexpanded)Configuration · Controlled
Translated buttons (
Builtlabels)Configuration · Collapsible
Theming & tokens
The text and the buttons take the surrounding type and colour: set them with className (a type role and a colour role, such as text-body-large text-on-surface). The buttons use the body roles' emphasized weight and underline on hover, focus and press. Set the tokens below on the text or any ancestor (its root carries data-tokens="wm-expandable-text"), and style the parts with classNames (root, content, button).
| Variable | Default | Paints |
|---|---|---|
--wm-expandable-text-button-weight | var(--md-sys-typescale-body-large-emphasized-weight) | “See more” and “See less”: the body roles’ emphasized weight. |
--wm-expandable-text-fade-length | 2em | How far the cut line fades out before “See more”. |
--wm-expandable-text-less-gap | 4px | Between the text and “See less”. |