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

Migrate Label component to TS #19146

Merged
merged 2 commits into from
Jul 24, 2023

Conversation

gabrielmj23
Copy link
Contributor

@gabrielmj23 gabrielmj23 commented May 15, 2023

Explanation

Fixes #19123

Update Label component in https://github.com/MetaMask/metamask-extension/tree/e5fdb72acc03ce1932b7ad51c788f141a884acd9/ui/components/component-library/label to Typescript.

I've also gone ahead and changed the DISPLAY and FLEX_DIRECTION constant helper objects in the design system into enums. I'm seeing there's an open issue for this, but I've kept the same expected enum names.

Also added an optional htmlFor field to the Text component, given that Label uses it to render and Typescript doesn't like passing the htmlFor field when it's not part of Text. Shouldn't break anything as it's optional, and specified in documentation.

Screenshots/Screencaps

No visual regression was observed when checking the component on Storybook.

Before

Screenshot 2023-07-20 at 1 46 30 PM

After

Screenshot 2023-07-20 at 1 46 25 PM

Manual Testing Steps

Running yarn jest ui/components/component-library/label, passes all tests for this component.

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@gabrielmj23 gabrielmj23 requested a review from a team as a code owner May 15, 2023 16:32
@github-actions
Copy link
Contributor

github-actions bot commented May 15, 2023

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.

@gabrielmj23
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@georgewrmarshall georgewrmarshall added the team-design-system All issues relating to design system in Extension label May 15, 2023
Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

Hey @gabrielmj23, thanks for your contribution this is looking great. There are some conventions in other TS component files that would be great if we could follow for the Label component. You could checkout the BadgeWrapper component files. In particular the label.types.ts file

Comment on lines 11 to 15
export const Label: React.FC<{
htmlFor?: string;
className?: string;
children: string | React.ReactNode;
}> = ({ htmlFor, className, children, ...props }) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to move these to a .types.ts file and export the LabelProps that will match our other component conventions. Could we also forwardRef to the Text component. I think all of our components should forward refs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestions, I made two commits with the changes

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your contribution 💯

  • checked storybook

Comment on lines 111 to 114
/**
* The id of the input associated with the label (in case Text is used as a Label)
*/
htmlFor?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Going to work on a fixing the Box types to allow for polymorphic props so we can pass html attributes down to the html element without having to adding types to the original types. We can merge this and I'll work on it next.

@georgewrmarshall
Copy link
Contributor

Oh look like you may have to rebase

@gabrielmj23
Copy link
Contributor Author

Tried to rebase there, hope it works, let me know

@georgewrmarshall
Copy link
Contributor

Hey @gabrielmj23, Thanks for your time and effort in creating this pull request. We have identified an issue related to the typing of the Box component, specifically with the polymorphic as prop. To address this issue, we have an open ticket at #19239 and a draft pull request at #19363 that needs to be merged before we can proceed with your PR. Thanks for your patience

@georgewrmarshall
Copy link
Contributor

georgewrmarshall commented Jun 27, 2023

Blocked by #19949

@codecov
Copy link

codecov bot commented Jul 20, 2023

Codecov Report

Merging #19146 (a96c726) into develop (733391a) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop   #19146      +/-   ##
===========================================
- Coverage    69.38%   69.37%   -0.00%     
===========================================
  Files          987      987              
  Lines        37267    37268       +1     
  Branches     10008    10009       +1     
===========================================
- Hits         25854    25853       -1     
- Misses       11413    11415       +2     
Impacted Files Coverage Δ
ui/components/component-library/label/label.tsx 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

LGTM!

@garrettbear garrettbear merged commit 9b0f8d4 into MetaMask:develop Jul 24, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external-contributor team-design-system All issues relating to design system in Extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate components to TS: Label
4 participants