Skip to content

Commit 74e496b

Browse files
committed
feat: update plugins using toRgba
1 parent b9db0c4 commit 74e496b

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/plugins/gradientColorStops.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash'
22
import flattenColorPalette from '../util/flattenColorPalette'
33
import nameClass from '../util/nameClass'
44
import toColorValue from '../util/toColorValue'
5-
import { toRgba } from '../util/withAlphaVariable'
5+
import { toRgba, toHsla } from '../util/withAlphaVariable'
66

77
export default function () {
88
return function ({ addUtilities, theme, variants }) {
@@ -16,8 +16,9 @@ export default function () {
1616
}
1717

1818
try {
19-
const [r, g, b] = toRgba(value)
20-
return `rgba(${r}, ${g}, ${b}, 0)`
19+
const isHSL = value.startsWith('hsl')
20+
const [i, j, k] = isHSL ? toHsla(value) : toRgba(value)
21+
return `${isHSL ? 'hsla' : 'rgba'}(${i}, ${j}, ${k}, 0)`
2122
} catch (_error) {
2223
return `rgba(255, 255, 255, 0)`
2324
}

src/plugins/ringWidth.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import _ from 'lodash'
22
import nameClass from '../util/nameClass'
3-
import { toRgba } from '../util/withAlphaVariable'
3+
import { toHsla, toRgba } from '../util/withAlphaVariable'
44

55
export default function () {
66
return function ({ addUtilities, theme, variants }) {
7-
function safeCall(callback, defaultValue) {
7+
const ringColorDefault = (() => {
8+
const isHSL = (theme('ringColor.DEFAULT') || '').startsWith('hsl')
9+
const opacity = theme('ringOpacity.DEFAULT', '0.5')
810
try {
9-
return callback()
11+
const [i, j, k] = isHSL
12+
? toHsla(theme('ringColor.DEFAULT'))
13+
: toRgba(theme('ringColor.DEFAULT'))
14+
return `${isHSL ? 'hsla' : 'rgba'}(${i}, ${j}, ${k}, ${opacity})`
1015
} catch (_error) {
11-
return defaultValue
16+
return `rgba(147, 197, 253, ${opacity})`
1217
}
13-
}
14-
15-
const ringColorDefault = (([r, g, b]) => {
16-
return `rgba(${r}, ${g}, ${b}, ${theme('ringOpacity.DEFAULT', '0.5')})`
17-
})(safeCall(() => toRgba(theme('ringColor.DEFAULT')), ['147', '197', '253']))
18+
})()
1819

1920
addUtilities(
2021
{

0 commit comments

Comments
 (0)