Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 토글바 컴포넌트 #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/design-system/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const textVariants = cva("leading-[150%] tracking-[-2%]", {
"title/12_sb": "font-semibold text-[12px]",
"title/12_m": "font-medium text-[12px]",
"title/12_r": "font-normal text-[12px]",
"body/16_sb": "font-semibold text-[16px]",
},
},
});
Expand Down
19 changes: 19 additions & 0 deletions packages/design-system/ToggleBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Meta, StoryObj } from "@storybook/react";
import { ToggleBar } from "./ToggleBar";

const meta: Meta<typeof ToggleBar> = {
title: "ds/ToggleBar",
component: ToggleBar,
tags: ["autodocs"],
argTypes: {
onToggle: { action: "onToggle" },
},
};

export default meta;

type Story = StoryObj<typeof ToggleBar>;

export const Default: Story = {
render: (args) => <ToggleBar {...args} />,
};
45 changes: 45 additions & 0 deletions packages/design-system/ToggleBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useState } from "react";
import { Text, textVariants } from "./Text";
import { cn } from "./cn";

interface ToggleBarProps {
onToggle: (selected: "created" | "updated") => void;
}

export const ToggleBar: React.FC<ToggleBarProps> = ({ onToggle }) => {
const [selected, setSelected] = useState<"created" | "updated">("created");

const handleToggle = (option: "created" | "updated") => {
setSelected(option);
onToggle(option);
};

return (
<div className={cn("flex justify-between w-full h-[36px] px-4 items-end")}>
<Text as="h1" variant="title/24_sb">
독서기록
</Text>
<div className="flex gap-[18px]">
<button
onClick={() => handleToggle("created")}
className={cn(
selected === "created" ? "text-gray-500" : "text-gray-300",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 관리되면 실제 상태와 디자인간의 불일치가 발생할 수 있어보여요

  • 추가로 요런 토글컴포넌트 같은 경우는 저희 패키지에 ToggleButtonGroup이랑 ToggleButton 컴포넌트 사용하면 구현 가능합니다!
export default function Page() {
  const [value, setValue] = useState<string>("created");
  return (
    <ToggleButtonGroup value={value} onChange={(value) => setValue(value ?? "created")}>
      <Flex className=" gap-x-4">
        <ToggleButton
          value="updated"
          className={cn(" text-gray-300 data-[state=selected]:text-gray-500")}
        >
          updated
        </ToggleButton>
        <ToggleButton
          value="created"
          className={cn(" text-gray-300 data-[state=selected]:text-gray-500")}
        >
          created
        </ToggleButton>
      </Flex>
    </ToggleButtonGroup>
  );
}

textVariants({ variant: "body/16_sb" }),
)}
>
생성일 순
</button>

<button
onClick={() => handleToggle("updated")}
className={cn(
selected === "updated" ? "text-gray-500" : "text-gray-300",
textVariants({ variant: "body/16_sb" }),
)}
>
업데이트 순
</button>
</div>
</div>
);
};
6 changes: 3 additions & 3 deletions packages/design-system/TopNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BackIcon } from "@repo/icon/BackIcon";
import { type ComponentPropsWithoutRef, type Ref, forwardRef } from "react";
import { type ComponentPropsWithRef, type Ref, forwardRef } from "react";
import { Text } from "./Text";
import { cn } from "./cn";

interface TopNavigationProps extends ComponentPropsWithoutRef<"button"> {
interface TopNavigationProps extends ComponentPropsWithRef<"button"> {
title?: string;
}

export const TopNavigation = forwardRef(function SearchBar(
export const TopNavigation = forwardRef(function TopNavigation(
{ className, title = "독서기록", ...rest }: TopNavigationProps,
ref?: Ref<HTMLButtonElement>,
) {
Expand Down
Loading