-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(normalizeCSS): sr-only 추가 * feat(callout): Callout 컴포넌트 제작 * fix(normalizeCSS): body 테스트 스타일 제거 --------- Co-authored-by: baegofda <[email protected]>
- Loading branch information
Showing
13 changed files
with
323 additions
and
6 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/travelmakers-design-core/src/components/Callout/Callout/Callout.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,17 @@ | ||
import { createStyles } from "@travelmakers-design-v2/styles"; | ||
|
||
export default createStyles((theme) => { | ||
const { spacing, radius, colors } = theme; | ||
|
||
return { | ||
root: { | ||
display: "inline-flex", | ||
flexDirection: "column", | ||
rowGap: spacing.spacing10, | ||
margin: 0, | ||
padding: spacing.spacing30, | ||
borderRadius: radius.radius20, | ||
backgroundColor: colors.surface, | ||
}, | ||
}; | ||
}); |
71 changes: 71 additions & 0 deletions
71
packages/travelmakers-design-core/src/components/Callout/Callout/Callout.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,71 @@ | ||
import { | ||
ClassNames, | ||
PolymorphicComponentProps, | ||
PolymorphicRef, | ||
TmComponentProps, | ||
} from "@travelmakers-design-v2/styles"; | ||
import { forwardRef } from "react"; | ||
import { View } from "../../View"; | ||
import { CalloutHeader } from "../CalloutHader"; | ||
import { CalloutItem } from "../CalloutItem"; | ||
import useStyles from "./Callout.style"; | ||
|
||
export type CalloutStylesNames = ClassNames<typeof useStyles>; | ||
|
||
export type CalloutType = "default" | "warning"; | ||
|
||
export interface Props { | ||
type?: CalloutType; | ||
title: string; | ||
items?: string[]; | ||
emptyText?: string; | ||
} | ||
export interface SharedCalloutProps | ||
extends Props, | ||
TmComponentProps<CalloutStylesNames> {} | ||
|
||
export type CalloutProps<C extends React.ElementType> = | ||
PolymorphicComponentProps<C, SharedCalloutProps>; | ||
|
||
type CalloutComponent = <C extends React.ElementType = "dl">( | ||
props: CalloutProps<C> | ||
) => React.ReactElement; | ||
|
||
export const Callout: CalloutComponent & { | ||
displayName?: string; | ||
} = forwardRef( | ||
<C extends React.ElementType = "dl">( | ||
{ | ||
type = "default", | ||
title, | ||
items = [], | ||
emptyText = "", | ||
className, | ||
...props | ||
}: CalloutProps<C>, | ||
ref: PolymorphicRef<C> | ||
) => { | ||
const isEmptyItems = items.length === 0; | ||
const { classes, cx } = useStyles(); | ||
|
||
const _items = !isEmptyItems ? ( | ||
items.map((item, idx) => <CalloutItem key={idx} content={item} />) | ||
) : ( | ||
<CalloutItem content={emptyText} isEmpty /> | ||
); | ||
|
||
return ( | ||
<View<React.ElementType> | ||
component={"dl"} | ||
ref={ref} | ||
className={cx(classes.root, className)} | ||
{...props} | ||
> | ||
<CalloutHeader type={type} title={title} /> | ||
{_items} | ||
</View> | ||
); | ||
} | ||
); | ||
|
||
Callout.displayName = "Callout"; |
2 changes: 2 additions & 0 deletions
2
packages/travelmakers-design-core/src/components/Callout/Callout/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 { Callout } from "./Callout"; | ||
export type { CalloutProps } from "./Callout"; |
18 changes: 18 additions & 0 deletions
18
packages/travelmakers-design-core/src/components/Callout/CalloutHader/CalloutHeader.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,18 @@ | ||
import { createStyles } from "@travelmakers-design-v2/styles"; | ||
import { CalloutType } from "../Callout/Callout"; | ||
import { CALLOUT_COLOR } from "./CalloutHeader"; | ||
|
||
export default createStyles((theme, { type }: { type: CalloutType }) => { | ||
const { colors, typography, spacing } = theme; | ||
|
||
return { | ||
root: { | ||
display: "flex", | ||
alignItems: "center", | ||
color: colors[CALLOUT_COLOR[type]], | ||
...typography.body3, | ||
fontWeight: 700, | ||
columnGap: spacing.spacing10, | ||
}, | ||
}; | ||
}); |
66 changes: 66 additions & 0 deletions
66
packages/travelmakers-design-core/src/components/Callout/CalloutHader/CalloutHeader.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,66 @@ | ||
import { | ||
ClassNames, | ||
PolymorphicComponentProps, | ||
PolymorphicRef, | ||
TmColor, | ||
TmComponentProps, | ||
useTmTheme, | ||
} from "@travelmakers-design-v2/styles"; | ||
import { forwardRef } from "react"; | ||
import { Icon } from "../../Icon"; | ||
import { View } from "../../View"; | ||
import { CalloutType } from "../Callout/Callout"; | ||
import useStyles from "./CalloutHeader.style"; | ||
|
||
export type CalloutHeaderStylesNames = ClassNames<typeof useStyles>; | ||
|
||
export interface Props { | ||
type: CalloutType; | ||
title: string; | ||
} | ||
export interface SharedCalloutHeaderProps | ||
extends Props, | ||
TmComponentProps<CalloutHeaderStylesNames> {} | ||
|
||
export type CalloutHeaderProps<C extends React.ElementType> = | ||
PolymorphicComponentProps<C, SharedCalloutHeaderProps>; | ||
|
||
type CalloutHeaderComponent = <C extends React.ElementType = "dt">( | ||
props: CalloutHeaderProps<C> | ||
) => React.ReactElement; | ||
|
||
export const CALLOUT_COLOR: Record<CalloutType, TmColor> = { | ||
default: "secondary", | ||
warning: "error", | ||
}; | ||
|
||
export const CalloutHeader: CalloutHeaderComponent & { | ||
displayName?: string; | ||
} = forwardRef( | ||
<C extends React.ElementType = "dt">( | ||
{ type, title, className, ...props }: CalloutHeaderProps<C>, | ||
ref: PolymorphicRef<C> | ||
) => { | ||
const { colors } = useTmTheme(); | ||
const { classes, cx } = useStyles({ type }); | ||
|
||
return ( | ||
<View<React.ElementType> | ||
component={"dt"} | ||
ref={ref} | ||
className={cx(classes.root, className)} | ||
{...props} | ||
> | ||
<Icon | ||
src="IcAlert" | ||
width={14} | ||
height={14} | ||
color={colors[CALLOUT_COLOR[type]]} | ||
/> | ||
{title} | ||
</View> | ||
); | ||
} | ||
); | ||
|
||
CalloutHeader.displayName = "CalloutHeader"; |
2 changes: 2 additions & 0 deletions
2
packages/travelmakers-design-core/src/components/Callout/CalloutHader/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 { CalloutHeader } from "./CalloutHeader"; | ||
export type { CalloutHeaderProps } from "./CalloutHeader"; |
13 changes: 13 additions & 0 deletions
13
packages/travelmakers-design-core/src/components/Callout/CalloutItem/CalloutItem.style.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,13 @@ | ||
import { TmTheme, createStyles } from "@travelmakers-design-v2/styles"; | ||
|
||
export default createStyles((theme: TmTheme) => { | ||
const { colors, typography } = theme; | ||
|
||
return { | ||
root: { | ||
margin: 0, | ||
color: colors.onSurface, | ||
...typography.body3, | ||
}, | ||
}; | ||
}); |
50 changes: 50 additions & 0 deletions
50
packages/travelmakers-design-core/src/components/Callout/CalloutItem/CalloutItem.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,50 @@ | ||
import { | ||
ClassNames, | ||
PolymorphicComponentProps, | ||
PolymorphicRef, | ||
TmComponentProps, | ||
} from "@travelmakers-design-v2/styles"; | ||
import { forwardRef } from "react"; | ||
import { View } from "../../View"; | ||
import useStyles from "./CalloutItem.style"; | ||
|
||
export type CalloutItemStylesNames = ClassNames<typeof useStyles>; | ||
|
||
export interface Props { | ||
content: string; | ||
isEmpty?: boolean; | ||
} | ||
export interface SharedCalloutItemProps | ||
extends Props, | ||
TmComponentProps<CalloutItemStylesNames> {} | ||
|
||
export type CalloutItemProps<C extends React.ElementType> = | ||
PolymorphicComponentProps<C, SharedCalloutItemProps>; | ||
|
||
type CalloutItemComponent = <C extends React.ElementType = "dd">( | ||
props: CalloutItemProps<C> | ||
) => React.ReactElement; | ||
|
||
export const CalloutItem: CalloutItemComponent & { | ||
displayName?: string; | ||
} = forwardRef( | ||
<C extends React.ElementType = "dd">( | ||
{ content, isEmpty = false, className, ...props }: CalloutItemProps<C>, | ||
ref: PolymorphicRef<C> | ||
) => { | ||
const { classes, cx } = useStyles(); | ||
|
||
return ( | ||
<View<React.ElementType> | ||
component={"dd"} | ||
ref={ref} | ||
className={cx(classes.root, className, { "sr-only": isEmpty })} | ||
{...props} | ||
> | ||
{content} | ||
</View> | ||
); | ||
} | ||
); | ||
|
||
CalloutItem.displayName = "CalloutItem"; |
2 changes: 2 additions & 0 deletions
2
packages/travelmakers-design-core/src/components/Callout/CalloutItem/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 { CalloutItem } from "./CalloutItem"; | ||
export type { CalloutItemProps } from "./CalloutItem"; |
1 change: 1 addition & 0 deletions
1
packages/travelmakers-design-core/src/components/Callout/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 @@ | ||
export * from "./Callout"; |
64 changes: 64 additions & 0 deletions
64
packages/travelmakers-design-core/src/components/Callout/stories/Callout.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,64 @@ | ||
import { Meta } from "@storybook/react"; | ||
import { Callout } from "../Callout"; | ||
|
||
const data = { title: "타이틀", items: ["추가 설명을 위한 영역입니다."] }; | ||
const dataWithoutItems = { title: "타이틀(추가적인 설명 없음)", items: [] }; | ||
|
||
export default { | ||
title: "@travelmakers-design-v2/core/General/Callouts", | ||
component: Callout, | ||
argTypes: { | ||
type: { | ||
control: { type: "radio", options: ["default", "warning"] }, | ||
defaultValue: "default", | ||
description: "Callout의 type을 지정합니다.", | ||
table: { | ||
type: { | ||
summary: "string", | ||
}, | ||
}, | ||
}, | ||
title: { | ||
type: "string", | ||
description: "Callout에서 사용될 title을 나타냅니다.", | ||
table: { | ||
type: { | ||
summary: "string", | ||
}, | ||
}, | ||
}, | ||
items: { | ||
control: { type: "object" }, | ||
description: "Callout에서 title에 대한 추가 설명을 작성합니다.", | ||
defaultValue: [], | ||
table: { | ||
type: { | ||
summary: "string[]", | ||
}, | ||
}, | ||
}, | ||
emptyText: { | ||
type: "string", | ||
defaultValue: "", | ||
table: { | ||
type: { | ||
summary: "string", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
export const Default = (props) => { | ||
return <Callout title={data.title} {...props} items={data.items} />; | ||
}; | ||
|
||
export const CalloutWithoutItems = (props) => { | ||
return ( | ||
<Callout | ||
title={dataWithoutItems.title} | ||
items={dataWithoutItems.items} | ||
{...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
21 changes: 16 additions & 5 deletions
21
packages/travelmakers-design-styles/src/theme/NormalizeCSS.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