Skip to content

Commit 86bdd77

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 536460b commit 86bdd77

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
@@ -152,6 +152,18 @@ async function migrateTheme(
152152
}
153153
delete resolvedConfig.theme.aria
154154
}
155+
156+
if ('data' in resolvedConfig.theme) {
157+
for (let [key, value] of Object.entries(resolvedConfig.theme.data ?? {})) {
158+
// Will be handled by bare values if the names match.
159+
// E.g.: `data-foo:flex` should produce `[data-foo]`
160+
if (key === value) continue
161+
162+
// Create custom variant
163+
variants.set(`data-${key}`, `&[data-${value}]`)
164+
}
165+
delete resolvedConfig.theme.data
166+
}
155167
}
156168

157169
// Convert theme values to CSS custom properties
@@ -389,7 +401,7 @@ const ALLOWED_THEME_KEYS = [
389401
// Used by @tailwindcss/container-queries
390402
'containers',
391403
]
392-
const BLOCKED_THEME_KEYS = ['supports', 'data']
404+
const BLOCKED_THEME_KEYS = ['supports']
393405
function onlyAllowedThemeValues(theme: ThemeConfig): boolean {
394406
for (let key of Object.keys(theme)) {
395407
if (!ALLOWED_THEME_KEYS.includes(key)) {

0 commit comments

Comments
 (0)