Skip to content

Commit 79cd4a8

Browse files
committed
migrate theme.data to custom @custom-variant data-* variants
But we will make sure that we skip the ones that would be handled automatically by bare values. E.g.: `data-foo:flex` will generate `[data-foo]`.
1 parent b087751 commit 79cd4a8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/@tailwindcss-upgrade/src/codemods/config/migrate-js-config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ async function migrateTheme(
153153
}
154154
delete resolvedConfig.theme.aria
155155
}
156+
157+
if ('data' in resolvedConfig.theme) {
158+
for (let [key, value] of Object.entries(resolvedConfig.theme.data ?? {})) {
159+
// Will be handled by bare values if the names match.
160+
// E.g.: `data-foo:flex` should produce `[data-foo]`
161+
if (key === value) continue
162+
163+
// Create custom variant
164+
variants.set(`data-${key}`, `&[data-${value}]`)
165+
}
166+
delete resolvedConfig.theme.data
167+
}
156168
}
157169

158170
// Convert theme values to CSS custom properties
@@ -401,7 +413,7 @@ const ALLOWED_THEME_KEYS = [
401413
// Used by @tailwindcss/container-queries
402414
'containers',
403415
]
404-
const BLOCKED_THEME_KEYS = ['supports', 'data']
416+
const BLOCKED_THEME_KEYS = ['supports']
405417
function onlyAllowedThemeValues(theme: ThemeConfig): boolean {
406418
for (let key of Object.keys(theme)) {
407419
if (!ALLOWED_THEME_KEYS.includes(key)) {

0 commit comments

Comments
 (0)