diff --git a/src/components/tab/TabGroup.tsx b/src/components/tab/TabGroup.tsx new file mode 100644 index 0000000..5b628f1 --- /dev/null +++ b/src/components/tab/TabGroup.tsx @@ -0,0 +1,118 @@ +import clsx from "clsx"; +import { HTMLProps, useState } from "react"; + + +export interface Tab { + tabHeader: React.ReactNode; + headerClasses?: string; + tabContent: React.ReactNode; + contentClasses?: string; + active?: boolean; + onTabClick?: () => void; +} + +export interface TabGroupProps extends HTMLProps{ + tabs: Tab[]; +} + + +export default function TabGroup(props: TabGroupProps){ + const { tabs, className } = props; + const [ activeTab, setActiveTab ] = useState(tabs.map((tab, index) => tab.active ? index : undefined)[0] ?? 0); + //TODO: Possible to maintain state of past tabs if we "cache" them in a useState() on their first render + + + return ( +
+
+ { + tabs.map((tab, index) => ( + { setActiveTab(index); tab.onTabClick?.(); }} + /> + )) + } +
+   +
+
+
+ { + tabs.map((tab, index) => ( + + )) + } +
+
+ ); +} + + +function TabHeader({ + tab, + onClick, + active +}:{ + tab: Tab; + onClick: () => void; + active: boolean; +}){ + return ( +
+ {tab.tabHeader} +
+ ); +} + +function TabContent({ + tab, + active +}:{ + tab: Tab; + active: boolean; +}){ + if(!active){ + return null; + } + + + return ( +
+ {tab.tabContent} +
+ ); +} diff --git a/src/index.css b/src/index.css index 212bc60..fa28255 100644 --- a/src/index.css +++ b/src/index.css @@ -39,8 +39,8 @@ body { min-height: 100vh; max-width: var(--breakpoint-2xl); - margin-top: 82px; margin-inline: auto; + padding-top: 82px; padding-inline: 1rem; text-align: center; diff --git a/src/pages/public/TestPage.tsx b/src/pages/public/TestPage.tsx index f42adb0..0416d30 100644 --- a/src/pages/public/TestPage.tsx +++ b/src/pages/public/TestPage.tsx @@ -1,334 +1,66 @@ -import { ButtonShape, ButtonSizeType, ButtonVariant } from "@/components/button/Button"; -import DangerButton from "@/components/button/DangerButton"; -import PrimaryButton from "@/components/button/PrimaryButton"; -import SecondaryButton from "@/components/button/SecondaryButton"; -import SuccessButton from "@/components/button/SuccessButton"; -import TertiaryButton from "@/components/button/TertiaryButton"; -import WarningButton from "@/components/button/WarningButton"; +import TabGroup, { Tab } from "@/components/tab/TabGroup"; export default function TestPage(){ - const sizes: ButtonSizeType[] = ["xsm", "sm", "md", "lg", "xl"]; - const variants: ButtonVariant[] = ["solid", "icon", "outline", "outline-ghost", "ghost"]; - const shapes: ButtonShape[] = ["horizontal", "square", "vertical"]; + const tabs: Tab[] = [ + { + tabHeader: "Tab 1", + tabContent: + }, + { + tabHeader: "Tab 2", + tabContent: + }, + { + tabHeader: "Tab 3", + tabContent: + } + ]; + + return (
- {/* Primary Button */} -
- { - sizes.map((size, cnt) => ( - - Primary {size} - - )) - } -
-
- { - variants.map((variant, cnt) => ( - - Primary {variant} - - )) - } -
-
- { - shapes.map((shape, cnt) => ( - - Primary {shape} - - )) - } -
- {/* Secondary Button */} -
- { - sizes.map((size, cnt) => ( - - Secondary {size} - - )) - } -
-
- { - variants.map((variant, cnt) => ( - - Secondary {variant} - - )) - } -
-
- { - shapes.map((shape, cnt) => ( - - Secondary {shape} - - )) - } -
- {/* Tertiary Button */} -
- { - sizes.map((size, cnt) => ( - - Tertiary {size} - - )) - } -
-
- { - variants.map((variant, cnt) => ( - - Tertiary {variant} - - )) - } -
-
- { - shapes.map((shape, cnt) => ( - - Tertiary {shape} - - )) - } -
- {/* Success Button */} -
- { - sizes.map((size, cnt) => ( - - Success {size} - - )) - } -
-
- { - variants.map((variant, cnt) => ( - - Success {variant} - - )) - } -
-
- { - shapes.map((shape, cnt) => ( - - Success {shape} - - )) - } -
- {/* Warning Button */} -
- { - sizes.map((size, cnt) => ( - - Warning {size} - - )) - } -
-
- { - variants.map((variant, cnt) => ( - - Warning {variant} - - )) - } -
-
- { - shapes.map((shape, cnt) => ( - - Warning {shape} - - )) - } -
- {/* Danger Button */} -
- { - sizes.map((size, cnt) => ( - - Danger {size} - - )) - } -
-
- { - variants.map((variant, cnt) => ( - - Danger {variant} - - )) - } -
-
- { - shapes.map((shape, cnt) => ( - - Danger {shape} - - )) - } -
+
); } + + +function Tab1(){ + console.log("Tab 1"); + + + return ( +
+ Tab 1 Content +
+ ); +} + +function Tab2(){ + console.log("Tab 2"); + + + return ( +
+ Tab 2 Content +
+ ); +} + +function Tab3(){ + console.log("Tab 3"); + + + return ( +
+ Tab 3 Content +
+ ); +}