Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit 8963807

Browse files
Adding themes to CSS-in-JS architecture
1 parent 894beab commit 8963807

File tree

18 files changed

+801
-202
lines changed

18 files changed

+801
-202
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,16 @@ yarn add @metamask/design-tokens
7979
2. Use design tokens in code by importing from library:
8080

8181
```js
82-
import { colors } from '@metamask/design-tokens';
82+
import { lightTheme, darkTheme } from '@metamask/design-tokens';
8383

84-
const createStyles = (colors) =>
84+
// Create provider that swaps theme (sudo code)
85+
<ThemeProviderContext theme={(theme = 'light' ? lightTheme : darkTheme)} />;
86+
87+
const createStyles = (theme) =>
8588
StyleSheet.create({
8689
modalContainer: {
87-
backgroundColor: colors.background.default,
88-
borderColor: colors.border.default,
90+
backgroundColor: theme.colors.background.default,
91+
borderColor: theme.colors.border.default,
8992
},
9093
});
9194
```

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { colors, typography } from './js';
1+
export { colors, typography, lightTheme, darkTheme, Theme } from './js';

src/js/colors/colors.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { colors as importableColors } from '.';
33

44
const designTokens = require('../../figma/tokens.json');
55

6-
// js tokens for font family matches figma tokens
7-
86
describe('Light Theme Colors', () => {
97
it('js tokens for background.default matches figma tokens background.default', () => {
108
expect(importableColors.light.background.default).toStrictEqual(

src/js/colors/colors.ts

Lines changed: 6 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,199 +1,14 @@
1-
import { Colors } from './types';
1+
import { lightTheme, darkTheme } from '../themes';
22

3-
/* eslint-disable jsdoc/check-property-names, jsdoc/tag-lines */
43
/**
5-
* MetaMask's Design System Colors
6-
*
7-
* NOTE - This documentation doesn't reflect the actual structure of the colors object. We are only documenting the common properties between light and dark themes.
8-
*
9-
* @property {string} background.default - For default neutral backgrounds
10-
* @property {string} background.alternative - For a subtle contrast option for neutral backgrounds. (Example: backdrop, header background)
11-
*
12-
* @property {string} text.default - For general text that takes main priority in the information hierarchy
13-
* @property {string} text.alternative - For a weaker contrast option for neutral text
14-
* @property {string} text.muted - For inactive or lowest priority text. (Example: placeholder)
15-
*
16-
* @property {string} icon.default - For default neutral icons
17-
* @property {string} icon.alternative - For a weaker contrast option for neutral icons
18-
* @property {string} icon.muted - For inactive or lowest priority icons
19-
*
20-
* @property {string} border.default - For default neutral borders with visible contrast. (Example: text inputs)
21-
* @property {string} border.muted - For a weaker contrast option for neutral borders.
22-
*
23-
* @property {string} overlay.default - For shading layers behind modality screens
24-
* @property {string} overlay.alternative - For a stronger shading layer option behind modality screens
25-
* @property {string} overlay.inverse - [Deprecated] Should be used for elements over an overlay
26-
*
27-
* @property {string} primary.default - For primary user action related elements
28-
* @property {string} primary.alternative - For the \"pressed\" state of interactive primary elements
29-
* @property {string} primary.muted - For lowest contrast background used in primary elements
30-
* @property {string} primary.disabled - [Deprecated] Should be used for disabled state
31-
* @property {string} primary.inverse - For elements used on top of primary/default. (Example: label of primary button, check in a checkbox)
32-
*
33-
* @property {string} secondary.default - [Deprecated] Should be used for any secondary actions. It should not be used for any negative connotations such as warnings or errors as it is quite closely tied to the MetaMask Fox
34-
* @property {string} secondary.alternative - [Deprecated] Should be used as an alternative to secondary.default for things such as hover states
35-
* @property {string} secondary.muted - [Deprecated] It’s a very low contrasting secondary variant for things such as alert backgrounds. secondary.muted and secondary.inverse should not be used together in a foreground and background combination
36-
* @property {string} secondary.disabled - [Deprecated] Should be used for all disabled secondary action components
37-
* @property {string} secondary.inverse - [Deprecated] Should be used only as the foreground element on top of primary/default and primary/alternative. It is intended to be the most contrasting color to primary/default. It should meet all AA and AAA accessibility standards such as the text or icon of a primary button
38-
*
39-
* @property {string} error.default - For high-level alert danger/critical elements. Used for text, background, icon or border
40-
* @property {string} error.alternative - For the \"pressed\" state of interactive danger/critical elements
41-
* @property {string} error.muted - For lowest contrast background used in high-level alert danger/critical elements. (Example: notification background)
42-
* @property {string} error.disabled - [Deprecated] Should be used for disabled state
43-
* @property {string} error.inverse - For elements used on top of error/default (Example: label of danger/critical button)
44-
*
45-
* @property {string} warning.default - For low-mid level alert elements. Used for text, background, icon or border
46-
* @property {string} warning.alternative - [Deprecated] Should be used as an alternative to warning/default for things like hover or pressed states
47-
* @property {string} warning.muted - For lowest contrast background used in warning elements. (Example: notification background)
48-
* @property {string} warning.disabled - [Deprecated] Should be used for disabled state
49-
* @property {string} warning.inverse - For elements used on top of warning/default. Used for text, icon or border
50-
*
51-
* @property {string} success.default - For positive & good semantic elements. Used for text, background, icon or border
52-
* @property {string} success.alternative - [Deprecated] Should be used as an alternative to success/default for things like hover or pressed states
53-
* @property {string} success.muted - For lowest contrast background used in success semantic. (Example: notification background)
54-
* @property {string} success.disabled - [Deprecated] Should be used for disabled state
55-
* @property {string} success.inverse - For elements used on top of success/default. Used for text, icon or border
56-
*
57-
* @property {string} info.default - For informational semantic elements. Used for text, background, icon or border
58-
* @property {string} info.alternative - [Deprecated] Should be used as an alternative to info/default for things like hover or pressed states
59-
* @property {string} info.muted - For lowest contrast background used in informational semantic. (Example: notification background)
60-
* @property {string} info.disabled - [Deprecated] Should be used for disabled state
61-
* @property {string} info.inverse - SFor elements used on top of info/default. Used for text, icon or border
4+
* This object is DEPRECATED in favour of the theme objects
625
*/
63-
/* eslint-enable jsdoc/check-property-names, jsdoc/tag-lines */
64-
export const colors: Colors = {
6+
7+
export const colors = {
658
light: {
66-
background: {
67-
default: '#FFFFFF',
68-
alternative: '#F2F4F6',
69-
},
70-
text: {
71-
default: '#24272A',
72-
alternative: '#535A61',
73-
muted: '#BBC0C5',
74-
},
75-
icon: {
76-
default: '#24272A',
77-
alternative: '#6A737D',
78-
muted: '#BBC0C5',
79-
},
80-
border: {
81-
default: '#BBC0C5',
82-
muted: '#D6D9DC',
83-
},
84-
overlay: {
85-
default: '#00000099',
86-
inverse: '#FCFCFC',
87-
alternative: '#000000CC',
88-
},
89-
primary: {
90-
default: '#037DD6',
91-
alternative: '#0260A4',
92-
muted: '#037DD619',
93-
inverse: '#FCFCFC',
94-
disabled: '#037DD680',
95-
},
96-
secondary: {
97-
default: '#F66A0A',
98-
alternative: '#C65507',
99-
muted: '#F66A0A19',
100-
inverse: '#FCFCFC',
101-
disabled: '#F66A0A80',
102-
},
103-
error: {
104-
default: '#D73A49',
105-
alternative: '#B92534',
106-
muted: '#D73A4919',
107-
inverse: '#FCFCFC',
108-
disabled: '#D73A4980',
109-
},
110-
warning: {
111-
default: '#F66A0A',
112-
alternative: '#FFC70A',
113-
muted: '#FFD33D19',
114-
inverse: '#FCFCFC',
115-
disabled: '#FFD33D80',
116-
},
117-
success: {
118-
default: '#28A745',
119-
alternative: '#1E7E34',
120-
muted: '#28A74519',
121-
inverse: '#FCFCFC',
122-
disabled: '#28A74580',
123-
},
124-
info: {
125-
default: '#037DD6',
126-
alternative: '#0260A4',
127-
muted: '#037DD619',
128-
inverse: '#FCFCFC',
129-
disabled: '#037DD680',
130-
},
9+
...lightTheme.colors,
13110
},
13211
dark: {
133-
background: {
134-
default: '#24272A',
135-
alternative: '#141618',
136-
},
137-
text: {
138-
default: '#FFFFFF',
139-
alternative: '#D6D9DC',
140-
muted: '#9FA6AE',
141-
},
142-
icon: {
143-
default: '#FFFFFF',
144-
alternative: '#BBC0C5',
145-
muted: '#9FA6AE',
146-
},
147-
border: {
148-
default: '#848C96',
149-
muted: '#3B4046',
150-
},
151-
overlay: {
152-
default: '#00000099',
153-
inverse: '#FCFCFC',
154-
alternative: '#000000CC',
155-
},
156-
primary: {
157-
default: '#1098FC',
158-
alternative: '#43AEFC',
159-
muted: '#1098FC26',
160-
inverse: '#FCFCFC',
161-
disabled: '#1098FC80',
162-
},
163-
secondary: {
164-
default: '#F8883B',
165-
alternative: '#FAA66C',
166-
muted: '#F8883B26',
167-
inverse: '#FCFCFC',
168-
disabled: '#F8883B80',
169-
},
170-
error: {
171-
default: '#D73A49',
172-
alternative: '#E06470',
173-
muted: '#D73A4926',
174-
inverse: '#FCFCFC',
175-
disabled: '#D73A4980',
176-
},
177-
warning: {
178-
default: '#FFD33D',
179-
alternative: '#FFDF70',
180-
muted: '#FFD33D26',
181-
inverse: '#141618',
182-
disabled: '#FFD33D80',
183-
},
184-
success: {
185-
default: '#28A745',
186-
alternative: '#5DD879',
187-
muted: '#28A74526',
188-
inverse: '#FCFCFC',
189-
disabled: '#28A74580',
190-
},
191-
info: {
192-
default: '#1098FC',
193-
alternative: '#43AEFC',
194-
muted: '#1098FC26',
195-
inverse: '#FCFCFC',
196-
disabled: '#037DD680',
197-
},
12+
...darkTheme.colors,
19813
},
19914
};

src/js/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
export { Theme } from './themes';
2+
export { lightTheme } from './themes';
3+
export { darkTheme } from './themes';
4+
5+
// DEPRECATED in favor of importing theme objects above
16
export { colors } from './colors';
27
export { typography } from './typography';

0 commit comments

Comments
 (0)