Giter Site home page Giter Site logo

tw-in-js / twind-line-clamp Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 0.0 25 KB

A Twind extension that provides utilities for visually truncating text after a fixed number of lines.

License: MIT License

TypeScript 100.00%
twind twind-extension tailwindcss twind-plugin

twind-line-clamp's Introduction

@twind/line-clamp

A Twind extension that provides utilities for visually truncating text after a fixed number of lines.

MIT License Latest Release Github Module Size Typescript

Based on @tailwindcss/line-clamp.

Installation

Install from npm:

# Using npm
npm install @twind/line-clamp

# Using Yarn
yarn add @twind/line-clamp

Usage as Directive

Use the lineClamp(lines) function to specify how many lines of text should be visible before truncating:

import { lineClamp } from '@twind/line-clamp'

document.body.innerHTML = `
  <p class="${tw`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.
  </p>
`

To remove any line-clamping, use lineClamp('none'):

document.body.innerHTML = `
  <p class="${tw`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.
  </p>
`

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:

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:

<p class="line-clamp-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.
</p>

To remove any line-clamping, use line-clamp-none:

<p class="line-clamp-3 md:line-clamp-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.
</p>

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.

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

License

MIT

twind-line-clamp's People

Contributors

sastan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

twind-line-clamp's Issues

plugins for deno

trying to write a micro-blog service with Fresh. twind is the recommended css-in-js solution. it's working great so far, just would like access to certain plugins, like this one. am i just being dumb? i cannot find documentation for getting external plugins integrated, there's also no package available for deno from what i can tell...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.