Skip to content

Commit d45129b

Browse files
adds brand colors to dcs exports
1 parent d6a6cfd commit d45129b

File tree

2 files changed

+70
-13
lines changed

2 files changed

+70
-13
lines changed

src/pipeline/fluentui-dcs.ts

+61-12
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,88 @@ import * as Utils from "./utils"
33
import _ from "lodash"
44

55

6-
const constructCssName = (path: any[]): string =>
6+
const tokenOverrides = {
7+
"globalColorBrand10": "#001919",
8+
"globalColorBrand20": "#012826",
9+
"globalColorBrand30": "#01322e",
10+
"globalColorBrand40": "#033f38",
11+
"globalColorBrand50": "#054d43",
12+
"globalColorBrand60": "#0a5c50",
13+
"globalColorBrand70": "#0c695a",
14+
"globalColorBrand80": "#117865",
15+
"globalColorBrand90": "#1f937e",
16+
"globalColorBrand100": "#2aac94",
17+
"globalColorBrand110": "#3abb9f",
18+
"globalColorBrand120": "#52c7aa",
19+
"globalColorBrand130": "#78d3b9",
20+
"globalColorBrand140": "#9ee0cb",
21+
"globalColorBrand150": "#c0ecdd",
22+
"globalColorBrand160": "#e3f7ef",
23+
}
24+
25+
const constructCssName = (path: any, prop: any): string =>
726
{
8-
let newName = path[0] !== "Global" && path[3] === "Color" ? `color${Utils.pascalCase(path)}` : _.camelCase(path.join(" "))
27+
let newName = path[0] !== "Global" && prop.attributes.category === "color" ? `color${Utils.pascalCase(path)}` : _.camelCase(path.join(""))
928
newName = newName.replace("Rest", "")
10-
newName = newName.replace("set", "")
11-
newName = newName.replace("FillColor", "")
12-
newName = newName.replace("StrokeColor", "")
13-
newName = newName.replace("BorderColor", "")
14-
newName = newName.replace("globalColorHc", "globalColorhc")
29+
30+
// Check if the constructed name is in the tokenOverrides object
31+
if (tokenOverrides.hasOwnProperty(newName))
32+
{
33+
prop.value = tokenOverrides[newName]
34+
}
1535

1636
return newName
1737
}
1838

1939
StyleDictionary.registerTransform({
2040
name: "dcs/name/json",
2141
type: "name",
22-
transformer: prop => `${constructCssName(Utils.getTokenExportPath(prop))}`,
42+
transformer: prop => `${constructCssName(Utils.getTokenExportPath(prop), prop)}`,
2343
})
2444

2545
StyleDictionary.registerTransform({
2646
name: "dcs/alias/json",
2747
type: "value",
2848
matcher: prop => "resolvedAliasPath" in prop,
29-
transformer: prop => `var(--${constructCssName(prop.resolvedAliasPath)})`,
49+
transformer: prop => `var(--${constructCssName(prop.resolvedAliasPath, prop)})`,
3050
})
3151

3252
StyleDictionary.registerTransform({
3353
name: "dcs/name/css",
3454
type: "name",
35-
transformer: prop => `${constructCssName(Utils.getTokenExportPath(prop))}`,
55+
transformer: prop => `${constructCssName(Utils.getTokenExportPath(prop), prop)}`,
3656
})
3757

3858
StyleDictionary.registerTransform({
3959
name: "dcs/alias/css",
4060
type: "value",
4161
matcher: prop => "resolvedAliasPath" in prop,
42-
transformer: prop => `var(--${constructCssName(prop.resolvedAliasPath)})`,
62+
transformer: prop => `var(--${constructCssName(prop.resolvedAliasPath, prop)})`,
63+
})
64+
65+
StyleDictionary.registerTransform({
66+
name: "dcs/name/mixins",
67+
type: "name",
68+
transformer: prop => `${constructCssName(Utils.getTokenExportPath(prop), prop)}`,
69+
})
70+
71+
StyleDictionary.registerTransform({
72+
name: "dcs/alias/mixins",
73+
type: "value",
74+
matcher: prop => "resolvedAliasPath" in prop,
75+
transformer: prop => `var(--${constructCssName(prop.resolvedAliasPath, prop)})`,
4376
})
4477

4578
StyleDictionary.registerTransformGroup({
4679
name: "dcs/json",
4780
transforms: ["dcs/name/json", "time/seconds", "fluentui/size/css", "fluentui/color/css", "fluentui/strokealignment/css", "fluentui/shadow/css", "fluentui/font/css", "dcs/alias/json"],
4881
})
4982

83+
StyleDictionary.registerTransformGroup({
84+
name: "dcs/mixins",
85+
transforms: ["dcs/name/css", "time/seconds", "fluentui/size/css", "fluentui/color/css", "fluentui/strokealignment/css", "fluentui/shadow/css", "fluentui/font/css", "dcs/alias/css"],
86+
})
87+
5088
StyleDictionary.registerTransformGroup({
5189
name: "dcs/css",
5290
transforms: ["dcs/name/css", "time/seconds", "fluentui/size/css", "fluentui/color/css", "fluentui/strokealignment/css", "fluentui/shadow/css", "fluentui/font/css", "dcs/alias/css"],
@@ -62,6 +100,17 @@ StyleDictionary.registerFormat({
62100
}
63101
})
64102

103+
StyleDictionary.registerFormat({
104+
name: "fluentui/dcs/mixins",
105+
formatter: function (dictionary: { allProperties: { name: any; value: any }[] }, config: any)
106+
{
107+
return `${this.selector} {
108+
${dictionary.allProperties.map((prop: { name: any; value: any }) => ` --${prop.name}: ${prop.value};`).join("\n")}
109+
}`
110+
}
111+
})
112+
113+
65114
StyleDictionary.registerFormat({
66115
name: "fluentui/dcs/json",
67116
formatter: (dictionary: { allProperties: any[] }) =>
@@ -71,7 +120,7 @@ StyleDictionary.registerFormat({
71120
const tokens: any = {}
72121
for (const thisProp of sortedProps)
73122
{
74-
tokens[constructCssName(thisProp.path)] = thisProp.value
123+
tokens[constructCssName(thisProp.path, thisProp)] = thisProp.value
75124
}
76125

77126
return JSON.stringify(tokens, /* replacer: */ undefined, /* space: */ "\t")

src/pipeline/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export const buildOutputs = (input: string[] | string, outputPath: string, platf
4040
}
4141
}
4242
}
43-
4443
}
4544

4645

@@ -212,6 +211,15 @@ export const buildOutputs = (input: string[] | string, outputPath: string, platf
212211
{ destination: `css/fluent-${theme}.css`, format: "fluentui/dcs/css", selector: `[data-theme="fluent-${theme}"]` },
213212
],
214213
},
214+
dcsMixins:
215+
{
216+
transformGroup: "dcs/mixins",
217+
buildPath: useSubfolders ? `${outputPath}dcs/` : outputPath,
218+
files: [
219+
220+
{ destination: `scss/fluent-${theme}.scss`, format: "fluentui/dcs/mixins", selector: `@mixin install-fluent-${theme}-tokens` },
221+
],
222+
},
215223
dcsJson:
216224
{
217225
transformGroup: "dcs/json",

0 commit comments

Comments
 (0)