@esri/calcite-design-tokens 1.1.1-next.0 → 2.0.0-rc.0

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.
Files changed (148) hide show
  1. package/README.md +7 -9
  2. package/dist/css/breakpoint.css +29 -0
  3. package/dist/css/classes.css +327 -0
  4. package/dist/css/core.css +344 -0
  5. package/dist/css/dark.css +45 -0
  6. package/dist/css/global.css +103 -0
  7. package/dist/css/index.css +176 -0
  8. package/dist/css/light.css +45 -0
  9. package/dist/es6/core.d.ts +342 -0
  10. package/dist/es6/core.js +342 -0
  11. package/dist/es6/global.d.ts +207 -0
  12. package/dist/es6/global.js +207 -0
  13. package/dist/js/core.d.ts +466 -0
  14. package/dist/js/core.js +8795 -0
  15. package/dist/js/global.d.ts +331 -0
  16. package/dist/js/global.js +6597 -0
  17. package/dist/scss/breakpoints.scss +37 -0
  18. package/dist/scss/core.scss +342 -0
  19. package/dist/scss/dark.scss +43 -0
  20. package/dist/scss/index.scss +92 -0
  21. package/dist/scss/light.scss +43 -0
  22. package/dist/scss/mixins.scss +342 -0
  23. package/package.json +28 -21
  24. package/.eslintrc.cjs +0 -85
  25. package/.turbo/turbo-build.log +0 -7036
  26. package/.turbo/turbo-test.log +0 -14
  27. package/CHANGELOG.md +0 -25
  28. package/CONTRIBUTING.md +0 -41
  29. package/dist/css/brand-light.css +0 -9
  30. package/dist/css/calcite-dark.css +0 -504
  31. package/dist/css/calcite-headless.css +0 -2615
  32. package/dist/css/calcite-light.css +0 -507
  33. package/dist/es6/brand-light.d.ts +0 -7
  34. package/dist/es6/brand-light.js +0 -7
  35. package/dist/es6/calcite-dark.d.ts +0 -502
  36. package/dist/es6/calcite-dark.js +0 -502
  37. package/dist/es6/calcite-headless.d.ts +0 -2613
  38. package/dist/es6/calcite-headless.js +0 -2613
  39. package/dist/es6/calcite-light.d.ts +0 -505
  40. package/dist/es6/calcite-light.js +0 -505
  41. package/dist/js/brand-light.d.ts +0 -72
  42. package/dist/js/brand-light.js +0 -95
  43. package/dist/js/calcite-dark.d.ts +0 -563
  44. package/dist/js/calcite-dark.js +0 -10024
  45. package/dist/js/calcite-headless.d.ts +0 -1730
  46. package/dist/js/calcite-headless.js +0 -50082
  47. package/dist/js/calcite-light.d.ts +0 -544
  48. package/dist/js/calcite-light.js +0 -10090
  49. package/dist/scss/calcite-dark.scss +0 -535
  50. package/dist/scss/calcite-headless.scss +0 -3012
  51. package/dist/scss/calcite-light.scss +0 -538
  52. package/jest.config.json +0 -16
  53. package/src/$metadata.json +0 -76
  54. package/src/$themes.json +0 -2363
  55. package/src/brand/dark.json +0 -1
  56. package/src/brand/global.json +0 -1
  57. package/src/brand/light.json +0 -20
  58. package/src/calcite/dark.json +0 -2488
  59. package/src/calcite/light.json +0 -2508
  60. package/src/component/accordion-item.json +0 -172
  61. package/src/component/accordion.json +0 -192
  62. package/src/component/action-bar-grid.json +0 -66
  63. package/src/component/action-bar.json +0 -66
  64. package/src/component/action-pad-grid.json +0 -80
  65. package/src/component/action-pad.json +0 -80
  66. package/src/component/action.json +0 -156
  67. package/src/component/alert.json +0 -258
  68. package/src/component/avatar.json +0 -140
  69. package/src/component/block-section.json +0 -124
  70. package/src/component/block.json +0 -198
  71. package/src/component/button.json +0 -650
  72. package/src/component/card.json +0 -116
  73. package/src/component/checkbox.json +0 -110
  74. package/src/component/chip.json +0 -382
  75. package/src/component/color-picker.json +0 -148
  76. package/src/component/combobox.json +0 -152
  77. package/src/component/date-picker.json +0 -354
  78. package/src/component/dropdown-item.json +0 -384
  79. package/src/component/dropdown.json +0 -58
  80. package/src/component/fab.json +0 -490
  81. package/src/component/filter.json +0 -174
  82. package/src/component/icon.json +0 -18
  83. package/src/component/input-date-picker.json +0 -224
  84. package/src/component/input-datetime-local.json +0 -230
  85. package/src/component/input-email.json +0 -244
  86. package/src/component/input-file.json +0 -244
  87. package/src/component/input-message.json +0 -72
  88. package/src/component/input-month.json +0 -244
  89. package/src/component/input-number.json +0 -244
  90. package/src/component/input-password.json +0 -244
  91. package/src/component/input-search.json +0 -244
  92. package/src/component/input-telephone.json +0 -244
  93. package/src/component/input-text.json +0 -244
  94. package/src/component/input-time.json +0 -1
  95. package/src/component/input-week.json +0 -244
  96. package/src/component/label.json +0 -26
  97. package/src/component/link.json +0 -44
  98. package/src/component/loader.json +0 -130
  99. package/src/component/modal.json +0 -278
  100. package/src/component/notice.json +0 -280
  101. package/src/component/pagination.json +0 -152
  102. package/src/component/panel-header.json +0 -88
  103. package/src/component/popover.json +0 -170
  104. package/src/component/radio.json +0 -124
  105. package/src/component/rating.json +0 -243
  106. package/src/component/scrim.json +0 -18
  107. package/src/component/segmented-control.json +0 -154
  108. package/src/component/slider-histogram-range.json +0 -284
  109. package/src/component/slider-histogram.json +0 -280
  110. package/src/component/slider-range.json +0 -226
  111. package/src/component/slider.json +0 -226
  112. package/src/component/split-button.json +0 -830
  113. package/src/component/stepper-item.json +0 -372
  114. package/src/component/stepper.json +0 -152
  115. package/src/component/switch.json +0 -178
  116. package/src/component/tab-title.json +0 -228
  117. package/src/component/tabs.json +0 -242
  118. package/src/component/textarea.json +0 -200
  119. package/src/component/time-picker.json +0 -138
  120. package/src/component/tip-manager.json +0 -118
  121. package/src/component/tip.json +0 -114
  122. package/src/component/tooltip.json +0 -66
  123. package/src/component/tree-item.json +0 -176
  124. package/src/core.json +0 -1833
  125. package/src/semantic.json +0 -1709
  126. package/support/run.ts +0 -16
  127. package/support/token-transformer/format/javascript.ts +0 -22
  128. package/support/token-transformer/format/scss.ts +0 -81
  129. package/support/token-transformer/getThemes.ts +0 -41
  130. package/support/token-transformer/parse/expandComposites.test.ts +0 -144
  131. package/support/token-transformer/parse/expandComposites.ts +0 -72
  132. package/support/token-transformer/sd-run.ts +0 -191
  133. package/support/token-transformer/transform/nameCamelCase.test.ts +0 -36
  134. package/support/token-transformer/transform/nameCamelCase.ts +0 -15
  135. package/support/token-transformer/transform/nameKebabCase.test.ts +0 -36
  136. package/support/token-transformer/transform/nameKebabCase.ts +0 -26
  137. package/support/token-transformer/utils/compositeTokens.test.ts +0 -133
  138. package/support/token-transformer/utils/compositeTokens.ts +0 -103
  139. package/support/token-transformer/utils/convertTokenToStyleDictionaryFormat.ts +0 -20
  140. package/support/token-transformer/utils/matchList.ts +0 -11
  141. package/support/token-transformer/utils/parseName.ts +0 -18
  142. package/support/token-transformer/utils/parseTokenPath.ts +0 -19
  143. package/support/token-transformer/utils/regex.ts +0 -9
  144. package/support/token-transformer/utils/sortAllTokens.ts +0 -12
  145. package/support/token-transformer/utils/transformOptions.ts +0 -31
  146. package/tsconfig-base.json +0 -17
  147. package/tsconfig-eslint.json +0 -4
  148. package/tsconfig.json +0 -4
package/support/run.ts DELETED
@@ -1,16 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import { resolve, dirname } from "path";
3
- import { fileURLToPath } from "url";
4
- import { getThemes } from "./token-transformer/getThemes.js";
5
- import { run } from "./token-transformer/sd-run.js";
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
-
10
- /**
11
- * Get all themes defined int the tokens/$themes.json and generate a Style Dictionary output for each theme
12
- */
13
- const rawData = readFileSync(resolve(__dirname, "../src/$themes.json"), { encoding: "utf-8" });
14
- const data = JSON.parse(rawData);
15
-
16
- getThemes(data).then((themes) => Promise.all(themes.map((theme) => run("src", "dist", theme))));
@@ -1,22 +0,0 @@
1
- import StyleDictionary, { Dictionary, File } from "style-dictionary";
2
- import { default as JsonToTS } from "json-to-ts";
3
-
4
- type FormatOptions = { dictionary: Dictionary; file: File };
5
-
6
- export function formatJs({ dictionary, file }: FormatOptions): string {
7
- return (
8
- StyleDictionary.formatHelpers.fileHeader({ file }) +
9
- "export default" +
10
- JSON.stringify(dictionary.tokens, null, 2) +
11
- ";\n"
12
- );
13
- }
14
-
15
- export function formatTs({ dictionary, file }: FormatOptions): string {
16
- return (
17
- StyleDictionary.formatHelpers.fileHeader({ file }) +
18
- "declare const root: RootObject\n" +
19
- "export default root\n" +
20
- JsonToTS(dictionary.properties).join("\n")
21
- );
22
- }
@@ -1,81 +0,0 @@
1
- import { pascalCase, sentenceCase } from "change-case";
2
- import StyleDictionary, { Dictionary, File, Platform, Options } from "style-dictionary";
3
- import { sortAllTokens } from "../utils/sortAllTokens.js";
4
-
5
- const regexThemeGroup = /calcite|brand/gi;
6
- const regexFileNameWithoutExtension = /\w+(?=\.\w+$)/gi;
7
-
8
- /**
9
- * Exports SCSS style formats
10
- *
11
- * @param {object} fileInfo the file object
12
- * @param {Dictionary} fileInfo.dictionary the Style Dictionary object
13
- * @param {File} fileInfo.file information about the file to be generated
14
- * @param {Platform} [fileInfo.platform] the platform to generate the asset for
15
- * @param {Options} fileInfo.options the Style Dictionary format options passed from the config
16
- * @returns {string} a string that is passed to fs.writeFileSync
17
- */
18
- export function formatSCSS(fileInfo: {
19
- dictionary: Dictionary;
20
- file: File;
21
- platform?: Platform;
22
- options: Options & { themeable?: boolean };
23
- }): string {
24
- const { dictionary, file, options } = fileInfo;
25
- const { outputReferences } = options;
26
- const themeName = pascalCase(
27
- sentenceCase(file.destination.match(regexFileNameWithoutExtension)[0])
28
- .split(" ")
29
- .filter((n) => !regexThemeGroup.test(n))
30
- .join(" ")
31
- ).toLowerCase();
32
- const sassProps = StyleDictionary.formatHelpers.createPropertyFormatter({
33
- outputReferences,
34
- dictionary,
35
- format: "sass",
36
- });
37
- const cssProps = StyleDictionary.formatHelpers.createPropertyFormatter({
38
- outputReferences,
39
- dictionary,
40
- format: "css",
41
- });
42
- const sortedTokens = sortAllTokens(dictionary, outputReferences);
43
- const coreTokens = [...sortedTokens].reduce(
44
- (acc, token) => {
45
- token.value = token.value.includes(" ") ? `"${token.value}"` : token.value === "Demi" ? 600 : token.value;
46
- acc[1].push(cssProps(token));
47
-
48
- if (token.filePath.includes("core")) {
49
- const sassToken = { ...token };
50
- const path = sassToken.path.filter((p) => !/(core|default|font$)/.test(p));
51
- sassToken.name = sassToken.type === "color" ? path.slice(-1).join("-") : path.join("-");
52
- sassToken.original.value = sassToken.original.value[0] === "{" ? sassToken.value : sassToken.original.value;
53
- acc[0].push(sassProps(sassToken));
54
- }
55
-
56
- if (/dark|light/.test(token.filePath) && !token.path.includes("component")) {
57
- const sassToken = { ...token };
58
- const path = sassToken.path.reduce((acc, p) => {
59
- if (p === "default") {
60
- return acc;
61
- }
62
- acc.push(p === "color" ? "ui" : p);
63
- return acc;
64
- }, []);
65
- path.push(token.filePath.includes("dark") ? "dark" : "light");
66
- sassToken.name = path.join("-");
67
- acc[0].push(sassProps(sassToken));
68
- }
69
-
70
- return acc;
71
- },
72
- [[], []]
73
- );
74
-
75
- return `${StyleDictionary.formatHelpers.fileHeader({ file })}
76
- ${coreTokens[0].join("\n")}
77
-
78
- @mixin calcite-theme-${themeName}() {
79
- ${coreTokens[1].join("\n")}
80
- }`;
81
- }
@@ -1,41 +0,0 @@
1
- import { Options } from "style-dictionary";
2
-
3
- export interface ThemeFileInterface {
4
- id: string;
5
- name: string;
6
- selectedTokenSets: Record<string, "enabled" | "disabled" | "source">;
7
- $figmaStyleReferences?: Record<string, string>;
8
- }
9
-
10
- export type Theme = {
11
- name: string;
12
- enabled: string[];
13
- disabled: string[];
14
- source: string[];
15
- id?: string;
16
- options?: Options;
17
- };
18
-
19
- /**
20
- *
21
- * @param {ThemeFileInterface} themes an array of Figma Token Studio theme definition objects
22
- * @returns {Array} an array of Style Dictionary theme definition objects
23
- */
24
- export async function getThemes(themes: ThemeFileInterface[]): Promise<Theme[]> {
25
- return themes.map((themeConfig) => {
26
- const themeTypes = { enabled: [], disabled: [], source: [] };
27
- const { name, id, selectedTokenSets } = themeConfig;
28
- const { enabled, disabled, source } = Object.entries(selectedTokenSets).reduce((acc, [key, value]) => {
29
- acc[value].push(key);
30
- return acc;
31
- }, themeTypes);
32
-
33
- return {
34
- name,
35
- id,
36
- enabled,
37
- disabled,
38
- source,
39
- };
40
- });
41
- }
@@ -1,144 +0,0 @@
1
- const mockCorrectTypeCompoundToken = {
2
- core: {
3
- 1: {
4
- type: "sizing",
5
- value: "10",
6
- },
7
- },
8
- compound: {
9
- value: {
10
- fontFamily: "$core.font.font-family.primary",
11
- fontWeight: "$core.font.font-weight.light",
12
- lineHeight: "$core.font.line-height.fixed.0",
13
- fontSize: "$core.font.font-size.0",
14
- letterSpacing: "$core.font.letter-spacing.normal",
15
- paragraphSpacing: "$core.font.paragraph-spacing.normal",
16
- textDecoration: "$core.font.text-decoration.none",
17
- textCase: "$core.font.text-case.none",
18
- },
19
- type: "typography",
20
- },
21
- };
22
- const mockTransformedCompoundTokens = {
23
- core: {
24
- 1: {
25
- type: "sizing",
26
- value: "10",
27
- },
28
- },
29
- compound: {
30
- "font-family": {
31
- value: "$core.font.font-family.primary",
32
- type: "font-family",
33
- },
34
- "font-weight": {
35
- value: "$core.font.font-weight.light",
36
- type: "font-weights",
37
- },
38
- "line-height": {
39
- value: "$core.font.line-height.fixed.0",
40
- type: "line-heights",
41
- },
42
- "font-size": {
43
- value: "$core.font.font-size.0",
44
- type: "font-size",
45
- },
46
- "letter-spacing": {
47
- value: "$core.font.letter-spacing.normal",
48
- type: "letter-spacing",
49
- },
50
- "paragraph-spacing": {
51
- value: "$core.font.paragraph-spacing.normal",
52
- type: "paragraph-spacing",
53
- },
54
- "text-decoration": {
55
- value: "$core.font.text-decoration.none",
56
- type: "font-style",
57
- },
58
- "text-case": {
59
- value: "$core.font.text-case.none",
60
- type: "text-case",
61
- },
62
- },
63
- };
64
-
65
- const handleTokenStudioVariables = jest.fn((token) => (token.includes("$") ? `{${token.replace(/\$/g, "")}}` : token));
66
- const convertTokenToStyleDictionaryFormat = jest.fn(() => handleTokenStudioVariables);
67
- const shouldExpand = jest.fn().mockReturnValue(true);
68
- const expandToken = jest.fn().mockReturnValue(mockTransformedCompoundTokens);
69
-
70
- jest.mock("../utils/compositeTokens.js", () => {
71
- const originalModule = jest.requireActual("../utils/compositeTokens.js");
72
- return {
73
- __esModule: false,
74
- ...originalModule,
75
- shouldExpand,
76
- expandToken,
77
- };
78
- });
79
-
80
- jest.mock("../utils/convertTokenToStyleDictionaryFormat.js", () => {
81
- const originalModule = jest.requireActual("../utils/convertTokenToStyleDictionaryFormat.js");
82
- return {
83
- __esModule: false,
84
- ...originalModule,
85
- convertTokenToStyleDictionaryFormat,
86
- };
87
- });
88
-
89
- import * as expandComposites from "./expandComposites";
90
-
91
- describe("expand token dictionary", () => {
92
- beforeEach(() => {
93
- jest.clearAllMocks();
94
- });
95
-
96
- it("should not add placeholder elements", () => {
97
- const placeolderToken = {
98
- "[placeholder-component]": {
99
- type: "other",
100
- value: "#333",
101
- },
102
- };
103
- const placeholderValue = {
104
- compoonent: {
105
- type: "other",
106
- value: "[placholder-value]",
107
- },
108
- };
109
-
110
- // @ts-expect-error - it's fine.
111
- const testExpandPlaceholderKey = expandComposites.expandComposites(placeolderToken, "./fakePath");
112
- // @ts-expect-error - it's fine.
113
- const testExpandPlaceholderValue = expandComposites.expandComposites(placeholderValue, "./fakePath");
114
-
115
- expect(testExpandPlaceholderKey).toMatchObject({});
116
- expect(testExpandPlaceholderValue).toMatchObject({});
117
- });
118
-
119
- it('should loop through a dictionary and run "shouldExpand" and "expandToken" on each composite token', () => {
120
- // @ts-expect-error - it's fine.
121
- const testExpandComposite = expandComposites.expandComposites(mockCorrectTypeCompoundToken, "./fakePath");
122
- expect(handleTokenStudioVariables).toHaveBeenCalledTimes(1);
123
- expect(shouldExpand).toHaveBeenCalledTimes(1);
124
- expect(expandToken).toHaveBeenCalledTimes(1);
125
- expect(testExpandComposite).toMatchObject(mockTransformedCompoundTokens);
126
- });
127
-
128
- it("should not run expand token on unrecognized types", () => {
129
- const mockDictionary = {
130
- core: {
131
- type: "customType",
132
- value: {
133
- fontFamily: "Avanir",
134
- fontSize: "12px",
135
- },
136
- },
137
- };
138
- // @ts-expect-error - it's fine this is a test
139
- const testExpandComposite = expandComposites.expandComposites(mockDictionary, "./fakePath");
140
- expect(shouldExpand).not.toHaveBeenCalled();
141
- expect(expandToken).not.toHaveBeenCalled();
142
- expect(testExpandComposite).toMatchObject(mockDictionary);
143
- });
144
- });
@@ -1,72 +0,0 @@
1
- import { DeepKeyTokenMap } from "@tokens-studio/types";
2
- import { DesignToken } from "style-dictionary/types/DesignToken.js";
3
- import {
4
- TransformOptions,
5
- ExpandablesAsStrings,
6
- Expandables,
7
- expandablesAsStringsArr,
8
- } from "../utils/transformOptions.js";
9
- import { matchPlaceholderElement, tokenStudioCustomVariableIndicator } from "../utils/regex.js";
10
- import { shouldExpand, expandToken } from "../utils/compositeTokens.js";
11
- import { convertTokenToStyleDictionaryFormat } from "../utils/convertTokenToStyleDictionaryFormat.js";
12
-
13
- /**
14
- * Figma Token Studio creates an odd type of composite token where the "value" may contain an object of "key: value" pairs rather than a sting.
15
- * Here we will lift these composite tokens up to match the Style Dictionary format.
16
- *
17
- * @param {DeepKeyTokenMap} dictionary the raw JSON object in the token files. We will assume this is a token object generated by Figma Token Studio and may require composite tokens to be expanded.
18
- * @param {string} filePath the absolute file path to the JSON token file.
19
- * @param {TransformOptions} transformOpts the options passed in from the Style Dictionary config and runner
20
- * @returns {DeepKeyTokenMap} a token object where any Figma Token Studio composite tokens now match the Style Dictionary token format
21
- */
22
- export function expandComposites(
23
- dictionary: DeepKeyTokenMap,
24
- filePath: string,
25
- transformOpts: TransformOptions = {}
26
- ): DeepKeyTokenMap {
27
- const opts = {
28
- ...transformOpts,
29
- expand: {
30
- composition: true,
31
- typography: false,
32
- border: false,
33
- shadow: false,
34
- ...transformOpts.expand,
35
- },
36
- };
37
- const returnSlice: DeepKeyTokenMap = {};
38
- const handleTokenStudioVariables = convertTokenToStyleDictionaryFormat(tokenStudioCustomVariableIndicator);
39
- const newDictionary = Object.entries(dictionary).reduce((acc, [key, token]) => {
40
- const { type } = token;
41
-
42
- if (
43
- matchPlaceholderElement.test(`${key}`) ||
44
- (typeof token.value === "string" && matchPlaceholderElement.test(`${token.value}`))
45
- ) {
46
- return acc;
47
- }
48
-
49
- if (token.value && type) {
50
- const includesType = expandablesAsStringsArr.includes(`${type}`);
51
-
52
- if (includesType) {
53
- const expandType = (type as ExpandablesAsStrings) === "boxShadow" ? "shadow" : type;
54
- const expand = shouldExpand<Expandables>(token as Expandables, opts.expand[`${expandType}`], filePath);
55
- if (expand) {
56
- const expandedToken = expandToken(token as DesignToken, expandType === "shadow", handleTokenStudioVariables);
57
- return expandedToken;
58
- }
59
- } else if (typeof token.value === "string") {
60
- token.value = handleTokenStudioVariables(token.value);
61
- acc[key] = token;
62
- } else {
63
- acc[key] = token;
64
- }
65
- } else if (typeof token === "object") {
66
- acc[key] = expandComposites(token as DeepKeyTokenMap, filePath, transformOpts);
67
- }
68
- return acc;
69
- }, returnSlice);
70
-
71
- return newDictionary || {};
72
- }
@@ -1,191 +0,0 @@
1
- import { registerTransforms } from "@tokens-studio/sd-transforms";
2
- import StyleDictionary from "style-dictionary";
3
- import { expandComposites } from "./parse/expandComposites.js";
4
- import { formatSCSS } from "./format/scss.js";
5
- import { matchExclusions } from "./utils/regex.js";
6
- import { matchList } from "./utils/matchList.js";
7
- import { nameCamelCase } from "./transform/nameCamelCase.js";
8
- import { nameKebabCase } from "./transform/nameKebabCase.js";
9
- import { parseName } from "./utils/parseName.js";
10
- import { Theme } from "./getThemes.js";
11
- import { formatJs, formatTs } from "./format/javascript.js";
12
-
13
- /**
14
- * Style Dictionary runner configuration overrides.
15
- *
16
- * @param {string} tokenDir the directory containing design token files
17
- * @param {string} buildPath the directory to write generated assets to
18
- * @param {Theme} theme the theme configuration to use to generate the platform asset files
19
- * @param {string} theme.name the name of the theme. This will be used as the basis for the generated asset file names.
20
- * @param {string[]} theme.enabled an array of partial file names matching the token files which should be included in the output
21
- * @param {string[]} theme.disabled an array of partial file names matching the token files which should explicitly not be included in the output
22
- * @param {string[]} theme.source an array of partial file names matching the token files which should not always be included in the output but who's values should be used for variables references in the "enabled" files
23
- */
24
- export const run = async (
25
- tokenDir = "tokens",
26
- buildPath = "dist",
27
- theme: Pick<Theme, "enabled" | "disabled" | "name" | "source">
28
- ): Promise<void> => {
29
- const fileName = parseName(theme.name);
30
- const include = theme.source.map((tokenFile) => `${tokenDir}/${tokenFile}.json`);
31
- const source = theme.enabled.map((tokenFile) => `${tokenDir}/${tokenFile}.json`);
32
- const options = {
33
- enabled: theme.enabled,
34
- source: theme.source,
35
- disabled: theme.disabled,
36
- outputReferences: false,
37
- sourceReferencesOnly: false,
38
- };
39
-
40
- // Here we are registering the Transforms provided by Token Studio
41
- // https://github.com/tokens-studio/sd-transforms
42
- // @ts-expect-error - @token-studio does not keep their types up to date.
43
- await registerTransforms(StyleDictionary, {
44
- expand: false,
45
- });
46
-
47
- // Register custom formatter https://amzn.github.io/style-dictionary/#/formats?id=custom-formats
48
- StyleDictionary.registerFormat({
49
- name: "calcite/scss",
50
- formatter: formatSCSS,
51
- });
52
-
53
- StyleDictionary.registerFormat({
54
- name: "calcite/js-module",
55
- formatter: formatJs,
56
- });
57
-
58
- StyleDictionary.registerFormat({
59
- name: "calcite/ts-module",
60
- formatter: formatTs,
61
- });
62
-
63
- // Registering Style Dictionary transformers https://amzn.github.io/style-dictionary/#/transforms?id=defining-custom-transforms
64
- StyleDictionary.registerTransform({
65
- name: "name/calcite/camel",
66
- type: "name",
67
- transformer: nameCamelCase,
68
- });
69
-
70
- StyleDictionary.registerTransform({
71
- name: "name/calcite/kebab",
72
- type: "name",
73
- transformer: nameKebabCase,
74
- });
75
-
76
- StyleDictionary.registerFilter({
77
- name: "filterSource",
78
- matcher: (token) => token.isSource,
79
- });
80
-
81
- // We are programmatically creating the Style Dictionary configuration here
82
- // https://amzn.github.io/style-dictionary/#/config
83
- const sd = StyleDictionary.extend({
84
- source,
85
- include,
86
- platforms: {
87
- js: {
88
- buildPath: `${buildPath}/js/`,
89
- files: [
90
- {
91
- destination: `${fileName}.js`,
92
- format: "calcite/js-module",
93
- filter: "filterSource",
94
- },
95
- {
96
- destination: `${fileName}.d.ts`,
97
- format: "calcite/ts-module",
98
- filter: "filterSource",
99
- },
100
- ],
101
- },
102
- es6: {
103
- transformGroup: "js",
104
- buildPath: `${buildPath}/es6/`,
105
- files: [
106
- {
107
- format: "javascript/es6",
108
- destination: `${fileName}.js`,
109
- filter: "filterSource",
110
- options: { ...options, outputReferences: true },
111
- },
112
- {
113
- format: "typescript/es6-declarations",
114
- destination: `${fileName}.d.ts`,
115
- filter: "filterSource",
116
- options: { ...options, outputReferences: true },
117
- },
118
- ],
119
- },
120
- css: {
121
- prefix: "calcite",
122
- transforms: [
123
- "ts/descriptionToComment",
124
- "ts/size/px",
125
- "ts/opacity",
126
- "ts/size/lineheight",
127
- "ts/type/fontWeight",
128
- "ts/resolveMath",
129
- "ts/size/css/letterspacing",
130
- "ts/color/css/hexrgba",
131
- "ts/color/modifiers",
132
- "name/calcite/kebab",
133
- ],
134
- buildPath: `${buildPath}/css/`,
135
- files: [
136
- {
137
- destination: `${fileName}.css`,
138
- format: "css/variables",
139
- filter: /headless/gi.test(fileName) ? null : "filterSource",
140
- options: /headless/gi.test(fileName) ? { ...options, outputReferences: true } : options,
141
- },
142
- ],
143
- },
144
- scss: {
145
- prefix: "calcite",
146
- transforms: [
147
- "ts/descriptionToComment",
148
- "ts/size/px",
149
- "ts/opacity",
150
- "ts/size/lineheight",
151
- "ts/type/fontWeight",
152
- "ts/resolveMath",
153
- "ts/size/css/letterspacing",
154
- "ts/color/css/hexrgba",
155
- "ts/color/modifiers",
156
- "name/calcite/kebab",
157
- ],
158
- buildPath: `${buildPath}/scss/`,
159
- files: [
160
- {
161
- destination: `${fileName}.scss`,
162
- format: "calcite/scss",
163
- filter: /headless/gi.test(fileName) ? null : "filterSource",
164
- options: /headless/gi.test(fileName) ? { ...options, outputReferences: true } : options,
165
- },
166
- ],
167
- },
168
- },
169
- parsers: [
170
- {
171
- pattern: /\.json$/,
172
- parse: (file) => {
173
- if (matchList(file.filePath, [...include, ...theme.source, ...theme.enabled], matchExclusions)) {
174
- const obj = JSON.parse(file.contents);
175
- const expanded = expandComposites(obj, file.filePath);
176
- return expanded;
177
- }
178
-
179
- return {};
180
- },
181
- },
182
- ],
183
- });
184
-
185
- try {
186
- sd.cleanAllPlatforms();
187
- sd.buildAllPlatforms();
188
- } catch (error) {
189
- console.error(error);
190
- }
191
- };
@@ -1,36 +0,0 @@
1
- import { nameCamelCase } from "./nameCamelCase";
2
-
3
- describe("transform names to camel case", () => {
4
- it("should transform a token path to token name in a camel case format", () => {
5
- const mockToken = {
6
- name: "current-name",
7
- path: ["test", "token", "name"],
8
- value: "fake-value",
9
- filePath: "./fakePath.json",
10
- original: {
11
- value: "fake-value",
12
- type: "composite",
13
- },
14
- isSource: true,
15
- };
16
- expect(nameCamelCase(mockToken, {})).toBe("testTokenName");
17
- });
18
-
19
- it("should add prefix to token name", () => {
20
- const mockToken = {
21
- name: "current-name",
22
- path: ["test", "token", "name"],
23
- value: "fake-value",
24
- filePath: "./fakePath.json",
25
- original: {
26
- value: "fake-value",
27
- type: "composite",
28
- },
29
- isSource: true,
30
- };
31
- const mockOptions = {
32
- prefix: "calcite",
33
- };
34
- expect(nameCamelCase(mockToken, mockOptions)).toBe("calciteTestTokenName");
35
- });
36
- });
@@ -1,15 +0,0 @@
1
- import { camelCase } from "change-case";
2
- import { TransformedToken } from "style-dictionary/types/TransformedToken.js";
3
- import { Options } from "style-dictionary/types/Options.js";
4
- import { parseTokenPath } from "../utils/parseTokenPath.js";
5
-
6
- /**
7
- * Convert token name to camel case
8
- *
9
- * @param {TransformedToken} token Style Dictionary token object
10
- * @param {Options} options Style Dictionary format options
11
- * @returns {string} an updated name for the token which will be used for the final output
12
- */
13
- export function nameCamelCase(token: TransformedToken, options: Options): string {
14
- return camelCase([options.prefix].concat(parseTokenPath(token.path)).join(" "));
15
- }
@@ -1,36 +0,0 @@
1
- import { nameKebabCase } from "./nameKebabCase";
2
-
3
- describe("transform names to kebab case", () => {
4
- it("should transform a token path to token name in a kebab case format", () => {
5
- const mockToken = {
6
- name: "current-name",
7
- path: ["test", "token", "name"],
8
- value: "fake-value",
9
- filePath: "./fakePath.json",
10
- original: {
11
- value: "fake-value",
12
- type: "composite",
13
- },
14
- isSource: true,
15
- };
16
- expect(nameKebabCase(mockToken, {})).toBe("test-token-name");
17
- });
18
-
19
- it("should add prefix to token name", () => {
20
- const mockToken = {
21
- name: "current-name",
22
- path: ["test", "token", "name"],
23
- value: "fake-value",
24
- filePath: "./fakePath.json",
25
- original: {
26
- value: "fake-value",
27
- type: "composite",
28
- },
29
- isSource: true,
30
- };
31
- const mockOptions = {
32
- prefix: "calcite",
33
- };
34
- expect(nameKebabCase(mockToken, mockOptions)).toBe("calcite-test-token-name");
35
- });
36
- });
@@ -1,26 +0,0 @@
1
- import { paramCase } from "change-case";
2
- import { TransformedToken } from "style-dictionary/types/TransformedToken.js";
3
- import { Options } from "style-dictionary/types/Options.js";
4
- import { parseTokenPath } from "../utils/parseTokenPath.js";
5
-
6
- /**
7
- * convert token name to kebab case
8
- *
9
- * @param {TransformedToken} token Style Dictionary token object
10
- * @param {Options} options Style Dictionary format options
11
- * @returns {string} an updated name for the token which will be used for the final output
12
- */
13
- export function nameKebabCase(token: TransformedToken, options: Options): string {
14
- const paths = token.path.reduce((acc, p, idx) => {
15
- if (p === "core") {
16
- acc.push("app");
17
- } else if (typeof token.path[idx + 1] === "string" && !new RegExp(`${p}`).test(token.path[idx + 1])) {
18
- acc.push(p);
19
- } else if (idx === token.path.length - 1) {
20
- acc.push(p);
21
- }
22
- return acc;
23
- }, []);
24
-
25
- return paramCase([options.prefix].concat(parseTokenPath(paths)).join(" "));
26
- }