Skip to content

Commit 33dcf98

Browse files
BenOsodracIonitron
andauthored
fix(tokens): review the generation of utility-classes (#30498)
Issue number: internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Currently some utility-classes are not as effective as they could be, because they don't affect, for example, the --background or --color css API's. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Changed the way the classes are generated, so that it affects the css custom properties as well. - Make the background classes to only be generated for the tokens that contain 'bg'. - Update the style for the body background on the ionic theme (this triggered some snapshots differences). ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> --------- Co-authored-by: ionitron <[email protected]>
1 parent 5458e06 commit 33dcf98

File tree

14 files changed

+478
-1159
lines changed

14 files changed

+478
-1159
lines changed

core/scripts/tokens/utils.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ function generateTypographyOutput(prop, propName, isVariable) {
142142

143143
// Generates a color based css utility-class from a color Design Token structure
144144
function generateColorUtilityClasses(prop, className) {
145-
return `.${variablesPrefix}-${className} {\n color: $${variablesPrefix}-${prop.name};\n}
146-
.${variablesPrefix}-background-${className} {\n background-color: $${variablesPrefix}-${prop.name};\n}`;
145+
const isBg = className.includes('bg');
146+
const cssProp = isBg ? 'background-color' : 'color';
147+
return `.${variablesPrefix}-${className} {
148+
--${cssProp}: $${variablesPrefix}-${prop.name};
149+
${cssProp}: $${variablesPrefix}-${prop.name};
150+
}`;
147151
}
148152

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

265269
// Generates a valid box-shadow value from a shadow Design Token structure
266270
function generateRadiusUtilityClasses(propName) {
267-
return `.${variablesPrefix}-${propName} {\n border-radius: $${variablesPrefix}-${propName};\n}`;
271+
return `.${variablesPrefix}-${propName} {
272+
--border-radius: $${variablesPrefix}-${propName};
273+
border-radius: $${variablesPrefix}-${propName};
274+
}`;
268275
}
269276

270277
// Generates a border based css utility-class from a font Design Token structure
@@ -282,7 +289,10 @@ function generateBorderUtilityClasses(prop, propName) {
282289
default:
283290
attribute = 'border-color';
284291
}
285-
return `.${variablesPrefix}-${propName} {\n ${attribute}: $${variablesPrefix}-${propName};\n}`;
292+
return `.${variablesPrefix}-${propName} {
293+
--${attribute}: $${variablesPrefix}-${propName};
294+
${attribute}: $${variablesPrefix}-${propName};
295+
}`;
286296
}
287297

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

293303
// Generates a valid box-shadow value from a shadow Design Token structure
294304
function generateShadowUtilityClasses(propName) {
295-
return `.${variablesPrefix}-${propName} {\n box-shadow: $${variablesPrefix}-${propName};\n}`;
305+
return `.${variablesPrefix}-${propName} {
306+
--box-shadow: $${variablesPrefix}-${propName};
307+
box-shadow: $${variablesPrefix}-${propName};
308+
}`;
296309
}
297310

298311
// Generates a utility class for a given token category and name

core/src/components/accordion-group/test/expand/accordion-group.e2e.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
1010
<style>
1111
/* Background styles to show the border radius */
1212
:root {
13-
background: #ccc7c7;
13+
--background: #ccc7c7;
1414
}
1515
</style>
1616
<ion-accordion-group>
@@ -48,7 +48,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
4848
<style>
4949
/* Background styles to show the border radius */
5050
:root {
51-
background: #ccc7c7;
51+
--background: #ccc7c7;
5252
}
5353
</style>
5454
<ion-accordion-group value="first">
@@ -88,7 +88,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
8888
<style>
8989
/* Background styles to show the border radius */
9090
:root {
91-
background: #ccc7c7;
91+
--background: #ccc7c7;
9292
}
9393
</style>
9494
<ion-accordion-group expand="inset">
@@ -126,7 +126,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
126126
<style>
127127
/* Background styles to show the border radius */
128128
:root {
129-
background: #ccc7c7;
129+
--background: #ccc7c7;
130130
}
131131
</style>
132132
<ion-accordion-group value="first" expand="inset">

core/src/components/accordion-group/test/shape/accordion-group.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
1010
<style>
1111
/* Background styles to show the border radius */
1212
:root {
13-
background: #222;
13+
--background: #222;
1414
}
1515
</style>
1616

core/src/components/accordion/test/shape/accordion.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
1010
<style>
1111
/* Background styles to show the border radius */
1212
:root {
13-
background: #222;
13+
--background: #222;
1414
}
1515
</style>
1616

core/src/components/progress-bar/test/shape/progress-bar.e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
88
`
99
<style>
1010
:root {
11-
background: #ccc7c7;
11+
--background: #ccc7c7;
1212
}
1313
1414
.container {
@@ -33,7 +33,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
3333
`
3434
<style>
3535
:root {
36-
background: #ccc7c7;
36+
--background: #ccc7c7;
3737
}
3838
3939
.container {

core/src/components/searchbar/test/shape/searchbar.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
1414
<style>
1515
/* Background styles to show the border radius */
1616
:root {
17-
background: #000;
17+
--background: #000;
1818
}
1919
</style>
2020

core/src/components/tab-bar/test/basic/tab-bar.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ configs({ modes: ['ionic-md', 'md', 'ios'] }).forEach(({ title, screenshot, conf
1111
`
1212
<style>
1313
:root {
14-
background: #ccc7c7;
14+
--background: #ccc7c7;
1515
}
1616
</style>
1717

core/src/components/tab-bar/test/shape/tab-bar.e2e.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
1313
`
1414
<style>
1515
:root {
16-
background: #ccc7c7;
16+
--background: #ccc7c7;
1717
}
1818
</style>
1919
@@ -49,7 +49,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
4949
`
5050
<style>
5151
:root {
52-
background: #ccc7c7;
52+
--background: #ccc7c7;
5353
}
5454
</style>
5555
@@ -85,7 +85,7 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ title, screensh
8585
`
8686
<style>
8787
:root {
88-
background: #ccc7c7;
88+
--background: #ccc7c7;
8989
}
9090
</style>
9191

core/src/css/ionic/core.ionic.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ html {
2323
}
2424

2525
body {
26-
background: var(--ion-background-color);
26+
background: var(--ion-background-color, #{globals.$ion-bg-body});
2727
color: var(--ion-text-color);
2828
}
2929

0 commit comments

Comments
 (0)