-
Notifications
You must be signed in to change notification settings - Fork 2
Add auto-collapsed React code blocks for large code snippets. #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds automatic collapsing for large live JSX/TSX code blocks in the ReactCodeBlock component, matching Primer’s product style.
- Introduces height measurement, collapse/expand state, and a toggle button with smooth scrolling on collapse.
- Updates CSS for collapsed state styling and collapse button appearance.
- Renames the demo section and marks the example as
jsx live
in the MD file.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
packages/theme/components/layout/code-block/ReactCodeBlock.tsx | Added refs, effects, unique IDs, and collapse/expand logic |
packages/theme/components/layout/code-block/ReactCodeBlock.module.css | Styled the collapsed editor, wrapper, and collapse button |
packages/site/content/content-example/tabbed-component/react.mdx | Renamed section and updated code fence to jsx live |
.changeset/bright-parrots-smash.md | Added changeset entry for the auto-collapse feature |
Comments suppressed due to low confidence (2)
packages/theme/components/layout/code-block/ReactCodeBlock.tsx:50
- There are no unit tests covering the collapse/expand logic; adding tests to simulate editor heights above and below COLLAPSE_HEIGHT would help ensure this behavior remains stable.
}, [code, isCodePaneCollapsed])
packages/site/content/content-example/tabbed-component/react.mdx:98
- [nitpick] The example uses multiple identical
<Animate>
blocks to simulate a long code snippet; consider consolidating them within a single code fence or clarifying intention to avoid confusion.
<Animate animate="fade-in">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! 🚀
Towards primer/brand#1062
Adds auto collapsed React code block pane similar to primer.style/product (with some minor differences).
jsx live
code fencespreviewCode
andfullCode
to determine what shows in collapsed and original states respectively.🔗 preview
Screen.Recording.2025-06-25.at.12.06.41.mov