diff --git a/core/static/bundled/core/accordion-index.ts b/core/static/bundled/core/accordion-index.ts new file mode 100644 index 00000000..39e37564 --- /dev/null +++ b/core/static/bundled/core/accordion-index.ts @@ -0,0 +1,25 @@ +const setMaxHeight = (element: HTMLDetailsElement) => { + element.setAttribute("style", `max-height: ${element.scrollHeight}px`); +}; + +// Initialize max-height at load +window.addEventListener("DOMContentLoaded", () => { + for (const el of document.querySelectorAll("details.accordion")) { + setMaxHeight(el as HTMLDetailsElement); + } +}); + +// Accordion opened +new MutationObserver((mutations: MutationRecord[]) => { + for (const mutation of mutations) { + const target = mutation.target as HTMLDetailsElement; + if (target.tagName !== "DETAILS" || !target.classList.contains("accordion")) { + continue; + } + setMaxHeight(target); + } +}).observe(document.body, { + attributes: true, + attributeFilter: ["open"], + subtree: true, +}); diff --git a/core/static/core/accordion.scss b/core/static/core/accordion.scss new file mode 100644 index 00000000..07793a7a --- /dev/null +++ b/core/static/core/accordion.scss @@ -0,0 +1,55 @@ +details.accordion>summary { + margin: 2px 0 0 0; + padding: .5em .5em .5em .7em; + cursor: pointer; + user-select: none; + display: block; + + border-top-right-radius: 3px; + border-top-left-radius: 3px; +} + +details[open].accordion>summary { + border: 1px solid #003eff; + background: #007fff; + color: #ffffff; +} + + +details:not([open]).accordion>summary { + border-bottom-right-radius: 3px; + border-bottom-left-radius: 3px; + + border: 1px solid #c5c5c5; + background: #f6f6f6; + color: #454545; +} + +details.accordion>summary::before { + font-family: FontAwesome; + content: '\f0da'; + margin-right: 5px; + transition: 700ms; + font-size: 0.8em; +} + +details[open]>summary::before { + font-family: FontAwesome; + content: '\f0d7'; +} + +// ::details-content isn't available on firefox yet +// we use .accordion-content as a workaround +details.accordion>.accordion-content { + background: #ffffff; + color: #333333; + padding: 1em 2.2em; + overflow: auto; + border: 1px solid #dddddd; + border-bottom-right-radius: 3px; + border-bottom-left-radius: 3px; +} + +details.accordion { + transition: max-height 300ms ease-in-out; +} \ No newline at end of file diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index 6479e833..e7b2b3ca 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -12,6 +12,7 @@ + {% block jquery_css %} {# Thile file is quite heavy (around 250kb), so declaring it in a block allows easy removal #} @@ -26,6 +27,7 @@ + diff --git a/core/templates/core/user_account.jinja b/core/templates/core/user_account.jinja index 467f864a..a54c9bef 100644 --- a/core/templates/core/user_account.jinja +++ b/core/templates/core/user_account.jinja @@ -1,7 +1,7 @@ {% extends "core/base.jinja" %} {% macro monthly(objects) %} -