Skip to content

Commit feefb61

Browse files
committed
refactor(themes): update config structure and interface
1 parent 3fd1d5c commit feefb61

6 files changed

Lines changed: 29 additions & 11 deletions

File tree

core/src/themes/base/default.tokens.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export const defaultTheme: DefaultTheme = {
1111
dark: darkTheme,
1212
},
1313

14-
formHighlight: false,
15-
rippleEffect: false,
14+
config: {
15+
formHighlight: false,
16+
rippleEffect: false,
17+
},
1618

1719
spacing: {
1820
0: '0px',

core/src/themes/ionic/default.tokens.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ export const defaultTheme: DefaultTheme = {
1414
dark: darkTheme,
1515
},
1616

17-
formHighlight: false,
18-
rippleEffect: false,
17+
config: {
18+
formHighlight: true,
19+
},
1920

2021
// TODO(FW-6745): see if we can remove this after the md tokens are added
2122
fontFamily: 'initial',

core/src/themes/themes.interfaces.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
import type { IonicConfig } from '../utils/config';
2+
13
// Platform-specific theme
24
export type PlatformTheme = Omit<BaseTheme, 'ios' | 'md'>;
35

46
// Base tokens for all palettes
57
export type BaseTheme = {
6-
// CONFIG TOKENS
7-
rippleEffect?: boolean;
8-
formHighlight?: boolean;
9-
108
// GLOBAL THEME TOKENS
119
backgroundColor?: string;
1210
backgroundColorRgb?: string;
@@ -205,4 +203,6 @@ export type DefaultTheme = BaseTheme & {
205203
light?: LightTheme;
206204
dark?: DarkTheme;
207205
};
206+
207+
config?: IonicConfig;
208208
};

core/src/utils/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export interface IonicConfig {
1212
*/
1313
animated?: boolean;
1414

15+
/**
16+
* When it's set to `false`, it disables the form highlight effect across the app.
17+
* Defaults to `false`.
18+
*/
19+
formHighlight?: boolean;
20+
1521
/**
1622
* When it's set to `false`, it disables all material-design ripple-effects across the app.
1723
* Defaults to `true`.

core/src/utils/test/theme.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ describe('getCustomTheme', () => {
186186
describe('generateCSSVars', () => {
187187
it('should not generate CSS variables for an empty theme', () => {
188188
const theme = {
189+
name: 'test',
189190
palette: {
190191
light: {},
191192
dark: {},
@@ -198,14 +199,17 @@ describe('generateCSSVars', () => {
198199

199200
it('should generate CSS variables for a given theme', () => {
200201
const theme = {
202+
name: 'test',
201203
palette: {
202204
light: {},
203205
dark: {
204206
enabled: 'system',
205207
},
206208
},
207-
rippleEffect: true,
208-
formHighlight: true,
209+
config: {
210+
rippleEffect: true,
211+
formHighlight: true,
212+
},
209213
borderWidth: {
210214
sm: '4px',
211215
},
@@ -309,6 +313,7 @@ describe('injectCSS', () => {
309313
describe('generateGlobalThemeCSS', () => {
310314
it('should generate global CSS for a given theme', () => {
311315
const theme = {
316+
name: 'test',
312317
palette: {
313318
light: {},
314319
dark: {
@@ -339,6 +344,7 @@ describe('generateGlobalThemeCSS', () => {
339344

340345
it('should generate global CSS for a given theme with light palette', () => {
341346
const theme = {
347+
name: 'test',
342348
palette: {
343349
light: {
344350
color: {
@@ -425,6 +431,7 @@ describe('generateGlobalThemeCSS', () => {
425431

426432
it('should not include component or palette variables in global CSS', () => {
427433
const theme = {
434+
name: 'test',
428435
palette: {
429436
light: {},
430437
dark: {
@@ -479,6 +486,7 @@ describe('generateGlobalThemeCSS', () => {
479486

480487
it('should generate global CSS for a given theme with dark palette enabled for system preference', () => {
481488
const theme = {
489+
name: 'test',
482490
palette: {
483491
light: {},
484492
dark: {
@@ -598,6 +606,7 @@ describe('generateColorClasses', () => {
598606

599607
it('should generate color classes for a given theme', () => {
600608
const theme = {
609+
name: 'test',
601610
palette: {
602611
light: {
603612
color: {

core/src/utils/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const generateCSSVars = (theme: any, prefix: string = CSS_PROPS_PREFIX):
8787
}
8888

8989
// Do not generate CSS variables for excluded keys
90-
const excludedKeys = ['enabled', 'ripple-effect', 'form-highlight'];
90+
const excludedKeys = ['name', 'enabled', 'config'];
9191
if (excludedKeys.includes(key)) {
9292
return [];
9393
}

0 commit comments

Comments
 (0)