<div class="c-collapsible c-collapsible--btn o-collapsible">
<p class="c-collapsible__title o-collapsible__title js-collapsible-title">
Element title
</p>
<div class="c-collapsible__content">
<label for="createpsw-field" class="has-password-button" aria-label="">
Password <span class="required-marker" aria-hidden="true">*</span>
<input id="createpsw-field" type="password" class="" placeholder="Inserisci qui la tua password" value="" autocomplete="new-password">
<button type="button" class="js-pwd-button" data-show-text="Mostra" data-hide-text="Nascondi" aria-label="Mostra password">Mostra</button>
</label>
</div>
</div>
<div class="c-collapsible c-collapsible--btn o-collapsible">
<p class="c-collapsible__title o-collapsible__title js-collapsible-title">
{{ title }}
</p>
<div class="c-collapsible__content">
{{> @input create-psw }}
</div>
</div>
{
"name": "default",
"title": "Element title",
"text": "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Maxime recusandae eligendi beatae nesciunt sit. Officiis nulla maiores, alias minima, dolorum harum et earum molestias odio architecto tempore est consequuntur ullam.",
"id": "molecule-collapsible--default",
"create-psw": {
"label_id": "createpsw-field",
"label_message": "Password",
"label_class": "has-password-button",
"hasPasswordButton": true,
"atom-input": {
"id": "createpsw-field",
"type": "password",
"class": null,
"autocomplete": "new-password",
"placeholder": "Inserisci qui la tua password",
"required": true
}
}
}
/*------------------------------------*\
Simple
\*------------------------------------*/
.c-collapsible--simple {
background-color: secondary(soft, 100);
border-radius: remify(16px);
margin-bottom: remify(24px);
border: remify(1px) solid primary(night, 10);
.c-collapsible__title {
color: primary(night, 100);
@include font-scale(level-2, regular);
cursor: pointer;
button {
display: flex;
padding: remify(12px) remify(24px);
}
button span.h2 {
display: flex;
justify-content: space-between;
width: 100%;
align-items: center;
color: currentColor;
}
}
h3 {
.c-canvas__paper & {
font-size: 115%;
font-weight: fw(semibold);
}
}
h4 {
@include font-scale(level-3, semibold);
}
}
.c-collapsible--simple:hover,
.c-collapsible--simple:has([aria-expanded="true"]) {
.c-collapsible__title {
color: primary(sky, 100);
}
}
/*------------------------------------*\
Button
\*------------------------------------*/
.c-collapsible--btn {
border-bottom: none;
.c-form__alone--createpsw & {
flex-grow: 1;
}
.c-collapsible__title {
// Hack for Safari (web and mobile)
// See also in: 'src/views/01-atoms/ctas/atom-button/_button.scss'
// @supports (-webkit-appearance:none) {
// color: #fff;
// }
.c-form--sticker & {
margin-bottom: 0;
}
}
[aria-expanded="false"],
[aria-expanded="true"] {
&:after {
content: "\25be";
display: inline-block;
margin-left: remify(4px);
// transition: transform .3s ease;
}
}
[aria-expanded="true"] {
margin-bottom: remify(24px);
&:after {
transform: rotate(-180deg);
}
}
.c-collapsible__title button {
color: primary(sky, 120);
text-align: right;
display: block;
width: auto;
@extend .c-button;
@extend .c-button--ghost;
padding-left: remify(16px);
padding-right: remify(16px);
svg.arrow-up,
svg.arrow-down {
@extend .u-visuallyhidden;
}
.c-form__alone--createpsw & {
margin-top: 0;
margin-right: remify(24px);
}
}
}
/*------------------------------------*\
Password
\*------------------------------------*/
.c-collapsible--psw {
[aria-expanded="false"],
[aria-expanded="true"] {
&:after {
content: "\25be";
display: inline-block;
transition: transform .3s ease;
}
}
[aria-expanded="true"] {
margin-bottom: remify(24px);
&:after {
transform: rotate(-180deg);
}
}
}
/*------------------------------------*\
Invoice
\*------------------------------------*/
.c-collapsible--invoice {
.alert-msg {
font-size: 75%;
line-height: 1.5;
text-align: center;
position: relative;
top: remify(40px);
@include min-screen (bp(tablet)) {
width: 70%;
margin: 0 auto;
}
}
}
/*------------------------------------*\
Baloon
\*------------------------------------*/
.c-collapsible__content--baloon {
@include shadow(medium);
padding: remify(16px);
border-radius: remify(4px);
position: relative;
background-color: #F4F6F7;
&:before{
content: "";
position: absolute;
@include css-triangle("up", 10px, #F4F6F7);
top: remify(-20px);
left: 50%;
transform: translateX(-50%);
@include shadow(medium);
}
@include min-screen (bp(tablet)) {
padding: remify(24px);
}
}
/*------------------------------------*\
Faq
\*------------------------------------*/
.c-collapsible--faq {
// .c-collapsible__title button {
// border-radius: remify(8px);
// @include min-screen (bp(tablet)) {
// padding: remify(20px) remify(16px);
// }
// }
// .c-collapsible__title {
// font-size: 100%;
// @include min-screen (bp(tablet)) {
// font-size: 125%;
// }
// }
}
/*------------------------------------*\
Privacy
\*------------------------------------*/
.c-collapsible--privacy {
margin: remify(16px) 0;
// .c-collapsible__title {
// button {
// padding: remify(8px) remify(8px);
// }
// }
}
/*------------------------------------*\
Docs
\*------------------------------------*/
.c-collapsible__content {
.c-media {
margin-bottom: remify(16px);
}
}
// ES5
'use strict';
(function () {
// Get all the <h4> headings
var headings = document.querySelectorAll('.js-collapsible-title');
function isHTML(str) {
var a = document.createElement('div');
a.innerHTML = str;
for (var c = a.childNodes, i = c.length; i--; ) {
if (c[i].nodeType == 1) return true;
}
return false;
}
Array.prototype.forEach.call(headings, function (heading) {
// Give each <h4> a toggle button child
// with the SVG plus/minus icon
// heading.innerHTML = '<button class="c-collapsible__button" type="button" data-opens-text="apri" data-closes-text="chiudi" aria-expanded="false">' + heading.innerHTML + '<svg class="arrow-down" viewBox="0 0 24 24"><path d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"></path></svg><svg class="arrow-up" viewBox="0 0 24 24"><path d="M12 8l-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z" ></path></svg></button>';
var headingcontent = heading.innerHTML;
if ((isHTML(headingcontent)) && ($(headingcontent).is('button'))) {
//console.log("continene html button");
// Checks if the string contains HTML and if it has already been converted to a button
// (ie. in Endurance CMS pages)
// and prevent double code injection
} else {
// console.log("no html button");
// injects toggle button
heading.innerHTML = '<button class="c-collapsible__button" type="button" data-opens-text="apri" data-closes-text="chiudi" aria-expanded="false">' + headingcontent + '<svg class="arrow-down" viewBox="0 0 24 24"><path d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"></path></svg><svg class="arrow-up" viewBox="0 0 24 24"><path d="M12 8l-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z" ></path></svg></button>';
};
// Function to create a node list
// of the content between this <h4> and the next
var getContent = function getContent(elem) {
var elems = [];
while (elem.nextElementSibling && elem.nextElementSibling.tagName !== 'p.js-collapsible-title') {
elems.push(elem.nextElementSibling);
elem = elem.nextElementSibling;
}
// Delete the old versions of the content nodes
elems.forEach(function (node) {
node.parentNode.removeChild(node);
});
return elems;
};
// Assign the contents to be expanded/collapsed (array)
var contents = getContent(heading);
// Create a wrapper element for `contents` and hide it
var wrapper = document.createElement('div');
wrapper.classList.add("o-collapsible__content");
wrapper.hidden = true;
// Add each element of `contents` to `wrapper`
contents.forEach(function (node) {
wrapper.appendChild(node);
});
// Add the wrapped content back into the DOM
// after the heading
heading.parentNode.insertBefore(wrapper, heading.nextElementSibling);
// Assign the button
var btn = heading.querySelector('button');
btn.onclick = function () {
// Cast the state as a boolean
var expanded = btn.getAttribute('aria-expanded') === 'true' || false;
// Switch the state
btn.setAttribute('aria-expanded', !expanded);
// Switch the content's visibility
wrapper.hidden = expanded;
};
});
// gestione apertura collapsible in caso di match tra url e id
// wrapper dell'collapsible
var collapsibleElem = $('.o-collapsible');
// iterazione dei vari collapsible in pagina
$(collapsibleElem).each(function (index) {
collapsibleBtn = $(this).find('.c-collapsible__button');
collapsibleTitle = $(this).find('.js-collapsible-title'),
titleId = $(collapsibleTitle).attr('id'),
indexString = $(location).attr('href'),
content = $(this).find('.o-collapsible__content');
if (Array.prototype.includes) {
// se l'url contiene l'id del collapsible ed ha una lunghezza maggiore di 0
if (indexString.includes(titleId) && titleId.length > 0) {
// imposta come true l'attributo aria-expanded
$(collapsibleBtn).attr('aria-expanded', true);
// rimuovi l'attributo hidden dal contenuto espandibile
$(content).removeAttr('hidden');
// scrolla la pagina fino al collapsible
$('html, body').animate({
scrollTop: $(this).offset().top - 100
}, 2000);
}
}
})
})();
You can copy and paste the code of this component wherever you want instead importing.