mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2026-02-01 17:26:34 +00:00
Fix formatting
This commit is contained in:
parent
70787fc088
commit
721e57312b
@ -37,23 +37,20 @@ export default function withAlphaVariable({ color, property, variable }) {
|
||||
}
|
||||
|
||||
if (isValidColor(color)) {
|
||||
const { alpha = 1, mode } = culori.parse(color)
|
||||
const parsed = culori.parse(color)
|
||||
|
||||
if (alpha !== 1) {
|
||||
if ('alpha' in parsed) {
|
||||
// Has an alpha value, return color as-is
|
||||
return {
|
||||
[property]: color,
|
||||
}
|
||||
}
|
||||
|
||||
let value
|
||||
if (mode === 'hsl') {
|
||||
const { h, s, l } = culori.hsl(color)
|
||||
value = `hsla(${h}, ${s}, ${l}, var(${variable}))`
|
||||
} else {
|
||||
const { r, g, b } = culori.rgb(color)
|
||||
value = `rgba(${r}, ${g}, ${b}, var(${variable}))`
|
||||
}
|
||||
const formatFn = parsed.mode === 'hsl' ? 'formatHsl' : 'formatRgb'
|
||||
const value = culori[formatFn]({
|
||||
...parsed,
|
||||
alpha: 0.3,
|
||||
}).replace('0.3)', `var(${variable}))`)
|
||||
|
||||
return {
|
||||
[variable]: '1',
|
||||
|
||||
@ -7,6 +7,16 @@ test('it adds the right custom property', () => {
|
||||
'--tw-text-opacity': '1',
|
||||
color: 'rgba(255, 0, 0, var(--tw-text-opacity))',
|
||||
})
|
||||
expect(
|
||||
withAlphaVariable({
|
||||
color: 'hsl(240 100% 50%)',
|
||||
property: 'color',
|
||||
variable: '--tw-text-opacity',
|
||||
})
|
||||
).toEqual({
|
||||
'--tw-text-opacity': '1',
|
||||
color: 'hsla(240, 100%, 50%, var(--tw-text-opacity))',
|
||||
})
|
||||
})
|
||||
|
||||
test('it ignores colors that cannot be parsed', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user