generated from MetaMask/metamask-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Initial Tailwind Preset Package with colors (#41)
## **Description** This PR introduces the logic for the `@metamask/design-system-tailwind-preset` to the MetaMask Design System monorepo. This package provides a Tailwind CSS preset that encapsulates MetaMask's design tokens and styling conventions for color making it easier for developers to create consistent UIs across MetaMask Tailwind projects. Subsequent PRs will add shadow, typography, space, etc **NOTE:** This PR does not contain tests. Tests are in a separate PR, as they need to check against the design tokens stylesheet and are quite intensive, deserving their own PR and review: #51 ## **Related issues** Fixes: #34 ## **Manual testing steps** 1. Pull this branch. 2. Navigate to the `design-system-tailwind-preset` package: `cd package/design-system-tailwind-preset`. 3. Run `yarn build`. 4. Ensure you're using `yarn version 1.22.22`: `yarn set version 1.22.22`. 5. Run `yarn link`. 6. Navigate to the `metamask-portfolio` repo. 7. Pull this branch: [feat/design-system-tailwind-preset](https://github.com/consensys-vertical-apps/metamask-portfolio/tree/feat/design-system-tailwind-preset). 8. Run `yarn link "@metamask/design-system-tailwind-preset"`. 9. Run `yarn && yarn start`. 10. Verify that the MetaMask design tokens are available as Tailwind classes. ## **Screenshots/Recordings** The recording shows a locally linked `@metamask/design-system-tailwind-preset` package inside the `metamask-portfolio`. The `tailwind.config.js` has been updated, and the design token-generated Tailwind class names have been removed in favor of the preset package. The preset package is now responsible for generating all of the design token-aligned Tailwind class names for color. https://github.com/user-attachments/assets/f13350cb-e64c-44d1-b7d5-020cff07b011 ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) - [x] I've completed the PR template to the best of my ability - [ ] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). 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.
- Loading branch information
1 parent
e666367
commit ac1a779
Showing
7 changed files
with
174 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { colors } from './colors'; | ||
|
||
describe('Colors', () => { | ||
// TODO: Implement tests for colors https://github.com/MetaMask/metamask-design-system/issues/48 | ||
it('should have a dummy test', () => { | ||
expect(colors).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
export const colors = { | ||
background: { | ||
default: 'var(--color-background-default)', | ||
'default-hover': 'var(--color-background-default-hover)', | ||
'default-pressed': 'var(--color-background-default-pressed)', | ||
alternative: 'var(--color-background-alternative)', | ||
'alternative-hover': 'var(--color-background-alternative-hover)', | ||
'alternative-pressed': 'var(--color-background-alternative-pressed)', | ||
hover: 'var(--color-background-hover)', | ||
pressed: 'var(--color-background-pressed)', | ||
}, | ||
text: { | ||
default: 'var(--color-text-default)', | ||
alternative: 'var(--color-text-alternative)', | ||
muted: 'var(--color-text-muted)', | ||
}, | ||
border: { | ||
default: 'var(--color-border-default)', | ||
muted: 'var(--color-border-muted)', | ||
}, | ||
icon: { | ||
default: 'var(--color-icon-default)', | ||
alternative: 'var(--color-icon-alternative)', | ||
muted: 'var(--color-icon-muted)', | ||
}, | ||
overlay: { | ||
default: 'var(--color-overlay-default)', | ||
alternative: 'var(--color-overlay-alternative)', | ||
inverse: 'var(--color-overlay-inverse)', | ||
}, | ||
primary: { | ||
default: 'var(--color-primary-default)', | ||
'default-hover': 'var(--color-primary-default-hover)', | ||
'default-pressed': 'var(--color-primary-default-pressed)', | ||
alternative: 'var(--color-primary-alternative)', | ||
muted: 'var(--color-primary-muted)', | ||
inverse: 'var(--color-primary-inverse)', | ||
}, | ||
error: { | ||
default: 'var(--color-error-default)', | ||
'default-hover': 'var(--color-error-default-hover)', | ||
'default-pressed': 'var(--color-error-default-pressed)', | ||
alternative: 'var(--color-error-alternative)', | ||
muted: 'var(--color-error-muted)', | ||
inverse: 'var(--color-error-inverse)', | ||
}, | ||
warning: { | ||
default: 'var(--color-warning-default)', | ||
'default-hover': 'var(--color-warning-default-hover)', | ||
'default-pressed': 'var(--color-warning-default-pressed)', | ||
muted: 'var(--color-warning-muted)', | ||
inverse: 'var(--color-warning-inverse)', | ||
}, | ||
success: { | ||
default: 'var(--color-success-default)', | ||
'default-hover': 'var(--color-success-default-hover)', | ||
'default-pressed': 'var(--color-success-default-pressed)', | ||
muted: 'var(--color-success-muted)', | ||
inverse: 'var(--color-success-inverse)', | ||
}, | ||
info: { | ||
default: 'var(--color-info-default)', | ||
muted: 'var(--color-info-muted)', | ||
inverse: 'var(--color-info-inverse)', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import greeter from '.'; | ||
import tailwindConfig from '.'; | ||
|
||
describe('Test', () => { | ||
it('greets', () => { | ||
const name = 'Huey'; | ||
const result = greeter(name); | ||
expect(result).toBe('Hello, Huey!'); | ||
describe('Tailwind Preset', () => { | ||
// TODO: Implement tests for Tailwind preset https://github.com/MetaMask/metamask-design-system/issues/48 | ||
it('should have a dummy test', () => { | ||
expect(tailwindConfig).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
/** | ||
* Example function that returns a greeting for the given name. | ||
* | ||
* @param name - The name to greet. | ||
* @returns The greeting. | ||
*/ | ||
export default function greeter(name: string): string { | ||
return `Hello, ${name}!`; | ||
} | ||
import type { Config } from 'tailwindcss'; | ||
|
||
import { colors } from './colors'; | ||
|
||
const tailwindConfig: Config = { | ||
content: [], | ||
theme: { | ||
extend: { | ||
colors: { | ||
...colors, | ||
}, | ||
// Reduces redundancy by enabling shorter Tailwind class names | ||
textColor: ({ theme }) => ({ | ||
...theme('colors'), // Incorporate existing color utilities like text-primary-default | ||
...colors.text, // e.g. text-default instead of text-text-default | ||
}), | ||
backgroundColor: ({ theme }) => ({ | ||
...theme('colors'), // Incorporate existing color utilities like bg-primary-default | ||
...colors.background, // e.g. bg-default instead of bg-background-default | ||
}), | ||
borderColor: ({ theme }) => ({ | ||
...theme('colors'), // Incorporate existing color utilities like border-primary-default | ||
...colors.border, // e.g. border-default instead of border-border-default | ||
}), | ||
}, | ||
}, | ||
plugins: [], | ||
}; | ||
|
||
export default tailwindConfig; | ||
|
||
module.exports = tailwindConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters