Files
homepage/src/components/tab.jsx
T
dependabot[bot] 81accd8dbe
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Chore(deps-dev): Bump eslint-config-next from 15.5.22 to 16.3.3 (#7082)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
2026-09-01 10:52:46 -07:00

45 lines
1.2 KiB
React

import classNames from "classnames";
import { useContext } from "react";
import { TabContext } from "utils/contexts/tab";
function slugify(tabName) {
return tabName.toString().replace(/\s+/g, "-").toLowerCase();
}
export function slugifyAndEncode(tabName) {
return tabName !== undefined ? encodeURIComponent(slugify(tabName)) : "";
}
export default function Tab({ tab }) {
const { activeTab, setActiveTab } = useContext(TabContext);
const matchesTab = decodeURIComponent(activeTab) === slugify(tab);
return (
<li
key={tab}
role="presentation"
className={classNames("text-theme-700 dark:text-theme-200 relative h-10 w-full rounded-md flex")}
>
<button
id={`${tab}-tab`}
type="button"
role="tab"
aria-controls={`#${tab}`}
aria-selected={matchesTab ? "true" : "false"}
className={classNames(
"w-full rounded-md m-1",
matchesTab ? "bg-theme-300/20 dark:bg-white/10" : "hover:bg-theme-100/20 dark:hover:bg-white/5",
)}
onClick={() => {
setActiveTab(slugifyAndEncode(tab));
window.location.hash = `#${slugifyAndEncode(tab)}`;
}}
>
{tab}
</button>
</li>
);
}