-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from prgrms-web-devcourse-final-project/feature/
#61 feat: ChatMessage 컴포넌트 개발
- Loading branch information
Showing
4 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
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,40 @@ | ||
import { Text } from "components/atoms"; | ||
import { | ||
ChatMessageWrapper, | ||
MessageInfoWrapper, | ||
MessageWrapper, | ||
} from "./styled"; | ||
import { getTime } from "utils"; | ||
|
||
export interface IChatMessageProps { | ||
/** 채팅 메시지 내용 */ | ||
msg: string; | ||
/** 채팅 보낸 유저가 나인지 타인인지 구분 */ | ||
isMe: boolean; | ||
/** 해당 채팅이 그룹에서 마지막 메시지인지 구분,(시간 표시 유무 구분)*/ | ||
isLastMsg: boolean; | ||
/** 해당 채팅을 읽었는지 구분 */ | ||
isRead: boolean; | ||
/** 해당 메시지 보낸 시간 */ | ||
createdAt: string; | ||
} | ||
|
||
export const ChatMessage = ({ | ||
isMe, | ||
isRead, | ||
isLastMsg, | ||
msg, | ||
createdAt, | ||
}: IChatMessageProps) => { | ||
return ( | ||
<ChatMessageWrapper isMe={isMe}> | ||
<MessageWrapper> | ||
<Text content={msg} /> | ||
</MessageWrapper> | ||
<MessageInfoWrapper> | ||
{!isRead && <Text variant="button" content={"1"} />} | ||
{isLastMsg && <Text variant="button" content={getTime(createdAt)} />} | ||
</MessageInfoWrapper> | ||
</ChatMessageWrapper> | ||
); | ||
}; |
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,32 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { ChatMessage } from "."; | ||
|
||
const meta: Meta<typeof ChatMessage> = { | ||
title: "Organisms/ChatMessage", | ||
component: ChatMessage, | ||
tags: ["autodocs"], | ||
}; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
isMe: false, | ||
isLastMsg: true, | ||
isRead: true, | ||
msg: "안녕하세요", | ||
createdAt: "2024-11-28 16:29:36", | ||
}, | ||
}; | ||
|
||
export const MyMessage: Story = { | ||
args: { | ||
isMe: true, | ||
isLastMsg: true, | ||
isRead: false, | ||
msg: "안녕하세요", | ||
createdAt: new Date().toString(), | ||
}, | ||
}; | ||
|
||
export default meta; |
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,35 @@ | ||
import { css } from "@emotion/react"; | ||
import styled from "@emotion/styled"; | ||
import type { IChatMessageProps } from "."; | ||
|
||
export const MessageWrapper: ReturnType<typeof styled.div> = styled.div` | ||
background-color: #d9d9d9; | ||
padding: 0.5rem; | ||
border-radius: 0.5rem; | ||
max-width: 70%; | ||
`; | ||
export const MessageInfoWrapper: ReturnType<typeof styled.div> = styled.div` | ||
flex-shrink: 0; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: start; | ||
`; | ||
|
||
export const ChatMessageWrapper: ReturnType< | ||
typeof styled.div<Pick<IChatMessageProps, "isMe">> | ||
> = styled.div<Pick<IChatMessageProps, "isMe">>` | ||
display: flex; | ||
flex-direction: ${({ isMe }) => (isMe ? "row-reverse" : "row")}; | ||
align-items: end; | ||
gap: 0.25rem; | ||
${({ isMe }) => | ||
isMe && | ||
css` | ||
${MessageWrapper} { | ||
background-color: #a9a9a9; | ||
} | ||
${MessageInfoWrapper} { | ||
align-items: end; | ||
} | ||
`} | ||
`; |
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