feat: add useExpandableText hook (character + line budget) - #4
Conversation
Collapse long text behind a show-more toggle, capping by a character
budget (pure/SSR-safe, word-boundary aware), a line budget (CSS
line-clamp measured via ResizeObserver, responsive), or both — whichever
clips first wins. Returns { text, isExpanded, isTruncated, toggle,
expand, collapse, ref, clampStyle }. Registered in the barrel + manifest
(40 → 41); README/count regenerated from the manifest.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds the doc-page entry (usage, API tables, type aliases), an interactive three-mode demo (chars / lines / both), and the vendored source snapshot. Re-renders the brand banner's hook-count pill 40 → 41 (SVG + 2x PNG, mirrored to public/). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (10)
📝 WalkthroughWalkthroughAdds ChangesExpandable text hook
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant DocsDemo
participant useExpandableText
participant TextElement
User->>DocsDemo: Select clamp mode
DocsDemo->>useExpandableText: Pass text and options
useExpandableText->>TextElement: Apply ref and clampStyle
TextElement-->>useExpandableText: Measure rendered height
useExpandableText-->>DocsDemo: Return text and truncation state
DocsDemo-->>User: Render text and toggle control
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
useExpandableText — hook #41
Collapse long text behind a show-more toggle, capping by a character budget, a line budget, or both — whichever clips first wins. The two limits cover each other's blind spots:
maxChars— pure string logic: SSR-safe and yields a genuinely shortened string (trimmed to a word boundary + ellipsis).maxLines— CSS-webkit-line-clampmeasured with aResizeObserver, so it re-clips as the container narrows.isTruncatedis true if either would clip.What's included
src/hooks/use-expandable-text/(hook + colocated vitest test, 8 cases) + barrel + manifest entry (40 → 41); README/count regenerated from the manifest.public/).SSR-safe, zero-dep, fully typed. Gate green (143 tests pass; lint + typecheck + build across both workspaces).
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
useExpandableTexthook for collapsing long text by character count, line count, or both.Tests