mirror of
https://github.com/morris/vanilla-todo.git
synced 2025-08-21 05:11:20 +02:00
35 lines
671 B
JavaScript
35 lines
671 B
JavaScript
/**
|
|
* @param {HTMLElement} el
|
|
*/
|
|
export function AppCollapsible(el) {
|
|
let show = true;
|
|
|
|
setTimeout(() => el.classList.add('-animated'), 200);
|
|
|
|
el.addEventListener('collapse', (e) => {
|
|
if (typeof e.detail === 'boolean') {
|
|
show = e.detail;
|
|
}
|
|
|
|
update();
|
|
});
|
|
|
|
el.querySelector('.bar > .toggle').addEventListener('click', () => {
|
|
show = !show;
|
|
update();
|
|
});
|
|
|
|
update();
|
|
|
|
function update() {
|
|
el.querySelector('.bar > .toggle > .app-icon').classList.toggle(
|
|
'-r180',
|
|
show,
|
|
);
|
|
|
|
el.querySelectorAll('.body').forEach((el) => {
|
|
el.style.height = show ? `${el.children[0].offsetHeight}px` : '0';
|
|
});
|
|
}
|
|
}
|