Skip to content

Commit

Permalink
Merge pull request #25 from depromeet/feature/11/icon-component
Browse files Browse the repository at this point in the history
Feature/11/icon component
  • Loading branch information
donghunee authored Jul 9, 2024
2 parents a971571 + d50f24b commit be18ea7
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 1 deletion.
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} />
<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;
}

0 comments on commit be18ea7

Please sign in to comment.