Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call color functions when using theme('...') on all color related sections. #4533

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/util/transformThemeValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,29 @@ export default function transformThemeValue(themeSection) {
'transitionTimingFunction',
'backgroundImage',
'backgroundSize',
'backgroundColor',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having a hard time understanding why this was here. I removed it and it didn't break any tests so that's good but I can't help but feel like I'm missing something.

'cursor',
'animation',
].includes(themeSection)
) {
return (value) => (Array.isArray(value) ? value.join(', ') : value)
}

if (themeSection === 'colors') {
if (
[
'backgroundColor',
'borderColor',
'caretColor',
'colors',
'divideColor',
'fill',
'gradientColorStops',
'placeholderColor',
'ringColor',
'ringOffsetColor',
'stroke',
'textColor',
].includes(themeSection)
) {
return (value) => (typeof value === 'function' ? value({}) : value)
}

Expand Down
54 changes: 54 additions & 0 deletions tests/evaluateTailwindFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,60 @@ test('it looks up values in the theme using dot notation', () => {
})
})

test('color can be a function', () => {
const input = `
.backgroundColor { color: theme('backgroundColor.fn') }
.borderColor { color: theme('borderColor.fn') }
.caretColor { color: theme('caretColor.fn') }
.colors { color: theme('colors.fn') }
.divideColor { color: theme('divideColor.fn') }
.fill { color: theme('fill.fn') }
.gradientColorStops { color: theme('gradientColorStops.fn') }
.placeholderColor { color: theme('placeholderColor.fn') }
.ringColor { color: theme('ringColor.fn') }
.ringOffsetColor { color: theme('ringOffsetColor.fn') }
.stroke { color: theme('stroke.fn') }
.textColor { color: theme('textColor.fn') }
`

const output = `
.backgroundColor { color: #f00 }
.borderColor { color: #f00 }
.caretColor { color: #f00 }
.colors { color: #f00 }
.divideColor { color: #f00 }
.fill { color: #f00 }
.gradientColorStops { color: #f00 }
.placeholderColor { color: #f00 }
.ringColor { color: #f00 }
.ringOffsetColor { color: #f00 }
.stroke { color: #f00 }
.textColor { color: #f00 }
`

const fn = () => `#f00`

return run(input, {
theme: {
backgroundColor: { fn },
borderColor: { fn },
caretColor: { fn },
colors: { fn },
divideColor: { fn },
fill: { fn },
gradientColorStops: { fn },
placeholderColor: { fn },
ringColor: { fn },
ringOffsetColor: { fn },
stroke: { fn },
textColor: { fn },
},
}).then((result) => {
expect(result.css).toEqual(output)
expect(result.warnings().length).toBe(0)
})
})

test('quotes are optional around the lookup path', () => {
const input = `
.banana { color: theme(colors.yellow); }
Expand Down