Skip to content

Commit d4a05e5

Browse files
committed
feat(tokens): add gray colors for dark
1 parent 0cc323a commit d4a05e5

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

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

Lines changed: 2 additions & 1 deletion
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 { DarkTheme } from '../themes.interfaces';
33

44
const colors = {
@@ -160,6 +160,7 @@ export const darkTheme: DarkTheme = {
160160
tint: mix('#000', colors.dark, '12%'),
161161
},
162162
},
163+
gray: generateColorSteps('#fff', '#000', true),
163164
},
164165

165166
backgroundColor: '#000000',

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { generateColorSteps } from '../../utils/theme';
21
import type { DefaultTheme } from '../themes.interfaces';
32

43
import { darkTheme } from './dark.tokens';
@@ -161,8 +160,4 @@ export const defaultTheme: DefaultTheme = {
161160
xl: '2',
162161
xxl: '2.4',
163162
},
164-
165-
color: {
166-
gray: generateColorSteps('#fff', '#000'),
167-
},
168163
};

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

Lines changed: 2 additions & 1 deletion
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 { LightTheme } from '../themes.interfaces';
33

44
const colors = {
@@ -159,5 +159,6 @@ export const lightTheme: LightTheme = {
159159
tint: mix('#fff', colors.dark, '4%'),
160160
},
161161
},
162+
gray: generateColorSteps('#fff', '#000'),
162163
},
163164
};

core/src/utils/theme.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,21 @@ export const mix = (baseColor: string, mixColor: string, weight: string): string
485485
*
486486
* @param {string} lightColor - The lighter base color hex value.
487487
* @param {string} darkColor - The darker base color hex value.
488+
* @param {boolean} isInverted - If true, generates the scale in reverse (dark to light).
488489
* @returns {NumberStringKeys} An object of color shades.
489490
*
490491
* @example
491492
* mix('#ffffff', '#000000', 5%) results in the color for key '50'
492493
* mix('#ffffff', '#000000', 95%) results in the color for key '950'
493494
*/
494-
export const generateColorSteps = (lightColor: string, darkColor: string): NumberStringKeys => {
495-
const colorSteps: NumberStringKeys = {};
495+
export const generateColorSteps = (lightColor: string, darkColor: string, isInverted = false): NumberStringKeys => {
496+
const colorSteps: NumberStringKeys = {
497+
0: isInverted ? darkColor : lightColor,
498+
1000: isInverted ? lightColor : darkColor,
499+
};
496500

497501
for (let i = 50; i <= 950; i += 50) {
498-
const weight = `${i / 10}%`;
502+
const weight = isInverted ? `${100 - i / 10}%` : `${i / 10}%`;
499503

500504
colorSteps[i.toString() as keyof NumberStringKeys] = mix(lightColor, darkColor, weight);
501505
}

0 commit comments

Comments
 (0)