Skip to content

Commit

Permalink
[AC-1747] Apply UIKit classNames to user message text & suggested rep…
Browse files Browse the repository at this point in the history
…lies (#131)

* Add classNames to message text & suggestedReplies
* Add styled-components.d.ts to override DefaultTheme
  • Loading branch information
AhyoungRyu authored Mar 26, 2024
1 parent 6ea755d commit ce77775
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 43 deletions.
6 changes: 1 addition & 5 deletions src/components/CurrentUserMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ const Root = styled.div<{ enableEmojiFeedback: boolean }>`
enableEmojiFeedback ? '20px' : '0'};
`;

const TextComponent = styled.div`
white-space: pre-line;
`;

type Props = {
message: UserMessage;
};
Expand All @@ -35,7 +31,7 @@ export default function CurrentUserMessage(props: Props) {
</SentTime>
<BodyContainer>
<BodyComponent>
<TextComponent>{message.message}</TextComponent>
<div className="sendbird-word">{message.message}</div>
</BodyComponent>
</BodyContainer>
</Root>
Expand Down
2 changes: 1 addition & 1 deletion src/components/CustomMessageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function CustomMessageBody(props: Props) {

return (
<Root>
<Text>{sanitizedMessage}</Text>
<Text className="sendbird-word">{sanitizedMessage}</Text>
</Root>
);
}
47 changes: 18 additions & 29 deletions src/components/DynamicRepliesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,28 @@ import styled from 'styled-components';

import { useSendMessage } from '../hooks/useSendMessage';

interface SuggestedReplyItemProps {
isActive: boolean;
}
export const ReplyItem = styled.div<SuggestedReplyItemProps>`
export const ReplyItem = styled.div`
white-space: nowrap;
height: 32px;
font-size: 12px;
padding: 3px 14px;
display: flex;
align-items: center;
color: ${({ isActive, theme }: SuggestedReplyItemProps) =>
isActive ? theme.textColor.suggestedReply : '#EEEEEE'};
border: ${({ isActive, theme }: SuggestedReplyItemProps) =>
isActive
? `1px solid ${theme.textColor.suggestedReply}`
: '1px solid #EEEEEE'};
border-radius: 18px;
background-color: ${({ theme }) => theme.bgColor.suggestedReply};
cursor: ${(props: SuggestedReplyItemProps) =>
props.isActive ? 'pointer' : 'not-allowed'};
&:hover {
${({ isActive, theme }: SuggestedReplyItemProps) => {
if (isActive) {
return `background-color: ${theme.bgColor.hover.suggestedReply};`;
}
}};
}
&:active {
${({ isActive, theme }: SuggestedReplyItemProps) => {
if (isActive) {
return `background-color: ${theme.textColor.suggestedReply}; color: ${theme.textColor.outgoingMessage};`;
}
}};
cursor: pointer;
&& {
// To override the default color with the self service theme color
color: ${({ theme }) => theme.textColor.suggestedReply};
border: ${({ theme }) => `1px solid ${theme.textColor.suggestedReply}`};
border-radius: 18px;
background-color: ${({ theme }) => theme.bgColor.suggestedReply};
&:hover {
${({ theme }) =>
`background-color: ${theme.bgColor.hover.suggestedReply}`};
}
&:active {
${({ theme }) =>
`background-color: ${theme.textColor.suggestedReply}; color: ${theme.textColor.outgoingMessage};`};
}
}
`;

Expand Down Expand Up @@ -70,14 +59,14 @@ const DynamicRepliesPanel = (props: Props) => {
};

return quickReplies && quickReplies.length > 0 ? (
<Panel>
<Panel className="sendbird-suggested-replies">
{replyOptions.map((option: string) => {
return (
<ReplyItem
className="sendbird-suggested-replies__option"
id={option}
key={option}
onClick={(e) => onClickReply(e, option)}
isActive={true}
>
{option}
</ReplyItem>
Expand Down
7 changes: 1 addition & 6 deletions src/components/StaticRepliesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ const StaticRepliesPanel = (props: Props) => {
<Panel>
{suggestedReplies.map((suggestedReply: SuggestedReply, i: number) => {
return (
<ReplyItem
id={i + ''}
key={i}
onClick={onClickSuggestedReply}
isActive={true}
>
<ReplyItem id={i + ''} key={i} onClick={onClickSuggestedReply}>
{suggestedReply.title}
</ReplyItem>
);
Expand Down
6 changes: 6 additions & 0 deletions src/styled-components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'styled-components';
import { type CommonTheme } from './theme';
declare module 'styled-components' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DefaultTheme extends CommonTheme {}
}
2 changes: 1 addition & 1 deletion src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getColorBasedOnSaturation, generateColorVariants } from './colors';
interface CommonTheme {
export interface CommonTheme {
bgColor: {
chatBottom: string;
messageInput: string;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"include": [
"src",
"./src/custom.d.ts",
"node_modules/@sendbird/uikit-react/index.d.ts",
"./src/styled-components.d.ts",
],
"exclude": ["node_modules"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down

0 comments on commit ce77775

Please sign in to comment.