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: fixing text variants, adding style prop and changing as to asChild #148

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

georgewrmarshall
Copy link
Contributor

@georgewrmarshall georgewrmarshall commented Nov 22, 2024

Description

This PR introduces several important updates to the Text component in the design system react:

  1. Added a new style prop to allow inline styles when needed for more flexible styling
  2. Fixes broken text variants BodySm and BodyXs with proper responsive font sizes
  3. Added the asChild prop to enable better component composition while maintaining styles as mentioned in the technical spike
  4. Added comprehensive documentation and examples for all new features

These changes improve the component's flexibility and maintainability while maintaining its core functionality.

Related issues

Fixes: #149

Manual testing steps

  1. Go to Storybook and navigate to the Text component stories
  2. Test each variant to ensure proper responsive behavior
  3. Test the asChild prop with different elements (span, button, input)
  4. Verify inline styles work correctly when applied
  5. Test all existing functionality still works (colors, weights, transforms, etc.)

Screenshots/Recordings

Before

Text component had limited styling options and no composition capabilities

before720.mov

After

  • Improved responsive typography
  • Added component composition via asChild
  • Added inline style support
  • Added comprehensive documentation
after720.mov

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link

socket-security bot commented Nov 22, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@radix-ui/[email protected] Transitive: environment +2 303 kB vladmoroz

View full report↗︎

Copy link

socket-security bot commented Nov 22, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/@radix-ui/[email protected], npm/@radix-ui/[email protected]

View full report↗︎

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

@@ -47,6 +47,7 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@radix-ui/react-slot": "^1.1.0",
Copy link
Contributor Author

@georgewrmarshall georgewrmarshall Nov 22, 2024

Choose a reason for hiding this comment

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

Utilizes Radix Slot, which provides asChild functionality. See the technical spike documentation or the Radix docs for more details.

@@ -185,37 +185,58 @@ Use the boolean `ellipsis` prop to make the `Text` component have an ellipsis.

<Canvas of={TextStories.Ellipsis} />

### As
### AsChild
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating docs

Comment on lines +19 to +21
'text-s-body-sm font-s-body-sm leading-s-body-sm tracking-s-body-sm md:text-l-body-sm',
[TextVariant.BodyXs]:
'text-s-body-xs font-s-body-xs leading-s-body-xs tracking-s-body-xs',
'text-s-body-xs font-s-body-xs leading-s-body-xs tracking-s-body-xs md:text-l-body-xs',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes incorrect font sizes for BodySm and BodyXs

Before

before720.mov

After

after720.mov

@@ -159,19 +160,35 @@ export const Ellipsis: Story = {
),
};

export const As: Story = {
export const AsChild: Story = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating stories from As to AsChild

@@ -56,10 +56,10 @@ describe('Text Component', () => {
expect(container.firstChild).toHaveClass('truncate');
});

it('renders with custom HTML element when as prop is provided', () => {
it('renders with asChild prop correctly', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating tests

@@ -117,28 +123,6 @@ export enum TextAlign {
Justify = 'text-justify',
}

export type ValidTag =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer needed as we can use the asChild prop

@georgewrmarshall
Copy link
Contributor Author

@SocketSecurity ignore-all

Marked as acceptable risk as we are protected against supply chain attack with lavamoat

Screenshot 2024-11-22 at 2 47 28 PM

@georgewrmarshall georgewrmarshall force-pushed the text-updates branch 2 times, most recently from 8486a80 to a39a11e Compare November 23, 2024 01:34

### Strong
Copy link
Contributor Author

@georgewrmarshall georgewrmarshall Nov 23, 2024

Choose a reason for hiding this comment

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

No longer supported we can add these styles to the root CSS stylesheet if we want all strong tags to be bold

Comment on lines +166 to +179
<Text asChild className="block">
<span>Text rendered as span</span>
</Text>
<Text asChild className="block">
<button type="button" onClick={action('button-clicked')}>
Text rendered as button
</button>
</Text>
<Text asChild className="bg-default border border-default">
<input
type="text"
placeholder="Rendered as input"
defaultValue="Text component as input"
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After

Screenshot 2024-11-22 at 5 40 12 PM

@@ -84,37 +83,6 @@ describe('Text Component', () => {
});
});

describe('HTML Elements', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer using ValidTag so we can remove this test and rely on Radix's Slot

@georgewrmarshall georgewrmarshall marked this pull request as ready for review November 23, 2024 01:56
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner November 23, 2024 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Text component with style prop, asChild and fix variants
1 participant