feat: Detailed code component for longer code examples#3236
feat: Detailed code component for longer code examples#3236
Conversation
|
View your CI Pipeline Execution ↗ for commit 5d10a0a ☁️ Nx Cloud last updated this comment at |
LinKCoding
left a comment
There was a problem hiding this comment.
I really like what you've done!
I've added some notes to polish up the PR, but would love to hear your thoughts :)
Thanks for taking this on!
packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedForm/codeExample.ts
Outdated
Show resolved
Hide resolved
|
LinKCoding
left a comment
There was a problem hiding this comment.
I really like the changes! Adding some notes for us to disc :)
packages/styleguide/.storybook/components/Elements/DetailedCode/elements.tsx
Outdated
Show resolved
Hide resolved
packages/styleguide/.storybook/components/Elements/DetailedCode/elements.tsx
Outdated
Show resolved
Hide resolved
packages/styleguide/.storybook/components/Elements/DetailedCode/elements.tsx
Outdated
Show resolved
Hide resolved
packages/styleguide/.storybook/components/Elements/DetailedCode/elements.tsx
Outdated
Show resolved
Hide resolved
packages/styleguide/.storybook/components/Elements/DetailedCode/elements.tsx
Outdated
Show resolved
Hide resolved
packages/styleguide/.storybook/components/Elements/DetailedCode/DetailedCodeBody/index.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Adds a new internal DetailedCode Storybook/docs component to better display long code examples with a collapsed “preview” and an expand/collapse control, and migrates the ConnectedForm docs’ large example into this component.
Changes:
- Introduces
DetailedCode(wrapper + body + toggle button) underpackages/styleguide/.storybook/components/Elements/DetailedCode. - Exposes
DetailedCodevia the styleguide Storybook components barrel export. - Updates
ConnectedForm.mdxto useDetailedCodeand moves the long example into a separateexample.tsstring export.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedForm/example.ts | Adds extracted long-form example code as a string for reuse in docs. |
| packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedForm/ConnectedForm.mdx | Replaces inline fenced code block with the new <DetailedCode /> component. |
| packages/styleguide/.storybook/components/index.tsx | Re-exports DetailedCode for use in MDX docs (~styleguide/blocks). |
| packages/styleguide/.storybook/components/Elements/DetailedCode/types.ts | Defines prop types for DetailedCode and its subcomponents. |
| packages/styleguide/.storybook/components/Elements/DetailedCode/index.tsx | Implements preview/expand logic and composes body + toggle. |
| packages/styleguide/.storybook/components/Elements/DetailedCode/elements.tsx | Adds styled wrappers and the floating “more lines” indicator styling. |
| packages/styleguide/.storybook/components/Elements/DetailedCode/DetailedCodeButton/index.tsx | Adds the expand/collapse control UI. |
| packages/styleguide/.storybook/components/Elements/DetailedCode/DetailedCodeBody/index.tsx | Renders Storybook Source and the truncated-code indicator. |
| /* Color to match the text color in the Source component */ | ||
| textColor: '#C9CDCF', |
There was a problem hiding this comment.
FloatingIndicator uses a hardcoded hex value for textColor (#C9CDCF). Please switch this to an existing Gamut token/semantic color so it stays theme-consistent and avoids hardcoded colors.
| /* Color to match the text color in the Source component */ | |
| textColor: '#C9CDCF', | |
| /* Use semantic text color to match the Source component */ | |
| textColor: 'text-secondary', |
| <Source code={code} dark language={language} /> | ||
| {showEllipses && ( | ||
| <FloatingIndicator aria-label="More code below"> | ||
| ...{codeLines} more lines |
There was a problem hiding this comment.
The floating indicator text uses codeLines (total lines) in ...{codeLines} more lines, but when previewing a snippet the value should represent remaining hidden lines (e.g., total - previewLines). As-is, the UI will over-report how many lines are hidden.
| ...{codeLines} more lines | |
| ...{codeLines} lines total |
| export const example = `import { | ||
| ConnectedCheckbox, | ||
| ConnectedInput, | ||
| ConnectedSelect, |
There was a problem hiding this comment.
This code example references <SubmitButton> later, but the import block in the snippet doesn't include it. Since this is intended to be copy/pastable example code, please add SubmitButton to the @codecademy/gamut import list (or remove the usage).
| ConnectedSelect, | |
| ConnectedSelect, | |
| SubmitButton, |
|
📬 Published Alpha Packages:
|
|
🚀 Styleguide deploy preview ready! Preview URL: https://69d546641e23fb07d93368ec--gamut-preview.netlify.app |
LinKCoding
left a comment
There was a problem hiding this comment.
Making good progress!!
| ### Example Code Preview False | ||
|
|
||
| <DetailedCode code={example} language="tsx" /> |
There was a problem hiding this comment.
Nice, I would add some kind of comment to say that this is for testing purposes to show the comparison -- as to denote that you're going to clean this up after review
| code: string; | ||
| language?: SourceLanguage; | ||
| initiallyExpanded?: boolean; | ||
| preview?: boolean; | ||
| previewLines?: number; |
There was a problem hiding this comment.
For these types, and the other types as well, I'd recommend adding comments to explain what the prop is for/doing
see: packages/gamut/src/Disclosure/types.ts as an example
Fwiw, this is def something you can prompt the robot to do
| }, | ||
| /* Reserves space under the text for the overlay */ | ||
| '& .docblock-source pre': { | ||
| pb: hasShowCodeButton ? 48 : 20, |
There was a problem hiding this comment.
changing the 20 => 24 would make the TS error go away
see: https://gamut.codecademy.com/?path=/docs/foundations-layout--docs#spacing
| export const FloatingIndicator = styled(Box)( | ||
| css({ | ||
| position: 'absolute', | ||
| bottom: 16, | ||
| left: 16, | ||
| px: 12, | ||
| fontSize: 14, | ||
| fontFamily: 'monospace', | ||
| textColor: '#C9CDCF', |
There was a problem hiding this comment.
On the second thought, let's follow some best practices and follow the design system
I want you to use text-secondary here (or text if you prefer)
You will need to make more changes, lemme know if you'd want a hint but think of it as a challenge :)
| <DetailedCodeBodyWrapper hasShowCodeButton={showEllipses}> | ||
| <Source code={code} dark language={language} /> | ||
| {showEllipses && ( | ||
| <FloatingIndicator aria-label="More code below"> |
There was a problem hiding this comment.
Right now the flow on VoiceOver is:
- Reads over the code as plain text
- Reads the copy button
- Reads this text, "more code below"
Is it possible to make it so that "more code below" is read before the "copy" button?
Overview
Adds an internal detailed code component for code examples that run longer.
PR Checklist
Testing Instructions
Don't make me tap the sign.
/?path=/docs/organisms-connectedform-connectedform--docs#example-codePR Links and Envs