All Projects → vivaxy → react-text-more-less

vivaxy / react-text-more-less

Licence: MIT License
📃React component to show more text or show less

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to react-text-more-less

ngx-line-truncation
An Angular line truncating solution. Truncate text block by given line number and add ellipsis to the end.
Stars: ✭ 13 (-18.75%)
Mutual labels:  truncate, shave
react-nft-gallery
🖼️ React component to display your NFTs as a gallery
Stars: ✭ 50 (+212.5%)
Mutual labels:  react-component
react-touch-ripple
Create ripple effect from Material Design with React
Stars: ✭ 27 (+68.75%)
Mutual labels:  react-component
react-liff
A react context provider for LIFF (LINE Front-end Framework)
Stars: ✭ 22 (+37.5%)
Mutual labels:  react-component
react-fake-component
Chuck Norris faking components
Stars: ✭ 24 (+50%)
Mutual labels:  react-component
react-quick-pinch-zoom
A react component that providing multi-touch gestures for zooming and dragging on any DOM element.
Stars: ✭ 124 (+675%)
Mutual labels:  react-component
react-carousel-minimal
React.js Responsive Minimal Carousel
Stars: ✭ 76 (+375%)
Mutual labels:  react-component
react-duotone
React Duotone Component
Stars: ✭ 26 (+62.5%)
Mutual labels:  react-component
react-taggy
A simple zero-dependency React component for tagging user-defined entities within a block of text.
Stars: ✭ 29 (+81.25%)
Mutual labels:  react-component
react-form-base
Base React component for generic forms
Stars: ✭ 18 (+12.5%)
Mutual labels:  react-component
mighty-input
Text input for modern web
Stars: ✭ 20 (+25%)
Mutual labels:  react-component
markdown-navbar
Best markdown navigation bar for React.
Stars: ✭ 122 (+662.5%)
Mutual labels:  react-component
candy mobile
No description or website provided.
Stars: ✭ 16 (+0%)
Mutual labels:  react-component
react-instagram-authless-feed
React component to provide a token-less Instagram feed.
Stars: ✭ 50 (+212.5%)
Mutual labels:  react-component
react-video-players
📺 Library of React video player components that offer a consistent interface and callback system for Vimeo, YouTube and the <video> tag. Along with a handy higher order component for building your own 😉
Stars: ✭ 13 (-18.75%)
Mutual labels:  react-component
tailwindcss-truncate-multiline
Tailwind CSS plugin to generate truncate multiline utilities
Stars: ✭ 92 (+475%)
Mutual labels:  truncate
strings-truncation
Truncate strings with fullwidth characters and ANSI codes.
Stars: ✭ 45 (+181.25%)
Mutual labels:  truncate
font-picker-react
✏️ Font selector component for Google Fonts
Stars: ✭ 126 (+687.5%)
Mutual labels:  react-component
react-middle-ellipsis
Truncate a long string in the middle, instead of the end.
Stars: ✭ 44 (+175%)
Mutual labels:  react-component
termy-the-terminal
Web-based terminal powered by React
Stars: ✭ 43 (+168.75%)
Mutual labels:  react-component

react-text-more-less

NPM Version NPM Downloads MIT License Conventional Commits

Initialized by vivaxy/gt-npm-package.

Based on dollarshaveclub/shave.

See demo.

Installation

npm install react-text-more-less

yarn add react-text-more-less

Usage

import React, { Component } from 'react';
import ReactTextMoreLess from 'react-text-more-less';

class Demo extends Component {
  state = {
    collapsed: true,
  };

  render() {
    const { collapsed } = this.state;
    return (
      <ReactTextMoreLess
        collapsed={collapsed}
        text="1926年1—6月,他一连发表了四篇论文,题目都是《量子化就是本征值问题》,系统地阐明了波动力学理论。在此以前,德国物理学家W.K.海森堡、M.玻恩和E.P.约旦于1925年7—9月通过另一途径建立了矩阵力学。1926年3月,薛定谔发现波动力学和矩阵力学在数学上是等价的,是量子力学的两种形式,可以通过数学变换,从一个理论转到另一个理论。薛定谔起初试图把波函数解释为三维空间中的振动,把振幅解释为电荷密度,把粒子解释为波包。但他无法解决“波包扩散”的困难。最后物理学界普遍接受了玻恩提出的波函数的几率解释。"
        lessHeight={72}
        showMoreText="... 展示更多"
        showMoreElement={
          <span>
            ... <span className="show-more-text">展示更多</span>
          </span>
        }
        showLessElement={<span className="show-more-text">收起</span>}
        onClick={() => {
          this.setState({ collapsed: !collapsed });
        }}
      />
    );
  }
}

If you like to prevent collapse on user select, add this before setting collapsed.

const selection = window.getSelection();
if (!selection.toString()) {
  /* Set `collapsed` prop */
}

Props

name type isRequired default description
text string N/A text in the container Be careful with XSS attacks, #82
lessHeight number N/A container collapsed height
collapsed bool true is the container collapsed according to the lessHeight
className string undefined className of the container
showMoreText string ... the ellipse text to show more
showMoreElement element undefined the element to show when container collapsed
showLessElement element undefined the element to show when container expanded
onClick func () => {} container click handler
rootProps object {} root container props, could be any props a div accepts

If showMoreElement supplied, showMoreText will be replaced, this props is useful when you want to custom showMoreText style or to use a more complex dom structure to display showMoreText.

Related Projects

Change Log

Change Log

Licence

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].