Allow default letterSpacing in fontSize config

Extend the configuration syntax to allow specifying letterSpacing
alongside lineHeight in the fontSize config.

The syntax looks like
```
module.exports = {
  theme: {
    // ...
    fontSize: {
      sm: ['14px', { lineHeight: '20px', letterSpacing: '0.01em' }],
      // ...
    }
  }
}
```

Also retains backwards compatibility with array syntax of 1.3
This commit is contained in:
Dan Wood 2020-06-29 10:10:27 +10:00
parent 2b0b306a77
commit 07e330d2bb

View File

@ -4,7 +4,11 @@ export default function() {
return function({ addUtilities, e, theme, variants }) {
const utilities = _.fromPairs(
_.map(theme('fontSize'), (value, modifier) => {
const [fontSize, lineHeight] = Array.isArray(value) ? value : [value]
const [fontSize, options] = Array.isArray(value) ? value : [value]
// Tailwind 1.3+ syntax allowed line height to be specified in the array like
// ['16px', '24px'], so we can get it from there as well as from object syntax
const lineHeight = options instanceof Object ? options.lineHeight : options
const letterSpacing = options && options.letterSpacing
return [
`.${e(`text-${modifier}`)}`,
@ -15,6 +19,11 @@ export default function() {
: {
'line-height': lineHeight,
}),
...(letterSpacing === undefined
? {}
: {
'letter-spacing': letterSpacing,
}),
},
]
})