-
Notifications
You must be signed in to change notification settings - Fork 0
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: creating a price #10
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
packages/travelmakers-design-core/src/components/Price/Price.style.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { createStyles } from "@travelmakers-design-v2/styles"; | ||
import { Props } from "./Price"; | ||
|
||
export default createStyles((theme, { type }: Pick<Props, "type">) => { | ||
return { | ||
root: { | ||
display: "flex", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
width: "100%", | ||
}, | ||
|
||
percentText: { | ||
...theme.typography.display6, | ||
fontWeight: "700", | ||
width: "39px", | ||
color: theme.colors.error, | ||
}, | ||
nightText: { | ||
...theme.typography.body3, | ||
fontWeight: "700", | ||
textAlign: "right", | ||
width: "28px", | ||
color: theme.colors.primary1, | ||
}, | ||
priceText: { | ||
...theme.typography.display4, | ||
fontWeight: "700", | ||
color: theme.colors.primary1, | ||
marginLeft: theme.spacing.spacing5, | ||
}, | ||
priceBeforeText: { | ||
...theme.typography.body2, | ||
fontWeight: "700", | ||
color: theme.colors.primary1, | ||
}, | ||
priceStartText: { | ||
...theme.typography.body3, | ||
fontWeight: "400", | ||
color: theme.colors.primary2, | ||
marginLeft: theme.spacing.spacing5, | ||
}, | ||
|
||
// NOTE: Type is 'secondary' | ||
labelSecondary: { | ||
...theme.typography.body3, | ||
fontWeight: "400", | ||
color: theme.colors.primary1, | ||
marginRight: theme.spacing.spacing5, | ||
}, | ||
nightSecondaryText: { | ||
...theme.typography.body3, | ||
fontWeight: "700", | ||
color: theme.colors.primary1, | ||
textAlign: "right", | ||
marginRight: theme.spacing.spacing5, | ||
}, | ||
priceSecondaryText: { | ||
...theme.typography.body3, | ||
fontWeight: "400", | ||
color: theme.colors.primary2, | ||
}, | ||
priceBeforeSecondaryText: { | ||
...theme.typography.body3, | ||
fontWeight: "400", | ||
color: theme.colors.primary2, | ||
}, | ||
couponWrap: { | ||
display: "flex", | ||
alignItems: "center", | ||
width: "74px", | ||
background: theme.colors.secondaryContainer, | ||
borderRadius: theme.spacing.spacing5, | ||
marginLeft: theme.spacing.spacing5, | ||
}, | ||
couponWord: { | ||
...theme.typography.caption, | ||
fontWeight: "700", | ||
color: theme.colors.secondary1, | ||
}, | ||
}; | ||
}); |
123 changes: 123 additions & 0 deletions
123
packages/travelmakers-design-core/src/components/Price/Price.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { PolymorphicRef } from "@travelmakers-design-v2/styles"; | ||
import { forwardRef, PropsWithChildren } from "react"; | ||
import { View } from "../View"; | ||
import useStyles from "./Price.style"; | ||
import { PriceProps, PriceComponent } from "./Price.type"; | ||
import { Icon } from "../Icon"; | ||
|
||
export interface Props { | ||
/** Price 컴포넌트의 타입을 정합니다. */ | ||
type?: "primary" | "secondary"; | ||
|
||
/** (secondary type 한정) Price 컴포넌트의 레이블을 표시합니다. */ | ||
label?: string; | ||
|
||
/** Price 컴포넌트의 할인율을 표시합니다. */ | ||
percentText?: number; | ||
|
||
/** Price 컴포넌트의 1박을 표시합니다. */ | ||
nightText?: number; | ||
|
||
/** Price 컴포넌트의 가격을 표시합니다. */ | ||
priceText?: number; | ||
|
||
/** Price 컴포넌트의 시작가격을 표시합니다. */ | ||
priceStartText?: string; | ||
|
||
/** (secondary type 한정) Price 컴포넌트의 쿠폰 표시여부를 결정합니다. */ | ||
isCoupon?: boolean; | ||
} | ||
|
||
export const Price: PriceComponent & { | ||
displayName?: string; | ||
} = forwardRef( | ||
<C extends React.ElementType = "div">( | ||
{ | ||
type = "primary", | ||
label, | ||
percentText, | ||
nightText, | ||
priceText, | ||
priceStartText, | ||
isCoupon = true, | ||
className, | ||
children, | ||
...props | ||
}: PropsWithChildren<PriceProps<C>>, | ||
ref: PolymorphicRef<C> | ||
) => { | ||
const { classes, cx } = useStyles({ type }); | ||
|
||
const Primary = () => { | ||
return ( | ||
<View<React.ElementType> | ||
component={"div"} | ||
ref={ref} | ||
className={cx(classes.root, className)} | ||
{...props} | ||
> | ||
{percentText && ( | ||
<span className={cx(classes.percentText)}>{percentText}%</span> | ||
)} | ||
{nightText && ( | ||
<span className={cx(classes.nightText)}>{nightText}박</span> | ||
)} | ||
{priceText && ( | ||
<> | ||
<span className={cx(classes.priceText)}> | ||
{priceText.toLocaleString("ko")} | ||
</span> | ||
<span className={cx(classes.priceBeforeText)}>원~</span> | ||
</> | ||
)} | ||
{priceStartText && ( | ||
<span className={cx(classes.priceStartText)}> | ||
| {priceStartText} | ||
</span> | ||
)} | ||
</View> | ||
); | ||
}; | ||
|
||
const Secondary = () => { | ||
return ( | ||
<View<React.ElementType> | ||
component={"div"} | ||
ref={ref} | ||
className={cx(classes.root, className)} | ||
{...props} | ||
> | ||
{label && <span className={cx(classes.labelSecondary)}>{label}</span>} | ||
{nightText && ( | ||
<span className={cx(classes.nightSecondaryText)}> | ||
{nightText}박 | ||
</span> | ||
)} | ||
{priceText && ( | ||
<> | ||
<span className={cx(classes.priceSecondaryText)}> | ||
{priceText?.toLocaleString("ko")} | ||
</span> | ||
<span className={cx(classes.priceBeforeSecondaryText)}>원</span> | ||
</> | ||
)} | ||
{isCoupon && ( | ||
<div className={cx(classes.couponWrap)}> | ||
<Icon | ||
src="IcDiscount" | ||
width={16} | ||
height={16} | ||
style={{ margin: "0 4px" }} | ||
/> | ||
<span className={cx(classes.couponWord)}>쿠폰 적용가</span> | ||
</div> | ||
)} | ||
</View> | ||
); | ||
}; | ||
|
||
return type === "primary" ? <Primary /> : <Secondary />; | ||
} | ||
); | ||
|
||
Price.displayName = "Price"; |
20 changes: 20 additions & 0 deletions
20
packages/travelmakers-design-core/src/components/Price/Price.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "./Price"; | ||
import useStyles from "./Price.style"; | ||
|
||
type PriceStylesNames = ClassNames<typeof useStyles>; | ||
|
||
interface SharedPriceProps extends Props, TmComponentProps<PriceStylesNames> {} | ||
|
||
export type PriceProps<C extends React.ElementType> = PolymorphicComponentProps< | ||
C, | ||
SharedPriceProps | ||
>; | ||
|
||
export type PriceComponent = <C extends React.ElementType = "div">( | ||
props: PriceProps<C> | ||
) => React.ReactElement; |
2 changes: 2 additions & 0 deletions
2
packages/travelmakers-design-core/src/components/Price/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { Price } from "./Price"; | ||
export type { PriceProps } from "./Price.type"; |
80 changes: 80 additions & 0 deletions
80
packages/travelmakers-design-core/src/components/Price/stories/Price.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from "react"; | ||
import { Price } from "../Price"; | ||
|
||
export default { | ||
title: "@travelmakers-design-v2/core/General/Price", | ||
component: Price, | ||
argTypes: { | ||
type: { | ||
defaultValue: "primary", | ||
description: "Price 컴포넌트의 타입을 정합니다.", | ||
options: ["primary", "secondary"], | ||
control: { type: "inline-radio" }, | ||
}, | ||
label: { | ||
defaultValue: "", | ||
description: "(secondary type 한정)Price 컴포넌트의 레이블을 표시합니다.", | ||
table: { | ||
type: { | ||
summary: "string", | ||
}, | ||
}, | ||
control: { type: "text" }, | ||
}, | ||
percentText: { | ||
defaultValue: 70, | ||
description: "Price 컴포넌트의 할인율을 표시합니다.", | ||
table: { | ||
type: { | ||
summary: "number", | ||
}, | ||
}, | ||
control: { type: "number" }, | ||
}, | ||
nightText: { | ||
defaultValue: 1, | ||
description: "Price 컴포넌트의 1박을 표시합니다.", | ||
table: { | ||
type: { | ||
summary: "number", | ||
}, | ||
}, | ||
control: { type: "number" }, | ||
}, | ||
priceText: { | ||
defaultValue: 10000, | ||
description: "Price 컴포넌트의 가격을 표시합니다.", | ||
table: { | ||
type: { | ||
summary: "number", | ||
}, | ||
}, | ||
control: { type: "number" }, | ||
}, | ||
priceStartText: { | ||
defaultValue: "1박 100,000원부터", | ||
description: "Price 컴포넌트의 시작가격을 표시합니다.", | ||
table: { | ||
type: { | ||
summary: "string", | ||
}, | ||
}, | ||
control: { type: "text" }, | ||
}, | ||
isCoupon: { | ||
defaultValue: true, | ||
description: | ||
" (secondary type 한정) Price 컴포넌트의 쿠폰 표시여부를 결정합니다.", | ||
table: { | ||
type: { | ||
summary: "boolean", | ||
}, | ||
}, | ||
control: { type: "boolean" }, | ||
}, | ||
}, | ||
}; | ||
|
||
export const Default = (props) => { | ||
return <Price {...props} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P4: children은 사용하지 않으니 다 제거해주면 좋을 것 같네용