Skip to content

feat: Detailed code component for longer code examples#3236

Open
nhivpham wants to merge 20 commits intomainfrom
np-gmt-257
Open

feat: Detailed code component for longer code examples#3236
nhivpham wants to merge 20 commits intomainfrom
np-gmt-257

Conversation

@nhivpham
Copy link
Copy Markdown
Contributor

@nhivpham nhivpham commented Jan 20, 2026

Overview

Adds an internal detailed code component for code examples that run longer.

PR Checklist

  • Related to designs:
  • Related to JIRA ticket: GMT-257
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions tests for the code change
  • The alpha package of this PR is passing end-to-end tests in all relevant Codecademy repositories

Testing Instructions

Don't make me tap the sign.

  1. Go to /?path=/docs/organisms-connectedform-connectedform--docs#example-code
  2. View example code preview
  3. Click on code drop down
  4. Close code drop down
  5. Preview example without code preview
  6. Finish and do a celebratory dance

PR Links and Envs

Repository PR Link
Monolith Monolith PR
Mono Mono PR

@nhivpham nhivpham requested a review from a team as a code owner January 20, 2026 18:34
@nhivpham nhivpham marked this pull request as draft January 20, 2026 18:35
@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Jan 20, 2026

View your CI Pipeline Execution ↗ for commit 5d10a0a


☁️ Nx Cloud last updated this comment at 2026-04-07 17:57:51 UTC

Copy link
Copy Markdown
Contributor

@LinKCoding LinKCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 3, 2026

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@nhivpham nhivpham marked this pull request as ready for review March 16, 2026 16:09
@nhivpham nhivpham requested a review from LinKCoding March 17, 2026 17:16
Copy link
Copy Markdown
Contributor

@LinKCoding LinKCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the changes! Adding some notes for us to disc :)

Copy link
Copy Markdown

Copilot AI left a 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 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) under packages/styleguide/.storybook/components/Elements/DetailedCode.
  • Exposes DetailedCode via the styleguide Storybook components barrel export.
  • Updates ConnectedForm.mdx to use DetailedCode and moves the long example into a separate example.ts string 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.

Comment on lines +42 to +43
/* Color to match the text color in the Source component */
textColor: '#C9CDCF',
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
/* Color to match the text color in the Source component */
textColor: '#C9CDCF',
/* Use semantic text color to match the Source component */
textColor: 'text-secondary',

Copilot uses AI. Check for mistakes.
<Source code={code} dark language={language} />
{showEllipses && (
<FloatingIndicator aria-label="More code below">
...{codeLines} more lines
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
...{codeLines} more lines
...{codeLines} lines total

Copilot uses AI. Check for mistakes.
export const example = `import {
ConnectedCheckbox,
ConnectedInput,
ConnectedSelect,
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
ConnectedSelect,
ConnectedSelect,
SubmitButton,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems valid fwiw, @nhivpham

@codecademydev
Copy link
Copy Markdown
Collaborator

📬 Published Alpha Packages:

Package Version npm Diff
@codecademy/gamut 68.2.3-alpha.5ad85b.0 npm diff
@codecademy/gamut-icons 9.57.3-alpha.5ad85b.0 npm diff
@codecademy/gamut-illustrations 0.58.10-alpha.5ad85b.0 npm diff
@codecademy/gamut-kit 0.6.593-alpha.5ad85b.0 npm diff
@codecademy/gamut-patterns 0.10.29-alpha.5ad85b.0 npm diff
@codecademy/gamut-styles 17.13.2-alpha.5ad85b.0 npm diff
@codecademy/gamut-tests 5.3.4-alpha.5ad85b.0 npm diff
@codecademy/variance 0.26.2-alpha.5ad85b.0 npm diff
eslint-plugin-gamut 2.4.4-alpha.5ad85b.0 npm diff

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

@nhivpham nhivpham requested a review from LinKCoding April 7, 2026 18:03
Copy link
Copy Markdown
Contributor

@LinKCoding LinKCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making good progress!!

Comment on lines +46 to +48
### Example Code Preview False

<DetailedCode code={example} language="tsx" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +7 to +11
code: string;
language?: SourceLanguage;
initiallyExpanded?: boolean;
preview?: boolean;
previewLines?: number;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the 20 => 24 would make the TS error go away
see: https://gamut.codecademy.com/?path=/docs/foundations-layout--docs#spacing

Comment on lines +32 to +40
export const FloatingIndicator = styled(Box)(
css({
position: 'absolute',
bottom: 16,
left: 16,
px: 12,
fontSize: 14,
fontFamily: 'monospace',
textColor: '#C9CDCF',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the flow on VoiceOver is:

  1. Reads over the code as plain text
  2. Reads the copy button
  3. Reads this text, "more code below"

Is it possible to make it so that "more code below" is read before the "copy" button?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants