Skip to content

Commit 5ef6ac9

Browse files
committed
Add compat layer for theme.content config
1 parent e26a0eb commit 5ef6ac9

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

packages/tailwindcss/src/compat/apply-compat-hooks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createCompatConfig } from './config/create-compat-config'
1010
import { resolveConfig } from './config/resolve-config'
1111
import type { UserConfig } from './config/types'
1212
import { registerContainerCompat } from './container'
13+
import { registerContentCompat } from './content-compat'
1314
import { darkModePlugin } from './dark-mode'
1415
import { registerLegacyUtilities } from './legacy-utilities'
1516
import { buildPluginApi, type CssPluginOptions, type Plugin } from './plugin-api'
@@ -358,6 +359,7 @@ function upgradeToFullPluginSupport({
358359
registerThemeVariantOverrides(resolvedUserConfig, designSystem)
359360
registerScreensConfig(resolvedUserConfig, designSystem)
360361
registerContainerCompat(resolvedUserConfig, designSystem)
362+
registerContentCompat(resolvedUserConfig, designSystem)
361363

362364
// If a prefix has already been set in CSS don't override it
363365
if (!designSystem.theme.prefix && resolvedConfig.prefix) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { expect, test } from 'vitest'
2+
import { compile } from '..'
3+
4+
const css = String.raw
5+
6+
test('creates custom utilities to represent content keys', async () => {
7+
let input = css`
8+
@config "./config.js";
9+
@tailwind utilities;
10+
`
11+
12+
let compiler = await compile(input, {
13+
loadModule: async () => ({
14+
base: '/root',
15+
path: '',
16+
module: {
17+
theme: {
18+
content: {
19+
slash: '"/"',
20+
},
21+
},
22+
},
23+
}),
24+
})
25+
26+
expect(compiler.build(['content-slash'])).toMatchInlineSnapshot(`
27+
".content-slash {
28+
--tw-content: "/";
29+
content: var(--tw-content);
30+
}
31+
"
32+
`)
33+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { decl } from '../ast'
2+
import type { DesignSystem } from '../design-system'
3+
import type { ResolvedConfig } from './config/types'
4+
5+
export function registerContentCompat(userConfig: ResolvedConfig, designSystem: DesignSystem) {
6+
let content = userConfig.theme.content || {}
7+
8+
if (typeof content !== 'object' || content === null) return
9+
10+
for (let [key, value] of Object.entries(content)) {
11+
if (typeof value !== 'string') continue
12+
13+
designSystem.utilities.static(`content-${key}`, () => [
14+
decl('--tw-content', value),
15+
decl('content', 'var(--tw-content)'),
16+
])
17+
}
18+
}

0 commit comments

Comments
 (0)