-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
tokens.js
235 lines (198 loc) · 4.36 KB
/
tokens.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
* Copyright IBM Corp. 2018, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { unstable_tokens as type } from '@carbon/type';
import { unstable_tokens as layout } from '@carbon/layout';
// The color token names for a Carbon theme, value corresponds to what they're
// exported as in JavaScript
const colors = [
// Core
'interactive01',
'interactive02',
'interactive03',
'interactive04',
'uiBackground',
'ui01',
'ui02',
'ui03',
'ui04',
'ui05',
'text01',
'text02',
'text03',
'text04',
'text05',
'textError',
'icon01',
'icon02',
'icon03',
'link01',
'inverseLink',
'field01',
'field02',
'inverse01',
'inverse02',
'support01',
'support02',
'support03',
'support04',
'inverseSupport01',
'inverseSupport02',
'inverseSupport03',
'inverseSupport04',
'overlay01',
'danger',
// Interactive states
'focus',
'inverseFocusUi',
'hoverPrimary',
'activePrimary',
'hoverPrimaryText',
'hoverSecondary',
'activeSecondary',
'hoverTertiary',
'activeTertiary',
'hoverUI',
'activeUI',
'selectedUI',
'hoverSelectedUI',
'inverseHoverUI',
'hoverDanger',
'activeDanger',
'hoverRow',
'visitedLink',
'disabled01',
'disabled02',
'disabled03',
'highlight',
'decorative01',
'skeleton01',
'skeleton02',
// Deprecated
'brand01',
'brand02',
'brand03',
'active01',
'hoverField',
];
const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
/**
* Format a given token into the format expected in CSS/SCSS-based projects.
* @param {string} token
* @returns {string}
*/
export function formatTokenName(token) {
let string = '';
for (let i = 0; i < token.length; i++) {
// If we run into a number, we hit the scale step at the end of a token name
// and can safely truncate the rest of the token
if (numbers.indexOf(token[i]) !== -1) {
string += '-' + token.slice(i);
break;
}
// When encountering an uppercase name, we will want to start adding `-`
// between words
if (token[i] === token[i].toUpperCase()) {
// Check backwards to see if previous letter was also capitalized, if so
// we are in a special case like UI where each piece should be connected
if (token[i - 1] && token[i - 1] === token[i - 1].toUpperCase()) {
string += token[i].toLowerCase();
continue;
}
// Otherwise, just concatenate this new part on to the existing string
string += '-' + token[i].toLowerCase();
continue;
}
// By default, we add the current character to the output string
string += token[i];
}
return string;
}
export const tokens = {
colors,
type,
layout,
};
export const unstable__meta = {
colors: [
{
type: 'core',
tokens: [
'uiBackground',
'interactive01',
'interactive02',
'interactive03',
'interactive04',
'brand01',
'brand02',
'brand03',
'danger',
'ui01',
'ui02',
'ui03',
'ui04',
'ui05',
'text01',
'text02',
'text03',
'text04',
'text05',
'textError',
'link01',
'icon01',
'icon02',
'icon03',
'field01',
'field02',
'inverse01',
'inverse02',
'inverseLink',
'support01',
'support02',
'support03',
'support04',
'inverseSupport01',
'inverseSupport02',
'inverseSupport03',
'inverseSupport04',
'overlay01',
],
},
{
type: 'interactive',
tokens: [
'focus',
'inverseFocusUi',
'hoverPrimary',
'hoverPrimaryText',
'hoverSecondary',
'hoverTertiary',
'hoverUI',
'hoverSelectedUI',
'hoverDanger',
'hoverRow',
'activePrimary',
'activeSecondary',
'activeTertiary',
'activeUI',
'activeDanger',
'selectedUI',
'highlight',
'skeleton01',
'skeleton02',
'visitedLink',
'disabled01',
'disabled02',
'disabled03',
'inverseHoverUI',
'active01',
'hoverField',
'decorative01',
],
},
],
deprecated: ['brand01', 'brand02', 'brand03', 'active01'],
};