Skip to content

Commit e9c913a

Browse files
Support JS config to overwrite breakpoints
1 parent d9aad77 commit e9c913a

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ function themeableValues(config: ResolvedConfig['theme']): [string[], unknown][]
111111
}
112112

113113
function keyPathToCssProperty(path: string[]) {
114-
if (path[0] === 'colors') {
115-
path[0] = 'color'
116-
}
114+
if (path[0] === 'colors') path[0] = 'color'
115+
if (path[0] === 'screens') path[0] = 'breakpoint'
117116

118117
return (
119118
path

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22
import { compile } from '..'
33
import plugin from '../plugin'
44
import { flattenColorPalette } from './flatten-color-palette'
@@ -978,3 +978,65 @@ describe('default font family compatibility', () => {
978978
`)
979979
})
980980
})
981+
982+
test('merges css breakpoints with js config screens', async () => {
983+
let input = css`
984+
@theme default {
985+
--breakpoint-sm: 40rem;
986+
--breakpoint-md: 48rem;
987+
--breakpoint-lg: 64rem;
988+
--breakpoint-xl: 80rem;
989+
--breakpoint-2xl: 96rem;
990+
}
991+
@theme {
992+
--breakpoint-md: 50rem;
993+
}
994+
@config "./config.js";
995+
@tailwind utilities;
996+
`
997+
998+
let compiler = await compile(input, {
999+
loadConfig: async () => ({
1000+
theme: {
1001+
extend: {
1002+
screens: {
1003+
sm: '44rem',
1004+
},
1005+
},
1006+
},
1007+
}),
1008+
})
1009+
1010+
expect(compiler.build(['sm:flex', 'md:flex', 'lg:flex', 'min-sm:max-md:underline']))
1011+
.toMatchInlineSnapshot(`
1012+
":root {
1013+
--breakpoint-md: 50rem;
1014+
--breakpoint-lg: 64rem;
1015+
--breakpoint-xl: 80rem;
1016+
--breakpoint-2xl: 96rem;
1017+
}
1018+
.sm\\:flex {
1019+
@media (width >= 44rem) {
1020+
display: flex;
1021+
}
1022+
}
1023+
.min-sm\\:max-md\\:underline {
1024+
@media (width >= 44rem) {
1025+
@media (width < 50rem) {
1026+
text-decoration-line: underline;
1027+
}
1028+
}
1029+
}
1030+
.md\\:flex {
1031+
@media (width >= 50rem) {
1032+
display: flex;
1033+
}
1034+
}
1035+
.lg\\:flex {
1036+
@media (width >= 64rem) {
1037+
display: flex;
1038+
}
1039+
}
1040+
"
1041+
`)
1042+
})

packages/tailwindcss/src/compat/default-theme.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -883,11 +883,11 @@ export default {
883883
...barePercentages,
884884
},
885885
screens: {
886-
sm: '640px',
887-
md: '768px',
888-
lg: '1024px',
889-
xl: '1280px',
890-
'2xl': '1536px',
886+
sm: '40rem',
887+
md: '48rem',
888+
lg: '64rem',
889+
xl: '80rem',
890+
'2xl': '96rem',
891891
},
892892
scrollMargin: ({ theme }) => theme('spacing'),
893893
scrollPadding: ({ theme }) => theme('spacing'),

0 commit comments

Comments
 (0)