A twind plugin that provides utilities for visually truncating text after a fixed number of lines.
npm install @twind/line-clampA plugin for Twind that provides utilities for visually truncating text after a fixed number of lines.





> Based on @tailwindcss/line-clamp.
Install from npm:
``shUsing npm
npm install @twind/line-clamp
Usage as Directive
Use the
lineClamp(lines) function to specify how many lines of text should be visible before truncating:`js
import { lineClamp } from '@twind/line-clamp'document.body.innerHTML =
max-w-xs mx-auto ${lineClamp(3)}}">
Et molestiae hic earum repellat aliquid est doloribus delectus. Enim illum odio porro ut omnis dolor debitis natus. Voluptas possimus deserunt sit delectus est saepe nihil. Qui voluptate possimus et quia. Eligendi voluptas voluptas dolor cum. Rerum est quos quos id ut molestiae fugit.
`To remove any line-clamping, use
lineClamp('none'):`js
document.body.innerHTML = max-w-xs mx-auto ${lineClamp(3)} md:${lineClamp('none')}}">
Et molestiae hic earum repellat aliquid est doloribus delectus. Enim illum odio porro ut omnis dolor debitis natus. Voluptas possimus deserunt sit delectus est saepe nihil. Qui voluptate possimus et quia. Eligendi voluptas voluptas dolor cum. Rerum est quos quos id ut molestiae fugit.
`> Note that the
lineClamp(lines) set other properties like display and overflow in addition to -webkit-line-clamp which are not unset by lineClamp('none'), so depending on what you are trying to achieve you may need to explicitly override those properties with utilities like flex or overflow-visible as well.Usage as Plugin
Add the plugin to plugins of your setup call:
`js
import { lineClamp } from '@twind/line-clamp'setup({
plugins: {
'line-clamp': lineClamp,
},
})
`Use the
line-clamp-{n} utilities to specify how many lines of text should be visible before truncating:`html
Et molestiae hic earum repellat aliquid est doloribus delectus. Enim illum odio porro ut omnis
dolor debitis natus. Voluptas possimus deserunt sit delectus est saepe nihil. Qui voluptate
possimus et quia. Eligendi voluptas voluptas dolor cum. Rerum est quos quos id ut molestiae fugit.
`To remove any line-clamping, use
line-clamp-none:`html
Et molestiae hic earum repellat aliquid est doloribus delectus. Enim illum odio porro ut omnis
dolor debitis natus. Voluptas possimus deserunt sit delectus est saepe nihil. Qui voluptate
possimus et quia. Eligendi voluptas voluptas dolor cum. Rerum est quos quos id ut molestiae fugit.
`Theming
A
lineClamp section is added to the theme. Its values are used for looking up the value. If no value us found the given parameter is used.`js
setup({
theme: {
lineClamp: {
card: '5',
},
},
})tw(lineClamp('card'))
// => -webkit-line-clamp:5
// Not found in theme => use as is
tw(lineClamp('7'))
// => -webkit-line-clamp:7
``