Skip to content

Commit c009c9c

Browse files
Support the color property in JS theme configuration callbacks (#14651)
While working on some fixes for #14639 I noticed that the following v3 configuration file would not load properly in v4: ```ts import { type Config } from 'tailwindcss' export default { content: ['./src/**/*.{js,jsx,ts,tsx}'], theme: { extend: { colors: ({ colors }) => ({ gray: colors.neutral, }), }, } satisfies Config ``` The reason for this is that we did not pass the `colors` property to the callback function. Since we have colors available now, we can easily add it. --------- Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
1 parent e6d3fa0 commit c009c9c

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Add support for `tailwindcss/colors.js`, `tailwindcss/defaultTheme.js`, and `tailwindcss/plugin.js` exports ([#14595](https://github.com/tailwindlabs/tailwindcss/pull/14595))
1313
- Support `keyframes` in JS config file themes ([#14594](https://github.com/tailwindlabs/tailwindcss/pull/14594))
14+
- Support the `color` parameter in JS theme configuration callbacks ([#14651](https://github.com/tailwindlabs/tailwindcss/pull/14651))
1415
- _Upgrade (experimental)_: Migrate v3 PostCSS setups to v4 in some cases ([#14612](https://github.com/tailwindlabs/tailwindcss/pull/14612))
1516
- _Upgrade (experimental)_: Automatically discover JavaScript config files ([#14597](https://github.com/tailwindlabs/tailwindcss/pull/14597))
1617
- _Upgrade (experimental)_: Migrate legacy classes to the v4 alternative ([#14643](https://github.com/tailwindlabs/tailwindcss/pull/14643))

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ test('theme keys can read from the CSS theme', () => {
198198
// Reads from the --color-* namespace directly
199199
secondary: theme('color.green'),
200200
}),
201+
caretColor: ({ colors }) => ({
202+
// Gives access to the colors object directly
203+
primary: colors.green,
204+
}),
201205
},
202206
},
203207
base: '/root',
@@ -218,6 +222,21 @@ test('theme keys can read from the CSS theme', () => {
218222
primary: 'green',
219223
secondary: 'green',
220224
},
225+
caretColor: {
226+
primary: {
227+
'50': '#f0fdf4',
228+
'100': '#dcfce7',
229+
'200': '#bbf7d0',
230+
'300': '#86efac',
231+
'400': '#4ade80',
232+
'500': '#22c55e',
233+
'600': '#16a34a',
234+
'700': '#15803d',
235+
'800': '#166534',
236+
'900': '#14532d',
237+
'950': '#052e16',
238+
},
239+
},
221240
},
222241
})
223242
})

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DesignSystem } from '../../design-system'
2+
import colors from '../colors'
23
import type { PluginWithConfig } from '../plugin-api'
34
import { createThemeFn } from '../plugin-functions'
45
import { deepMerge, isPlainObject } from './deep-merge'
@@ -117,6 +118,7 @@ export function mergeThemeExtension(
117118

118119
export interface PluginUtils {
119120
theme(keypath: string, defaultValue?: any): any
121+
colors: typeof colors
120122
}
121123

122124
function extractConfigs(ctx: ResolutionContext, { config, base, path }: ConfigFile): void {
@@ -176,6 +178,7 @@ function extractConfigs(ctx: ResolutionContext, { config, base, path }: ConfigFi
176178
function mergeTheme(ctx: ResolutionContext) {
177179
let api: PluginUtils = {
178180
theme: createThemeFn(ctx.design, () => ctx.theme, resolveValue),
181+
colors,
179182
}
180183

181184
function resolveValue(value: ThemeValue | null | undefined): ResolvedThemeValue {

0 commit comments

Comments
 (0)