({
children,
to,
hotKey,
}: {
children: React.ReactNode;
to?: string;
hotKey?: string;
})
| 66 | } |
| 67 | |
| 68 | function SidebarLink({ |
| 69 | children, |
| 70 | to, |
| 71 | hotKey, |
| 72 | }: { |
| 73 | children: React.ReactNode; |
| 74 | to?: string; |
| 75 | hotKey?: string; |
| 76 | }) { |
| 77 | const location = useLocation(); |
| 78 | |
| 79 | const isActive = location.pathname === to; |
| 80 | |
| 81 | const { minimal } = useJsonDoc(); |
| 82 | const [theme] = useTheme(); |
| 83 | |
| 84 | const queryParams = new URLSearchParams(); |
| 85 | |
| 86 | if (typeof minimal === "boolean") { |
| 87 | queryParams.set("minimal", String(minimal)); |
| 88 | |
| 89 | if (theme) { |
| 90 | queryParams.set("theme", theme); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | const href = `${to}${queryParams.toString().length > 0 ? `?${queryParams.toString()}` : "" |
| 95 | }`; |
| 96 | |
| 97 | if (hotKey) { |
| 98 | const navigate = useNavigate(); |
| 99 | useHotkeys( |
| 100 | hotKey, |
| 101 | (e) => { |
| 102 | e.preventDefault(); |
| 103 | if (!isActive && to) { |
| 104 | navigate(href); |
| 105 | } |
| 106 | }, |
| 107 | [navigate, isActive, to] |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | const classes = isActive |
| 112 | ? "relative w-10 h-10 mb-1 text-white bg-indigo-700 rounded-sm cursor:pointer transition" |
| 113 | : "relative w-10 h-10 mb-1 text-slate-700 hover:bg-slate-300 rounded-sm cursor:pointer transition dark:text-white dark:hover:bg-slate-700"; |
| 114 | |
| 115 | return !!to ? ( |
| 116 | <Link to={href} prefetch={isActive ? "none" : "render"}> |
| 117 | <li className={classes}>{children}</li> |
| 118 | </Link> |
| 119 | ) : ( |
| 120 | <li className={classes}>{children}</li> |
| 121 | ); |
| 122 | } |
nothing calls this directly
no test coverage detected