diff --git a/src/components/Menu.js b/src/components/Menu.js new file mode 100644 index 0000000..ca93792 --- /dev/null +++ b/src/components/Menu.js @@ -0,0 +1,25 @@ +import { $html, $for } from "sigpro"; +import { val, joinClass } from "../core/utils.js"; + +/** MENU */ +export const Menu = (props) => { + const renderItems = (items) => + $for( + () => items || [], + (it) => + $html("li", {}, [ + it.children + ? $html("details", { open: it.open }, [ + $html("summary", {}, [it.icon && $html("span", { class: "mr-2" }, it.icon), it.label]), + $html("ul", {}, renderItems(it.children)), + ]) + : $html("a", { class: () => (val(it.active) ? "active" : ""), onclick: it.onclick }, [ + it.icon && $html("span", { class: "mr-2" }, it.icon), + it.label, + ]), + ]), + (it, i) => it.label || i, + ); + + return $html("ul", { ...props, class: joinClass("menu bg-base-200 rounded-box", props.class) }, renderItems(props.items)); +};