Skip to content

Commit 4f83cd2

Browse files
authored
Merge pull request #50 from Leets-Official/46-feat/ChatBubble-컴포넌트-제작
[Feat] ChatBubble 컴포넌트 제작
2 parents dfbb863 + 7e01bf9 commit 4f83cd2

4 files changed

Lines changed: 83 additions & 0 deletions

File tree

src/pages/playground.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BannerCard } from '@shared/ui/BannerCard/BannerCard';
22
import { Button } from '@shared/ui/Button/Button';
33
import { Card } from '@shared/ui/Card/Card';
4+
import { ChatBubble } from '@shared/ui/ChatBubble';
45
import { ChatInput } from '@shared/ui/ChatInput';
56
import { ChatPromptList } from '@shared/ui/ChatPromptList';
67
import { Checkbox } from '@shared/ui/Checkbox/Checkbox';
@@ -136,6 +137,20 @@ export default function Playground() {
136137
onPromptClick={(prompt) => console.log('prompt click:', prompt)}
137138
/>
138139
</section>
140+
{/* Chat Bubble */}
141+
<section className="flex flex-col gap-4">
142+
<h2 className="typo-body-1">ChatBubble</h2>
143+
<div className="flex flex-col gap-6" role="log" aria-live="polite">
144+
<ChatBubble variant="receiver" message="대답" meta="오전 00:00" metaDateTime="2024-01-01T00:00:00+09:00" />
145+
<ChatBubble variant="sender" message="직접질문" meta="오후 00:00" metaDateTime="2024-01-01T12:00:00+09:00" />
146+
<ChatBubble
147+
variant="sender"
148+
message="메시지가 길어질 경우에는 이렇게 줄바꿈이 됩니다아아아아아아아아아아 얼마나 늘려야 줄바꿈이 될까요"
149+
meta="오후 00:00"
150+
metaDateTime="2024-01-01T12:00:00+09:00"
151+
/>
152+
</div>
153+
</section>
139154
{/* Chat Input */}
140155
<section className="flex flex-col gap-4">
141156
<h2 className="typo-body-1">ChatInput</h2>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { chatBubbleVariants } from './ChatBubble.variants';
2+
import type { ComponentPropsWithoutRef } from 'react';
3+
import type { VariantProps } from 'tailwind-variants';
4+
5+
export type ChatBubbleProps = ComponentPropsWithoutRef<'div'> &
6+
VariantProps<typeof chatBubbleVariants> & {
7+
message: string;
8+
meta?: string;
9+
metaDateTime?: string;
10+
};
11+
12+
export const ChatBubble = ({ message, meta, metaDateTime, variant, className, ...props }: ChatBubbleProps) => {
13+
const styles = chatBubbleVariants({ variant });
14+
15+
return (
16+
<div className={styles.root({ className })} role="listitem" {...props}>
17+
<div className={styles.bubble()}>
18+
<span className={styles.text()}>{message}</span>
19+
</div>
20+
{meta && (
21+
<time className={styles.meta()} dateTime={metaDateTime}>
22+
{meta}
23+
</time>
24+
)}
25+
</div>
26+
);
27+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { tv } from 'tailwind-variants';
2+
3+
export const chatBubbleVariants = tv({
4+
slots: {
5+
root: ['flex w-full items-end gap-[10px]'],
6+
bubble: [
7+
'inline-flex',
8+
'items-center',
9+
'justify-center',
10+
'min-h-[60px]',
11+
'px-[31px]',
12+
'py-[18px]',
13+
'rounded-[var(--radius-l)]',
14+
'max-w-[559px]',
15+
],
16+
text: ['typo-body-1', 'whitespace-pre-wrap', 'break-words'],
17+
meta: ['typo-caption-2', 'text-[var(--color-gray-400)]'],
18+
},
19+
20+
variants: {
21+
variant: {
22+
receiver: {
23+
root: ['justify-start'],
24+
bubble: ['bg-[var(--color-gray-100)]'],
25+
text: ['text-[var(--color-gray-900)]'],
26+
meta: ['order-last'],
27+
},
28+
sender: {
29+
root: ['justify-end', 'flex-row-reverse'],
30+
bubble: ['bg-[var(--color-brand-primary)]'],
31+
text: ['text-[var(--color-gray-900)]'],
32+
meta: ['order-last'],
33+
},
34+
},
35+
},
36+
37+
defaultVariants: {
38+
variant: 'receiver',
39+
},
40+
});

src/shared/ui/ChatBubble/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ChatBubble } from './ChatBubble';

0 commit comments

Comments
 (0)