-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Style] chatting bubble 컴포넌트 제작 및 소켓 라이브러리 설치 #65
Merged
Merged
Changes from all 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,10 @@ | ||
import { createProxyMiddleware } from 'http-proxy-middleware' | ||
|
||
module.exports = (app) => { | ||
app.use( | ||
createProxyMiddleware('/api/chat-stomp', { | ||
target: process.env.VITE_BASE_URL, | ||
ws: true, | ||
}), | ||
) | ||
} | ||
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,42 @@ | ||
import styled from '@emotion/styled' | ||
import { type HTMLAttributes, type ReactNode } from 'react' | ||
|
||
import { type TextType, theme } from '@/styles/theme' | ||
/** | ||
* @param as Text 컴포넌트의 종류 : 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'div'; | ||
* @param typo Typo theme 선택 | ||
* @param color Palette theme 선택 | ||
*/ | ||
|
||
export interface TextProps extends HTMLAttributes<HTMLDivElement> { | ||
as?: 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'div' | ||
typo: TextType['typo'] | ||
color?: TextType['color'] | ||
children: ReactNode | ||
} | ||
|
||
export type TextPropsKey = 'typo' | 'color' | ||
|
||
export const ChattingText = ({ | ||
typo = 'Body_16', | ||
as = 'h1', | ||
color, | ||
children, | ||
...props | ||
}: TextProps) => { | ||
return ( | ||
<StyledText typoKey={typo} as={as} colorKey={color} {...props}> | ||
{children} | ||
</StyledText> | ||
) | ||
} | ||
|
||
const StyledText = styled.span<{ | ||
typoKey: TextType['typo'] | ||
colorKey?: TextType['color'] | ||
}>` | ||
white-space: pre-wrap; | ||
color: ${({ colorKey }) => { | ||
return colorKey && theme.palette[colorKey] | ||
}}; | ||
` |
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,83 @@ | ||
import styled from '@emotion/styled' | ||
import { ComponentProps } from 'react' | ||
|
||
import { ChattingText } from '@/components/common/ChattingText' | ||
import { FlexBox } from '@/components/common/Flexbox' | ||
import { palette } from '@/styles/palette' | ||
import { type KeyOfPalette, type KeyOfTypo } from '@/styles/theme' | ||
|
||
interface ChattingBubbleProps extends ComponentProps<'div'> { | ||
isMyChat?: boolean | ||
message: string | ||
time: string | ||
messageTypo?: KeyOfTypo | ||
messageColor?: KeyOfPalette | ||
timeTypo?: KeyOfTypo | ||
timeColor?: KeyOfPalette | ||
color?: KeyOfPalette | ||
} | ||
|
||
/** | ||
* @param isMychat : 내 채팅인지, 상대방의 채팅인지 여부 / 기본 : false | ||
* @param message : 메시지 내용 | ||
* @param time : 메시지 작성 시간 | ||
* @param messageType : message에 적용할 typo | ||
* @param messageColor: message에 적용시킬 color | ||
* @param timeType : time에 적용할 typo | ||
* @param timeColor : time에 적용할 color | ||
*/ | ||
|
||
const ChattingBubble = ({ | ||
isMyChat = false, | ||
message, | ||
time, | ||
messageTypo = 'Body_12', | ||
messageColor = 'BLACK', | ||
timeTypo = 'Caption_11', | ||
timeColor = 'GRAY500', | ||
...props | ||
}: ChattingBubbleProps) => { | ||
return ( | ||
<BubbleContainer | ||
justify={'flex-start'} | ||
gap={10} | ||
fullWidth={true} | ||
isMyChat={isMyChat} | ||
{...props} | ||
> | ||
<StyledText isMyChat={isMyChat}> | ||
<MessageText typo={'Body_20'} color={messageColor} {...props}> | ||
{message} | ||
</MessageText> | ||
</StyledText> | ||
<TimeText typo={'Body_20'} color={timeColor} {...props}> | ||
{time} | ||
</TimeText> | ||
</BubbleContainer> | ||
) | ||
} | ||
|
||
const BubbleContainer = styled(FlexBox)<{ isMyChat: boolean }>` | ||
justify-content: ${(props) => props.isMyChat && 'flex-end'}; | ||
` | ||
|
||
const StyledText = styled.div<{ | ||
isMyChat: boolean | ||
}>` | ||
border-radius: 10px; | ||
background-color: ${palette.WHITE}; | ||
padding: 7px 12px; | ||
word-wrap: break-word; | ||
order: ${(props) => (props.isMyChat ? '2' : '1')}; | ||
` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오... order를 사용해서 해결하셨네요 기발합니다 ㅎㅎ 👍👍 |
||
|
||
const TimeText = styled(ChattingText)` | ||
order: 1; | ||
line-height: 150%; | ||
` | ||
|
||
const MessageText = styled(ChattingText)` | ||
line-height: 150%; | ||
` | ||
|
||
export default ChattingBubble |
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
Oops, something went wrong.
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.
이 라이브러리가 하는 역할을 간단하게 설명해줄 수 있나요~~??
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.
vite.config.ts는 protocol: wss로 되어있던데 여기는 ws: true로 해야하는 건가요?
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.
setupProxy.ts 파일은 제가 cra 환경에서 세팅해줬던 파일인데 vite에서는 vite.config.ts에서 사전 세팅을 해줘야 하는 것 같더라구요! 그래서 혹시 몰라 둘다 해줬는데 채팅 구현해보면서 해당 파일은 필요가 없으면 삭제하려고 했습니다!!
ws:true로 한 이유는 wss:true 로 하니까 에러가 나서 일단 에러 안 나는 방향으로 커밋한겁니다ㅎㅎ
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.
아~ 좋습니다 ㅎㅎ 수고하셨습니당 👍👍👍