@thi.ng/rdom-components
Version:
Collection of unstyled, customizable components for @thi.ng/rdom
31 lines (30 loc) • 860 B
JavaScript
import { div } from "@thi.ng/hiccup-html/blocks";
import { section } from "@thi.ng/hiccup-html/sections";
import { $list } from "@thi.ng/rdom/list";
import { $promise } from "@thi.ng/rdom/promise";
import { dedupe } from "@thi.ng/transducers/dedupe";
import { map } from "@thi.ng/transducers/map";
import { range } from "@thi.ng/transducers/range";
const accordion = (src, { attribs, head, sections, error }) => {
return $list(
src.transform(
dedupe(),
map((id) => [
...map((i) => [i, i === id], range(sections.length))
])
),
"div",
attribs.wrapper,
([i, sel]) => section(
sel ? attribs.sectionOn : attribs.sectionOff,
head(src, sections[i].title, i, sel),
sel ? div(
attribs.content,
$promise(sections[i].content(i), error)
) : null
)
);
};
export {
accordion
};