Add expandable image and table MDX components#684
Add expandable image and table MDX components#684hfxsd wants to merge 1 commit intopingcap:masterfrom
Conversation
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.
|
@hfxsd is attempting to deploy a commit to the test-vi Team on Vercel. A member of the Team first needs to authorize it. |
Summary of ChangesHello, 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, Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
|
@shhdgit Please help review, thanks~ |
There was a problem hiding this comment.
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.
| 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; | ||
| } |
There was a problem hiding this comment.
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.
| 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; | ||
| } |
There was a problem hiding this comment.
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.
| onClick={(event) => { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| setExpanded((prev) => !prev); | ||
| }} |
There was a problem hiding this comment.
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.
| onClick={(event) => { | |
| event.preventDefault(); | |
| event.stopPropagation(); | |
| setExpanded((prev) => !prev); | |
| }} | |
| onClick={(event) => { | |
| event.stopPropagation(); | |
| setExpanded((prev) => !prev); | |
| }} |
| .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; | ||
| } |
There was a problem hiding this comment.
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;
}
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.