Skip to content

Add expandable image and table MDX components#684

Open
hfxsd wants to merge 1 commit intopingcap:masterfrom
hfxsd:add-expand-table-effect
Open

Add expandable image and table MDX components#684
hfxsd wants to merge 1 commit intopingcap:masterfrom
hfxsd:add-expand-table-effect

Conversation

@hfxsd
Copy link
Contributor

@hfxsd hfxsd commented Mar 4, 2026

Introduce ExpandableImage and ExpandableTable MDX components with i18n labels (en/zh/ja) and toggle buttons. Components use useI18next for localized button text, manage expanded state, and expose aria-expanded for accessibility; ExpandableImage prevents default/propagation on the toggle click. Export the components as MDX shortcodes (img and table) in the MDXComponents index and add corresponding styles in docTemplate.css: collapsed containers have a max-height of 360px with overflow and border, and an expanded state removes the max-height. These changes enable collapsing large tables/images by default while allowing users to expand them.

Introduce ExpandableImage and ExpandableTable MDX components with i18n labels (en/zh/ja) and toggle buttons. Components use useI18next for localized button text, manage expanded state, and expose aria-expanded for accessibility; ExpandableImage prevents default/propagation on the toggle click. Export the components as MDX shortcodes (img and table) in the MDXComponents index and add corresponding styles in docTemplate.css: collapsed containers have a max-height of 360px with overflow and border, and an expanded state removes the max-height. These changes enable collapsing large tables/images by default while allowing users to expand them.
@vercel
Copy link

vercel bot commented Mar 4, 2026

@hfxsd is attempting to deploy a commit to the test-vi Team on Vercel.

A member of the Team first needs to authorize it.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces new MDX components, ExpandableImage and ExpandableTable, to enhance content presentation by allowing large images and tables to be collapsed by default and expanded on demand. This improves readability and user experience, especially for documentation containing extensive visual or tabular data, by preventing them from overwhelming the page layout. The components support internationalization for toggle labels and include accessibility features.

Highlights

  • New MDX Components: Introduced ExpandableImage and ExpandableTable MDX components to allow large images and tables to be collapsed and expanded.
  • Internationalization (i18n) Support: Implemented i18n for the expand/collapse toggle button labels, supporting English, Chinese, and Japanese.
  • Dynamic Styling: Added CSS to control the visual presentation of collapsed and expanded states, including max-height, overflow, and borders, with smooth transitions.
  • MDX Shortcode Integration: The new components are exported as MDX shortcodes, img and table, enabling their use directly within MDX content.
  • Accessibility: Included aria-expanded attributes for improved accessibility, and ExpandableImage prevents default and propagation on toggle clicks.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/components/MDXComponents/ExpandableImage.tsx
    • Added ExpandableImage component with i18n support for expand/collapse labels.
    • Implemented state management for expansion and accessibility attributes.
  • src/components/MDXComponents/ExpandableTable.tsx
    • Added ExpandableTable component with i18n support for expand/collapse labels.
    • Implemented state management for expansion and accessibility attributes.
  • src/components/MDXComponents/index.tsx
    • Exported ExpandableTable as table and ExpandableImage as img for MDX shortcode usage.
  • src/styles/docTemplate.css
    • Added CSS rules for .expandable-toggle-button, .expandable-table, .expandable-table-container, .expandable-image, and .expandable-image-frame to control their appearance and expansion behavior.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@hfxsd
Copy link
Contributor Author

hfxsd commented Mar 4, 2026

@shhdgit Please help review, thanks~

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces new ExpandableImage and ExpandableTable MDX components to allow collapsing large images and tables by default. The implementation is solid, including i18n for labels and accessibility attributes. My review includes a few suggestions to improve code maintainability by reducing duplication in both the React components and the accompanying CSS. I've also pointed out a minor redundancy in an event handler.

Comment on lines +19 to +26
function getImageLabel(language: string, expanded: boolean) {
const lang = language.startsWith("zh")
? "zh"
: language.startsWith("ja")
? "ja"
: "en";
return expanded ? IMAGE_LABELS[lang].collapse : IMAGE_LABELS[lang].expand;
}

Choose a reason for hiding this comment

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

medium

This getImageLabel function and its language detection logic are duplicated in ExpandableTable.tsx. To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, please consider extracting the language key detection logic into a shared utility function that both components can use.

Comment on lines +19 to +26
function getTableLabel(language: string, expanded: boolean) {
const lang = language.startsWith("zh")
? "zh"
: language.startsWith("ja")
? "ja"
: "en";
return expanded ? TABLE_LABELS[lang].collapse : TABLE_LABELS[lang].expand;
}

Choose a reason for hiding this comment

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

medium

This getTableLabel function and its language detection logic are duplicated in ExpandableImage.tsx. To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, please consider extracting the language key detection logic into a shared utility function that both components can use.

Comment on lines +40 to +44
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
setExpanded((prev) => !prev);
}}

Choose a reason for hiding this comment

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

low

The call to event.preventDefault() is redundant here because the button has type="button". Buttons with this type don't have a default action that needs to be prevented. You can simplify the onClick handler by removing it.

Suggested change
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
setExpanded((prev) => !prev);
}}
onClick={(event) => {
event.stopPropagation();
setExpanded((prev) => !prev);
}}

Comment on lines +64 to +96
.expandable-table-container {
max-height: 360px;
overflow: auto;
border: 1px solid var(--tiui-palette-carbon-300);
border-radius: var(--tiui-shape-border-radius);
transition: max-height 0.2s ease;
}

.expandable-table-container.expanded {
max-height: none;
}

.expandable-table-container table {
margin: 0;
}

.expandable-image {
display: block;
margin: 16px 0;
}

.expandable-image-frame {
display: block;
max-height: 360px;
overflow: auto;
border: 1px solid var(--tiui-palette-carbon-300);
border-radius: var(--tiui-shape-border-radius);
transition: max-height 0.2s ease;
}

.expandable-image-frame.expanded {
max-height: none;
}

Choose a reason for hiding this comment

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

low

There's some style duplication for the expandable containers and their expanded states. You can combine the common styles using a comma-separated selector to make the CSS more concise and maintainable.

    .expandable-table-container,
    .expandable-image-frame {
      max-height: 360px;
      overflow: auto;
      border: 1px solid var(--tiui-palette-carbon-300);
      border-radius: var(--tiui-shape-border-radius);
      transition: max-height 0.2s ease;
    }

    .expandable-table-container.expanded,
    .expandable-image-frame.expanded {
      max-height: none;
    }

    .expandable-table-container table {
      margin: 0;
    }

    .expandable-image-frame {
      display: block;
    }

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.

1 participant