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

Accordion 컴포넌트 스토리 작성 #24

Open
wants to merge 4 commits 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
57 changes: 57 additions & 0 deletions src/components/Accordion/Accordion.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Meta, StoryObj } from "@storybook/react";

import Accordion, { type AccordionProps } from "./Accordion";
import { type AccordionSummaryProps } from "./AccordionSummary";

type AccordionCompositionProps = Pick<AccordionProps, "width" | "open"> &
Pick<AccordionSummaryProps, "color" | "size">;

const meta: Meta = {
component: Accordion,
tags: ["autodocs"],
argTypes: {
children: {
table: { disable: true },
},
color: {
control: "inline-radio",
options: ["black", "grey"],
description: "Accordion.Summary의 글씨 색상을 결정합니다.",
table: {
defaultValue: { summary: "black" },
category: "Accordion.Summary",
},
},
size: {
control: "inline-radio",
options: ["sm", "md"],
description: "Accordion.Summary의 크기를 결정합니다.",
table: {
defaultValue: { summary: "md" },
category: "Accordion.Summary",
},
},
},
};

export default meta;
type Story = StoryObj<AccordionCompositionProps>;

export const Variants: Story = {
args: {
width: "200px",
open: false,
color: "black",
size: "md",
},
render: ({ width, open, color, size }) => (
<Accordion width={width} open={open}>
<Accordion.Details>
<Accordion.Summary color={color} size={size}>
Summary
</Accordion.Summary>
Details
</Accordion.Details>
</Accordion>
),
};
15 changes: 13 additions & 2 deletions src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import { AccordionContextProvider } from "./AccordionContextProvider";
import AccordionDetails from "./AccordionDetails";
import AccordionSummary from "./AccordionSummary";

interface AccordionProps {
export interface AccordionProps {
/**
* Accordion의 너비를 결정합니다.
* @default 200
*/
width?: number | string;
/**
* Accordion의 초기 열림 상태를 결정합니다.
* @default false
*/
open?: boolean;
children: ReactNode;
}

export default function Accordion({
Copy link
Member Author

@YuHyun-P YuHyun-P Jan 31, 2024

Choose a reason for hiding this comment

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

Accordion을 export default 한 후에 Details, Summary 속성을 추가하면 아래와 같이 스토리북 실행 도중 웹팩 컴파일 에러가 발생합니다. 정확한 이유는 못 찾았지만.. 속성 추가 코드와 export default 문 순서를 바꾸니 해결됐습니다😅

에러 메시지
accordion chunk load error

에러가 발생한 코드
스크린샷 2024-01-31 오후 5 10 58

/** Accordion은 세부 내용을 숨기거나 보여줄 수 있는 컴포넌트입니다. */
function Accordion({
width = 200,
open: initOpen = false,
children,
Expand All @@ -24,3 +33,5 @@ export default function Accordion({

Accordion.Details = AccordionDetails;
Accordion.Summary = AccordionSummary;

export default Accordion;
4 changes: 2 additions & 2 deletions src/components/Accordion/AccordionSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
type AccordionContextType,
useAccordion,
} from "./AccordionContextProvider";
import ChevronIcon from "./ChevronIcon/ChevronIcon";
import ChevronIcon from "./ChevronIcon";

interface AccordionSummaryProps {
export interface AccordionSummaryProps {
color?: "black" | "grey";
size?: "md" | "sm";
children: ReactNode | RenderComponentType;
Expand Down
Loading