Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
adds text-wrap, text-nowrap to align with tailwindlabs/tailwindcss#11320
Browse files Browse the repository at this point in the history
  • Loading branch information
themaxgross committed Jan 15, 2024
1 parent 8054785 commit d2632af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

Adds utilty classes for `text-wrap: balance` and `text-wrap: pretty` in Tailwind CSS.

This plugin is intended to act as a stepping stone until tailwindcss supports `text-wrap: balance` natively.
It aims to act as a drop-in
for [tailwindcss pull request #11320](https://github.com/tailwindlabs/tailwindcss/pull/11320).

See the [Chrome Developers Blog](https://developer.chrome.com/blog/css-text-wrap-balance/) for more
information about `text-wrap: balance` in CSS and why it's useful.

Expand All @@ -25,7 +29,7 @@ module.exports = {
}
```

This plugin generates the following utilities:
This plugin generates the following utilities when the classes are used:

```css
.text-balance {
Expand All @@ -35,6 +39,14 @@ This plugin generates the following utilities:
.text-pretty {
text-wrap: pretty;
}

.text-wrap {
text-wrap: wrap;
}

.text-nowrap {
text-wrap: nowrap;
}
```

Not all browsers support `text-wrap: balance` yet. You can use the
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const textBalance = plugin(function({ addUtilities }) {
'.text-pretty': {
'text-wrap': 'pretty',
},
'.text-wrap': { 'text-wrap': 'wrap' },
'.text-nowrap': { 'text-wrap': 'nowrap' },
})
})

Expand Down
28 changes: 20 additions & 8 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,34 @@ it('should output the text-wrap:pretty css', async () => {
`)
})

// skipping this test because the actual output is doubled, and I don't know why
it.skip('should output the text-wrap:balance and text-wrap:pretty css', async () => {
it('should output the text-wrap:wrap css', async () => {
const { css } = await postcss([
require('tailwindcss')({
content: [{ raw: 'text-balance text-pretty' }],
content: [{ raw: 'text-wrap' }],
plugins: [plugin],
corePlugins: { preflight: false },
}),
]).process('@tailwind utilities;', { from: undefined })

expect(css).toMatchInlineSnapshot(`
".text-balance {
text-wrap: balance
}
.text-pretty {
text-wrap: pretty
".text-wrap {
text-wrap: wrap
}"
`)
})

it('should output the text-wrap:nowrap css', async () => {
const { css } = await postcss([
require('tailwindcss')({
content: [{ raw: 'text-nowrap' }],
plugins: [plugin],
corePlugins: { preflight: false },
}),
]).process('@tailwind utilities;', { from: undefined })

expect(css).toMatchInlineSnapshot(`
".text-nowrap {
text-wrap: nowrap
}"
`)
})

0 comments on commit d2632af

Please sign in to comment.