@carbon/themes 12.0.0-alpha.1 → 12.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.js +5572 -0
- package/lib/__tests__/themes-test.d.ts +1 -0
- package/lib/__tests__/tools-test.d.ts +1 -0
- package/lib/tokens/__tests__/Token-test.d.ts +1 -0
- package/lib/tokens/__tests__/TokenFormat-test.d.ts +1 -0
- package/lib/tokens/__tests__/TokenGroup-test.d.ts +1 -0
- package/lib/tokens/__tests__/TokenSet-test.d.ts +1 -0
- package/lib/tokens/__tests__/metadata-test.d.ts +1 -0
- package/lib/tokens/__tests__/v11-test.d.ts +1 -0
- package/lib/v10/__tests__/themes-test.d.ts +1 -0
- package/lib/v10/__tests__/tokens-test.d.ts +1 -0
- package/package.json +12 -4
- package/umd/index.js +6322 -0
- package/docs/sass.md +0 -189
- package/js/generated/component-tokens/button.d.ts +0 -98
- package/js/generated/component-tokens/button.js +0 -98
- package/js/generated/component-tokens/content-switcher.d.ts +0 -25
- package/js/generated/component-tokens/content-switcher.js +0 -25
- package/js/generated/component-tokens/notification.d.ts +0 -65
- package/js/generated/component-tokens/notification.js +0 -65
- package/js/generated/component-tokens/status.d.ts +0 -63
- package/js/generated/component-tokens/status.js +0 -63
- package/js/generated/component-tokens/tag.d.ts +0 -247
- package/js/generated/component-tokens/tag.js +0 -247
- package/js/generated/themes/g10.d.ts +0 -242
- package/js/generated/themes/g10.js +0 -242
- package/js/generated/themes/g100.d.ts +0 -242
- package/js/generated/themes/g100.js +0 -242
- package/js/generated/themes/g90.d.ts +0 -242
- package/js/generated/themes/g90.js +0 -242
- package/js/generated/themes/white.d.ts +0 -242
- package/js/generated/themes/white.js +0 -242
- package/src/dtcg/README.md +0 -336
- package/src/dtcg/color-palette.json +0 -4424
- package/src/dtcg/components/button.json +0 -193
- package/src/dtcg/components/content-switcher.json +0 -60
- package/src/dtcg/components/notification.json +0 -130
- package/src/dtcg/components/status.json +0 -122
- package/src/dtcg/components/tag.json +0 -486
- package/src/dtcg/themes.json +0 -3356
- package/src/index.ts +0 -129
- package/src/tokens/Token.ts +0 -41
- package/src/tokens/TokenFormat.ts +0 -93
- package/src/tokens/TokenGroup.ts +0 -185
- package/src/tokens/TokenSet.ts +0 -91
- package/src/tokens/components.ts +0 -120
- package/src/tokens/index.ts +0 -59
- package/src/tokens/layout.ts +0 -39
- package/src/tokens/type.ts +0 -49
- package/src/tokens/types.ts +0 -28
- package/src/tokens/v10.ts +0 -188
- package/src/tokens/v11TokenGroup.ts +0 -546
- package/src/tokens/v11TokenSet.ts +0 -93
- package/src/tools.ts +0 -69
- package/src/v10/g10.ts +0 -349
- package/src/v10/g100.ts +0 -348
- package/src/v10/g90.ts +0 -350
- package/src/v10/index.ts +0 -22
- package/src/v10/metadata.yml +0 -217
- package/src/v10/tokens.ts +0 -397
- package/src/v10/white.ts +0 -352
- package/style-dictionary/formats/js-component-tokens.js +0 -128
- package/style-dictionary/formats/js-themes.js +0 -84
- package/style-dictionary/formats/scss-component-tokens.js +0 -149
- package/style-dictionary/formats/scss-themes.js +0 -127
- package/style-dictionary/formats/scss-tokens.js +0 -91
- package/style-dictionary/preprocessors/component-tokens.js +0 -172
- package/style-dictionary/preprocessors/dual-role.js +0 -157
- package/style-dictionary/preprocessors/theme-metadata.js +0 -46
- package/style-dictionary/sd.config.js +0 -449
- package/style-dictionary/transforms/alpha-modifier.js +0 -68
- package/style-dictionary/transforms/color-flatten.js +0 -79
- package/test-dtcg.scss +0 -28
- package/tsconfig.json +0 -8
- package/tsconfig.types.json +0 -10
package/src/index.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2026
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// The imports below reference build artifacts in js/generated/ that are
|
|
9
|
-
// produced by `yarn build:js-tokens` (tasks/generate-js-tokens.js) before
|
|
10
|
-
// this file is bundled. Run `yarn build` to generate them first.
|
|
11
|
-
import * as white from '../js/generated/themes/white.js';
|
|
12
|
-
import * as g10 from '../js/generated/themes/g10.js';
|
|
13
|
-
import * as g90 from '../js/generated/themes/g90.js';
|
|
14
|
-
import * as g100 from '../js/generated/themes/g100.js';
|
|
15
|
-
import * as v10 from './v10';
|
|
16
|
-
import * as buttonTokens from '../js/generated/component-tokens/button.js';
|
|
17
|
-
import * as tagTokens from '../js/generated/component-tokens/tag.js';
|
|
18
|
-
import * as notificationTokens from '../js/generated/component-tokens/notification.js';
|
|
19
|
-
import * as statusTokens from '../js/generated/component-tokens/status.js';
|
|
20
|
-
import * as contentSwitcherTokens from '../js/generated/component-tokens/content-switcher.js';
|
|
21
|
-
import { formatTokenName } from './tools';
|
|
22
|
-
import { unstable_metadata } from './tokens';
|
|
23
|
-
|
|
24
|
-
const themes = {
|
|
25
|
-
white,
|
|
26
|
-
g10,
|
|
27
|
-
g90,
|
|
28
|
-
g100,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export * from '../js/generated/themes/white.js';
|
|
32
|
-
export {
|
|
33
|
-
white,
|
|
34
|
-
g10,
|
|
35
|
-
g90,
|
|
36
|
-
g100,
|
|
37
|
-
themes,
|
|
38
|
-
v10,
|
|
39
|
-
buttonTokens,
|
|
40
|
-
tagTokens,
|
|
41
|
-
notificationTokens,
|
|
42
|
-
statusTokens,
|
|
43
|
-
contentSwitcherTokens,
|
|
44
|
-
unstable_metadata,
|
|
45
|
-
formatTokenName,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// Re-export type and layout tokens that were previously re-exported via the
|
|
49
|
-
// hand-authored theme files (white.ts, g10.ts, g90.ts, g100.ts) to preserve
|
|
50
|
-
// backward compatibility with @carbon/themes consumers.
|
|
51
|
-
export {
|
|
52
|
-
caption01,
|
|
53
|
-
caption02,
|
|
54
|
-
label01,
|
|
55
|
-
label02,
|
|
56
|
-
helperText01,
|
|
57
|
-
helperText02,
|
|
58
|
-
bodyShort01,
|
|
59
|
-
bodyLong01,
|
|
60
|
-
bodyShort02,
|
|
61
|
-
bodyLong02,
|
|
62
|
-
code01,
|
|
63
|
-
code02,
|
|
64
|
-
heading01,
|
|
65
|
-
productiveHeading01,
|
|
66
|
-
heading02,
|
|
67
|
-
productiveHeading02,
|
|
68
|
-
productiveHeading03,
|
|
69
|
-
productiveHeading04,
|
|
70
|
-
productiveHeading05,
|
|
71
|
-
productiveHeading06,
|
|
72
|
-
productiveHeading07,
|
|
73
|
-
expressiveHeading01,
|
|
74
|
-
expressiveHeading02,
|
|
75
|
-
expressiveHeading03,
|
|
76
|
-
expressiveHeading04,
|
|
77
|
-
expressiveHeading05,
|
|
78
|
-
expressiveHeading06,
|
|
79
|
-
expressiveParagraph01,
|
|
80
|
-
quotation01,
|
|
81
|
-
quotation02,
|
|
82
|
-
display01,
|
|
83
|
-
display02,
|
|
84
|
-
display03,
|
|
85
|
-
display04,
|
|
86
|
-
} from '@carbon/type';
|
|
87
|
-
export {
|
|
88
|
-
spacing01,
|
|
89
|
-
spacing02,
|
|
90
|
-
spacing03,
|
|
91
|
-
spacing04,
|
|
92
|
-
spacing05,
|
|
93
|
-
spacing06,
|
|
94
|
-
spacing07,
|
|
95
|
-
spacing08,
|
|
96
|
-
spacing09,
|
|
97
|
-
spacing10,
|
|
98
|
-
spacing11,
|
|
99
|
-
spacing12,
|
|
100
|
-
spacing13,
|
|
101
|
-
// Fluid spacing
|
|
102
|
-
fluidSpacing01,
|
|
103
|
-
fluidSpacing02,
|
|
104
|
-
fluidSpacing03,
|
|
105
|
-
fluidSpacing04,
|
|
106
|
-
// Containers
|
|
107
|
-
container01,
|
|
108
|
-
container02,
|
|
109
|
-
container03,
|
|
110
|
-
container04,
|
|
111
|
-
container05,
|
|
112
|
-
sizeXSmall,
|
|
113
|
-
sizeSmall,
|
|
114
|
-
sizeMedium,
|
|
115
|
-
sizeLarge,
|
|
116
|
-
sizeXLarge,
|
|
117
|
-
size2XLarge,
|
|
118
|
-
// Icon sizes
|
|
119
|
-
iconSize01,
|
|
120
|
-
iconSize02,
|
|
121
|
-
// Layout (deprecated)
|
|
122
|
-
layout01,
|
|
123
|
-
layout02,
|
|
124
|
-
layout03,
|
|
125
|
-
layout04,
|
|
126
|
-
layout05,
|
|
127
|
-
layout06,
|
|
128
|
-
layout07,
|
|
129
|
-
} from '@carbon/layout';
|
package/src/tokens/Token.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2026
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A Token is the simplest unit in our theme. It can have a name, properties
|
|
10
|
-
* that it applies to like border or background, along with a state if the
|
|
11
|
-
* token should only be used for specific states like hover or focus.
|
|
12
|
-
*/
|
|
13
|
-
import type { TokenDefinition, TokenProperties } from './types';
|
|
14
|
-
|
|
15
|
-
export class Token {
|
|
16
|
-
kind: 'Token';
|
|
17
|
-
name: string;
|
|
18
|
-
properties?: TokenProperties;
|
|
19
|
-
state?: string;
|
|
20
|
-
|
|
21
|
-
static create(token: string | TokenDefinition) {
|
|
22
|
-
if (typeof token === 'string') {
|
|
23
|
-
return new Token(token);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return new Token(token.name, token.properties, token.state);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
constructor(name: string, properties?: TokenProperties, state?: string) {
|
|
30
|
-
this.kind = 'Token';
|
|
31
|
-
this.name = name;
|
|
32
|
-
|
|
33
|
-
if (properties) {
|
|
34
|
-
this.properties = properties;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (state) {
|
|
38
|
-
this.state = state;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2026
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { TokenDefinition } from './types';
|
|
9
|
-
|
|
10
|
-
type TokenFormatName = 'javascript' | 'scss';
|
|
11
|
-
|
|
12
|
-
const formats: Record<'js' | 'scss', TokenFormatName> = {
|
|
13
|
-
js: 'javascript',
|
|
14
|
-
scss: 'scss',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const TokenFormat = {
|
|
18
|
-
formats,
|
|
19
|
-
|
|
20
|
-
convert({
|
|
21
|
-
name,
|
|
22
|
-
format,
|
|
23
|
-
}: Pick<TokenDefinition, 'name'> & { format?: TokenFormatName }) {
|
|
24
|
-
if (format === formats.js) {
|
|
25
|
-
const keywords = new Set(['ui']);
|
|
26
|
-
|
|
27
|
-
return name
|
|
28
|
-
.split('-')
|
|
29
|
-
.map((part, index) => {
|
|
30
|
-
if (index === 0) {
|
|
31
|
-
return part;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (keywords.has(part)) {
|
|
35
|
-
return part.toUpperCase();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return part[0].toUpperCase() + part.slice(1);
|
|
39
|
-
})
|
|
40
|
-
.join('');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (format === formats.scss) {
|
|
44
|
-
return formatNameToScss(name);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return name;
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Format a given token into the format expected in CSS/SCSS-based projects.
|
|
55
|
-
*/
|
|
56
|
-
const formatNameToScss = (token: string) => {
|
|
57
|
-
let string = '';
|
|
58
|
-
|
|
59
|
-
for (let i = 0; i < token.length; i++) {
|
|
60
|
-
if (token[i] === '-') {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// If we run into a number, we hit the scale step at the end of a token name
|
|
65
|
-
// and can safely truncate the rest of the token
|
|
66
|
-
if (numbers.indexOf(token[i]) !== -1) {
|
|
67
|
-
string += '-' + token.slice(i);
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// When encountering an uppercase name, we will want to start adding `-`
|
|
72
|
-
// between words
|
|
73
|
-
if (token[i] === token[i].toUpperCase()) {
|
|
74
|
-
// Check backwards to see if previous letter was also capitalized, if so
|
|
75
|
-
// we are in a special case like UI where each piece should be connected
|
|
76
|
-
if (token[i - 1] && token[i - 1] === token[i - 1].toUpperCase()) {
|
|
77
|
-
string += token[i].toLowerCase();
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (token[i - 1] !== '-') {
|
|
82
|
-
// Otherwise, just concatenate this new part on to the existing string
|
|
83
|
-
string += '-' + token[i].toLowerCase();
|
|
84
|
-
}
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// By default, we add the current character to the output string
|
|
89
|
-
string += token[i];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return string;
|
|
93
|
-
};
|
package/src/tokens/TokenGroup.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2026
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Token } from './Token';
|
|
9
|
-
import type {
|
|
10
|
-
ResolvedToken,
|
|
11
|
-
TokenContext,
|
|
12
|
-
TokenDefinition,
|
|
13
|
-
TokenProperties,
|
|
14
|
-
} from './types';
|
|
15
|
-
|
|
16
|
-
type TokenGroupChild = Token | TokenGroup;
|
|
17
|
-
|
|
18
|
-
type TokenGroupDefinition = {
|
|
19
|
-
name: string;
|
|
20
|
-
properties?: TokenProperties;
|
|
21
|
-
tokens?: Array<Token | TokenDefinition | TokenGroup | string>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A TokenGroup allows us to group up a collection of tokens and nested token
|
|
26
|
-
* groups. A group allows us to colocate related tokens and write information
|
|
27
|
-
* once that applies to the entire collection of tokens. For example, if all the
|
|
28
|
-
* tokens apply to the `border` color property then we can specify this property
|
|
29
|
-
* at the group level
|
|
30
|
-
*
|
|
31
|
-
* A TokenGroup allows us to colocate all this information while also providing
|
|
32
|
-
* ways to get information about the entire group, including properties and
|
|
33
|
-
* states
|
|
34
|
-
*/
|
|
35
|
-
export class TokenGroup {
|
|
36
|
-
kind: 'TokenGroup';
|
|
37
|
-
name: string;
|
|
38
|
-
properties?: TokenProperties;
|
|
39
|
-
children: TokenGroupChild[];
|
|
40
|
-
|
|
41
|
-
static create({ name, properties, tokens = [] }: TokenGroupDefinition) {
|
|
42
|
-
return new TokenGroup(name, tokens, properties);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
constructor(
|
|
46
|
-
name: string,
|
|
47
|
-
tokens: Array<Token | TokenDefinition | TokenGroup | string>,
|
|
48
|
-
properties?: TokenProperties
|
|
49
|
-
) {
|
|
50
|
-
this.kind = 'TokenGroup';
|
|
51
|
-
this.name = name;
|
|
52
|
-
|
|
53
|
-
if (properties) {
|
|
54
|
-
this.properties = properties;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.children = tokens.map((child) => {
|
|
58
|
-
if (
|
|
59
|
-
typeof child !== 'string' &&
|
|
60
|
-
'kind' in child &&
|
|
61
|
-
child.kind === 'TokenGroup'
|
|
62
|
-
) {
|
|
63
|
-
return child;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return Token.create(child);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
*[Symbol.iterator](): Generator<TokenGroupChild, void, unknown> {
|
|
71
|
-
yield this;
|
|
72
|
-
|
|
73
|
-
for (const child of this.children) {
|
|
74
|
-
yield child;
|
|
75
|
-
|
|
76
|
-
if (child.kind === 'TokenGroup') {
|
|
77
|
-
yield* child;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Get all the tokens available in every Token Group in this TokenGroup,
|
|
84
|
-
* including itself.
|
|
85
|
-
*/
|
|
86
|
-
getTokens(parentContext: TokenContext = {}): ResolvedToken[] {
|
|
87
|
-
const context = {
|
|
88
|
-
...parentContext,
|
|
89
|
-
groups: parentContext.groups
|
|
90
|
-
? parentContext.groups.concat(this.name)
|
|
91
|
-
: [this.name],
|
|
92
|
-
properties: this.properties || parentContext.properties,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return this.children.flatMap((child) => {
|
|
96
|
-
if (child.kind === 'TokenGroup') {
|
|
97
|
-
return child.getTokens(context);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const token: ResolvedToken = {
|
|
101
|
-
...context,
|
|
102
|
-
name: child.name,
|
|
103
|
-
properties: child.properties || context.properties,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
if (child.state) {
|
|
107
|
-
token.state = child.state;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return token;
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Get a specific token from the TokenGroup, or form one of its nested
|
|
116
|
-
* TokenGroups
|
|
117
|
-
*/
|
|
118
|
-
getToken(tokenOrName: Token | string): Token | null {
|
|
119
|
-
const name =
|
|
120
|
-
typeof tokenOrName === 'string' ? tokenOrName : tokenOrName.name;
|
|
121
|
-
for (const child of this) {
|
|
122
|
-
if (child.kind === 'TokenGroup') {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (child.name === name) {
|
|
127
|
-
return child;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Get all the unique groups in the token group, including this group
|
|
135
|
-
*/
|
|
136
|
-
getTokenGroups() {
|
|
137
|
-
const set = new Set<TokenGroup>();
|
|
138
|
-
|
|
139
|
-
for (const child of this) {
|
|
140
|
-
if (child.kind !== 'TokenGroup') {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
set.add(child);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return Array.from(set);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Get all the unique properties in the token group, including this group
|
|
151
|
-
*/
|
|
152
|
-
getTokenProperties() {
|
|
153
|
-
const set = new Set<string>();
|
|
154
|
-
|
|
155
|
-
for (const child of this) {
|
|
156
|
-
if (!Array.isArray(child.properties)) {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
for (const property of child.properties) {
|
|
161
|
-
set.add(property);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return Array.from(set);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Get all the unique states in the token group, including this group
|
|
170
|
-
*/
|
|
171
|
-
getTokenStates() {
|
|
172
|
-
const set = new Set<string>();
|
|
173
|
-
|
|
174
|
-
for (const child of this) {
|
|
175
|
-
if (child.kind !== 'Token') {
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
if (child.state) {
|
|
179
|
-
set.add(child.state);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return Array.from(set);
|
|
184
|
-
}
|
|
185
|
-
}
|
package/src/tokens/TokenSet.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2026
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A token set is a collection of tokens which should be along with each other.
|
|
10
|
-
* For example, we have tokens that correspond to a layer level in a UI. A
|
|
11
|
-
* token set allows us to group these tokens together in a way that's different
|
|
12
|
-
* than their token group.
|
|
13
|
-
*/
|
|
14
|
-
import { Token } from './Token';
|
|
15
|
-
|
|
16
|
-
type TokenSetChild = Token | TokenSet;
|
|
17
|
-
|
|
18
|
-
type TokenSetDefinition = {
|
|
19
|
-
name: string;
|
|
20
|
-
tokens?: TokenSetChild[];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export class TokenSet {
|
|
24
|
-
kind: 'TokenSet';
|
|
25
|
-
name: string;
|
|
26
|
-
children: TokenSetChild[];
|
|
27
|
-
|
|
28
|
-
static create({ name, tokens = [] }: TokenSetDefinition) {
|
|
29
|
-
return new TokenSet(name, tokens);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
constructor(name: string, tokens: TokenSetChild[]) {
|
|
33
|
-
this.kind = 'TokenSet';
|
|
34
|
-
this.name = name;
|
|
35
|
-
this.children = tokens;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
*[Symbol.iterator](): Generator<TokenSetChild, void, unknown> {
|
|
39
|
-
for (const child of this.children) {
|
|
40
|
-
yield child;
|
|
41
|
-
|
|
42
|
-
if (child.kind === 'TokenSet') {
|
|
43
|
-
yield* child;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getTokenSets(): TokenSet[] {
|
|
49
|
-
const children = this.children
|
|
50
|
-
.filter((child) => {
|
|
51
|
-
return child.kind === 'TokenSet';
|
|
52
|
-
})
|
|
53
|
-
.flatMap((child) => {
|
|
54
|
-
return child.getTokenSets();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return [this, ...children];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getTokenSet(name: string) {
|
|
61
|
-
for (const child of this) {
|
|
62
|
-
// TODO: Is this code necessary given the old code was invalid?
|
|
63
|
-
if (child.kind !== 'TokenSet') {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (child.name === name) {
|
|
68
|
-
return child;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
hasToken(tokenOrName: Token | string) {
|
|
76
|
-
const name =
|
|
77
|
-
typeof tokenOrName === 'string' ? tokenOrName : tokenOrName.name;
|
|
78
|
-
|
|
79
|
-
for (const child of this) {
|
|
80
|
-
if (child.kind === 'TokenSet') {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (child.name === name) {
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}
|
package/src/tokens/components.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2026
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { TokenGroup } from './TokenGroup';
|
|
9
|
-
|
|
10
|
-
export const button = TokenGroup.create({
|
|
11
|
-
name: 'Button',
|
|
12
|
-
properties: [],
|
|
13
|
-
tokens: [
|
|
14
|
-
'button-separator',
|
|
15
|
-
'button-primary',
|
|
16
|
-
'button-secondary',
|
|
17
|
-
'button-tertiary',
|
|
18
|
-
'button-danger-primary',
|
|
19
|
-
'button-danger-secondary',
|
|
20
|
-
'button-danger-active',
|
|
21
|
-
'button-primary-active',
|
|
22
|
-
'button-secondary-active',
|
|
23
|
-
'button-tertiary-active',
|
|
24
|
-
'button-danger-hover',
|
|
25
|
-
'button-primary-hover',
|
|
26
|
-
'button-secondary-hover',
|
|
27
|
-
'button-tertiary-hover',
|
|
28
|
-
'button-disabled',
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const notification = TokenGroup.create({
|
|
33
|
-
name: 'Notification',
|
|
34
|
-
properties: [],
|
|
35
|
-
tokens: [
|
|
36
|
-
'notification-background-error',
|
|
37
|
-
'notification-background-success',
|
|
38
|
-
'notification-background-info',
|
|
39
|
-
'notification-background-warning',
|
|
40
|
-
'notification-action-hover',
|
|
41
|
-
'notification-action-tertiary-inverse',
|
|
42
|
-
'notification-action-tertiary-inverse-active',
|
|
43
|
-
'notification-action-tertiary-inverse-hover',
|
|
44
|
-
'notification-action-tertiary-inverse-text',
|
|
45
|
-
'notification-action-tertiary-inverse-text-on-color-disabled',
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
export const tag = TokenGroup.create({
|
|
50
|
-
name: 'Tag',
|
|
51
|
-
properties: [],
|
|
52
|
-
tokens: [
|
|
53
|
-
'tag-background-red',
|
|
54
|
-
'tag-color-red',
|
|
55
|
-
'tag-hover-red',
|
|
56
|
-
'tag-background-magenta',
|
|
57
|
-
'tag-color-magenta',
|
|
58
|
-
'tag-hover-magenta',
|
|
59
|
-
'tag-background-purple',
|
|
60
|
-
'tag-color-purple',
|
|
61
|
-
'tag-hover-purple',
|
|
62
|
-
'tag-background-blue',
|
|
63
|
-
'tag-color-blue',
|
|
64
|
-
'tag-hover-blue',
|
|
65
|
-
'tag-background-cyan',
|
|
66
|
-
'tag-color-cyan',
|
|
67
|
-
'tag-hover-cyan',
|
|
68
|
-
'tag-background-teal',
|
|
69
|
-
'tag-color-teal',
|
|
70
|
-
'tag-hover-teal',
|
|
71
|
-
'tag-background-green',
|
|
72
|
-
'tag-color-green',
|
|
73
|
-
'tag-hover-green',
|
|
74
|
-
'tag-background-gray',
|
|
75
|
-
'tag-color-gray',
|
|
76
|
-
'tag-hover-gray',
|
|
77
|
-
'tag-border-red',
|
|
78
|
-
'tag-border-blue',
|
|
79
|
-
'tag-border-cyan',
|
|
80
|
-
'tag-border-teal',
|
|
81
|
-
'tag-border-green',
|
|
82
|
-
'tag-border-magenta',
|
|
83
|
-
'tag-border-purple',
|
|
84
|
-
'tag-border-gray',
|
|
85
|
-
'tag-border-cool-gray',
|
|
86
|
-
'tag-border-warm-gray',
|
|
87
|
-
'tag-background-cool-gray',
|
|
88
|
-
'tag-color-cool-gray',
|
|
89
|
-
'tag-hover-cool-gray',
|
|
90
|
-
'tag-background-warm-gray',
|
|
91
|
-
'tag-color-warm-gray',
|
|
92
|
-
'tag-hover-warm-gray',
|
|
93
|
-
],
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
export const status = TokenGroup.create({
|
|
97
|
-
name: 'Status',
|
|
98
|
-
properties: [],
|
|
99
|
-
tokens: [
|
|
100
|
-
'status-red',
|
|
101
|
-
'status-orange',
|
|
102
|
-
'status-orange-outline',
|
|
103
|
-
'status-yellow',
|
|
104
|
-
'status-yellow-outline',
|
|
105
|
-
'status-purple',
|
|
106
|
-
'status-green',
|
|
107
|
-
'status-blue',
|
|
108
|
-
'status-gray',
|
|
109
|
-
],
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
export const contentSwitcher = TokenGroup.create({
|
|
113
|
-
name: 'Content Switcher',
|
|
114
|
-
properties: [],
|
|
115
|
-
tokens: [
|
|
116
|
-
'content-switcher-selected',
|
|
117
|
-
'content-switcher-background',
|
|
118
|
-
'content-switcher-background-hover',
|
|
119
|
-
],
|
|
120
|
-
});
|
package/src/tokens/index.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2026
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Token } from './Token';
|
|
9
|
-
import { TokenFormat } from './TokenFormat';
|
|
10
|
-
import { TokenGroup } from './TokenGroup';
|
|
11
|
-
import { TokenSet } from './TokenSet';
|
|
12
|
-
import { group, contextual } from './v11TokenGroup';
|
|
13
|
-
import { set } from './v11TokenSet';
|
|
14
|
-
import * as components from './components';
|
|
15
|
-
import { type } from './type';
|
|
16
|
-
import { layout } from './layout';
|
|
17
|
-
import { v10 } from './v10';
|
|
18
|
-
import type { TokenMetadata } from './types';
|
|
19
|
-
|
|
20
|
-
export { Token, TokenFormat, TokenGroup, TokenSet, group, set };
|
|
21
|
-
|
|
22
|
-
const formatMetadata = (name: string, type: TokenMetadata['type']) => ({
|
|
23
|
-
name,
|
|
24
|
-
type,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const v11: TokenMetadata[] = [
|
|
28
|
-
// Base color tokens
|
|
29
|
-
...group.getTokens().map((token) => {
|
|
30
|
-
return formatMetadata(token.name, 'color');
|
|
31
|
-
}),
|
|
32
|
-
|
|
33
|
-
// Contextual tokens
|
|
34
|
-
...contextual.getTokens().map((token) => {
|
|
35
|
-
return formatMetadata(token.name, 'color');
|
|
36
|
-
}),
|
|
37
|
-
|
|
38
|
-
// Component tokens
|
|
39
|
-
...Object.values(components).flatMap((group) => {
|
|
40
|
-
return group.getTokens().map((token) => {
|
|
41
|
-
return formatMetadata(token.name, 'color');
|
|
42
|
-
});
|
|
43
|
-
}),
|
|
44
|
-
|
|
45
|
-
// Typography
|
|
46
|
-
...type.getTokens().map((token) => {
|
|
47
|
-
return formatMetadata(token.name, 'type');
|
|
48
|
-
}),
|
|
49
|
-
|
|
50
|
-
// Layout (spacing)
|
|
51
|
-
...layout.getTokens().map((token) => {
|
|
52
|
-
return formatMetadata(token.name, 'layout');
|
|
53
|
-
}),
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
export const unstable_metadata = {
|
|
57
|
-
v11,
|
|
58
|
-
v10,
|
|
59
|
-
};
|