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-multi-clamp

v2.0.6

Published

Simple, efficient and easy-to-use multiline text clamp react component. (supports reverse clamp)

Downloads

7,583

Readme

react-multi-clamp npm

Simple, efficient and easy-to-use multiline text clamp react component. (supports reverse clamp)

简单、高效、易用的多行文本裁剪react组件。(支持反向裁剪)

Encapsulation based on multi-clamp module npm

本组件基于multi-clamp模块封装

Samples

Default multiline text clamp:

默认多行文本裁剪效果:

Default multiline text clamp

Custom ellipsis:

自定义省略符号:

Custom ellipsis

Reverse clamp:

反向裁剪:

Reversed clamp

Demo Page

Browser compatibility

Supports IE9+ / Android4.4+ / etc. ES5 enviroment.

支持PC/移动设备所有兼容ES5环境的浏览器。

Installation

You can install react-multi-clamp from npm.

你可以从npm安装react-multi-clamp组件。

npm install react-multi-clamp --save

Usage

Import react-multi-clamp.

引入react-multi-clamp组件。

import MultiClamp from 'react-multi-clamp';

Just wrap the content(must be pure text) in react-multi-clamp component.

将要裁减的内容(必须为纯文本)包裹起来即可。

<MultiClamp ellipsis="..." clamp={3}>{longText}</MultiClamp>

Options

ellipsis: PropTypes.string || PropTypes.element

Ellipsis can be string or react element. default: '...'

超出最大行数裁剪后的符号,可以为字符串或任意react元素。默认为:'...'

clamp: PropTypes.number || 'auto'

The max number of lines to show. It will try to fill up the available space when set to string 'auto', and at this point you should set a static height on the text container element. default: 3

最大行数。设置为字符串'auto'时会根据最大高度自适应裁剪,此时文本容器需要定义高度。默认为:3

reverse: PropTypes.bool

You can clamp the content from back to front, the ellipsis will be in the front. default: false

是否反向裁剪。反向将从后往前裁剪,ellipsis符号会显示在最前面。默认为:false

splitByWords: PropTypes.bool

The default behavior is to split by letters. If you want to split by words, set splitByWords to true. default: false

组件对于英文文本默认按字符进行裁剪。如果希望按单词裁剪,请将splitByWords设置为true。默认为:false

disableCssClamp: PropTypes.bool

React-multi-clamp will use native css clamp(-webkit-line-clamp) in supported browser when the ellipsis is set to '...'. If you don't want to use css clamp, set disableCssClamp to true. default: false

当ellipsis被设置为'...'时,组件会默认优先使用webkit的原生css裁剪(-webkit-line-clamp),如果想禁用css裁减,请将disableCssClamp设置为true。默认为:false

onClampStart: function({ needClamp: boolean }): void || false

This callback function will be executed when clamp starts, and will not be executed when use native css clamp. Clamp will be prevented when return value is false. default: function() {}

该回调函数在clamp开始时触发,使用原生css裁剪时不会触发。返回值为false时强制不进行clamp。默认为:function() {}

onClampEnd: function({ didClamp: boolean }): void

This callback function will be executed when clamp ends, and will not be executed when use native css clamp. default: function() {}

该回调函数在clamp结束时触发,使用原生css裁剪时不会触发。默认为:function() {}

Testing

git clone [email protected]:jackyr/react-multi-clamp.git
cd react-multi-clamp
npm install
npm start

Changelog

v2.0.6

  • Bugfix when text changes immediately after mount. #12
  • mount之后文本立即发生改变时bug修正。 #12

v2.0.5

  • Typescript definitions bugfix. #11
  • ts类型定义bug修正。 #11

v2.0.4

  • Typescript definitions bugfix. #9
  • ts类型定义bug修正。 #9

v2.0.3

  • Add typescript definitions. #8
  • 增加ts类型定义。 #8

v2.0.2

  • Bugfix when passing element object to option ellipsis. #5
  • 裁剪符号为react元素时bug修正。#5

v2.0.1

  • Bugfix when passing element object to option ellipsis. #3
  • 裁剪符号为react元素时bug修正。#3

v2.0.0

License

MIT