40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
|
import { AnyNode, Attrs, E, Elem } from "ren/node.ts";
|
||
|
import { classNames } from "ren/attrs.ts";
|
||
|
import { Context } from "../context.ts";
|
||
|
|
||
|
export function PageLayout(ctx: Context, children: AnyNode[]): Elem {
|
||
|
return E("div", { id: "main" }, [
|
||
|
Header(ctx),
|
||
|
E("div", classNames("content"), children),
|
||
|
// Footer(),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
export function Header(ctx: Context): Elem {
|
||
|
return E("header", classNames("header"), [
|
||
|
E("div", classNames("content-width"), [HeaderNav(ctx)]),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
export function HeaderNav(ctx: Context): Elem {
|
||
|
return E("nav", classNames("main-menu"), [
|
||
|
Link(navLink("/", ctx), "Главная"),
|
||
|
Link(navLink("/recipes", ctx), "Рецепты"),
|
||
|
Link(navLink("/ingredients", ctx), "Ингредиенты"),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
export function Link(attrs: Attrs | Attrs[], text: string): Elem {
|
||
|
return E("a", attrs, text);
|
||
|
}
|
||
|
|
||
|
function navLink(href: string, ctx?: Context): Attrs {
|
||
|
const attrs: Attrs = { href };
|
||
|
if (ctx?.locPath === href) attrs["aria-current"] = "true";
|
||
|
return attrs;
|
||
|
}
|
||
|
|
||
|
export function Footer(): Elem {
|
||
|
return E("footer", classNames("footer"), "footer");
|
||
|
}
|