Skip to content

Commit 28e8745

Browse files
committed
fix(themes): use correct background and text stepped values
1 parent 85e81f8 commit 28e8745

10 files changed

Lines changed: 44 additions & 246 deletions

core/src/themes/base/high-contrast.tokens.ts

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mix } from '../../utils/theme';
1+
import { mix, generateColorSteps } from '../../utils/theme';
22
import type { HighContrastTheme } from '../themes.interfaces';
33

44
const colors = {
@@ -167,47 +167,5 @@ export const highContrastTheme: HighContrastTheme = {
167167
textColor: '#000000',
168168
textColorRgb: '0, 0, 0',
169169

170-
backgroundColorStep: {
171-
50: '#818181',
172-
100: '#7a7a7a',
173-
150: '#747474',
174-
200: '#6d6d6d',
175-
250: '#666666',
176-
300: '#5f5f5f',
177-
350: '#585858',
178-
400: '#525252',
179-
450: '#4b4b4b',
180-
500: '#444444',
181-
550: '#3d3d3d',
182-
600: '#363636',
183-
650: '#303030',
184-
700: '#292929',
185-
750: '#222222',
186-
800: '#1b1b1b',
187-
850: '#141414',
188-
900: '#0e0e0e',
189-
950: '#070707',
190-
},
191-
192-
textColorStep: {
193-
50: '#070707',
194-
100: '#0e0e0e',
195-
150: '#141414',
196-
200: '#1b1b1b',
197-
250: '#222222',
198-
300: '#292929',
199-
350: '#303030',
200-
400: '#363636',
201-
450: '#3d3d3d',
202-
500: '#444444',
203-
550: '#4b4b4b',
204-
600: '#525252',
205-
650: '#585858',
206-
700: '#5f5f5f',
207-
750: '#666666',
208-
800: '#6d6d6d',
209-
850: '#747474',
210-
900: '#7a7a7a',
211-
950: '#818181',
212-
},
170+
textColorStep: generateColorSteps('#888888', '#000000'),
213171
};

core/src/themes/ios/dark.tokens.ts

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,12 @@
1+
import { generateColorSteps } from '../../utils/theme';
12
import { darkTheme as baseDarkTheme } from '../base/dark.tokens';
23
import type { DarkTheme } from '../themes.interfaces';
34

45
export const darkTheme: DarkTheme = {
56
...baseDarkTheme,
67

7-
backgroundColorStep: {
8-
50: '#0d0d0d',
9-
100: '#1a1a1a',
10-
150: '#262626',
11-
200: '#333333',
12-
250: '#404040',
13-
300: '#4d4d4d',
14-
350: '#595959',
15-
400: '#666666',
16-
450: '#737373',
17-
500: '#808080',
18-
550: '#8c8c8c',
19-
600: '#999999',
20-
650: '#a6a6a6',
21-
700: '#b3b3b3',
22-
750: '#bfbfbf',
23-
800: '#cccccc',
24-
850: '#d9d9d9',
25-
900: '#e6e6e6',
26-
950: '#f2f2f2',
27-
},
28-
29-
textColorStep: {
30-
50: '#f2f2f2',
31-
100: '#e6e6e6',
32-
150: '#d9d9d9',
33-
200: '#cccccc',
34-
250: '#bfbfbf',
35-
300: '#b3b3b3',
36-
350: '#a6a6a6',
37-
400: '#999999',
38-
450: '#8c8c8c',
39-
500: '#808080',
40-
550: '#737373',
41-
600: '#666666',
42-
650: '#595959',
43-
700: '#4d4d4d',
44-
750: '#404040',
45-
800: '#333333',
46-
850: '#262626',
47-
900: '#1a1a1a',
48-
950: '#0d0d0d',
49-
},
8+
backgroundColorStep: generateColorSteps('#000000', '#ffffff'),
9+
textColorStep: generateColorSteps('#ffffff', '#000000'),
5010

5111
components: {
5212
IonCard: {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import { generateColorSteps } from '../../utils/theme';
12
import { highContrastDarkTheme as baseHighContrastDarkTheme } from '../base/high-contrast-dark.tokens';
23
import type { HighContrastDarkTheme } from '../themes.interfaces';
34

45
export const highContrastDarkTheme: HighContrastDarkTheme = {
56
...baseHighContrastDarkTheme,
7+
8+
backgroundColorStep: generateColorSteps('#ffffff', '#000000'),
9+
textColorStep: generateColorSteps('#888888', '#ffffff'),
610
};

core/src/themes/ios/high-contrast.tokens.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,4 @@ import type { HighContrastTheme } from '../themes.interfaces';
33

44
export const highContrastTheme: HighContrastTheme = {
55
...baseHighContrastTheme,
6-
7-
backgroundColorStep: {
8-
50: '#818181',
9-
100: '#7a7a7a',
10-
150: '#747474',
11-
200: '#6d6d6d',
12-
250: '#666666',
13-
300: '#5f5f5f',
14-
350: '#585858',
15-
400: '#525252',
16-
450: '#4b4b4b',
17-
500: '#444444',
18-
550: '#3d3d3d',
19-
600: '#363636',
20-
650: '#303030',
21-
700: '#292929',
22-
750: '#222222',
23-
800: '#1b1b1b',
24-
850: '#141414',
25-
900: '#0e0e0e',
26-
950: '#070707',
27-
},
28-
29-
textColorStep: {
30-
50: '#070707',
31-
100: '#0e0e0e',
32-
150: '#141414',
33-
200: '#1b1b1b',
34-
250: '#222222',
35-
300: '#292929',
36-
350: '#303030',
37-
400: '#363636',
38-
450: '#3d3d3d',
39-
500: '#444444',
40-
550: '#4b4b4b',
41-
600: '#525252',
42-
650: '#585858',
43-
700: '#5f5f5f',
44-
750: '#666666',
45-
800: '#6d6d6d',
46-
850: '#747474',
47-
900: '#7a7a7a',
48-
950: '#818181',
49-
},
506
};

core/src/themes/md/dark.tokens.ts

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { generateColorSteps } from '../../utils/theme';
12
import { darkTheme as baseDarkTheme } from '../base/dark.tokens';
23
import type { DarkTheme } from '../themes.interfaces';
34

@@ -12,49 +13,8 @@ export const darkTheme: DarkTheme = {
1213
background: '#1f1f1f',
1314
},
1415

15-
backgroundColorStep: {
16-
50: '#1e1e1e',
17-
100: '#2a2a2a',
18-
150: '#363636',
19-
200: '#414141',
20-
250: '#4d4d4d',
21-
300: '#595959',
22-
350: '#656565',
23-
400: '#717171',
24-
450: '#7d7d7d',
25-
500: '#898989',
26-
550: '#949494',
27-
600: '#a0a0a0',
28-
650: '#acacac',
29-
700: '#b8b8b8',
30-
750: '#c4c4c4',
31-
800: '#d0d0d0',
32-
850: '#dbdbdb',
33-
900: '#e7e7e7',
34-
950: '#f3f3f3',
35-
},
36-
37-
textColorStep: {
38-
50: '#f3f3f3',
39-
100: '#e7e7e7',
40-
150: '#dbdbdb',
41-
200: '#d0d0d0',
42-
250: '#c4c4c4',
43-
300: '#b8b8b8',
44-
350: '#acacac',
45-
400: '#a0a0a0',
46-
450: '#949494',
47-
500: '#898989',
48-
550: '#7d7d7d',
49-
600: '#717171',
50-
650: '#656565',
51-
700: '#595959',
52-
750: '#4d4d4d',
53-
800: '#414141',
54-
850: '#363636',
55-
900: '#2a2a2a',
56-
950: '#1e1e1e',
57-
},
16+
backgroundColorStep: generateColorSteps('#121212', '#ffffff'),
17+
textColorStep: generateColorSteps('#ffffff', '#121212'),
5818

5919
components: {
6020
IonCard: {
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { generateColorSteps } from '../../utils/theme';
12
import { highContrastDarkTheme as baseHighContrastDarkTheme } from '../base/high-contrast-dark.tokens';
23
import type { HighContrastDarkTheme } from '../themes.interfaces';
34

@@ -11,25 +12,6 @@ export const highContrastDarkTheme: HighContrastDarkTheme = {
1112
background: '#1f1f1f',
1213
},
1314

14-
backgroundColorStep: {
15-
50: '#1e1e1e',
16-
100: '#2a2a2a',
17-
150: '#363636',
18-
200: '#414141',
19-
250: '#4d4d4d',
20-
300: '#595959',
21-
350: '#656565',
22-
400: '#717171',
23-
450: '#7d7d7d',
24-
500: '#898989',
25-
550: '#949494',
26-
600: '#a0a0a0',
27-
650: '#acacac',
28-
700: '#b8b8b8',
29-
750: '#c4c4c4',
30-
800: '#d0d0d0',
31-
850: '#dbdbdb',
32-
900: '#e7e7e7',
33-
950: '#f3f3f3',
34-
},
15+
backgroundColorStep: generateColorSteps('#ffffff', '#121212'),
16+
textColorStep: generateColorSteps('#888888', '#ffffff'),
3517
};

core/src/themes/md/high-contrast.tokens.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,4 @@ import type { HighContrastTheme } from '../themes.interfaces';
33

44
export const highContrastTheme: HighContrastTheme = {
55
...baseHighContrastTheme,
6-
7-
backgroundColorStep: {
8-
50: '#818181',
9-
100: '#7a7a7a',
10-
150: '#747474',
11-
200: '#6d6d6d',
12-
250: '#666666',
13-
300: '#5f5f5f',
14-
350: '#585858',
15-
400: '#525252',
16-
450: '#4b4b4b',
17-
500: '#444444',
18-
550: '#3d3d3d',
19-
600: '#363636',
20-
650: '#303030',
21-
700: '#292929',
22-
750: '#222222',
23-
800: '#1b1b1b',
24-
850: '#141414',
25-
900: '#0e0e0e',
26-
950: '#070707',
27-
},
28-
29-
textColorStep: {
30-
50: '#070707',
31-
100: '#0e0e0e',
32-
150: '#141414',
33-
200: '#1b1b1b',
34-
250: '#222222',
35-
300: '#292929',
36-
350: '#303030',
37-
400: '#363636',
38-
450: '#3d3d3d',
39-
500: '#444444',
40-
550: '#4b4b4b',
41-
600: '#525252',
42-
650: '#585858',
43-
700: '#5f5f5f',
44-
750: '#666666',
45-
800: '#6d6d6d',
46-
850: '#747474',
47-
900: '#7a7a7a',
48-
950: '#818181',
49-
},
506
};

core/src/themes/test/steps/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ <h2>Text</h2>
8888
return;
8989
}
9090

91-
for (let i = 50; i < 950; i += 50) {
91+
for (let i = 50; i <= 950; i += 50) {
9292
const backgroundColor = `--ion-background-color-step-${i}`;
9393

9494
const colorValue = bodyStyles.getPropertyValue(backgroundColor).trim();

core/src/themes/themes.interfaces.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ export type BaseTheme = {
1111
backgroundColorRgb?: string;
1212
textColor?: string;
1313
textColorRgb?: string;
14-
backgroundColorStep?: {
15-
[key: string]: string;
16-
};
17-
textColorStep?: {
18-
[key: string]: string;
19-
};
14+
backgroundColorStep?: NumberStringKeys;
15+
textColorStep?: NumberStringKeys;
2016

2117
// TODO(FW-6864): Remove once IonToolbar themes are added
2218
toolbar?: any;
@@ -303,3 +299,8 @@ export type IonPadding = {
303299
bottom?: string | number;
304300
start?: string | number;
305301
};
302+
303+
export type NumberStringKeys = {
304+
// Enforce keys are strings of numbers (like 50, '50', etc.)
305+
[K in number as `${K}`]?: string;
306+
};

core/src/utils/theme.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { printIonWarning } from '@utils/logging';
22

33
import type { Color, CssClassMap } from '../interface';
4+
import type { NumberStringKeys } from '../themes/themes.interfaces';
45

56
import { deepMerge } from './helpers';
67

@@ -633,3 +634,23 @@ export function currentColor(variation: string, alpha: number | string | null =
633634
export function clamp(min: number | string, val: number | string, max: number | string): string {
634635
return `clamp(${min}, ${val}, ${max})`;
635636
}
637+
638+
/**
639+
* Generates a series of color steps between a base color and a mix color.
640+
*
641+
* @param baseColor Base color (e.g. `'#0054e9'`)
642+
* @param mixColor Color to mix in (e.g. `'#000000'` or `'#fff'`)
643+
*
644+
* @returns An object containing the generated color steps
645+
*/
646+
export const generateColorSteps = (baseColor: string, mixColor: string): NumberStringKeys => {
647+
const colorSteps: NumberStringKeys = {};
648+
649+
for (let step = 50; step <= 950; step += 50) {
650+
const weight = `${step / 10}%`;
651+
652+
colorSteps[`${step}`] = mix(baseColor, mixColor, weight);
653+
}
654+
655+
return colorSteps;
656+
};

0 commit comments

Comments
 (0)