/** * notion-enhancer * (c) 2023 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ import { extendProps, setState, useState } from "../state.mjs"; function SidebarHeading({}, ...children) { const { html } = globalThis.__enhancerApi; return html`

${children}

`; } function SidebarButton({ id, icon, ...props }, ...children) { const { html } = globalThis.__enhancerApi, $btn = html`<${props.href ? "a" : "button"} class="flex select-none cursor-pointer w-full items-center py-[5px] px-[15px] text-[14px] last:mb-[12px] transition hover:bg-[color:var(--theme--bg-hover)]" ...${props} > ${icon ? html`` : ""} ${children} `; if (!props.href) { extendProps($btn, { onclick: () => setState({ transition: "fade", view: id }), }); useState(["view"], ([view = "welcome"]) => { const active = view.toLowerCase() === id.toLowerCase(); $btn.style.background = active ? "var(--theme--bg-hover)" : ""; $btn.style.fontWeight = active ? "600" : ""; }); } return $btn; } function Sidebar({ items, categories }) { const { html, isEnabled } = globalThis.__enhancerApi, $sidebar = html``; for (const { title, mods } of categories) { const $title = html`<${SidebarHeading}>${title}`, $mods = mods.map((mod) => [ mod.id, html`<${SidebarButton} id=${mod.id}>${mod.name}`, ]); $sidebar.append($title, ...$mods.map(([, $btn]) => $btn)); useState(["rerender"], async () => { let sectionVisible = false; for (const [id, $btn] of $mods) { if (await isEnabled(id)) { $btn.style.display = ""; sectionVisible = true; } else $btn.style.display = "none"; } $title.style.display = sectionVisible ? "" : "none"; }); } return $sidebar; } export { Sidebar };