Skip to content

Commit 128aafa

Browse files
committed
Don’t unconditionally convert config keys to kebab-case
1 parent 3d899f7 commit 128aafa

File tree

3 files changed

+124
-7
lines changed

3 files changed

+124
-7
lines changed

packages/tailwindcss/src/compat/apply-config-to-theme.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ test('config values can be merged into the theme', () => {
118118
])
119119
expect(theme.resolve('2xl', ['--text'])).toEqual('2rem')
120120
expect(theme.resolveWith('2xl', ['--text'], ['--line-height'])).toEqual(['2rem', {}])
121-
expect(theme.resolve('super-wide', ['--tracking'])).toEqual('0.25em')
122-
expect(theme.resolve('super-loose', ['--leading'])).toEqual('3')
121+
expect(theme.resolve('superWide', ['--tracking'])).toEqual('0.25em')
122+
expect(theme.resolve('superLoose', ['--leading'])).toEqual('3')
123123
expect(theme.resolve('1/2', ['--width'])).toEqual('60%')
124124
expect(theme.resolve('0.5', ['--width'])).toEqual('60%')
125125
expect(theme.resolve('100%', ['--width'])).toEqual('100%')

packages/tailwindcss/src/compat/apply-config-to-theme.ts

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,81 @@ export function keyPathToCssProperty(path: string[]) {
169169
if (path[0] === 'screens') path[0] = 'breakpoint'
170170
if (path[0] === 'transitionTimingFunction') path[0] = 'ease'
171171

172+
if (path[0] == 'accentColor') path[0] = 'accent-color'
173+
if (path[0] == 'backdropBlur') path[0] = 'backdrop-blur'
174+
if (path[0] == 'backdropBrightness') path[0] = 'backdrop-brightness'
175+
if (path[0] == 'backdropContrast') path[0] = 'backdrop-contrast'
176+
if (path[0] == 'backdropGrayscale') path[0] = 'backdrop-grayscale'
177+
if (path[0] == 'backdropHueRotate') path[0] = 'backdrop-hue-rotate'
178+
if (path[0] == 'backdropInvert') path[0] = 'backdrop-invert'
179+
if (path[0] == 'backdropOpacity') path[0] = 'backdrop-opacity'
180+
if (path[0] == 'backdropSaturate') path[0] = 'backdrop-saturate'
181+
if (path[0] == 'backdropSepia') path[0] = 'backdrop-sepia'
182+
if (path[0] == 'backgroundColor') path[0] = 'background-color'
183+
if (path[0] == 'backgroundOpacity') path[0] = 'background-opacity'
184+
if (path[0] == 'borderColor') path[0] = 'border-color'
185+
if (path[0] == 'borderOpacity') path[0] = 'border-opacity'
186+
if (path[0] == 'borderSpacing') path[0] = 'border-spacing'
187+
if (path[0] == 'boxShadowColor') path[0] = 'box-shadow-color'
188+
if (path[0] == 'caretColor') path[0] = 'caret-color'
189+
if (path[0] == 'divideColor') path[0] = 'divide-color'
190+
if (path[0] == 'divideOpacity') path[0] = 'divide-opacity'
191+
if (path[0] == 'divideWidth') path[0] = 'divide-width'
192+
if (path[0] == 'flexBasis') path[0] = 'flex-basis'
193+
if (path[0] == 'gradientColorStops') path[0] = 'gradient-color-stops'
194+
if (path[0] == 'maxHeight') path[0] = 'max-height'
195+
if (path[0] == 'minHeight') path[0] = 'min-height'
196+
if (path[0] == 'minWidth') path[0] = 'min-width'
197+
if (path[0] == 'outlineColor') path[0] = 'outline-color'
198+
if (path[0] == 'placeholderColor') path[0] = 'placeholder-color'
199+
if (path[0] == 'placeholderOpacity') path[0] = 'placeholder-opacity'
200+
if (path[0] == 'ringColor') path[0] = 'ring-color'
201+
if (path[0] == 'ringOffsetColor') path[0] = 'ring-offset-color'
202+
if (path[0] == 'ringOpacity') path[0] = 'ring-opacity'
203+
if (path[0] == 'scrollMargin') path[0] = 'scroll-margin'
204+
if (path[0] == 'scrollPadding') path[0] = 'scroll-padding'
205+
if (path[0] == 'textColor') path[0] = 'text-color'
206+
if (path[0] == 'textDecorationColor') path[0] = 'text-decoration-color'
207+
if (path[0] == 'textIndent') path[0] = 'text-indent'
208+
if (path[0] == 'textOpacity') path[0] = 'text-opacity'
209+
if (path[0] == 'backgroundImage') path[0] = 'background-image'
210+
if (path[0] == 'backgroundPosition') path[0] = 'background-position'
211+
if (path[0] == 'backgroundSize') path[0] = 'background-size'
212+
if (path[0] == 'borderWidth') path[0] = 'border-width'
213+
if (path[0] == 'dropShadow') path[0] = 'drop-shadow'
214+
if (path[0] == 'flexGrow') path[0] = 'flex-grow'
215+
if (path[0] == 'flexShrink') path[0] = 'flex-shrink'
216+
if (path[0] == 'fontWeight') path[0] = 'font-weight'
217+
if (path[0] == 'gradientColorStopPositions') path[0] = 'gradient-color-stop-positions'
218+
if (path[0] == 'gridAutoColumns') path[0] = 'grid-auto-columns'
219+
if (path[0] == 'gridAutoRows') path[0] = 'grid-auto-rows'
220+
if (path[0] == 'gridColumn') path[0] = 'grid-column'
221+
if (path[0] == 'gridColumnEnd') path[0] = 'grid-column-end'
222+
if (path[0] == 'gridColumnStart') path[0] = 'grid-column-start'
223+
if (path[0] == 'gridRow') path[0] = 'grid-row'
224+
if (path[0] == 'gridRowEnd') path[0] = 'grid-row-end'
225+
if (path[0] == 'gridRowStart') path[0] = 'grid-row-start'
226+
if (path[0] == 'gridTemplateColumns') path[0] = 'grid-template-columns'
227+
if (path[0] == 'gridTemplateRows') path[0] = 'grid-template-rows'
228+
if (path[0] == 'hueRotate') path[0] = 'hue-rotate'
229+
if (path[0] == 'listStyleType') path[0] = 'list-style-type'
230+
if (path[0] == 'listStyleImage') path[0] = 'list-style-image'
231+
if (path[0] == 'lineClamp') path[0] = 'line-clamp'
232+
if (path[0] == 'objectPosition') path[0] = 'object-position'
233+
if (path[0] == 'outlineOffset') path[0] = 'outline-offset'
234+
if (path[0] == 'outlineWidth') path[0] = 'outline-width'
235+
if (path[0] == 'ringOffsetWidth') path[0] = 'ring-offset-width'
236+
if (path[0] == 'ringWidth') path[0] = 'ring-width'
237+
if (path[0] == 'strokeWidth') path[0] = 'stroke-width'
238+
if (path[0] == 'textDecorationThickness') path[0] = 'text-decoration-thickness'
239+
if (path[0] == 'textUnderlineOffset') path[0] = 'text-underline-offset'
240+
if (path[0] == 'transformOrigin') path[0] = 'transform-origin'
241+
if (path[0] == 'transitionDelay') path[0] = 'transition-delay'
242+
if (path[0] == 'transitionDuration') path[0] = 'transition-duration'
243+
if (path[0] == 'transitionProperty') path[0] = 'transition-property'
244+
if (path[0] == 'willChange') path[0] = 'will-change'
245+
if (path[0] == 'zIndex') path[0] = 'z-index'
246+
172247
for (let part of path) {
173248
if (!IS_VALID_KEY.test(part)) return null
174249
}
@@ -185,11 +260,16 @@ export function keyPathToCssProperty(path: string[]) {
185260
.map((path, idx, all) => (path === '1' && idx !== all.length - 1 ? '' : path))
186261

187262
// Resolve the key path to a CSS variable segment
188-
.map((part) =>
189-
part
190-
.replaceAll('.', '_')
191-
.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}-${b.toLowerCase()}`),
192-
)
263+
.map((part) => {
264+
part = part.replaceAll('.', '_')
265+
266+
if (part === 'lineHeight') return 'line-height'
267+
if (part.startsWith('-')) {
268+
part = part.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}-${b.toLowerCase()}`)
269+
}
270+
271+
return part
272+
})
193273

194274
// Remove the `DEFAULT` key at the end of a path
195275
// We're reading from CSS anyway so it'll be a string

packages/tailwindcss/src/index.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5935,6 +5935,43 @@ describe('`@property` polyfill', async () => {
59355935
}"
59365936
`)
59375937
})
5938+
5939+
// TODO: Move test into compat folder
5940+
it('camel case keys are preserved', async () => {
5941+
await expect(
5942+
compileCss(
5943+
css`
5944+
@tailwind utilities;
5945+
@theme {
5946+
--color-blue-green: slate;
5947+
}
5948+
@config "./plugin.js";
5949+
`,
5950+
['bg-lightGreen', 'bg-blue-green', 'bg-blueGreen'],
5951+
{
5952+
loadModule: async () => {
5953+
return {
5954+
base: '/',
5955+
path: '',
5956+
module: {
5957+
theme: {
5958+
extend: {
5959+
backgroundColor: {
5960+
lightGreen: '#c0ffee',
5961+
},
5962+
},
5963+
},
5964+
},
5965+
}
5966+
},
5967+
},
5968+
),
5969+
).resolves.toMatchInlineSnapshot(`
5970+
".bg-lightGreen {
5971+
background-color: #c0ffee;
5972+
}"
5973+
`)
5974+
})
59385975
})
59395976

59405977
describe('feature detection', () => {

0 commit comments

Comments
 (0)