@@ -3,50 +3,88 @@ import * as Utils from "./utils"
3
3
import _ from "lodash"
4
4
5
5
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 =>
7
26
{
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 ( "" ) )
9
28
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
+ }
15
35
16
36
return newName
17
37
}
18
38
19
39
StyleDictionary . registerTransform ( {
20
40
name : "dcs/name/json" ,
21
41
type : "name" ,
22
- transformer : prop => `${ constructCssName ( Utils . getTokenExportPath ( prop ) ) } ` ,
42
+ transformer : prop => `${ constructCssName ( Utils . getTokenExportPath ( prop ) , prop ) } ` ,
23
43
} )
24
44
25
45
StyleDictionary . registerTransform ( {
26
46
name : "dcs/alias/json" ,
27
47
type : "value" ,
28
48
matcher : prop => "resolvedAliasPath" in prop ,
29
- transformer : prop => `var(--${ constructCssName ( prop . resolvedAliasPath ) } )` ,
49
+ transformer : prop => `var(--${ constructCssName ( prop . resolvedAliasPath , prop ) } )` ,
30
50
} )
31
51
32
52
StyleDictionary . registerTransform ( {
33
53
name : "dcs/name/css" ,
34
54
type : "name" ,
35
- transformer : prop => `${ constructCssName ( Utils . getTokenExportPath ( prop ) ) } ` ,
55
+ transformer : prop => `${ constructCssName ( Utils . getTokenExportPath ( prop ) , prop ) } ` ,
36
56
} )
37
57
38
58
StyleDictionary . registerTransform ( {
39
59
name : "dcs/alias/css" ,
40
60
type : "value" ,
41
61
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 ) } )` ,
43
76
} )
44
77
45
78
StyleDictionary . registerTransformGroup ( {
46
79
name : "dcs/json" ,
47
80
transforms : [ "dcs/name/json" , "time/seconds" , "fluentui/size/css" , "fluentui/color/css" , "fluentui/strokealignment/css" , "fluentui/shadow/css" , "fluentui/font/css" , "dcs/alias/json" ] ,
48
81
} )
49
82
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
+
50
88
StyleDictionary . registerTransformGroup ( {
51
89
name : "dcs/css" ,
52
90
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({
62
100
}
63
101
} )
64
102
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
+
65
114
StyleDictionary . registerFormat ( {
66
115
name : "fluentui/dcs/json" ,
67
116
formatter : ( dictionary : { allProperties : any [ ] } ) =>
@@ -71,7 +120,7 @@ StyleDictionary.registerFormat({
71
120
const tokens : any = { }
72
121
for ( const thisProp of sortedProps )
73
122
{
74
- tokens [ constructCssName ( thisProp . path ) ] = thisProp . value
123
+ tokens [ constructCssName ( thisProp . path , thisProp ) ] = thisProp . value
75
124
}
76
125
77
126
return JSON . stringify ( tokens , /* replacer: */ undefined , /* space: */ "\t" )
0 commit comments