Skip to content

Commit 04e533b

Browse files
Callback in theme properties is also the theme function
1 parent c009c9c commit 04e533b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/tailwindcss/src/compat/config/resolve-config.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ test('theme keys can read from the CSS theme', () => {
202202
// Gives access to the colors object directly
203203
primary: colors.green,
204204
}),
205+
transitionColor: (theme) => ({
206+
// The parameter object is also the theme function
207+
...theme('colors'),
208+
}),
205209
},
206210
},
207211
base: '/root',
@@ -237,6 +241,10 @@ test('theme keys can read from the CSS theme', () => {
237241
'950': '#052e16',
238242
},
239243
},
244+
transitionColor: {
245+
red: 'red',
246+
green: 'green',
247+
},
240248
},
241249
})
242250
})

packages/tailwindcss/src/compat/config/resolve-config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ export function mergeThemeExtension(
116116
return undefined
117117
}
118118

119-
export interface PluginUtils {
120-
theme(keypath: string, defaultValue?: any): any
119+
type ThemeFunction = (keypath: string, defaultValue?: any) => any
120+
export type PluginUtils = ThemeFunction & {
121+
theme: ThemeFunction
121122
colors: typeof colors
122123
}
123124

@@ -176,14 +177,16 @@ function extractConfigs(ctx: ResolutionContext, { config, base, path }: ConfigFi
176177
}
177178

178179
function mergeTheme(ctx: ResolutionContext) {
180+
let theme = createThemeFn(ctx.design, () => ctx.theme, resolveValue)
179181
let api: PluginUtils = {
180-
theme: createThemeFn(ctx.design, () => ctx.theme, resolveValue),
182+
theme,
181183
colors,
182184
}
185+
Object.assign(theme, api)
183186

184187
function resolveValue(value: ThemeValue | null | undefined): ResolvedThemeValue {
185188
if (typeof value === 'function') {
186-
return value(api) ?? null
189+
return value(theme) ?? null
187190
}
188191

189192
return value ?? null

0 commit comments

Comments
 (0)