Skip to content

Commit

Permalink
Merge pull request #29 from SOPT-all/feat/#20/chipCommonComponent
Browse files Browse the repository at this point in the history
[Feat]칩 공통컴포넌트 구현
  • Loading branch information
ocahs9 authored Jan 13, 2025
2 parents b020f49 + 4fc980b commit 35b56cd
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 123 deletions.
3 changes: 3 additions & 0 deletions public/svgs/ic_delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/asset/svg/IcDelete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { SVGProps } from "react";

type SvgIcDeleteProps = SVGProps<SVGSVGElement> & {
color?: string;
};

const SvgIcDelete = ({ color = "#14B5F0", ...props }: SvgIcDeleteProps) => (
<svg xmlns="http://www.w3.org/2000/svg" width={24} height={24} fill="none" {...props}>
<title>SvgIcDelete</title>
<path stroke={color} strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M17 7 7 17M7 7l10 10" />
</svg>
);
export default SvgIcDelete;
1 change: 1 addition & 0 deletions src/asset/svg/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as IcDelete } from "./IcDelete";
export { default as IcTest } from "./IcTest";
export { default as React } from "./React";
export { default as Vite } from "./Vite";
45 changes: 45 additions & 0 deletions src/common/component/Chip/Chip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useState } from "react";
import { ChipType, chipItem } from "./ChipStyle.css.ts";
import { IcDelete } from "@asset/svg/index";

interface ChipProps {
label: string;
icon?: boolean;
color: "blue" | "gray";
onClick: () => void;
}

type CombinedChipProps = ChipProps & Exclude<ChipType, undefined>;

const Chip = ({ label, icon = false, color = "blue", onClick }: CombinedChipProps) => {
const [isActive, setIsActive] = useState(false);

const handleClick = () => {
if (color === "gray" || size === "large") return;
setIsActive(!isActive);
onClick();
};

const size = icon ? "large" : "small";

return (
// biome-ignore lint/a11y/useKeyWithClickEvents: <explanation>
<div
className={chipItem({ size, color, active: isActive })} // 스타일 적용
onClick={handleClick}
>
{label}
{icon && (
<IcDelete
color={color === "gray" ? "#717171" : "#14B5F0"}
style={{
position: "relative",
bottom: "1.3px",
}}
/>
)}
</div>
);
};

export default Chip;
59 changes: 59 additions & 0 deletions src/common/component/Chip/ChipStyle.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { color, font } from "@style/styles.css.ts";
import { recipe, RecipeVariants } from "@vanilla-extract/recipes";

export const chipItem = recipe({
base: [
font.body01,
{
display: "flex",
padding: "0.8rem 1.2rem",
justifyContent: "space-between",
alignItems: "center",

borderRadius: "9.9rem",
// background: color.gray.gray000,
color: color.primary.blue700,
border: `0.1rem solid ${color.primary.blue500}`,
},
],

variants: {
size: {
small: {
width: "5.8rem",
height: "3.6rem",
},
large: {
width: "8.2rem",
height: "4rem",
},
},

color: {
blue: {
color: color.primary.blue700,
border: `0.1rem solid ${color.primary.blue500}`,
},
gray: {
color: color.gray.gray700,
border: `0.1rem solid ${color.gray.gray700}`,
},
},

active: {
false: {
background: color.gray.gray000,
},
true: {
backgroundColor: "rgba(67, 214, 255, 0.16)",
},
},
},
defaultVariants: {
size: "small",
color: "blue",
active: false,
},
});

export type ChipType = RecipeVariants<typeof chipItem>;
124 changes: 1 addition & 123 deletions src/page/main/index/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,127 +1,5 @@
import Divider from "@common/component/Divider/Divider";
import Spacing from "@common/component/Spacing/Spacing";

/*
localhost:5173/main
*/
import React, { ChangeEvent, useState } from "react";
import { Button } from "@common/component/Button";
import { IcTest } from "@asset/svg";

const Main = () => {

return (
<>
<div style={{ margin: "3rem", display: "flex", gap: "1rem" }}>
<Button
label="Button"
size="small"
variant="solidPrimary"
disabled={true}
/>
<Button
label="Button"
size="small"
variant="solidPrimary"
disabled={false}
/>
<Button
label="Button"
size="medium"
variant="solidPrimary"
disabled={false}
/>
<Button
label="Button"
size="large"
variant="solidPrimary"
disabled={false}
/>
</div>
<div style={{ margin: "3rem", display: "flex", gap: "1rem" }}>
<Button
label="Button"
size="small"
variant="solidNeutral"
disabled={true}
/>
<Button
label="Button"
size="small"
variant="solidNeutral"
disabled={false}
/>
<Button
label="Button"
size="medium"
variant="solidNeutral"
disabled={false}
/>
<Button
label="Button"
size="large"
variant="solidNeutral"
disabled={false}
/>
</div>
<div style={{ margin: "3rem", display: "flex", gap: "1rem" }}>
<Button
label="Button"
size="small"
variant="outlinePrimary"
disabled={true}
/>
<Button
label="Button"
size="small"
variant="outlinePrimary"
disabled={false}
/>
<Button
label="Button"
size="medium"
variant="outlinePrimary"
disabled={false}
/>
<Button
label="Button"
size="large"
variant="outlinePrimary"
disabled={false}
/>
</div>
<div style={{ margin: "3rem", display: "flex", gap: "1rem" }}>
<Button
label="Button"
leftIcon={<IcTest />}
size="medium"
variant="solidPrimary"
disabled={false}
/>
<Button
label="Button"
rightIcon={<IcTest />}
size="medium"
variant="solidPrimary"
disabled={false}
/>
<Button
label="Button"
leftIcon={<IcTest />}
rightIcon={<IcTest />}
size="medium"
variant="solidPrimary"
disabled={false}
/>
</div>
<span>main</span>
<Spacing marginBottom="10" />
<Divider size="small" />
<Spacing marginBottom="10" />
<Divider />
</>

);
return <div>메인</div>;
};

export default Main;

0 comments on commit 35b56cd

Please sign in to comment.