Properly support colors as closures with ring utilities
This commit is contained in:
parent
b3ed7248c2
commit
62a47f95b1
8 changed files with 143 additions and 163 deletions
|
|
@ -1,32 +1,26 @@
|
|||
import _ from 'lodash'
|
||||
import flattenColorPalette from '../util/flattenColorPalette'
|
||||
import nameClass from '../util/nameClass'
|
||||
import { toRgba } from '../util/withAlphaVariable'
|
||||
import withAlphaVariable from '../util/withAlphaVariable'
|
||||
|
||||
export default function () {
|
||||
return function ({ addUtilities, theme, variants }) {
|
||||
const colors = flattenColorPalette(theme('ringColor'))
|
||||
|
||||
const getProperties = (value) => {
|
||||
return withAlphaVariable({
|
||||
color: value,
|
||||
property: '--ring-color',
|
||||
variable: '--ring-opacity',
|
||||
})
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
]
|
||||
}
|
||||
return [nameClass('ring', modifier), getProperties(value)]
|
||||
})
|
||||
)
|
||||
|
||||
addUtilities(utilities, variants('ringColor'))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue