Skip to content

chore: removing default font sizes and colors#739

Merged
georgewrmarshall merged 10 commits into
mainfrom
remove-default-colors-font-sizes
Jun 11, 2025
Merged

chore: removing default font sizes and colors#739
georgewrmarshall merged 10 commits into
mainfrom
remove-default-colors-font-sizes

Conversation

@georgewrmarshall

@georgewrmarshall georgewrmarshall commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Description

This PR enforces the use of design system components by removing default Tailwind CSS utilities while preserving essential semantic utilities.

What is the reason for the change?

  • Default Tailwind font sizes (like text-sm, text-lg) bypass our Text component and design system typography
  • Default Tailwind colors (like bg-blue-500, text-red-300) bypass our design system color tokens
  • We want to enforce consistent design system usage across the codebase

What is the improvement/solution?

  • Remove all default Tailwind font sizes (text-xs, text-sm, text-base, text-lg, text-xl, etc.) to enforce use of the Text component
  • Remove default Tailwind color palette (red-500, blue-600, etc.) while keeping essential semantic colors (inherit, current, transparent, black, white)
  • Update React Native press state handling from non-functional active:bg-pressed to proper Pressable state management
  • Apply changes across all Tailwind configurations: React web, React Native, and twrnc preset

Related issues

Fixes: #740

Manual testing steps

  1. Run Storybook: yarn storybook:react
  2. Navigate to Text component stories and verify all text variants render correctly
  3. Check that Text component variants (TextVariant.BodyMd, TextVariant.HeadingLg, etc.) work as expected
  4. Verify components using bg-transparent still render correctly (should appear with transparent background)
  5. Test that default Tailwind utilities are no longer available:
    • Try using text-sm - should not apply styles
    • Try using bg-red-500 - should not apply styles
    • Try using text-blue-300 - should not apply styles
  6. For React Native: Run yarn storybook:react-native and test press states work correctly
  7. Verify essential semantic utilities still work: bg-transparent, text-inherit, bg-black, bg-white

Screenshots/Recordings

Before

  • Default Tailwind font sizes were available, bypassing Text component
  • Default Tailwind colors were available, bypassing design system tokens
  • React Native press states used non-functional active: pseudo-classes
before480.mov
before.mov

After

  • Only design system font sizes available (enforces Text component usage)
  • Only design system colors + essential semantic colors available
  • React Native press states use proper Pressable state management
after.rn.mov
after.react.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.

@georgewrmarshall georgewrmarshall self-assigned this Jun 11, 2025
@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

@georgewrmarshall georgewrmarshall force-pushed the remove-default-colors-font-sizes branch from 10151b0 to 0689466 Compare June 11, 2025 05:29
@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

@georgewrmarshall georgewrmarshall force-pushed the remove-default-colors-font-sizes branch from 0689466 to fe1c7e0 Compare June 11, 2025 06:08
@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

extend: {},
},
plugins: [],
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updating the tailwind.config.js for intellisense. Going to look at generating this from tailwind.config.ts and pointing to the version that we can include in the twrnc preset

white: '#ffffff',
},
fontSize: {}, // This removes all default Tailwind font sizes. We want to rely on the design system font sizes and enforce use of the Text component
extend: {},

@georgewrmarshall georgewrmarshall Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated storybook Tailwind config to explicitly include essential semantic colors like inherit, current, transparent, black, and white, while removing the default palette (e.g., bg-red-500, bg-blue-400). I hadn’t realized that setting colors: {} also removes these semantic colors, which we still need. Although I previously added this to the preset, I was concerned about potentially breaking existing Tailwind projects. For now, we’ll manage this at the project level and ensure the @MetaMask/design-system-engineers team are code owners of these configuration files.

!isDanger &&
!isInverse && [
'bg-transparent border-2 border-icon-muted text-default',
'border-2 border-icon-muted bg-transparent text-default',

@georgewrmarshall georgewrmarshall Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now I understand why there were previous linting updates to these components. I broke bg-transparent when we used an empty object for colors

Before

bg-transparent isn't being generated due to an empty colors: {} object

Screenshot 2025-06-11 at 3 49 00 PM

After

bg-transparent is now being generated

Screenshot 2025-06-11 at 3 42 21 PM

@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

alignItems={BoxAlignItems.Center}
justifyContent={BoxJustifyContent.Between}
className="bg-transparent w-full px-4 py-2 hover:bg-hover active:bg-pressed md:px-8"
className="w-full px-4 py-2 hover:bg-hover active:bg-pressed md:px-8"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing unneeded bg-transparent classname

@georgewrmarshall georgewrmarshall force-pushed the remove-default-colors-font-sizes branch from 0f1125f to 5ae7103 Compare June 11, 2025 06:34
{/* Ethereum */}
<Pressable
style={tw`w-full flex-row items-center justify-between bg-transparent px-4 py-2`}
style={({ pressed }) =>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replacing unneeded bg-transparent with proper pressed example that mimics react example

@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

size={IconSize.Sm}
className={twMerge(
'text-inherit mr-2 animate-spin',
'mr-2 animate-spin text-inherit',

@georgewrmarshall georgewrmarshall Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixing previously broken text-inherit class and now linting is working as expected

Before

Screenshot 2025-06-11 at 4 13 00 PM

After

Screenshot 2025-06-11 at 4 07 39 PM

// Non-floating styles
!isFloating && [
'bg-transparent rounded',
'rounded bg-transparent',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

linting fixes now bg-transparent is being generated properly

{...args}
name={IconName[iconKey as keyof typeof IconName]}
/>
<div className="text-center text-xs">{iconKey}</div>

@georgewrmarshall georgewrmarshall Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing default font size classnames in favor of the text component. Also did a search for any font size classnames regex: \btext-(xs|sm|base|lg|xl|[2-9]xl)(/\d+)?\b

Screenshot 2025-06-11 at 2 59 27 PM Screenshot 2025-06-11 at 2 58 44 PM

name={IconName.AddSquare}
color={IconColor.IconDefault}
className="text-inherit text-lg"
className="text-inherit"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing unused font size classname

color={IconColor.IconDefault}
size={IconSize.Md}
className="text-inherit h-10 w-10"
className="h-10 w-10 text-inherit"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixing inherit color classname

const mergedClassName = twMerge(
// Reset padding, height and animations
'bg-transparent h-auto rounded-none px-0',
'h-auto rounded-none bg-transparent px-0',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lint fix now bg-transparent is being generated

fontSize: {
// Empty to remove default Tailwind font sizes (text-sm, text-lg, etc.)
// Design system font sizes added via extend
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because mobile won't have a tailwind config we can update the generateTailwindConfig function

@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

black: '#000000',
white: '#ffffff',
},
fontSize: {}, // This removes all default Tailwind font sizes. We want to rely on the design system font sizes and enforce use of the Text component

@georgewrmarshall georgewrmarshall Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We remove all default font sizes to enforce the use of the Text component. We aren't removing the below there are no inherit or other semantic default tailwind classnames for font size

text-xs	
text-sm	
text-base	
text-lg	
text-xl	
text-2xl	
text-3xl	
text-4xl	
text-5xl	
text-6xl	
text-7xl	
text-8xl	
text-9xl

@georgewrmarshall georgewrmarshall marked this pull request as ready for review June 11, 2025 07:02
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner June 11, 2025 07:02
brianacnguyen
brianacnguyen previously approved these changes Jun 11, 2025
@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

cursor[bot]

This comment was marked as outdated.

@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replacing default colors and font size classnames with Text component

Before

Screenshot 2025-06-12 at 8 14 13 AM

After

Screenshot 2025-06-12 at 8 17 06 AM

@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Misused Labels Confuse Screen Readers

Semantic HTML misuse: <label> elements are incorrectly used for text referenced by aria-labelledby and aria-describedby on ButtonBase components. Labels should only be used for form controls. This can confuse screen readers and assistive technologies. The affected elements should be div, span, or p.

packages/design-system-react/src/components/ButtonBase/ButtonBase.stories.tsx#L223-L251

<div>
<Text variant={TextVariant.BodyMd} className="mb-2 block" asChild>
<label id="save-label">Save your progress</label>
</Text>
<ButtonBase {...args} aria-labelledby="save-label">
💾 Save
</ButtonBase>
</div>
</div>
<div className="space-y-2">
<Text variant={TextVariant.HeadingSm}>Using aria-describedby</Text>
<Text variant={TextVariant.BodySm} color={TextColor.TextAlternative}>
Reference an element that provides additional description
</Text>
<div>
<ButtonBase {...args} aria-describedby="submit-description">
Submit Form
</ButtonBase>
<Text
variant={TextVariant.BodySm}
color={TextColor.TextAlternative}
className="mt-1 block"
asChild
>
<label id="submit-description">
This will submit your form and send you to the confirmation page
</label>
</Text>

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

@georgewrmarshall georgewrmarshall merged commit 3aa68e1 into main Jun 11, 2025
37 checks passed
@georgewrmarshall georgewrmarshall deleted the remove-default-colors-font-sizes branch June 11, 2025 23:08
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.

Removing default Tailwind font size and color utilities

2 participants