1.0.0 • Published 5 years ago
@jamespotz/react-simple-readmore v1.0.0
React Simple Readmore
React component for animating height using Spring Factor.
Quick start
Get it from npm
$ npm install --save @jamespotz/react-simple-readmore
Note
For React >= 16.8 because of Hooks.
How to use
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import ReadMore from '@jamespotz/react-simple-readmore';
import text from './data';
const App = () => {
const [shown, setShown] = useState(false);
return (
<ReadMore
onClick={value => setShown(value)}
fade
btn={
<button
style={{
background: `${shown ? 'red' : 'blue'}`,
padding: '10px 15px',
color: '#fff'
}}
>
{shown ? 'Read Less' : 'Read More'}
</button>
}
preset='wobbly'
>
<p
dangerouslySetInnerHTML={{
__html: text
}}
/>
</ReadMore>
);
};
ReactDOM.render(<App />, document.getElementById('root'));
Demo
Live Demo: https://codesandbox.io/embed/kind-night-bqd8e
To build the examples locally, run:
npm install
npm start
Then open localhost:3000
in your browser of choice.
API
Prop | Type | Default |
---|---|---|
minHeight | Number/String | 50 |
displayHeight | Number/String | 'auto' |
btnText | Text/Component (props ignored if btn is present) | |
btnTextShown | Text/Component (props ignored if btn is present) | |
defaultShownOnLess | Text/Component | |
btn | Component | |
onClick | Function | |
btnClassName | String | |
btnStyles | Object | |
fade | Boolean | |
fadeHeight | Number | minHeight/2 |
colorStopTop | String | 'rgba(255, 255, 255, 0)' |
colorStopBottom | String | 'white' |
precision | Number | 0.01 |
velocity | Number | 0 |
mass | Number | 1 |
stiffness | Number | |
damping | Number | |
prest | String of type 'noWobble', 'gentle', 'wobbly', 'stiff', 'slow', 'molasses' |
1.0.0
5 years ago
0.3.5
5 years ago
0.3.4
5 years ago
0.3.3
5 years ago
0.3.2
5 years ago
0.3.1
5 years ago
0.3.0
5 years ago
0.2.12
5 years ago
0.2.11
5 years ago
0.2.10
5 years ago
0.2.9
5 years ago
0.2.8
5 years ago
0.2.7
5 years ago
0.2.6
5 years ago
0.2.5
5 years ago
0.2.4
5 years ago
0.2.3
5 years ago
0.2.2
5 years ago
0.2.1
5 years ago
0.2.0
5 years ago
0.1.3
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago