11let variablesPrefix ; // Variable that holds the prefix used on all css and scss variables generated
2+ let classPrefix ; // Variable that holds the prefix used on all css utility-classes generated
23
34// Set the variable prefix value
4- export function setPrefixValue ( prefix ) {
5+ export function setVariablePrefixValue ( prefix ) {
56 variablesPrefix = prefix ;
67 return variablesPrefix ;
78}
89
10+ export function setClassesPrefixValue ( prefix ) {
11+ classPrefix = prefix ;
12+ return classPrefix ;
13+ }
14+
915// Generates a valid rgba() color
1016export function getRgbaValue ( propValue ) {
1117 // Check if its rgba color
@@ -117,6 +123,7 @@ export function generateValue(prop, propName) {
117123// Generates a typography based css utility-class or scss variable from a typography token structure
118124export function generateTypographyOutput ( prop , propName , isVariable ) {
119125 const typography = prop . original . $value ;
126+ const outerPrefix = isVariable ? variablesPrefix : classPrefix ;
120127
121128 // Extract the part after the last dot and trim any extraneous characters
122129 const extractLastPart = ( str ) => str . split ( '.' ) . pop ( ) . replace ( / [ ^ \w - ] / g, '' ) ;
@@ -128,7 +135,7 @@ export function generateTypographyOutput(prop, propName, isVariable) {
128135
129136 // This exact format is needed so that it compiles the tokens with the expected lint rules
130137 return `
131- ${ _prefix } ${ variablesPrefix } -${ propName } ${ _initialWrapper }
138+ ${ _prefix } ${ outerPrefix } -${ propName } ${ _initialWrapper }
132139 font-size: $${ variablesPrefix } -font-size-${ extractLastPart ( typography . fontSize ) } ${ _endChar }
133140 font-style: ${ prop . attributes . item ?. toLowerCase ( ) === 'italic' ? 'italic' : 'normal' } ${ _endChar }
134141 font-weight: $${ variablesPrefix } -font-weight-${ extractLastPart ( typography . fontWeight ) } ${ _endChar }
@@ -144,7 +151,7 @@ export function generateTypographyOutput(prop, propName, isVariable) {
144151export function generateColorUtilityClasses ( prop , className ) {
145152 const isBg = className . includes ( 'bg' ) ;
146153 const cssProp = isBg ? 'background-color' : 'color' ;
147- return `.${ variablesPrefix } -${ className } {
154+ return `.${ classPrefix } -${ className } {
148155 --${ cssProp } : $${ variablesPrefix } -${ prop . name } ;
149156 ${ cssProp } : $${ variablesPrefix } -${ prop . name } ;
150157}` ;
@@ -157,7 +164,7 @@ export function generateDefaultSpaceUtilityClasses() {
157164 const defaultMarginPaddingToken = 'space-400' ;
158165
159166 const marginPaddingTemplate = ( type ) => `
160- .${ variablesPrefix } -no-${ type } {
167+ .${ classPrefix } -no-${ type } {
161168 --${ type } -top: #{$${ variablesPrefix } -${ zeroMarginPaddingToken } };
162169 --${ type } -end: #{$${ variablesPrefix } -${ zeroMarginPaddingToken } };
163170 --${ type } -bottom: #{$${ variablesPrefix } -${ zeroMarginPaddingToken } };
@@ -166,7 +173,7 @@ export function generateDefaultSpaceUtilityClasses() {
166173 @include ${ type } ($${ variablesPrefix } -${ zeroMarginPaddingToken } );
167174};
168175
169- .${ variablesPrefix } -${ type } {
176+ .${ classPrefix } -${ type } {
170177 --${ type } -top: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
171178 --${ type } -end: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
172179 --${ type } -bottom: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
@@ -175,38 +182,38 @@ export function generateDefaultSpaceUtilityClasses() {
175182 @include ${ type } ($${ variablesPrefix } -${ defaultMarginPaddingToken } );
176183};
177184
178- .${ variablesPrefix } -${ type } -top {
185+ .${ classPrefix } -${ type } -top {
179186 --${ type } -top: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
180187
181188 @include ${ type } ($${ variablesPrefix } -${ defaultMarginPaddingToken } , null, null, null);
182189};
183190
184- .${ variablesPrefix } -${ type } -end {
191+ .${ classPrefix } -${ type } -end {
185192 --${ type } -end: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
186193
187194 @include ${ type } (null, $${ variablesPrefix } -${ defaultMarginPaddingToken } , null, null);
188195};
189196
190- .${ variablesPrefix } -${ type } -bottom {
197+ .${ classPrefix } -${ type } -bottom {
191198 --${ type } -bottom: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
192199
193200 @include ${ type } (null, null, $${ variablesPrefix } -${ defaultMarginPaddingToken } , null);
194201};
195202
196- .${ variablesPrefix } -${ type } -start {
203+ .${ classPrefix } -${ type } -start {
197204 --${ type } -start: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
198205
199206 @include ${ type } (null, null, null, $${ variablesPrefix } -${ defaultMarginPaddingToken } );
200207};
201208
202- .${ variablesPrefix } -${ type } -vertical {
209+ .${ classPrefix } -${ type } -vertical {
203210 --${ type } -top: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
204211 --${ type } -bottom: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
205212
206213 @include ${ type } ($${ variablesPrefix } -${ defaultMarginPaddingToken } , null, $${ variablesPrefix } -${ defaultMarginPaddingToken } , null);
207214};
208215
209- .${ variablesPrefix } -${ type } -horizontal {
216+ .${ classPrefix } -${ type } -horizontal {
210217 --${ type } -start: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
211218 --${ type } -end: #{$${ variablesPrefix } -${ defaultMarginPaddingToken } };
212219
@@ -222,7 +229,7 @@ export function generateSpaceUtilityClasses(prop, className) {
222229 // This exact format is needed so that it compiles the tokens with the expected lint rules
223230 // It will generate classes for margin and padding, for equal sizing on all side and each direction
224231 const marginPaddingTemplate = ( type ) => `
225- .${ variablesPrefix } -${ type } -${ className } {
232+ .${ classPrefix } -${ type } -${ className } {
226233 --${ type } -top: #{$${ variablesPrefix } -${ prop . name } };
227234 --${ type } -end: #{$${ variablesPrefix } -${ prop . name } };
228235 --${ type } -bottom: #{$${ variablesPrefix } -${ prop . name } };
@@ -231,25 +238,25 @@ export function generateSpaceUtilityClasses(prop, className) {
231238 @include ${ type } ($${ variablesPrefix } -${ prop . name } );
232239};
233240
234- .${ variablesPrefix } -${ type } -top-${ className } {
241+ .${ classPrefix } -${ type } -top-${ className } {
235242 --${ type } -top: #{$${ variablesPrefix } -${ prop . name } };
236243
237244 @include ${ type } ($${ variablesPrefix } -${ prop . name } , null, null, null);
238245};
239246
240- .${ variablesPrefix } -${ type } -end-${ className } {
247+ .${ classPrefix } -${ type } -end-${ className } {
241248 --${ type } -end: #{$${ variablesPrefix } -${ prop . name } };
242249
243250 @include ${ type } (null, $${ variablesPrefix } -${ prop . name } , null, null);
244251};
245252
246- .${ variablesPrefix } -${ type } -bottom-${ className } {
253+ .${ classPrefix } -${ type } -bottom-${ className } {
247254 --${ type } -bottom: #{$${ variablesPrefix } -${ prop . name } };
248255
249256 @include ${ type } (null, null, $${ variablesPrefix } -${ prop . name } , null);
250257};
251258
252- .${ variablesPrefix } -${ type } -start-${ className } {
259+ .${ classPrefix } -${ type } -start-${ className } {
253260 --${ type } -start: #{$${ variablesPrefix } -${ prop . name } };
254261
255262 @include ${ type } (null, null, null, $${ variablesPrefix } -${ prop . name } );
@@ -258,7 +265,7 @@ export function generateSpaceUtilityClasses(prop, className) {
258265
259266 // Add gap utility classes for gap tokens
260267 const generateGapUtilityClasses = ( ) => `
261- .${ variablesPrefix } -gap-${ prop . name } {
268+ .${ classPrefix } -gap-${ prop . name } {
262269 gap: #{$${ variablesPrefix } -${ prop . name } };
263270};
264271` ;
@@ -268,7 +275,7 @@ export function generateSpaceUtilityClasses(prop, className) {
268275
269276// Generates a valid box-shadow value from a shadow Design Token structure
270277export function generateRadiusUtilityClasses ( propName ) {
271- return `.${ variablesPrefix } -${ propName } {
278+ return `.${ classPrefix } -${ propName } {
272279 --border-radius: $${ variablesPrefix } -${ propName } ;
273280 border-radius: $${ variablesPrefix } -${ propName } ;
274281}` ;
@@ -289,26 +296,26 @@ export function generateBorderUtilityClasses(prop, propName) {
289296 default :
290297 attribute = 'border-color' ;
291298 }
292- return `.${ variablesPrefix } -${ propName } {
299+ return `.${ classPrefix } -${ propName } {
293300 --${ attribute } : $${ variablesPrefix } -${ propName } ;
294301 ${ attribute } : $${ variablesPrefix } -${ propName } ;
295302}` ;
296303}
297304
298305// Generates a font based css utility-class from a font Design Token structure
299306export function generateFontUtilityClasses ( prop , propName ) {
300- return `.${ variablesPrefix } -${ propName } {\n ${ prop . attributes . type } : $${ variablesPrefix } -${ propName } ;\n}` ;
307+ return `.${ classPrefix } -${ propName } {\n ${ prop . attributes . type } : $${ variablesPrefix } -${ propName } ;\n}` ;
301308}
302309
303310// Generates a valid box-shadow value from a shadow Design Token structure
304311export function generateShadowUtilityClasses ( propName ) {
305- return `.${ variablesPrefix } -${ propName } {
312+ return `.${ classPrefix } -${ propName } {
306313 --box-shadow: $${ variablesPrefix } -${ propName } ;
307314 box-shadow: $${ variablesPrefix } -${ propName } ;
308315}` ;
309316}
310317
311318// Generates a utility class for a given token category and name
312319export function generateUtilityClasses ( tokenCategory , propName ) {
313- return `.${ variablesPrefix } -${ propName } {\n ${ tokenCategory } : $${ variablesPrefix } -${ propName } ;\n}` ;
320+ return `.${ classPrefix } -${ propName } {\n ${ tokenCategory } : $${ variablesPrefix } -${ propName } ;\n}` ;
314321}
0 commit comments