Skip to content

konforti/react-truncate

Repository files navigation

✂️ React Truncate

React wrapper for @konforti/truncate

✨ Features

  • Truncate text by number of lines.
  • Truncate form end, start or middle.
  • Responsive truncation.
  • Get notified if a text has been truncated or not.
  • Custom ellipsis.

🔧 Installation

npm i -S @konforti/react-truncate
yarn add @konforti/react-truncate

🔧 Usage

import Truncate from '@konforti/react-truncate';

🔦 Examples

<Truncate truncFrom="middle">{text}</Truncate>
<Truncate lines={3}>{text}</Truncate>
<Truncate ellipsis=">>> " truncFrom="start">
    {text}
</Truncate>
<Truncate
    onTruncate={truncated => {
        if (truncated) {
            setState({ truncated: true });
        }
    }}
>
    {text}
</Truncate>