Skip to content

Commit

Permalink
fix(preset-mini): allow to use hyphens and numbers in theme config wi…
Browse files Browse the repository at this point in the history
…thout nesting (unocss#2621)
  • Loading branch information
schelmo committed May 14, 2023
1 parent ff1e50b commit 6a8d6d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/preset-mini/src/_utils/utilities.ts
Expand Up @@ -103,6 +103,12 @@ export function parseColor(body: string, theme: Theme): ParsedColorValue | undef

color = color || bracket

if (!color) {
const colorData = getThemeColor(theme, [main])
if (typeof colorData === 'string')
color = colorData
}

let no = 'DEFAULT'
if (!color) {
let colorData
Expand Down
5 changes: 5 additions & 0 deletions test/assets/output/preset-mini-non-nested-theme-colors.css
@@ -0,0 +1,5 @@
/* layer: default */
.bg-numbered321{--un-bg-opacity:1;background-color:rgba(51,34,17,var(--un-bg-opacity));}
.bg-with-hyphen{--un-bg-opacity:1;background-color:rgba(18,52,86,var(--un-bg-opacity));}
.text-numbered-123{--un-text-opacity:1;color:rgba(17,34,51,var(--un-text-opacity));}
.text-with-hyphen{--un-text-opacity:1;color:rgba(18,52,86,var(--un-text-opacity));}
19 changes: 17 additions & 2 deletions test/preset-mini.test.ts
Expand Up @@ -12,16 +12,19 @@ const uno = createGenerator({
],
theme: {
colors: {
custom: {
'custom': {
a: 'var(--custom)',
b: 'rgba(var(--custom), %alpha)',
},
a: {
'a': {
b: {
c: '#514543',
},
camelCase: '#234',
},
'with-hyphen': '#123456',
'numbered-123': '#123',
'numbered321': '#321',
},
spacing: {
safe: 'max(env(safe-area-inset-left), env(safe-area-inset-right))',
Expand Down Expand Up @@ -126,6 +129,18 @@ describe('preset-mini', () => {
expect(matched.size).toBe(3)
})

test('non-nested theme colors with hyphens and/or numbers', async () => {
const { css, matched } = await uno.generate([
'text-with-hyphen',
'bg-with-hyphen',
'text-numbered-123',
'bg-numbered321',
], { preflights: false })

expect(css).toMatchFileSnapshot('./assets/output/preset-mini-non-nested-theme-colors.css')
expect(matched.size).toBe(4)
})

test('none targets', async () => {
const { css, matched } = await uno.generate(new Set(presetMiniNonTargets), { minify: true, preflights: false })

Expand Down

0 comments on commit 6a8d6d2

Please sign in to comment.