1.1.0 • Published 2 years ago

react-expandable-content v1.1.0

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

Npm Version License Downloads Per Week

react-expandable-content

React component to enable text collapse based on a certain height

npm.io

Table of Contents

Installation

Install via npm or yarn

npm install react-expandable-content --save

yarn add react-expandable-content

Usage

ExpandableContent can receive any HTML elements or React components as its children.

import React from 'react';
import ExpandableContent from 'react-expandable-content';

const App = () => {
  return (
    <ExpandableContent maxHeight={100} collapseText={"Read less"} expandText={"Read more"}>
      <p>
        This content will be collapsed. It can be any kind of HTML or React components.
      </p>
      <p>
        Another section that will be collapsed.
      </p>
    </ExpandableContent>
  );
};

export default App;

Examples

Code Examples

Props

propsdefaulttypeusage
expandabletruebooleanEnable content to be expanded
expandText"Read more"stringText to display when content is collapsed
collapseText"Read less"stringText to display when content is expanded
className:x:stringCSS class applied to the expandable part
maxHeight100integerMax height in pixels for your collapsed content
showIcontruebooleanWhether the dropdown icon should be displayed
onCollapse:x:funcCallback function triggered when content is collapsed
onExpand:x:funcCallback function triggered when content is expanded
darkModefalsebooleanEnabling dark mode on your content (black background)

License

MIT

Contributors