Makes a block of content collapsible.
Overview
The collapse component can be used to let the user alternate the display of a block of content.
Each collapse has an element that acts as its header and it will trigger the change of the content block's display state when clicked.
Simple collapse.
A treasure lies inside of me...
βNo power and no treasure can outweigh the extension of our knowledge.β
β Democritus
Opened collapse.
I do not like to hide
βMaybe it's just hiding somewhere. Or gone on a trip to come home. But falling in love is always a pretty crazy thing. It might appear out of the blue and just grab you. Who knows β maybe even tomorrow.β
β Haruki Murakami
Card styled collapse.
It's clear where I do begin. Where I do end...
βAll limits are self-imposed.β
β Icarus
Usage
Dependencies
To get the Collapse component working, include the dependencies in your project in the following order:
"design-system": "git+ssh://git@github.com/Selectra-Dev/design-system.git"
@import 'design-system/src/scss/02-molecules/collapse';
import Collapse from 'design-system/src/js/02-molecules/collapse';
Basic code
The collapse component is composed of :
- A
div
parent element with thecollapse
class. - A
header
element with thecollapse__header
class.
The header is clickable, and acts as the collapse trigger. - A
div
element with the classcollapse__content
.
When the collapse is triggered, the contents of this block are shown/hidden.
This component has to be initialized with javascript. You must import the
<div class="collapse">
<h4 class="collapse__header">A treasure lies inside of me...</h4>
<div class="collapse__content">
<p>βNo power and no treasure can outweigh the extension of our knowledge.β<br /><br />β Democritus</p>
</div>
</div>
.collapse
h4.collapse__header A treasure lies inside of me...
.collapse__content
p
| βNo power and no treasure can outweigh the extension of our knowledge.β
br
br
| β Democritus
new Collapse();
HTML attributes
data-opened
When set to
"true"
the collapse will be initialized in it's opened state.
Check the second example on the
overview.
<div class="collapse" data-opened="true">
<h4 class="collapse__header">I do not like to hide</h4>
<div class="collapse__content">
<p>βMaybe it's just hiding somewhere. Or gone on a trip to come home. But falling in love is always a pretty crazy thing. It might appear out of the blue and just grab you. Who knows β maybe even tomorrow.β<br /><br />β Haruki Murakami</p>
</div>
</div>
.collapse(data-opened="true" data-opened="true")
h4.collapse__header I do not like to hide
.collapse__content
p
| βMaybe it's just hiding somewhere. Or gone on a trip to come home. But falling in love is always a pretty crazy thing. It might appear out of the blue and just grab you. Who knows β maybe even tomorrow.β
br
br
| β Haruki Murakami