Skip to content

Commit 433cb71

Browse files
authored
fix: combined variants overriding each other (#567)
* fix: combined variants overriding each other * test: add more tests for combined variants
1 parent ec328ef commit 433cb71

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

packages/uniwind/src/bundler/css-processor/processor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ export class ProcessorBuilder {
196196
})
197197

198198
if ([rtl, theme, active, focus, disabled, dataAttributes].some(Boolean)) {
199-
this.declarationConfig.rtl = rtl
200-
this.declarationConfig.theme = theme
201-
this.declarationConfig.active = active
202-
this.declarationConfig.focus = focus
203-
this.declarationConfig.disabled = disabled
204-
this.declarationConfig.dataAttributes = dataAttributes
199+
this.declarationConfig.rtl ??= rtl
200+
this.declarationConfig.theme ??= theme
201+
this.declarationConfig.active ??= active
202+
this.declarationConfig.focus ??= focus
203+
this.declarationConfig.disabled ??= disabled
204+
this.declarationConfig.dataAttributes ??= dataAttributes
205205

206206
rule.value.declarations?.declarations?.forEach(declaration => this.addDeclaration(declaration))
207207
rule.value.declarations?.importantDeclarations?.forEach(declaration => this.addDeclaration(declaration, true))

packages/uniwind/src/core/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type Style = {
1111
minWidth: number
1212
maxWidth: number
1313
orientation: Orientation | null
14-
theme: ColorScheme | null
14+
theme: ThemeName | null
1515
rtl: boolean | null
1616
native: boolean
1717
dependencies: Array<StyleDependency> | null

packages/uniwind/tests/native/styles-parsing/meta.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,23 @@ describe('Styles Metadata', () => {
2727
expect(stylesheet['bg-background'][0].dependencies).toContain(StyleDependency.Theme)
2828
expect(stylesheet['bg-foreground'][0].dependencies).toContain(StyleDependency.Theme)
2929
})
30+
31+
test('Combined variants', async () => {
32+
const { stylesheet } = await compileMetadata()
33+
34+
const expectMeta = (className: string, expected: Partial<StyleSheets[string][number]>) => {
35+
const meta = stylesheet[className][0]
36+
37+
expect(meta.theme).toBe(expected.theme ?? null)
38+
expect(meta.active).toBe(expected.active ?? null)
39+
expect(meta.focus).toBe(expected.focus ?? null)
40+
expect(meta.rtl).toBe(expected.rtl ?? null)
41+
expect(meta.disabled).toBe(expected.disabled ?? null)
42+
expect(meta.dataAttributes).toEqual(expected.dataAttributes ?? null)
43+
}
44+
45+
expectMeta('dark:active:bg-purple-700', { theme: 'dark', active: true })
46+
expectMeta('dark:active:focus:bg-purple-700', { theme: 'dark', active: true, focus: true })
47+
expectMeta('active:dark:bg-purple-700', { theme: 'dark', active: true })
48+
})
3049
})

0 commit comments

Comments
 (0)