Skip to content

Commit b91899e

Browse files
committed
fix(theme): do not generate global root vars for component level vars
1 parent 89de2f9 commit b91899e

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

core/src/utils/theme.spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,60 @@ describe('generateGlobalThemeCSS', () => {
204204
expect(css).toBe(expectedCSS);
205205
});
206206

207+
it('should not include component or palette variables in global CSS', () => {
208+
const theme = {
209+
palette: {
210+
light: {},
211+
dark: {
212+
enabled: 'never',
213+
},
214+
},
215+
borderWidth: {
216+
sm: '4px',
217+
},
218+
spacing: {
219+
md: '12px',
220+
},
221+
components: {
222+
IonChip: {
223+
hue: {
224+
subtle: {
225+
bg: 'red',
226+
},
227+
},
228+
shape: {
229+
round: {
230+
borderRadius: '4px',
231+
},
232+
},
233+
},
234+
IonButton: {
235+
color: {
236+
primary: {
237+
bg: 'blue',
238+
},
239+
},
240+
},
241+
},
242+
};
243+
244+
const css = generateGlobalThemeCSS(theme);
245+
246+
// Should include global design tokens
247+
expect(css).toContain('--ion-border-width-sm: 4px');
248+
expect(css).toContain('--ion-spacing-md: 12px');
249+
250+
// Should NOT include component variables
251+
expect(css).not.toContain('--ion-components-ion-chip-hue-subtle-bg');
252+
expect(css).not.toContain('--ion-components-ion-chip-shape-round-border-radius');
253+
expect(css).not.toContain('--ion-components-ion-button-color-primary-bg');
254+
expect(css).not.toContain('components');
255+
256+
// Should NOT include palette variables
257+
expect(css).not.toContain('--ion-color-palette-dark-enabled-never');
258+
expect(css).not.toContain('palette');
259+
});
260+
207261
it('should generate global CSS for a given theme with dark palette enabled for system preference', () => {
208262
const theme = {
209263
palette: {

core/src/utils/theme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export const generateGlobalThemeCSS = (theme: any): string => {
115115
return '';
116116
}
117117

118-
const { palette, ...defaultTokens } = theme;
118+
// Exclude components and palette from the default tokens
119+
const { palette, components, ...defaultTokens } = theme;
119120

120121
// Generate CSS variables for the default design tokens
121122
const defaultTokensCSS = generateCSSVars(defaultTokens);

0 commit comments

Comments
 (0)