Skip to content

Commit

Permalink
fix(variants): apply variants to theme root also
Browse files Browse the repository at this point in the history
fix #70
  • Loading branch information
RyanClementsHax committed Sep 26, 2023
1 parent b0c91ab commit c7517c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,24 @@ describe('multiThemePlugin', () => {
multiThemePlugin(config).handler(api)

expect(api.addVariant).toHaveBeenCalledWith('defaultTheme', [
'.escaped-defaultTheme &'
'.escaped-defaultTheme &',
'&.escaped-defaultTheme'
])
expect(api.addVariant).toHaveBeenCalledWith('darkTheme', [
'.escaped-darkTheme &'
'.escaped-darkTheme &',
'&.escaped-darkTheme'
])
expect(api.addVariant).not.toHaveBeenCalledWith('light', [
'.escaped-light &'
'.escaped-light &',
'&.escaped-light'
])
expect(api.addVariant).not.toHaveBeenCalledWith('neon', [
'.escaped-neon &'
'.escaped-neon &',
'&.escaped-neon'
])
expect(api.addVariant).not.toHaveBeenCalledWith('soft', [
'.escaped-soft &'
'.escaped-soft &',
'&.escaped-soft'
])
})

Expand Down Expand Up @@ -126,13 +131,20 @@ describe('multiThemePlugin', () => {

expect(api.addVariant).toHaveBeenCalledWith('darkTheme', [
'.dark-mode &',
'[data-theme="dark"] &'
'&.dark-mode',
'[data-theme="dark"] &',
'&[data-theme="dark"]'
])
expect(api.addVariant).toHaveBeenCalledWith('neon', [
'.high-contrast &',
'[data-theme="high-contrast"] &'
'&.high-contrast',
'[data-theme="high-contrast"] &',
'&[data-theme="high-contrast"]'
])
expect(api.addVariant).toHaveBeenCalledWith('soft', [
'.escaped-soft &',
'&.escaped-soft'
])
expect(api.addVariant).toHaveBeenCalledWith('soft', ['.escaped-soft &'])
})

it('doesnt add any selector based variants when none provided', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const addThemeVariants = (
if (selectors.length > 0) {
addVariant(
variantName,
selectors.map(x => `${x} &`)
selectors.flatMap(x => [`${x} &`, `&${x}`])
)
}

Expand Down

0 comments on commit c7517c9

Please sign in to comment.