<.accordion
class="accordion"
animation="custom"
on_value_change_client="my-accordion-changed"
items={Corex.Content.new([
%{label: "Lorem ipsum dolor sit amet", content: "Consectetur adipiscing elit. Sed sodales ullamcorper tristique."},
%{label: "Duis dictum gravida odio ac pharetra?", content: "Nullam eget vestibulum ligula, at interdum tellus."},
%{label: "Donec condimentum ex mi", content: "Congue molestie ipsum gravida a. Sed ac eros luctus."}
])}
/>
import { animate } from "motion"
import {
findAccordionContent,
animateHeightOpen,
animateHeightClose,
} from "corex"
const reducedMotion = () =>
window.matchMedia("(prefers-reduced-motion: reduce)").matches
document.addEventListener("my-accordion-changed", (e) => {
const root = document.getElementById(e.detail.id)
if (!root) return
e.detail.added.forEach((v) => {
const el = findAccordionContent(root, v)
if (!el) return
animateHeightOpen(el, { animator: animate, duration: 0.55, easing: [0.16, 1, 0.3, 1] })
if (!reducedMotion()) {
animate(
el,
{ filter: ["blur(12px)", "blur(0px)"], scale: [0.96, 1] },
{ duration: 0.6, easing: [0.16, 1, 0.3, 1] },
)
}
})
e.detail.removed.forEach((v) => {
const el = findAccordionContent(root, v)
if (!el) return
animateHeightClose(el, { animator: animate, duration: 0.32, easing: [0.7, 0, 0.84, 0] })
if (!reducedMotion()) {
animate(
el,
{ filter: ["blur(0px)", "blur(10px)"], scale: [1, 0.97] },
{ duration: 0.3, easing: "ease-in" },
)
}
})
})