Skip to content

Commit

Permalink
Fix issue where using theme with default line-heights did not resol…
Browse files Browse the repository at this point in the history
…ve correctly
  • Loading branch information
adamwathan committed Oct 19, 2020
1 parent a2c6dcc commit 15ae28a
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
62 changes: 62 additions & 0 deletions __tests__/processPlugins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2050,3 +2050,65 @@ test('keyframes are not escaped', () => {
}
`)
})

test('font sizes are retrieved without default line-heights or letter-spacing using theme function', () => {
const { components } = processPlugins(
[
function({ addComponents, theme }) {
addComponents({
'.foo': {
fontSize: theme('fontSize.sm'),
},
})
},
],
makeConfig({
theme: {
fontSize: {
sm: ['14px', '20px'],
},
},
})
)

expect(css(components)).toMatchCss(`
@layer components {
@variants {
.foo {
font-size: 14px;
}
}
}
`)
})

test('outlines are retrieved without outline-offset using theme function', () => {
const { components } = processPlugins(
[
function({ addComponents, theme }) {
addComponents({
'.foo': {
outline: theme('outline.black'),
},
})
},
],
makeConfig({
theme: {
outline: {
black: ['2px dotted black', '4px'],
},
},
})
)

expect(css(components)).toMatchCss(`
@layer components {
@variants {
.foo {
outline: 2px dotted black;
}
}
}
`)
})
21 changes: 21 additions & 0 deletions __tests__/themeFunction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,24 @@ test('font sizes are retrieved without default line-heights or letter-spacing',
expect(result.warnings().length).toBe(0)
})
})

test('outlines are retrieved without default outline-offset', () => {
const input = `
.element { outline: theme('outline.black'); }
`

const output = `
.element { outline: 2px dotted black; }
`

return run(input, {
theme: {
outline: {
black: ['2px dotted black', '4px'],
},
},
}).then(result => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
})
})
3 changes: 3 additions & 0 deletions src/lib/evaluateTailwindFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const themeTransforms = {
fontSize(value) {
return Array.isArray(value) ? value[0] : value
},
outline(value) {
return Array.isArray(value) ? value[0] : value
},
}

function defaultTransform(value) {
Expand Down
11 changes: 10 additions & 1 deletion src/util/processPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ export default function(plugins, config) {
handler({
postcss,
config: getConfigValue,
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue),
theme: (path, defaultValue) => {
const value = getConfigValue(`theme.${path}`, defaultValue)
const [rootPath] = _.toPath(path)

if (['fontSize', 'outline'].includes(rootPath)) {
return Array.isArray(value) ? value[0] : value
}

return value
},
corePlugins: path => {
if (Array.isArray(config.corePlugins)) {
return config.corePlugins.includes(path)
Expand Down

0 comments on commit 15ae28a

Please sign in to comment.