Files
ersatztv/design-system/components/navigation/NavItem.jsx
T
2026-07-02 07:37:00 +02:00

56 lines
2.5 KiB
React

import React from "react";
/**
* Single left-sidebar navigation item. Compose a list of these.
*/
export function NavItem({ icon = null, label, active = false, badge = null, badgeTone = "warn", onClick, href, style = {} }) {
const [hover, setHover] = React.useState(false);
const Comp = href ? "a" : "button";
const bt = { warn: "var(--status-warn)", error: "var(--status-error)", accent: "var(--action-primary)" }[badgeTone];
return (
<Comp
href={href}
onClick={onClick}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
style={{
position: "relative",
display: "flex",
alignItems: "center",
gap: "10px",
width: "100%",
height: "34px",
padding: "0 10px",
border: "none",
borderRadius: "var(--radius-sm)",
textDecoration: "none",
cursor: "pointer",
textAlign: "left",
font: `${active ? "var(--weight-medium)" : "var(--weight-normal)"} var(--text-sm)/1 var(--font-sans)`,
color: active ? "var(--text-primary)" : hover ? "var(--text-primary)" : "var(--text-secondary)",
background: active ? "var(--ctv-accent-soft)" : hover ? "var(--ctv-surface-2)" : "transparent",
transition: "background var(--dur-fast) var(--ease-standard), color var(--dur-fast)",
...style,
}}
>
{active && <span style={{ position: "absolute", left: 0, top: 7, bottom: 7, width: 2.5, borderRadius: 2, background: "var(--action-primary)" }} />}
{icon && <span style={{ display: "inline-flex", color: active ? "var(--action-primary)" : "currentColor", flex: "0 0 auto" }}>{icon}</span>}
<span style={{ flex: 1, minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{label}</span>
{badge != null && (
<span style={{ minWidth: 17, height: 17, padding: "0 5px", display: "inline-flex", alignItems: "center", justifyContent: "center", borderRadius: "var(--radius-pill)", background: bt, color: badgeTone === "warn" ? "#1A1206" : "#fff", font: "var(--weight-semibold) var(--text-2xs)/1 var(--font-mono)" }}>{badge}</span>
)}
</Comp>
);
}
/**
* Sidebar section label (eyebrow) that groups NavItems.
*/
export function NavSection({ children, style = {} }) {
return (
<div style={{ padding: "14px 10px 6px", font: "var(--weight-semibold) var(--text-2xs)/1 var(--font-sans)", letterSpacing: "var(--tracking-caps)", textTransform: "uppercase", color: "var(--text-disabled)", ...style }}>
{children}
</div>
);
}