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

Feature/11/icon component #25

Merged
merged 13 commits into from
Jul 9, 2024
7 changes: 7 additions & 0 deletions src/app/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useAtom } from "jotai";
import { messageAtom } from "@/store/messageAtom.tsx";
import Modal from "@/component/common/modal/Modal";
import useModal from "@/hooks/useModal";
import Icon from "@/component/common/Icon/Icon";

function MainPage() {
const [message] = useAtom(messageAtom);
Expand All @@ -15,6 +16,12 @@ function MainPage() {
<span>welcome to layer 🎇</span>
<div onClick={() => open({ title: "냠냠", content: "쩝쩝", callBack: () => console.log("확인") })}>{message}</div>
</div>

<Icon icon="ic_back" color="red" size={5} onClick={() => console.log("클릭")} />
<Icon icon="ic_back" color={"rgba(0,0,0,0.6)"} size={2} />
<Icon icon="ic_back" color="#00ff00" size={4} />
Comment on lines +20 to +22
Copy link
Member

Choose a reason for hiding this comment

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

오 쓰기 너무너무 좋은데요?! ✨

<Icon icon="ic_check" color="black" size={4} />

<Modal />
</>
);
Expand Down
1 change: 0 additions & 1 deletion src/assets/react.svg

This file was deleted.

8 changes: 8 additions & 0 deletions src/assets/svgs/common/ic_back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/assets/svgs/common/ic_check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/assets/svgs/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as ic_back } from "./ic_back.svg?react";
export { default as ic_check } from "./ic_check.svg?react";
2 changes: 2 additions & 0 deletions src/assets/svgs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./common";
export * from "./toast";
3 changes: 3 additions & 0 deletions src/assets/svgs/toast/ic_success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/svgs/toast/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ic_success } from "./ic_success.svg?react";
34 changes: 34 additions & 0 deletions src/component/common/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { memo } from "react";

import * as icons from "@/assets/svgs";
import { css } from "@emotion/react";

type IconType = keyof typeof icons;

type Props = {
icon: IconType;
color?: string;
size?: string | number;
onClick?: () => void;
};

const DEFAULT_ICON_COLOR = "#000000";

function Icon({ icon, color = DEFAULT_ICON_COLOR, size = "0.2rem", onClick }: Props) {
const SVGIcon = icons[icon];
const widthRem = typeof size === "number" ? `${size}rem` : size;

return (
<SVGIcon
onClick={onClick}
css={css`
color: ${color};
cursor: ${onClick ? "pointer" : "default"};
width: ${widthRem};
height: auto;
`}
/>
);
}

export default memo(Icon);
4 changes: 4 additions & 0 deletions src/svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.svg" {
const value: React.FunctionComponent<React.SVGAttributes<SVGElement>>;
export default value;
}
Loading