summaryrefslogtreecommitdiffstats
path: root/src/ui/objects/NavbarItem.tsx
blob: c0e347f63ad6cf158c5ac9c4ced924e80965bb01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { HTMLTag, Polymorphic } from "corvos/plugins/jsx.ts";

export type Props<Tag extends HTMLTag> = Polymorphic<{
	as: Tag;
	icon?: JSX.Element;
	pre?: JSX.Element;
	post?: JSX.Element;
	selected?: boolean;
}>;

export const NavbarItem = <T extends HTMLTag = "a">({
	children,
	as: Tag = "a" as T,
	icon,
	pre,
	post,
	selected,
	class: cls,
	...props
}: Props<T>) => (
	<Tag
		aria-current={selected ? "page" : undefined}
		class:list={["o-navbar__item", { "is-selected": selected }, cls]}
		role="menuitem"
		{...props}
	>
		{icon && <div class="o-navbar__item-label">{children}</div>}

		<div class="o-navbar__item-content">
			{pre} {icon ?? <span class="o-navbar__item-content-text">{children}</span>} {post}
		</div>
	</Tag>
);