Skip to content

Commit 859cae6

Browse files
authored
fix: shadow does not take into account custom color (#3391)
1 parent efe4f5a commit 859cae6

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/preset-mini/src/_utils/utilities.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,20 @@ export function colorableShadows(shadows: string | string[], colorVar: string) {
214214
const components = getStringComponents(shadows[i], ' ', 6)
215215
if (!components || components.length < 3)
216216
return shadows
217-
const color = parseCssColor(components.pop())
218-
if (color == null)
217+
218+
if (parseCssColor(components.at(0)))
219219
return shadows
220-
colored.push(`${components.join(' ')} var(${colorVar}, ${colorToString(color)})`)
220+
221+
let colorVarValue = ''
222+
if (parseCssColor(components.at(-1))) {
223+
const color = parseCssColor(components.pop())
224+
if (color)
225+
colorVarValue = `, ${colorToString(color)}`
226+
}
227+
228+
colored.push(`${components.join(' ')} var(${colorVar}${colorVarValue})`)
221229
}
230+
222231
return colored
223232
}
224233

test/layer.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ describe('layers', () => {
2222
expect(css).toMatchSnapshot()
2323
})
2424

25+
it('colors', async () => {
26+
const uno = createGenerator({
27+
theme: {
28+
colors: {
29+
blackA7: 'hsla(0, 0%, 0%, 0.169)',
30+
},
31+
},
32+
presets: [
33+
presetMini(),
34+
35+
],
36+
})
37+
const { css } = await uno.generate('shadow-[0_2px_10px] shadow-blackA7', { preflights: false })
38+
expect(css).toMatchInlineSnapshot(`
39+
"/* layer: default */
40+
.shadow-\\[0_2px_10px\\]{--un-shadow:0 2px 10px var(--un-shadow-color);box-shadow:var(--un-ring-offset-shadow), var(--un-ring-shadow), var(--un-shadow);}
41+
.shadow-blackA7{--un-shadow-opacity:0.169;--un-shadow-color:hsla(0, 0%, 0%, var(--un-shadow-opacity));}"
42+
`)
43+
})
44+
2545
it('@import layer', async () => {
2646
const uno = createGenerator({
2747
presets: [

0 commit comments

Comments
 (0)