All files / src/components/tabs/TabbedView TabbedView.tsx

0% Statements 0/6
0% Branches 0/4
0% Functions 0/3
0% Lines 0/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 34 35 36 37 38 39                                                                             
import { FC, ReactNode, useState } from "react";
import { capitalise } from "@/util/string";
 
export interface TabbedViewInterface {
  tabs: Record<string, ReactNode>;
}
 
export const TabbedView: FC<TabbedViewInterface> = (props) => {
  const tabKeys = Object.keys(props.tabs);
  const [activeTab, setActiveTab] = useState<string>(tabKeys[0]);
 
  return (
    <div>
      <div className="flex gap">
        {tabKeys.map((key) => (
          <button
            key={key}
            onClick={() => setActiveTab(key)}
            disabled={activeTab === key}
            className={
              activeTab === key
                ? "text-white bg-gray-900"
                : document.documentElement.classList.contains("dark")
                ? "text-white"
                : "text-black border-slate-500"
            }
          >
            {capitalise(key.replace("___", "/").replace("_", " "))}
          </button>
        ))}
      </div>
      <br></br>
      <div className="bg-gray-900 text-white p-4 rounded-lg">
        {props.tabs[activeTab]}
      </div>
    </div>
  );
};