mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Merge pull request #1676 from innocenzi/color-closure
Allow colors to be defined as closures
This commit is contained in:
commit
7371ea992b
@ -95,3 +95,15 @@ test('it ignores colors that already have an alpha channel', () => {
|
||||
'background-color': 'hsla(240, 100%, 50%, 0.5)',
|
||||
})
|
||||
})
|
||||
|
||||
test('it allows a closure to be passed', () => {
|
||||
expect(
|
||||
withAlphaVariable({
|
||||
color: ({ opacityVariable }) => `rgba(0, 0, 0, var(${opacityVariable}))`,
|
||||
property: 'background-color',
|
||||
variable: '--bg-opacity',
|
||||
})
|
||||
).toEqual({
|
||||
'background-color': 'rgba(0, 0, 0, var(--bg-opacity))',
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import createColor from 'color'
|
||||
import _ from 'lodash'
|
||||
|
||||
function hasAlpha(color) {
|
||||
return (
|
||||
@ -18,6 +19,12 @@ function toRgba(color) {
|
||||
}
|
||||
|
||||
export default function withAlphaVariable({ color, property, variable }) {
|
||||
if (_.isFunction(color)) {
|
||||
return {
|
||||
[property]: color({ opacityVariable: variable }),
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const [r, g, b, a] = toRgba(color)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user