Skip to content

Commit

Permalink
feat: add TabBar component (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisagi authored Nov 5, 2024
2 parents b265b2b + 5a9b6d4 commit c2eaa2f
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/components/TabBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Meta, StoryObj } from "@storybook/react";

import { createRemixStub } from "@remix-run/testing";
import { TabBar } from "./TabBar";

const meta: Meta<typeof TabBar> = {
title: "Components/TabBar",
component: TabBar,
argTypes: {
path: {
control: "radio",
options: ["/clothes", "/hair", "/hairColor"],
},
},
decorators: [
(Story) => {
const RemixStub = createRemixStub([
{
path: "*",
Component: Story,
},
]);

return <RemixStub />;
},
],
};

export default meta;

export const Default: StoryObj<typeof TabBar> = {
args: {
path: "/clothes",
},
};
51 changes: 51 additions & 0 deletions app/components/TabBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as Tabs from "@radix-ui/react-tabs";
import { cn } from "~/libs/utils";

const LINKS = [
{
href: "/clothes",
label: "服装",
},
{
href: "/hair",
label: "髪型",
},
{
href: "/hairColor",
label: "髪色",
},
];

export interface TabBarProps {
path: string;
className?: string;
}

export function TabBar({ path, className }: TabBarProps) {
const index = LINKS.findIndex((link) => link.href === path);

return (
<Tabs.Root
value={LINKS[index].href}
className={cn(
"relative w-full max-w-screen-sm overflow-hidden rounded-t-lg bg-gray-600",
className,
)}
>
<Tabs.List className="flex">
{LINKS.map((link) => (
<Tabs.Trigger
key={link.href}
value={link.href}
className={cn(
"flex-1 rounded-t-lg py-3 text-center text-white md:text-xl",
{ "bg-cyan-400": link.href === path },
)}
>
{link.label}
</Tabs.Trigger>
))}
</Tabs.List>
</Tabs.Root>
);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@builder.io/partytown": "0.10.2",
"@radix-ui/react-navigation-menu": "1.2.1",
"@radix-ui/react-slot": "1.1.0",
"@radix-ui/react-tabs": "1.1.1",
"@react-three/drei": "9.114.6",
"@react-three/fiber": "8.17.10",
"@remix-run/react": "2.13.1",
Expand Down
62 changes: 62 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2eaa2f

Please sign in to comment.