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

[FE] feat: IconButton 공통 컴포넌트 만들기(#48) #64

Merged
merged 9 commits into from
Jul 19, 2024
11 changes: 11 additions & 0 deletions frontend/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { StorybookConfig } from "@storybook/react-webpack5";
import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";

const config: StorybookConfig = {
stories: ["../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
Expand All @@ -17,5 +18,15 @@ const config: StorybookConfig = {
docs: {
autodocs: true,
},
webpackFinal: async (config) => {
if (!config.resolve) {
config.resolve = {};
}
if (!config.resolve.plugins) {
config.resolve.plugins = [];
}
config.resolve.plugins.push(new TsconfigPathsPlugin({}));
return config;
},
};
export default config;
15 changes: 0 additions & 15 deletions frontend/.storybook/preview.ts

This file was deleted.

26 changes: 26 additions & 0 deletions frontend/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import GlobalStyles from "../src/styles/globalStyles";
import { theme } from "../src/styles/theme";
import type { Preview } from "@storybook/react";
import React from "react";
import { ThemeProvider } from "styled-components";

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export const decorators = [
(Story) => (
<ThemeProvider theme={theme}>
<GlobalStyles />
<Story />
</ThemeProvider>
),
];
export default preview;
67 changes: 67 additions & 0 deletions frontend/package-lock.json

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

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"stylelint-order": "^6.0.4",
"ts-jest": "^29.2.2",
"ts-loader": "^9.5.1",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.5.3",
"webpack": "^5.92.1",
"webpack-cli": "^5.1.4",
Expand Down
49 changes: 49 additions & 0 deletions frontend/src/components/common/iconButton/IconButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import IconButton from "./IconButton";
import type { Meta, StoryObj } from "@storybook/react";

const meta = {
title: "common/IconButton",
component: IconButton,
parameters: {
docs: {
description: {
component: "아이콘 버튼 컴포넌트",
},
},
},
argTypes: {
iconKind: {
description: "아이콘 종류",
control: { type: "select" },
options: ["person", "link", "calendar"],
},
text: {
description: "아이콘 버튼 텍스트",
control: { type: "text" },
},
},
} satisfies Meta<typeof IconButton>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
iconKind: "person",
text: "person",
},
};

export const WithoutText: Story = {
args: {
iconKind: "link",
},
};

export const WithDifferentIcon: Story = {
args: {
iconKind: "calendar",
text: "calendar",
},
};
39 changes: 39 additions & 0 deletions frontend/src/components/common/iconButton/IconButton.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Icon from "../icon/Icon";
import styled from "styled-components";

export const IconButtonContainer = styled.div`
Copy link
Member

Choose a reason for hiding this comment

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

컴포넌트 이름도 IconButton인 만큼 div 태그보다는 button 태그로 나타내는 건 어떨까요?

Suggested change
export const IconButtonContainer = styled.div`
export const IconButtonContainer = styled.button`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 button이라는걸 잘 보여줄 수 있을 것 같네요! 수정하였습니다ㅎㅎ

display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
`;

export const IconButtonImg = styled.div`
cursor: pointer;

display: flex;
align-items: center;
justify-content: center;

width: 50px;
height: 50px;

border: 1px solid ${({ theme }) => theme.COLOR.grey1};
border-radius: 15px;
box-shadow: 0 4px 4px rgb(0 0 0 / 10%);

&:active {
position: relative;
top: 3px;
box-shadow: 0 1px 1px rgb(0 0 0 / 10%);
}
`;

export const StyledIcon = styled(Icon)`
width: 30px;
height: 30px;
`;

export const IconButtonText = styled.p`
font: ${({ theme }) => theme.TEXT.xSmall};
`;
21 changes: 21 additions & 0 deletions frontend/src/components/common/iconButton/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";
import * as S from "@/components/common/iconButton/IconButton.style";
import IconKind from "@/@types/icon";

interface IconButtonProps {
iconKind: IconKind;
text?: string;
}
Copy link
Member

Choose a reason for hiding this comment

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

IconButtonProps에 onclick이나 ariaLabel 속성도 추가되면 좋을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ButtonHTMLAttributes<HTMLButtonElement>를 확장하여 onClick 속성은 자동으로 추가되게 하였습니다.
icon이 없을 것을 대비해 aria-label="Icon Button" 속성을 추가하였습니다!


const IconButton = ({ iconKind, text = "" }: IconButtonProps) => {
return (
<S.IconButtonContainer>
<S.IconButtonImg>
<S.StyledIcon kind={iconKind} />
</S.IconButtonImg>
{text !== "" && <S.IconButtonText>{text}</S.IconButtonText>}
</S.IconButtonContainer>
);
};

export default IconButton;