Skip to content

Commit 2a1c991

Browse files
committed
feat: 채팅 버블 부가 정보 커스텀 스타일 프롭스 추가
1 parent 163a360 commit 2a1c991

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

packages/tds-widget/src/chat/bubble-container/bubble-container.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PropsWithChildren } from 'react'
2+
import { css, CSSProp } from 'styled-components'
23
import { Container } from '@titicaca/tds-ui'
34

45
import { DEFAULT_MESSAGE_ID_PREFIX } from '../chat/constants'
@@ -41,6 +42,14 @@ interface ContainerBaseProp {
4142
onReplyClick?: () => void
4243
/** 메세지 ref에 주입되는 callback 함수 */
4344
messageRefCallback?: (id: string) => void
45+
/** 메세지 부가 정보 (날짜, 프로필 등) 커스텀 스타일 */
46+
bubbleInfoStyle?: {
47+
dateDivider?: { css?: CSSProp }
48+
unreadCount?: { css?: CSSProp }
49+
dateTime?: { css?: CSSProp }
50+
profile?: { css?: CSSProp }
51+
thanks?: { css?: CSSProp }
52+
}
4453
}
4554

4655
type SentBubbleContainerProp = PropsWithChildren<
@@ -66,6 +75,7 @@ function SentBubbleContainer({
6675
onReplyClick,
6776
messageRefCallback,
6877
children,
78+
bubbleInfoStyle,
6979
...props
7080
}: SentBubbleContainerProp) {
7181
return (
@@ -96,6 +106,8 @@ function SentBubbleContainer({
96106
showTimeInfo={showTimeInfo}
97107
onReplyClick={onReplyClick}
98108
css={{ marginRight: 4, textAlign: 'right' }}
109+
dateTimeStyle={bubbleInfoStyle?.dateTime}
110+
unreadCountStyle={bubbleInfoStyle?.unreadCount}
99111
/>
100112
) : null}
101113

@@ -107,7 +119,13 @@ function SentBubbleContainer({
107119
count={thanks.count}
108120
haveMine={thanks.haveMine}
109121
onClick={onThanksClick}
110-
css={{ display: 'inline-flex', marginTop: 6, marginRight: 10 }}
122+
css={css`
123+
display: inline-flex;
124+
margin-top: 6px;
125+
margin-right: 10px;
126+
127+
${bubbleInfoStyle?.thanks?.css}
128+
`}
111129
/>
112130
) : null}
113131
</Container>
@@ -145,6 +163,7 @@ function ReceivedBubbleContainer({
145163
messageRefCallback,
146164
onUserClick,
147165
children,
166+
bubbleInfoStyle,
148167
...props
149168
}: ReceivedBubbleContainerProp) {
150169
return (
@@ -170,7 +189,12 @@ function ReceivedBubbleContainer({
170189
) : null}
171190
<Container css={{ marginLeft: 40 }}>
172191
{showProfile ? (
173-
<ProfileName size="mini" alpha={0.8} margin={{ bottom: 5 }}>
192+
<ProfileName
193+
size="mini"
194+
alpha={0.8}
195+
margin={{ bottom: 5 }}
196+
css={bubbleInfoStyle?.profile?.css}
197+
>
174198
{user
175199
? formatUsername({
176200
name: user?.name,
@@ -192,6 +216,8 @@ function ReceivedBubbleContainer({
192216
onReplyClick={onReplyClick}
193217
date={createdAt}
194218
css={{ marginLeft: 4, textAlign: 'left' }}
219+
dateTimeStyle={bubbleInfoStyle?.dateTime}
220+
unreadCountStyle={bubbleInfoStyle?.unreadCount}
195221
/>
196222
) : null}
197223

packages/tds-widget/src/chat/bubble-container/bubble-info.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Container, Text } from '@titicaca/tds-ui'
2-
import { styled } from 'styled-components'
2+
import styled, { CSSProp } from 'styled-components'
33
import { format, setDefaultOptions } from 'date-fns'
44
import { ko } from 'date-fns/locale'
55

@@ -36,6 +36,8 @@ export function BubbleInfo({
3636
showTimeInfo = true,
3737
showDateInfo = false,
3838
onReplyClick,
39+
dateTimeStyle,
40+
unreadCountStyle,
3941
...props
4042
}: {
4143
align: 'left' | 'right'
@@ -44,6 +46,8 @@ export function BubbleInfo({
4446
showTimeInfo?: boolean
4547
showDateInfo?: boolean
4648
onReplyClick?: () => void
49+
dateTimeStyle?: { css?: CSSProp }
50+
unreadCountStyle?: { css?: CSSProp }
4751
}) {
4852
return (
4953
<BubbleInfoContainer position="relative" display="inline-block" {...props}>
@@ -58,17 +62,19 @@ export function BubbleInfo({
5862
) : null}
5963

6064
{unreadCount ? (
61-
<UnreadMessageCountText>{unreadCount}</UnreadMessageCountText>
65+
<UnreadMessageCountText css={unreadCountStyle?.css}>
66+
{unreadCount}
67+
</UnreadMessageCountText>
6268
) : null}
6369

6470
{showDateInfo ? (
65-
<Text size={10} alpha={0.51}>
71+
<Text size={10} alpha={0.51} css={dateTimeStyle?.css}>
6672
{format(new Date(date), 'MM.dd')}
6773
</Text>
6874
) : null}
6975

7076
{showTimeInfo ? (
71-
<Text size={10} alpha={0.51}>
77+
<Text size={10} alpha={0.51} css={dateTimeStyle?.css}>
7278
{format(new Date(date), 'a h:mm')}
7379
</Text>
7480
) : null}

packages/tds-widget/src/chat/messages/date-divider.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { Text } from '@titicaca/tds-ui'
22
import { format } from 'date-fns'
33

4-
export function DateDivider({ date }: { date: Date }) {
4+
export function DateDivider({ date, ...props }: { date: Date }) {
55
return (
6-
<Text textAlign="center" size={11} color="gray700" margin={{ top: 30 }}>
6+
<Text
7+
textAlign="center"
8+
size={11}
9+
color="gray700"
10+
margin={{ top: 30 }}
11+
{...props}
12+
>
713
{format(date, 'yyyy년 MM월 dd일')}
814
</Text>
915
)

packages/tds-widget/src/chat/messages/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { ComponentType, Fragment } from 'react'
22
import { CSSProp } from 'styled-components'
33
import { InView } from 'react-intersection-observer'
44

5-
import BubbleContainer from '../bubble-container/bubble-container'
5+
import BubbleContainer, {
6+
BubbleContainerProp,
7+
} from '../bubble-container/bubble-container'
68
import BubbleUI, { BubbleUIProps } from '../bubble/bubble-ui'
79
import { UserInterface } from '../types'
810
import AlteredBubble from '../bubble/altered'
@@ -15,7 +17,7 @@ import { DateDivider } from './date-divider'
1517
interface MessagesProp<
1618
Message extends MessageBase<User>,
1719
User extends UserInterface,
18-
> {
20+
> extends Pick<BubbleContainerProp, 'bubbleInfoStyle'> {
1921
messages: MessageInterface<Message, User>[]
2022
pendingMessages: MessageInterface<Message, User>[]
2123
failedMessages: MessageInterface<Message, User>[]
@@ -68,6 +70,7 @@ export default function Messages<
6870
onOpenMenu,
6971
onParentMessageClick,
7072
onUserClick,
73+
bubbleInfoStyle,
7174
...bubbleProps
7275
}: MessagesProp<Message, User> &
7376
Omit<
@@ -200,6 +203,7 @@ export default function Messages<
200203
? new Date()
201204
: new Date(message.createdAt)
202205
}
206+
css={bubbleInfoStyle?.dateDivider?.css}
203207
/>
204208
) : null}
205209

@@ -249,6 +253,7 @@ export default function Messages<
249253
marginTop: isFirstMessageOfDate ? 20 : showProfile ? 16 : 5,
250254
}}
251255
onUserClick={onUserClick}
256+
bubbleInfoStyle={bubbleInfoStyle}
252257
>
253258
{getBubble({ message, my, hasArrow: showProfile })}
254259
</BubbleContainer>

0 commit comments

Comments
 (0)