Skip to content

Commit

Permalink
Add line-clamp utilities from @tailwindcss/line-clamp to core (#1…
Browse files Browse the repository at this point in the history
…0768)

* add `lineClamp` utility

This is coming from the `@tailwindcss/line-clamp` package that we now
merged into the core of Tailwind itself.

* update changelog
  • Loading branch information
RobinMalfait committed Mar 10, 2023
1 parent e40b73a commit 7eab762
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `caption-side` utilities ([#10470](https://github.com/tailwindlabs/tailwindcss/pull/10470))
- Add `justify-normal` and `justify-stretch` utilities ([#10560](https://github.com/tailwindlabs/tailwindcss/pull/10560))
- Add `content-normal` and `content-stretch` utilities ([#10645](https://github.com/tailwindlabs/tailwindcss/pull/10645))
- Add `line-clamp` utilities from `@tailwindcss/line-clamp` to core ([#10768](https://github.com/tailwindlabs/tailwindcss/pull/10768))

### Fixed

Expand Down
18 changes: 18 additions & 0 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,24 @@ export let corePlugins = {
})
},

lineClamp: ({ matchUtilities, addUtilities, theme }) => {
matchUtilities(
{
'line-clamp': (value) => ({
overflow: 'hidden',
display: '-webkit-box',
'-webkit-box-orient': 'vertical',
'-webkit-line-clamp': `${value}`,
}),
},
{ values: theme('lineClamp') }
)

addUtilities({
'.line-clamp-none': { '-webkit-line-clamp': 'unset' },
})
},

display: ({ addUtilities }) => {
addUtilities({
'.block': { display: 'block' },
Expand Down
8 changes: 8 additions & 0 deletions stubs/defaultConfig.stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,14 @@ module.exports = {
auto: 'auto',
...theme('spacing'),
}),
lineClamp: {
1: '1',
2: '2',
3: '3',
4: '4',
5: '5',
6: '6',
},
maxHeight: ({ theme }) => ({
...theme('spacing'),
none: 'none',
Expand Down
45 changes: 45 additions & 0 deletions tests/kitchen-sink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ crosscheck(({ stable, oxide }) => {
content: [
{
raw: html`
<div
class="line-clamp-2 line-clamp-[33] line-clamp-[var(--line-clamp-variable)] line-clamp-none"
></div>
<div class="range:text-right multi:text-left"></div>
<div
class="container hover:container sm:container md:container text-center sm:text-center md:text-center"
Expand Down Expand Up @@ -432,6 +435,27 @@ crosscheck(({ stable, oxide }) => {
.mt-6 {
margin-top: 1.5rem;
}
.line-clamp-2 {
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
display: -webkit-box;
overflow: hidden;
}
.line-clamp-\[33\] {
-webkit-line-clamp: 33;
-webkit-box-orient: vertical;
display: -webkit-box;
overflow: hidden;
}
.line-clamp-\[var\(--line-clamp-variable\)\] {
-webkit-line-clamp: var(--line-clamp-variable);
-webkit-box-orient: vertical;
display: -webkit-box;
overflow: hidden;
}
.line-clamp-none {
-webkit-line-clamp: unset;
}
.scale-50 {
--tw-scale-x: 0.5;
--tw-scale-y: 0.5;
Expand Down Expand Up @@ -976,6 +1000,27 @@ crosscheck(({ stable, oxide }) => {
.mt-6 {
margin-top: 1.5rem;
}
.line-clamp-2 {
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
display: -webkit-box;
overflow: hidden;
}
.line-clamp-\[33\] {
-webkit-line-clamp: 33;
-webkit-box-orient: vertical;
display: -webkit-box;
overflow: hidden;
}
.line-clamp-\[var\(--line-clamp-variable\)\] {
-webkit-line-clamp: var(--line-clamp-variable);
-webkit-box-orient: vertical;
display: -webkit-box;
overflow: hidden;
}
.line-clamp-none {
-webkit-line-clamp: unset;
}
.scale-50 {
--tw-scale-x: 0.5;
--tw-scale-y: 0.5;
Expand Down

0 comments on commit 7eab762

Please sign in to comment.