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