tailwindcss/src/util/transformThemeValue.js
Robin Malfait 9daebe43b9
Replace underscore with space in arbitrary values (#5460)
* refactor dropShadow plugin, use `matchUtilities`

* replace `_` with ` ` for arbitrary values

* remove custom `asList` function

* do not replace escaped underscores with spaces
2021-09-09 18:10:04 +02:00

37 lines
1 KiB
JavaScript

import postcss from 'postcss'
export default function transformThemeValue(themeSection) {
if (['fontSize', 'outline'].includes(themeSection)) {
return (value) => (Array.isArray(value) ? value[0] : value)
}
if (
[
'fontFamily',
'boxShadow',
'transitionProperty',
'transitionDuration',
'transitionDelay',
'transitionTimingFunction',
'backgroundImage',
'backgroundSize',
'backgroundColor',
'cursor',
'animation',
].includes(themeSection)
) {
return (value) => (Array.isArray(value) ? value.join(', ') : value)
}
// For backwards compatibility reasons, before we switched to underscores
// instead of commas for arbitrary values.
if (['gridTemplateColumns', 'gridTemplateRows', 'objectPosition'].includes(themeSection)) {
return (value) => (typeof value === 'string' ? postcss.list.comma(value).join(' ') : value)
}
if (themeSection === 'colors') {
return (value) => (typeof value === 'function' ? value({}) : value)
}
return (value) => value
}