-
-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
extendTheme
return to override (#2258)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com> Co-authored-by: Chris <1633711653@qq.com>
- Loading branch information
1 parent
4fe0a96
commit aae131b
Showing
5 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import type { UserConfig } from '@unocss/core' | ||
import { createGenerator } from '@unocss/core' | ||
import type { Theme } from '@unocss/preset-mini' | ||
import presetMini from '@unocss/preset-mini' | ||
import { describe, expect, test } from 'vitest' | ||
|
||
describe('config', () => { | ||
const createUno = (userConfig: UserConfig) => { | ||
return createGenerator<Theme>({ | ||
...userConfig, | ||
presets: [ | ||
presetMini(), | ||
], | ||
}) | ||
} | ||
test('theme', async () => { | ||
const uno = createUno({ | ||
theme: { | ||
colors: { | ||
red: { | ||
500: '#0f0', | ||
}, | ||
}, | ||
}, | ||
}) | ||
const { css } = await uno.generate('text-red-500 text-blue', { preflights: false }) | ||
expect(css).toMatchInlineSnapshot(` | ||
"/* layer: default */ | ||
.text-blue{--un-text-opacity:1;color:rgba(96,165,250,var(--un-text-opacity));} | ||
.text-red-500{--un-text-opacity:1;color:rgba(0,255,0,var(--un-text-opacity));}" | ||
`) | ||
}) | ||
|
||
test('extendTheme with return extend', async () => { | ||
const uno = createUno({ | ||
extendTheme(mergedTheme) { | ||
return { | ||
...mergedTheme, | ||
colors: { | ||
red: { | ||
500: 'red', | ||
}, | ||
}, | ||
} | ||
}, | ||
}) | ||
expect(uno.config.theme.colors).toEqual({ red: { 500: 'red' } }) | ||
}) | ||
|
||
test('extendTheme with return', async () => { | ||
const unocss = createGenerator<Theme>({ | ||
extendTheme: () => { | ||
return { | ||
colors: { | ||
red: { | ||
200: 'red', | ||
}, | ||
}, | ||
} | ||
}, | ||
presets: [ | ||
presetMini(), | ||
], | ||
}) | ||
const { css } = await unocss.generate('text-red-100 text-red-200', { preflights: false }) | ||
expect(css).toMatchInlineSnapshot(` | ||
"/* layer: default */ | ||
.text-red-200{color:red;}" | ||
`) | ||
}) | ||
|
||
test('extendTheme with mutation', async () => { | ||
const unocss = createGenerator<Theme>({ | ||
extendTheme: (theme) => { | ||
// @ts-expect-error test | ||
theme.colors.red[100] = 'green' | ||
// @ts-expect-error test | ||
theme.colors.red[200] = 'red' | ||
}, | ||
presets: [ | ||
presetMini(), | ||
], | ||
}) | ||
const { css } = await unocss.generate('text-red-100 text-red-200', { preflights: false }) | ||
expect(css).toMatchInlineSnapshot(` | ||
"/* layer: default */ | ||
.text-red-100{color:green;} | ||
.text-red-200{color:red;}" | ||
`) | ||
}) | ||
}) |