Skip to content

fix(tokens): review the generation of utility-classes #30498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 24, 2025
23 changes: 18 additions & 5 deletions core/scripts/tokens/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@ function generateTypographyOutput(prop, propName, isVariable) {

// Generates a color based css utility-class from a color Design Token structure
function generateColorUtilityClasses(prop, className) {
return `.${variablesPrefix}-${className} {\n color: $${variablesPrefix}-${prop.name};\n}
.${variablesPrefix}-background-${className} {\n background-color: $${variablesPrefix}-${prop.name};\n}`;
const isBg = className.includes('bg');
const cssProp = isBg ? 'background-color' : 'color';
return `.${variablesPrefix}-${className} {
--${cssProp}: $${variablesPrefix}-${prop.name};
${cssProp}: $${variablesPrefix}-${prop.name};
}`;
}

// Generates margin and padding utility classes to match the token-agnostic
Expand Down Expand Up @@ -264,7 +268,10 @@ function generateSpaceUtilityClasses(prop, className) {

// Generates a valid box-shadow value from a shadow Design Token structure
function generateRadiusUtilityClasses(propName) {
return `.${variablesPrefix}-${propName} {\n border-radius: $${variablesPrefix}-${propName};\n}`;
return `.${variablesPrefix}-${propName} {
--border-radius: $${variablesPrefix}-${propName};
border-radius: $${variablesPrefix}-${propName};
}`;
}

// Generates a border based css utility-class from a font Design Token structure
Expand All @@ -282,7 +289,10 @@ function generateBorderUtilityClasses(prop, propName) {
default:
attribute = 'border-color';
}
return `.${variablesPrefix}-${propName} {\n ${attribute}: $${variablesPrefix}-${propName};\n}`;
return `.${variablesPrefix}-${propName} {
--${attribute}: $${variablesPrefix}-${propName};
${attribute}: $${variablesPrefix}-${propName};
}`;
}

// Generates a font based css utility-class from a font Design Token structure
Expand All @@ -292,7 +302,10 @@ function generateFontUtilityClasses(prop, propName) {

// Generates a valid box-shadow value from a shadow Design Token structure
function generateShadowUtilityClasses(propName) {
return `.${variablesPrefix}-${propName} {\n box-shadow: $${variablesPrefix}-${propName};\n}`;
return `.${variablesPrefix}-${propName} {
--box-shadow: $${variablesPrefix}-${propName};
box-shadow: $${variablesPrefix}-${propName};
}`;
}

// Generates a utility class for a given token category and name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
<style>
/* Background styles to show the border radius */
:root {
background: #ccc7c7;
--background: #ccc7c7;
}
</style>
<ion-accordion-group>
Expand Down Expand Up @@ -48,7 +48,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
<style>
/* Background styles to show the border radius */
:root {
background: #ccc7c7;
--background: #ccc7c7;
}
</style>
<ion-accordion-group value="first">
Expand Down Expand Up @@ -88,7 +88,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
<style>
/* Background styles to show the border radius */
:root {
background: #ccc7c7;
--background: #ccc7c7;
}
</style>
<ion-accordion-group expand="inset">
Expand Down Expand Up @@ -126,7 +126,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
<style>
/* Background styles to show the border radius */
:root {
background: #ccc7c7;
--background: #ccc7c7;
}
</style>
<ion-accordion-group value="first" expand="inset">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
<style>
/* Background styles to show the border radius */
:root {
background: #222;
--background: #222;
}
</style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
<style>
/* Background styles to show the border radius */
:root {
background: #222;
--background: #222;
}
</style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
`
<style>
:root {
background: #ccc7c7;
--background: #ccc7c7;
}

.container {
Expand All @@ -33,7 +33,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
`
<style>
:root {
background: #ccc7c7;
--background: #ccc7c7;
}

.container {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
<style>
/* Background styles to show the border radius */
:root {
background: #000;
--background: #000;
}
</style>

Expand Down
2 changes: 1 addition & 1 deletion core/src/components/tab-bar/test/basic/tab-bar.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ configs({ modes: ['ionic-md', 'md', 'ios'] }).forEach(({ title, screenshot, conf
`
<style>
:root {
background: #ccc7c7;
--background: #ccc7c7;
}
</style>

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions core/src/components/tab-bar/test/shape/tab-bar.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
`
<style>
:root {
background: #ccc7c7;
--background: #ccc7c7;
}
</style>

Expand Down Expand Up @@ -49,7 +49,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
`
<style>
:root {
background: #ccc7c7;
--background: #ccc7c7;
}
</style>

Expand Down Expand Up @@ -85,7 +85,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
`
<style>
:root {
background: #ccc7c7;
--background: #ccc7c7;
}
</style>

Expand Down
2 changes: 1 addition & 1 deletion core/src/css/ionic/core.ionic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ html {
}

body {
background: var(--ion-background-color);
background: var(--ion-background-color, #{globals.$ion-bg-body});
color: var(--ion-text-color);
}

Expand Down
Loading
Loading