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

feat(card): creating a card #16

Merged
merged 18 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 17 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default createStyles(
root: {
width: fullWidth && "100%",
height: TM_HEIGHTS[size],
padding: `0 ${spacing.spacing50}`,
padding: isNonBoxShadow ? 0 : `0 ${spacing.spacing50}`,
borderRadius: roundness ? radius.radius100 : radius.radius20,
cursor: "pointer",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { createStyles } from "@travelmakers-design-v2/styles";
import { Props } from "./CouponCard";

export default createStyles((theme, { type }: Pick<Props, "type">) => {
const getBackgroundColor = () => {
return {
week: {
backgroundColor: theme.colors.secondary,
},
month: {
backgroundColor: theme.colors.secondary20,
},
all: {
backgroundColor: theme.colors.primary,
},
};
};

return {
container: {
width: "296px",
height: "142px",
backgroundColor: theme.colors.primary99,
borderRadius: theme.radius.radius20,
display: "flex",
},
leftBox: {
...getBackgroundColor()[type],
width: "80px",
display: "flex",
flexDirection: "column",
padding: theme.spacing.spacing10,
borderRadius: `${theme.radius.radius20} 0 0 ${theme.radius.radius20}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

P4: container에 borderRadius가 적용되어있어서 overflow: hidden을 추가하고 leftBox의 borderRadius는 제거해줘도 될 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

해당 백그라운드영역자체는 직사각형으로 자리가 잡혀있어서 hidden으로 영역제거가 되지 않는것 같습니다 ㅠ
해당 부분은 유지해두겠슴돠 :)

},
rightBox: {
width: "100%",
padding: theme.spacing.spacing20,
display: "flex",
flexDirection: "column",
gap: theme.spacing.spacing5,
},
discountBox: {
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
},
checkBox: {
backgroundColor: theme.colors.primaryContainer,
borderRadius: theme.radius.radius100,
width: 16,
height: 16,
display: "flex",
justifyContent: "center",
alignItems: "center",
},
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { PolymorphicRef, useTmTheme } from "@travelmakers-design-v2/styles";
import { forwardRef, PropsWithChildren } from "react";
import { View } from "../../View";
import useStyles from "./CouponCard.style";
import { CouponCardProps, CouponCardComponent } from "./CouponCard.type";
import { Typography } from "../../Typography";
import { Icon } from "../../Icon";

export interface Props {
/** CouponCard의 Type을 설정합니다. */
type: "week" | "month" | "all";

/** CouponCard의 상태를 설정합니다. */
state: "default" | "applied" | "checked";

/** CouponCard의 day를 설정합니다. */
day: number;

/** CouponCard의 타이틀을 설정합니다. */
title: string;

/** CouponCard의 서브 타이틀을 설정합니다. */
subTitle: string;

/** CouponCard의 적용상품 설정합니다. */
item?: string;

/** CouponCard의 잔여수량을 설정합니다. */
remainingQuantity?: number;

/** CouponCard의 내용을 설정합니다. */
content: string;
}

export const CouponCard: CouponCardComponent & {
displayName?: string;
} = forwardRef(
<C extends React.ElementType = "div">(
{
type,
state,
day,
title,
subTitle,
item,
remainingQuantity,
content,
className,
...props
}: PropsWithChildren<CouponCardProps<C>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

P4: children을 사용하지 않으니 PropsWithChildren타입은 정리해줘도 좋을 것 같습니다. 다른 컴포넌트들도 동일합니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ref: PolymorphicRef<C>
) => {
const { classes, cx } = useStyles({ type });
const theme = useTmTheme();
const DAY_TYPE = {
week: "Week",
month: "Month",
all: "All",
};

const getItemText = (
item: Props["item"],
remainingQuantity: Props["remainingQuantity"]
) => {
const firstText = item ?? "전체";
const secondText = ` | 잔여 ${remainingQuantity}개`;
if (remainingQuantity) {
return `${firstText} ${secondText}`;
} else {
return firstText;
}
};

const getStateIcon = (state: Props["state"]) => {
switch (state) {
case "applied":
return (
<Typography level="body3" color="primary3">
적용중
</Typography>
);

case "checked":
return (
<div className={classes.checkBox}>
<Icon
src="IcCheck"
width={12}
height={12}
color={theme.colors.white}
/>
</div>
);

default:
return null;
}
};

return (
<View<React.ElementType>
component={"div"}
ref={ref}
className={cx(className, classes.container)}
{...props}
>
<div className={classes.leftBox}>
<Typography level="display2" color={"white"}>
{day}
</Typography>
<Typography family="Noto Serif KR" level="body1" color={"white"}>
{DAY_TYPE[type]}
</Typography>
</div>
<div className={classes.rightBox}>
<div className={classes.discountBox}>
<div>
<Typography level="display6" color="secondary">
{title}
</Typography>
</div>
<div>{getStateIcon(state)}</div>
</div>
<Typography level="body3" color="primary">
{subTitle}
</Typography>
<Typography level="caption" color="errorInteract">
{getItemText(item, remainingQuantity)}
</Typography>
<Typography
level="caption"
color="primary3"
style={{ whiteSpace: "pre-line" }}
>
{content}
</Typography>
</div>
</View>
);
}
);

CouponCard.displayName = "CouponCard";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
ClassNames,
PolymorphicComponentProps,
TmComponentProps,
} from "@travelmakers-design-v2/styles";
import { Props } from "./CouponCard";
import useStyles from "./CouponCard.style";

type CouponCardStylesNames = ClassNames<typeof useStyles>;

interface SharedCouponCardProps
extends Props,
TmComponentProps<CouponCardStylesNames> {}

export type CouponCardProps<C extends React.ElementType> =
PolymorphicComponentProps<C, SharedCouponCardProps>;

export type CouponCardComponent = <C extends React.ElementType = "div">(
props: CouponCardProps<C>
) => React.ReactElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { CouponCard } from "./CouponCard";
export type { CouponCardProps } from "./CouponCard.type";
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Meta } from "@storybook/react";
import { CouponCard } from "../CouponCard";

export default {
title: "@travelmakers-design-v2/core/General/Card/CouponCard",
component: CouponCard,
argTypes: {
type: {
defaultValue: "week",
description: "CouponCard의 Type을 설정합니다.",
options: ["week", "month", "all"],
control: { type: "inline-radio" },
},
state: {
defaultValue: "default",
description: "CouponCard의 상태를 설정합니다.",
options: ["default", "applied", "checked"],
control: { type: "inline-radio" },
},
day: {
defaultValue: 1,
description: "CouponCard의 day를 설정합니다.",
table: {
type: {
summary: "number",
},
},
control: { type: "number" },
},
title: {
defaultValue: "00%",
description: "CouponCard의 타이틀을 설정합니다.",
table: {
type: {
summary: "string",
},
},
control: { type: "text" },
},
subTitle: {
defaultValue: "호텔에삶 특별 혜택",
description: "CouponCard의 서브 타이틀을 설정합니다.",
table: {
type: {
summary: "string",
},
},
control: { type: "text" },
},
item: {
defaultValue: "적용 상품",
description: "CouponCard의 적용상품 설정합니다.",
table: {
type: {
summary: "string",
},
},
control: { type: "text" },
},
remainingQuantity: {
defaultValue: 5,
description: "CouponCard의 잔여수량을 설정합니다.",
table: {
type: {
summary: "number",
},
},
control: { type: "number" },
},
content: {
defaultValue:
"*쿠폰 사용 안내 문구\n *쿠폰 사용 안내 문구 안내 문구\n *쿠폰사용안내 문구 안내 문구",
description: "CouponCard의 내용을 설정합니다.",
table: {
type: {
summary: "string",
},
},
control: { type: "text" },
},
},
} as Meta;

export const Default = (props) => {
return <CouponCard {...props} />;
};
Loading