From f631c50b7df11882c76b514a7f1328eac0905384 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 17 Oct 2018 20:42:23 +0300 Subject: [PATCH] Add Collapse --- snippets/Collapse.md | 69 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 snippets/Collapse.md diff --git a/snippets/Collapse.md b/snippets/Collapse.md new file mode 100644 index 000000000..16cb9dcb3 --- /dev/null +++ b/snippets/Collapse.md @@ -0,0 +1,69 @@ +### Collapse + +Renders a component with collapsible content. + +Use the value of the `collapsed` prop to determine the initial state of the content (collapsed/expanded). +Set the `state` of the component to the value of the `collapsed` prop (cast to a boolean value) and bind the `toggleCollapse` method to the component's context. +Use an object, `style`, to hold the styles for individual components and their states. +Create a method, `toggleCollapse`, which uses `Component.prototype.setState` to change the component's `state` from collapsed to expanded and vice versa. +In the `render()` method, use a `React.Fragment` to wrap both the ` +
+ {this.props.children} +
+ + ); + } +} +``` + +```jsx +ReactDOM.render( + +

This is a collapse

+

Hello world!

+
, + document.getElementById('root') +); +``` + + + +