Skip to content

Commit 15ae28a

Browse files
committed
Fix issue where using theme with default line-heights did not resolve correctly
1 parent a2c6dcc commit 15ae28a

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

__tests__/processPlugins.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,3 +2050,65 @@ test('keyframes are not escaped', () => {
20502050
}
20512051
`)
20522052
})
2053+
2054+
test('font sizes are retrieved without default line-heights or letter-spacing using theme function', () => {
2055+
const { components } = processPlugins(
2056+
[
2057+
function({ addComponents, theme }) {
2058+
addComponents({
2059+
'.foo': {
2060+
fontSize: theme('fontSize.sm'),
2061+
},
2062+
})
2063+
},
2064+
],
2065+
makeConfig({
2066+
theme: {
2067+
fontSize: {
2068+
sm: ['14px', '20px'],
2069+
},
2070+
},
2071+
})
2072+
)
2073+
2074+
expect(css(components)).toMatchCss(`
2075+
@layer components {
2076+
@variants {
2077+
.foo {
2078+
font-size: 14px;
2079+
}
2080+
}
2081+
}
2082+
`)
2083+
})
2084+
2085+
test('outlines are retrieved without outline-offset using theme function', () => {
2086+
const { components } = processPlugins(
2087+
[
2088+
function({ addComponents, theme }) {
2089+
addComponents({
2090+
'.foo': {
2091+
outline: theme('outline.black'),
2092+
},
2093+
})
2094+
},
2095+
],
2096+
makeConfig({
2097+
theme: {
2098+
outline: {
2099+
black: ['2px dotted black', '4px'],
2100+
},
2101+
},
2102+
})
2103+
)
2104+
2105+
expect(css(components)).toMatchCss(`
2106+
@layer components {
2107+
@variants {
2108+
.foo {
2109+
outline: 2px dotted black;
2110+
}
2111+
}
2112+
}
2113+
`)
2114+
})

__tests__/themeFunction.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,24 @@ test('font sizes are retrieved without default line-heights or letter-spacing',
154154
expect(result.warnings().length).toBe(0)
155155
})
156156
})
157+
158+
test('outlines are retrieved without default outline-offset', () => {
159+
const input = `
160+
.element { outline: theme('outline.black'); }
161+
`
162+
163+
const output = `
164+
.element { outline: 2px dotted black; }
165+
`
166+
167+
return run(input, {
168+
theme: {
169+
outline: {
170+
black: ['2px dotted black', '4px'],
171+
},
172+
},
173+
}).then(result => {
174+
expect(result.css).toMatchCss(output)
175+
expect(result.warnings().length).toBe(0)
176+
})
177+
})

src/lib/evaluateTailwindFunctions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const themeTransforms = {
55
fontSize(value) {
66
return Array.isArray(value) ? value[0] : value
77
},
8+
outline(value) {
9+
return Array.isArray(value) ? value[0] : value
10+
},
811
}
912

1013
function defaultTransform(value) {

src/util/processPlugins.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ export default function(plugins, config) {
5454
handler({
5555
postcss,
5656
config: getConfigValue,
57-
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue),
57+
theme: (path, defaultValue) => {
58+
const value = getConfigValue(`theme.${path}`, defaultValue)
59+
const [rootPath] = _.toPath(path)
60+
61+
if (['fontSize', 'outline'].includes(rootPath)) {
62+
return Array.isArray(value) ? value[0] : value
63+
}
64+
65+
return value
66+
},
5867
corePlugins: path => {
5968
if (Array.isArray(config.corePlugins)) {
6069
return config.corePlugins.includes(path)

0 commit comments

Comments
 (0)