|
1 |
| -import _ from "lodash"; |
2 |
| -import { |
3 |
| - StyleDictionaryTokenConfig, |
4 |
| - TokenTypes, |
5 |
| - tokensWithPrefix, |
6 |
| -} from "./tokens.util"; |
| 1 | +import { mergeConfigs, tokensWithPrefix } from "./tokens.util"; |
| 2 | +import { radiusTokenConfig } from "./tokens/border-radius"; |
7 | 3 | import { breakpointTokenConfig } from "./tokens/breakpoint";
|
8 |
| -import { fontTokenConfig } from "./tokens/font"; |
9 | 4 | import {
|
10 |
| - globalColorDarkModeConfig, |
11 |
| - globalColorLightModeConfig, |
12 |
| -} from "./tokens/global"; |
| 5 | + globalDarkTokens, |
| 6 | + globalLightTokens, |
| 7 | +} from "./tokens/colors/global.tokens"; |
| 8 | +import { semanticTokensForAllRoles } from "./tokens/colors/semantic-role.tokens"; |
| 9 | +import { semanticRootTokens } from "./tokens/colors/semantic-root.tokens"; |
| 10 | +import { fontTokenConfig } from "./tokens/font"; |
13 | 11 | import { opacityTokenConfig } from "./tokens/opacity";
|
14 |
| -import { radiusTokenConfig } from "./tokens/radius"; |
15 |
| -import { semanticTokenConfig } from "./tokens/semantic"; |
16 |
| -import { semanticTokensForAllRolesConfig } from "./tokens/semantic-roles"; |
17 | 12 | import { shadowTokenConfig } from "./tokens/shadow";
|
18 | 13 | import { spaceTokenConfig } from "./tokens/space";
|
19 |
| -import { textContrastTokenConfig } from "./tokens/text-contrast"; |
20 | 14 |
|
21 |
| -const mergeConfigs = ( |
22 |
| - configs: StyleDictionaryTokenConfig<TokenTypes>[], |
23 |
| -): StyleDictionaryTokenConfig<TokenTypes> => { |
24 |
| - return configs.reduce((acc, config) => _.merge(acc, config), {}); |
25 |
| -}; |
26 |
| - |
27 |
| -/** |
28 |
| - * Collection of configs for: |
29 |
| - * - Global lightmode colors |
30 |
| - * - Semantic tokens for each color-role |
31 |
| - * - Semantic tokens for standalone colors |
32 |
| - */ |
33 | 15 | export const lightModeTokens = () => {
|
34 |
| - return tokensWithPrefix( |
35 |
| - mergeConfigs([ |
36 |
| - shadowTokenConfig("light"), |
37 |
| - opacityTokenConfig("light"), |
38 |
| - semanticTokensForAllRolesConfig(), |
39 |
| - textContrastTokenConfig, |
40 |
| - semanticTokenConfig("light"), |
41 |
| - globalColorLightModeConfig, |
42 |
| - ]), |
43 |
| - ); |
| 16 | + const configs = [ |
| 17 | + shadowTokenConfig("light"), |
| 18 | + opacityTokenConfig("light"), |
| 19 | + semanticTokensForAllRoles(), |
| 20 | + semanticRootTokens("light"), |
| 21 | + globalLightTokens, |
| 22 | + ]; |
| 23 | + |
| 24 | + return tokensWithPrefix(mergeConfigs(configs)); |
44 | 25 | };
|
45 | 26 |
|
46 |
| -/** |
47 |
| - * Collection of configs for: |
48 |
| - * - Global darkmode colors |
49 |
| - */ |
50 | 27 | export const darkModeTokens = () => {
|
51 |
| - return tokensWithPrefix( |
52 |
| - mergeConfigs([ |
53 |
| - shadowTokenConfig("dark"), |
54 |
| - opacityTokenConfig("dark"), |
55 |
| - semanticTokensForAllRolesConfig(), |
56 |
| - textContrastTokenConfig, |
57 |
| - semanticTokenConfig("dark"), |
58 |
| - globalColorDarkModeConfig, |
59 |
| - ]), |
60 |
| - ); |
| 28 | + const configs = [ |
| 29 | + shadowTokenConfig("dark"), |
| 30 | + opacityTokenConfig("dark"), |
| 31 | + semanticTokensForAllRoles(), |
| 32 | + semanticRootTokens("dark"), |
| 33 | + globalDarkTokens, |
| 34 | + ]; |
| 35 | + |
| 36 | + return tokensWithPrefix(mergeConfigs(configs)); |
61 | 37 | };
|
62 | 38 |
|
63 | 39 | /**
|
64 |
| - * Collection of configs for: |
65 |
| - * - Space |
66 |
| - * - Radius |
| 40 | + * We deliberately extract space and border-radius tokens from other "root" tokens like breakline, font etc |
| 41 | + * so we can use the fuction for creating Figma-variables |
67 | 42 | */
|
68 | 43 | export const scaleTokens = () => {
|
69 |
| - return tokensWithPrefix(mergeConfigs([spaceTokenConfig, radiusTokenConfig])); |
| 44 | + const configs = [spaceTokenConfig, radiusTokenConfig]; |
| 45 | + |
| 46 | + return tokensWithPrefix(mergeConfigs(configs)); |
70 | 47 | };
|
71 | 48 |
|
72 | 49 | export const rootTokens = () => {
|
73 |
| - return tokensWithPrefix( |
74 |
| - mergeConfigs([scaleTokens().ax, breakpointTokenConfig, fontTokenConfig]), |
75 |
| - ); |
| 50 | + const configs = [scaleTokens().ax, breakpointTokenConfig, fontTokenConfig]; |
| 51 | + |
| 52 | + return tokensWithPrefix(mergeConfigs(configs)); |
76 | 53 | };
|
77 | 54 |
|
78 | 55 | export const allTokens = () => {
|
79 |
| - return tokensWithPrefix( |
80 |
| - mergeConfigs([ |
81 |
| - lightModeTokens().ax, |
82 |
| - scaleTokens().ax, |
83 |
| - breakpointTokenConfig, |
84 |
| - fontTokenConfig, |
85 |
| - ]), |
86 |
| - ); |
| 56 | + const configs = [ |
| 57 | + lightModeTokens().ax, |
| 58 | + scaleTokens().ax, |
| 59 | + breakpointTokenConfig, |
| 60 | + fontTokenConfig, |
| 61 | + ]; |
| 62 | + |
| 63 | + return tokensWithPrefix(mergeConfigs(configs)); |
87 | 64 | };
|
0 commit comments