Skip to content

Commit

Permalink
Merge pull request #31 from SpiderDan98/feat/add-leading-shorthand
Browse files Browse the repository at this point in the history
feat: add leading shorthand
  • Loading branch information
davidhellmann authored Mar 25, 2024
2 parents dca7bd3 + 43e10f9 commit 6ed11e7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ export function cn(...inputs: ClassValue[]) {
```

### Overwrite default line-height

Sometimes it may be useful to override the default line height that you set in your config. Therefore, this plugin supports the Tailwind font size line-height shorthand. This works as follows.

```html
<h1 class="text-9xl/snug">The quick brown fox jumps over the lazy dogs</h1>
```

See the [official Tailwind documentation](https://tailwindcss.com/blog/tailwindcss-v3-3#new-line-height-shorthand-for-font-size-utilities) for more information.

## 👉🏻 Live Demo

[Fluid Type Live Demo](https://play.tailwindcss.com/TegGD6vkSM)
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const createThemeOptions = require('./utils/createThemeOptions')

module.exports = plugin.withOptions(
function (options) {
return function ({addUtilities, variants, e}) {
addUtilities(createClasses(options, e),
return function ({addUtilities, variants, e, theme}) {
addUtilities(createClasses(options, e, theme),
variants('fontSizeFluid', defaults.variants));
};
},
Expand Down
7 changes: 3 additions & 4 deletions src/utils/createClasses.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const calcModularScale = require('./calcModularScale')
const createData = require('./createData')
const defaults = require("../config/defaults");
const createLeadingClasses = require('./createLeadingClasses');

module.exports = (options, e) => {
module.exports = (options, e, theme) => {
const data = createData(options, {}, defaults)

if (data.values) {
Expand Down Expand Up @@ -47,9 +48,7 @@ module.exports = (options, e) => {
}
}

return {
[`.${e(`${data.prefix}text-${key}`)}`]: output,
}
return createLeadingClasses(`.${e(`${data.prefix}text-${key}`)}`, output, e, theme)
})
}
}
15 changes: 15 additions & 0 deletions src/utils/createLeadingClasses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = (className, output, e, theme) => {
const lineHeights = theme('lineHeight')

const defaultClass = {
[className]: output,
}

return Object.entries(lineHeights).reduce((classes, [name, lineHeight]) => ({
...classes,
[`${className}${e(`/${name}`)}`]: {
...output,
lineHeight,
}
}), defaultClass)
}

0 comments on commit 6ed11e7

Please sign in to comment.