Skip to content
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

chore: tab component refactor #30143

Merged
merged 6 commits into from
Feb 7, 2025
Merged

Conversation

georgewrmarshall
Copy link
Contributor

@georgewrmarshall georgewrmarshall commented Feb 5, 2025

Description

This PR adds prop objects to access the children components inside the Tabs and Tab components, along with test coverage. This allows for the Tabs and Tab component to be further customized. There are no visual updates, so these components should remain unchanged with no visual regressions.

Tabs

  • Spread props to the root Box component
  • Spread tabListProps to the child tab list ul Box component
  • Spread tabContentProps to the child tabs content Box component

Tab

  • Spread props to the root component
  • Spread textProps to the child Text component

Open in GitHub Codespaces

Related issues

Fixes: #30138

Manual testing steps

To check no visual regressions

  1. Pull this branch and run storybook yarn storybook
  2. Navigate to the Tabs component
  3. Check against main branch storybook for no visual regressions

To check prop objects run tests

  1. Pull this branch
  2. Run tests using yarn jest ui/components/ui/tabs
  3. Verify tests run as expected and cover new prop object props

Screenshots/Recordings

Screen recordings show no visual regressions or changes to UI

Before

before.mov

After

after.mov

Pre-merge author checklist

Copy link
Contributor

github-actions bot commented Feb 5, 2025

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@georgewrmarshall georgewrmarshall self-assigned this Feb 5, 2025
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Feb 5, 2025
Comment on lines -5 to +6
BLOCK_SIZES,
DISPLAY,
BlockSize,
Display,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing deprecated constants for enums

import Box from '../../box';
import { Text } from '../../../component-library';
import { Text, Box } from '../../../component-library';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing deprecated Box component with component-library version

Comment on lines +74 to +79
children: PropTypes.node, // required, but we are not rendering it explicitly
textProps: PropTypes.object, // props to spread to the Text component
Copy link
Contributor Author

@georgewrmarshall georgewrmarshall Feb 5, 2025

Choose a reason for hiding this comment

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

  • Fixing spelling: explictly => explicitly
  • Adding PropType for textProps

@@ -0,0 +1,100 @@
import React from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding comprehensive unit test coverage for tab

import Box from '../box';
import { Box } from '../../component-library';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing deprecated Box component with component-library version

import {
BackgroundColor,
DISPLAY,
Display,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing deprecated consts with enum

@@ -0,0 +1,117 @@
import React from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding unit test coverage for tabs component

Comment on lines +89 to +94
{...tabListProps}
className={classnames(
'tabs__list',
tabsClassName,
tabListProps.className,
)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prevents all classNames being overridden if tabListProps contains a className

@georgewrmarshall georgewrmarshall added the team-design-system All issues relating to design system in Extension label Feb 5, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [b248779]
Page Load Metrics (1665 ± 38 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1529180616667636
domContentLoaded1513177216407737
load1526179516657938
domInteractive248641209
backgroundConnect97627189
firstReactRender1599382713
getState55315157
initialActions01000
loadScripts1070129711976431
setupStore890282713
uiStartup17522512193917986
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 665 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

Comment on lines 124 to 126
onTabClick={() => null}
tabsClassName=""
subHeader={null}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typescript linting fix

Screenshot 2025-02-05 at 1 03 02 PM

@metamaskbot
Copy link
Collaborator

Builds ready [e4b889b]
Page Load Metrics (1539 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1427179915437737
domContentLoaded1416171715167034
load1429178815397637
domInteractive2410134209
backgroundConnect107828209
firstReactRender1574322110
getState543884
initialActions01000
loadScripts980124410846230
setupStore75310105
uiStartup1647199017447737
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 909 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

@georgewrmarshall georgewrmarshall marked this pull request as ready for review February 5, 2025 23:15
@georgewrmarshall georgewrmarshall requested review from a team as code owners February 5, 2025 23:16
david0xd
david0xd previously approved these changes Feb 7, 2025
@georgewrmarshall georgewrmarshall force-pushed the fix/30138/tabs-refactor branch 2 times, most recently from adc06fd to fbe3743 Compare February 7, 2025 16:48
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner February 7, 2025 16:48
@@ -202,7 +202,7 @@ export default function Notifications() {
{hasNotifySnaps && (
<Tabs
defaultActiveTabKey={activeTab}
onTabClick={(tab) => setActiveTab(tab)}
onTabClick={(tab: string) => setActiveTab(tab as TAB_KEYS)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixes type error

Screenshot 2025-02-07 at 9 11 15 AM

Comment on lines -15 to +19
tabsClassName,
subHeader,
tabsClassName = '',
subHeader = null,
tabListProps = {},
tabContentProps = {},
...props
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding prop objects to access children components and setting defaults to prevent typescript errors where possible.

@@ -32,6 +32,7 @@ export const AssetPickerModalTabs = ({
<Tabs
defaultActiveTabKey={defaultActiveTabKey}
tabsClassName="modal-tab__tabs"
onTabClick={() => null}
Copy link
Contributor Author

@georgewrmarshall georgewrmarshall Feb 7, 2025

Choose a reason for hiding this comment

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

Tried a few approaches to avoid setting onTabClick={() => null} here, including setting defaults in the JavaScript component, but couldn’t resolve the issue without refactoring the Tabs component to TypeScript. The @MetaMask/design-system team is working on Tabs this quarter, so this is a temporary fix until the design-system-react component is ready.

@metamaskbot
Copy link
Collaborator

Builds ready [7663a36]
Page Load Metrics (1704 ± 60 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15122003169912158
domContentLoaded14741968167112359
load15122011170412460
domInteractive2189462311
backgroundConnect10144353014
firstReactRender16102393014
getState45610115
initialActions00000
loadScripts10691465121311053
setupStore785292713
uiStartup171224781983219105
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 713 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

@georgewrmarshall georgewrmarshall added this pull request to the merge queue Feb 7, 2025
Merged via the queue into main with commit 271c125 Feb 7, 2025
72 checks passed
@georgewrmarshall georgewrmarshall deleted the fix/30138/tabs-refactor branch February 7, 2025 18:31
@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 2025
@metamaskbot metamaskbot added the release-12.13.0 Issue or pull request that will be included in release 12.13.0 label Feb 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template release-12.13.0 Issue or pull request that will be included in release 12.13.0 team-design-system All issues relating to design system in Extension
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Design System]: Tabs Component Refactor for Multichain Design
4 participants