npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-shears

v1.0.3

Published

Trim text with ease!

Downloads

7

Readme

react-shears

npm npm bundle size GitHub stars

✂️ Multiline ellipsis for text ... that refreshes on window resize. Just define a maximum height!

Demo with resizing browser

react-shears places an ellipsis (...) in your text! All you have to do is define a maximum height and the component takes care of the rest.

Other benefits

  • Fits as much text in as possible. This is because it uses a binary search as well as a per-character fitting algorithm.

  • Accessible. Text that is hidden is still visible to screen readers and the ellipsis is hidden away.

  • Browser compatibility. Supports IE >= 8 by default. If you use the built-in fade effect (fadeInDuration), it uses CSS transition which is IE >= 10.


Get some shears!

npm i react-shears
yarn add react-shears

Note: Your project must support the use of React Hooks. (React >= 16.8.0)

Example usage

import Shears from 'react-shears'

<Shears
  maxHeight={ 42 }
  text={ title }
  tag="p"
  className="title"
  fadeInDuration={ 200 }
  debounceDuration={ 200 }
/>

Props

Option | Type | Default | Description ------ | ---- | ------- | ----------- maxHeight | number of pixels | - | Required. This is how high you want to limit your multiline trimmed text to. text | string | '' | Required. This is the text you want to trim. Strictly strings only, no HTML. tag | string | 'div' | Optional. Customise the HTML tag the <Shears / > component returns. className | string | '' | Optional. A custom class name. fadeInDuration | number of ms | 0 | Optional. Turns on a fade in effect on component mount (done with CSS transition property). debounceDuration | number of ms | 200 | Optional. Change the debounce time if desired.

v1.0.0 Release Notes

  • added options for fade in and debounce durations
  • now dynamically updates with text prop change
  • performance improvements

Limitations

  • Does not handle when the container itself resizes due transforming it's width with say, CSS. It only looks for width changes due to window resize events.
  • Currently only takes pure text input, and will not work with HTML.
  • Developer needs to handle sanitising input on their side.

Contributing & Bugs

PRs, feature requests and bug reports are welcome!