1.1.1 • Published 3 years ago

react-truncate-jsx v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Truncate JSX

You want to ellipsisify some text in your React app but it's encapsulated in a React component.

CodeSandBox DEMO

Installation

npm install react-truncate-jsx

// or 

yarn add react-truncate-jsx

Usage

import React, {forwardRef} from 'react';
import Truncate, {TruncateList} from 'react-truncate-jsx';

const tags = ['Orange', 'Apple', 'Pear', 'Lemon', 'Watermelon'];


const Ellipsis = forwardRef(
    ({moreCount, moreChildren, ...props}, ref) => {
        return (
            <div ref={ref} style={{ flexShrink: 0 }} {...props}>
                +{moreCount} tags
            </div>
        );
    }
);

const App = () => (
    <div style={{width:200}}>
        <Truncate>
            <div
                style={{
                    display: 'flex',
                    flexWrap: 'wrap'
                }}
            >
                <TruncateList ellipsis={Ellipsis}>
                    {tags.map((t) => (
                        <div
                            key={t}
                            style={{
                                padding: '3px 5px',
                                background: '#bababa',
                                flexShrink: 0,
                                marginRight: 5,
                            }}
                        >
                            {t}
                        </div>
                    ))}
                </TruncateList>
            </div>
        </Truncate>
    </div>
)

Prop types

Truncate

propsdefaulttype
isTruncatingtrueboolean

TruncateList

propsdefaulttypedescription
ellipsis...render propsee props bellow

Ellipsis

propsdefaulttype
moreCountnumber
moreChildrenArray of truncated children
1.1.1

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago