File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
packages/tailwindcss/src/compat Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { createCompatConfig } from './config/create-compat-config'
1010import { resolveConfig } from './config/resolve-config'
1111import type { UserConfig } from './config/types'
1212import { registerContainerCompat } from './container'
13+ import { registerContentCompat } from './content-compat'
1314import { darkModePlugin } from './dark-mode'
1415import { registerLegacyUtilities } from './legacy-utilities'
1516import { 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 ) {
Original file line number Diff line number Diff line change 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+ } )
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments