Skip to content

Commit 7efce37

Browse files
committed
fix(styles): color parsing
1 parent 693733e commit 7efce37

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/tasty/styles.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ describe('Tasty style tests', () => {
120120
expect(scrollbarStyle({})).toBeUndefined();
121121
});
122122

123+
it('should return correct styles for two colors', () => {
124+
expect(scrollbarStyle({ scrollbar: '#dark #clear' })).toEqual({
125+
'scrollbar-color': 'var(--dark-color) var(--clear-color)',
126+
'&::-webkit-scrollbar-corner': {
127+
background: 'var(--clear-color)',
128+
},
129+
});
130+
});
131+
123132
it('should return correct styles for `thin` scrollbar', () => {
124133
expect(scrollbarStyle({ scrollbar: 'thin' })).toEqual({
125134
'scrollbar-width': 'thin',

src/tasty/utils/styles.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface ParsedStyle {
4848
values: string[];
4949
all: string[];
5050
colors: string[];
51+
color?: string;
5152
/** The list of mods to apply */
5253
mods: string[];
5354
}
@@ -479,28 +480,26 @@ export function parseColor(val: string, ignoreError = false): ParsedColor {
479480
};
480481
}
481482

482-
let { values, mods, colors } = parseStyle(val);
483+
let { values, mods, color } = parseStyle(val);
483484

484485
let name, opacity;
485486

486-
if (colors.length > 0) {
487+
if (color) {
487488
return {
488-
color:
489-
(!colors[0].startsWith('var(') ? strToRgb(colors[0]) : colors[0]) ||
490-
colors[0],
489+
color: (!color.startsWith('var(') ? strToRgb(color) : color) || color,
491490
};
492491
}
493492

494493
values.forEach((token) => {
495494
if (token.match(/^((var|rgb|rgba|hsl|hsla)\(|#[0-9a-f]{3,6})/)) {
496-
colors[0] = !token.startsWith('var') ? strToRgb(token) : token;
495+
color = !token.startsWith('var') ? strToRgb(token) : token;
497496
} else if (token.endsWith('%')) {
498497
opacity = parseInt(token);
499498
}
500499
});
501500

502-
if (colors.length > 0) {
503-
return { color: colors[0] };
501+
if (color) {
502+
return { color };
504503
}
505504

506505
name = name || mods[0];

0 commit comments

Comments
 (0)