Skip to content

Commit

Permalink
Merge pull request #4 from adierkens/color-scheme-override
Browse files Browse the repository at this point in the history
Fix color scheme overrides
  • Loading branch information
tylerkrupicka authored Jan 2, 2020
2 parents ef433dc + 828db2f commit 5a7b8b8
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
4 changes: 2 additions & 2 deletions __tests__/modern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ it('Creates a simple css variable based theme with light and dark', () => {
--color: teal
}
.chair .light {
.chair.light {
--color: beige
}
.chair .dark {
.chair.dark {
--color: darkpurple
}
`,
Expand Down
100 changes: 100 additions & 0 deletions __tests__/precedence.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { run } from './test-utils';

jest.mock('browserslist', () => () => ['chrome 76']);

it('Overrides all themes from default', () => {
const config = {
default: {
light: {
color: 'red'
},
dark: {
color: 'blue'
}
},
mint: {
color: 'teal'
}
};

return run(
`
.test {
color: @theme color;
}
`,
`
.test {
color: var(--color);
}
:root {
--color: red;
}
.dark {
--color: blue;
}
.mint {
--color: teal;
}
`,
{
config
}
);
});

it('Overrides dark themes from default', () => {
const config = {
default: {
light: {
color: 'red'
},
dark: {
color: 'blue'
}
},
mint: {
light: {
color: 'purple'
},
dark: {
color: 'teal'
}
}
};

return run(
`
.test {
color: @theme color;
}
`,
`
.test {
color: var(--color);
}
:root {
--color: red;
}
.dark {
--color: blue;
}
.mint.light {
--color: purple;
}
.mint.dark {
--color: teal;
}
`,
{
config
}
);
});
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ const modernTheme = (
) {
rules.push(
createModernTheme(
isDefault ? rootClass : `${rootClass} .light`,
isDefault ? rootClass : `${rootClass}.light`,
filterUsed('light'),
localize
),
createModernTheme(
isDefault ? '.dark' : `${rootClass} .dark`,
isDefault ? '.dark' : `${rootClass}.dark`,
filterUsed('dark'),
localize
)
Expand Down

0 comments on commit 5a7b8b8

Please sign in to comment.