/
ringColor.js
32 lines (31 loc) · 963 Bytes
/
ringColor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import _ from 'lodash'
import flattenColorPalette from '../util/flattenColorPalette'
import nameClass from '../util/nameClass'
import { toRgba } from '../util/withAlphaVariable'
export default function () {
return function ({ addUtilities, theme, variants }) {
const colors = flattenColorPalette(theme('ringColor'))
const utilities = _.fromPairs(
_.map(_.omit(colors, 'DEFAULT'), (value, modifier) => {
try {
const [r, g, b, a] = toRgba(value)
return [
nameClass('ring', modifier),
{
'--ring-opacity': a === undefined ? '1' : a,
'--ring-color': `rgba(${r}, ${g}, ${b}, var(--ring-opacity))`,
},
]
} catch (_error) {
return [
nameClass('ring', modifier),
{
'--ring-color': value,
},
]
}
})
)
addUtilities(utilities, variants('ringColor'))
}
}