react-collapsible-content
Getting Started
Components
Examples
BasicBasic usageToggleButtonComponentTextComponentDynamic ContentTransition EventsTransition OptionsUnmount on CollapseMenu Component
Comparisons

Basic Example

In these examples we are using ToggleButtonComponent and TextComponent (see code below), but you can use your own components.

We are also using simple-flexbox and aphrodite to make these UI Components.

Basic usage

TOGGLE

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Diam sit amet nisl suscipit adipiscing. Diam phasellus vestibulum lorem sed risus. Mattis molestie a iaculis at erat pellentesque adipiscing commodo. Quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus mattis. Leo vel orci porta non pulvinar neque laoreet suspendisse interdum. Nulla facilisi cras fermentum odio eu feugiat pretium nibh ipsum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc. Dolor purus non enim praesent elementum facilisis leo. Pharetra vel turpis nunc eget lorem dolor sed viverra ipsum. At imperdiet dui accumsan sit amet nulla facilisi morbi tempus.

ToggleButtonComponent

import React from 'react';
import { StyleSheet, css } from 'aphrodite/no-important';
import { Row } from 'simple-flexbox';
const styles = StyleSheet.create({
button: {
border: '1px solid #2EBFA5',
borderRadius: 4,
cursor: 'pointer',
backgroundColor: '#f7f7f7',
transition: 'border-radius .725s ease-in-out'
},
buttonExpanded: {
borderBottom: 'none',
borderRadius: '4px 4px 0px 0px',
transition: 'border-radius .1s ease-in-out'
},
arrow: {
display: 'inline-block',
borderTop: '5px solid transparent',
borderBottom: '5px solid transparent',
borderLeft: '5px solid currentColor',
verticalAlign: 'middle',
marginRight: '.7rem',
transform: 'translateY(-2px)',
transition: 'transform .425s ease-in-out'
},
arrowExpanded: {
transform: 'rotate(90deg) translateX(-1px)'
},
arrowContainer: {
display: 'block',
margin: 10,
marginLeft: 20
},
label: {
margin: 10
}
});
function ToggleButtonComponent({ title = 'TOGGLE', expanded, onClick, style }) {
return (
<Row
wrap={false}
className={css(styles.button, expanded && styles.buttonExpanded)}
onClick={onClick}
style={style}
>
<div className={css(styles.arrowContainer)}>
<span
className={css(
styles.arrow,
expanded && styles.arrowExpanded
)}
>
{' '}
</span>
</div>
<span className={css(styles.label)}>{title}</span>
</Row>
);
}
export default ToggleButtonComponent;

TextComponent

import React from 'react';
export default function TextComponent({ limit }) {
const text = 'place a long text here'.substring(0, limit);
return (
<p
style={{
backgroundColor: '#2EBFA5',
borderRadius: '0px 0px 4px 4px',
color: '#2D3747',
margin: 0,
padding: 8
}}
>
{text}
</p>
);
}