Skip to content
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

Apply light / dark theme to custom components #84

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/components/BotMessageBottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ReactComponent as InfoIcon } from '../icons/info-icon.svg';
import 'react-popper-tooltip/dist/styles.css';

const Text = styled.div`
color: rgba(0, 0, 0, 0.5);
color: ${({ theme }) => theme.textColor.incomingMessage};
font-weight: 700;
font-size: 14px;
line-height: 20px;
Expand Down Expand Up @@ -42,6 +42,12 @@ const InfoIconButton = styled.div`
align-items: center;
width: 18px;
cursor: pointer;

svg {
path {
fill: ${({ theme }) => theme.textColor.incomingMessage};
}
}
`;

const InfoBox = styled.div`
Expand All @@ -52,7 +58,7 @@ const InfoBox = styled.div`
width: 100%;
background: rgb(0, 0, 0, 0.8);
border-radius: 8px;
color: white;
color: ${({ theme }) => theme.textColor.sourceInfo};
margin-top: 8px;
font-family: 'Roboto', sans-serif;
font-size: 14px;
Expand Down
23 changes: 10 additions & 13 deletions src/components/BotMessageWithBodyInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { User } from '@sendbird/chat';
import { UserMessage } from '@sendbird/chat/message';
import Avatar from '@sendbird/uikit-react/ui/Avatar';
import Label, {
LabelTypography,
LabelColors,
} from '@sendbird/uikit-react/ui/Label';
import { ReactNode } from 'react';
import styled from 'styled-components';

Expand All @@ -18,15 +22,9 @@ const Root = styled.div`
position: relative;
`;

const Sender = styled.div`
font-style: normal;
font-weight: 700;
font-size: 12px;
line-height: 12px;
color: rgba(0, 0, 0, 0.5);
transition: color 0.5s;
transition-timing-function: ease;
const Sender = styled(Label)`
margin: 0 0 4px 12px;
text-align: left;
`;

interface BodyContainerProps {
Expand All @@ -35,7 +33,7 @@ interface BodyContainerProps {

const BodyContainer = styled.div<BodyContainerProps>`
font-size: 14px;
color: rgba(0, 0, 0, 0.88);
color: ${({ theme }) => theme.textColor.incomingMessage};
max-width: calc(100% - 96px);
font-weight: normal;
font-stretch: normal;
Expand All @@ -46,7 +44,7 @@ const BodyContainer = styled.div<BodyContainerProps>`

const SentTime = styled.div`
width: fit-content;
color: rgba(0, 0, 0, 0.38);
color: ${({ theme }) => theme.textColor.sentTime};
font-size: 12px;
line-height: 1;
margin-bottom: 6px;
Expand Down Expand Up @@ -107,9 +105,8 @@ export default function BotMessageWithBodyInput(props: Props) {
<BodyContainer style={bodyStyle ?? {}}>
{displaySender && (
<Sender
style={{
textAlign: 'left',
}}
type={LabelTypography.CAPTION_2}
color={LabelColors.ONBACKGROUND_2}
>
{botUser.nickname}
</Sender>
Expand Down
20 changes: 15 additions & 5 deletions src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@sendbird/uikit-react/dist/index.css';
import '../css/index.css';
import SBProvider from '@sendbird/uikit-react/SendbirdProvider';
import { useMemo, useRef } from 'react';
import { ThemeProvider } from 'styled-components';

import { type Props as ChatWidgetProps } from './ChatAiWidget';
import CustomChannel from './CustomChannel';
Expand All @@ -14,8 +15,12 @@ import { HashedKeyProvider } from '../context/HashedKeyContext';
import SBConnectionStateProvider, {
useSbConnectionState,
} from '../context/SBConnectionContext';
import { getTheme } from '../theme';
import { assert, isMobile } from '../utils';

// TODO: Get the theme from the context
const DEFAULT_THEME = 'light';

const SBComponent = () => {
const {
applicationId,
Expand Down Expand Up @@ -63,6 +68,7 @@ const SBComponent = () => {
breakPoint={isMobile}
isReactionEnabled={enableEmojiFeedback}
isMentionEnabled={enableMention}
theme={DEFAULT_THEME}
uikitOptions={{
groupChannel: {
input: {
Expand Down Expand Up @@ -92,6 +98,8 @@ const Chat = ({
const CHAT_WIDGET_APP_ID = import.meta.env.VITE_CHAT_WIDGET_APP_ID;
const CHAT_WIDGET_BOT_ID = import.meta.env.VITE_CHAT_WIDGET_BOT_ID;

const theme = getTheme()[DEFAULT_THEME];

assert(
applicationId !== null && botId !== null,
'applicationId and botId must be provided'
Expand All @@ -105,11 +113,13 @@ const Chat = ({
botId={CHAT_WIDGET_BOT_ID ?? botId}
{...constantProps}
>
<HashedKeyProvider hashedKey={hashedKey ?? null}>
<SBConnectionStateProvider>
{isOpen && <SBComponent />}
</SBConnectionStateProvider>
</HashedKeyProvider>
<ThemeProvider theme={theme}>
<HashedKeyProvider hashedKey={hashedKey ?? null}>
<SBConnectionStateProvider>
{isOpen && <SBComponent />}
</SBConnectionStateProvider>
</HashedKeyProvider>
</ThemeProvider>
</ConstantStateProvider>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChatBottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const InnerContainer = styled.div<{ chatBottomBackgroundColor: string }>`
background: ${(props) =>
props.chatBottomBackgroundColor ||
'linear-gradient(273.73deg, #4DCD90 -0.83%, #6210CC 48.04%, #6210CC 75.45%)'};
color: rgba(255, 255, 255, 0.88);
color: ${({ theme }) => theme.textColor.chatBottom};
flex-wrap: wrap;
font-size: 13px;
`;
Expand Down
4 changes: 2 additions & 2 deletions src/components/CurrentUserMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const BodyContainer = styled.div`
`;

const SentTime = styled.div`
color: rgba(0, 0, 0, 0.38);
color: ${({ theme }) => theme.textColor.sentTime};
font-size: 12px;
line-height: 1;
margin-bottom: 6px;
Expand All @@ -35,7 +35,7 @@ const BodyComponent = styled.div`
&:hover {
background-color: #6211c8;
}
color: rgba(255, 255, 255, 0.88);
color: ${({ theme }) => theme.textColor.outgoingMessage};
max-width: 600px;
display: flex;
flex-direction: column;
Expand Down
8 changes: 6 additions & 2 deletions src/components/CustomChannelComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GroupChannel } from '@sendbird/chat/groupChannel';
import { SendingStatus } from '@sendbird/chat/message';
import ChannelHeader from '@sendbird/uikit-react/Channel/components/ChannelHeader';
import ChannelUI from '@sendbird/uikit-react/Channel/components/ChannelUI';
// import SuggestedReplies from '@sendbird/uikit-react/Channel/components/SuggestedReplies';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented since UIKit doesn't export the SuggestedReplies component yet.

import { useChannelContext } from '@sendbird/uikit-react/Channel/context';
import { useEffect, useState, useMemo, useRef } from 'react';
import ReactDOM from 'react-dom';
Expand Down Expand Up @@ -67,7 +68,7 @@ const Root = styled.div<RootStyleProps>`
border: none;
outline: none;
max-height: 116px;
background-color: #eeeeee;
background-color: ${({ theme }) => theme.bgColor.messageInput};
border-radius: 20px;
height: auto;
text-align: start;
Expand Down Expand Up @@ -192,7 +193,6 @@ export function CustomChannelComponent(props: CustomChannelComponentProps) {
const botWelcomeMessages = useMemo(() => {
return getBotWelcomeMessages(allMessages, botUser.userId);
}, [allMessages.length]);

return (
<Root hidePlaceholder={startingPagePlaceHolder} height={'100%'}>
<ChannelUI
Expand Down Expand Up @@ -229,6 +229,10 @@ export function CustomChannelComponent(props: CustomChannelComponentProps) {
{message.messageId === lastMessage.messageId &&
dynamicReplyOptions.length > 0 && (
<DynamicRepliesPanel replyOptions={dynamicReplyOptions} />
// <SuggestedReplies
// replyOptions={dynamicReplyOptions}
// onSendMessage={({ message }) => sendMessage(message)}
// />
)}
</>
);
Expand Down
15 changes: 8 additions & 7 deletions src/components/CustomChannelHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { User } from '@sendbird/chat';
import { GroupChannel } from '@sendbird/chat/groupChannel';
import Avatar from '@sendbird/uikit-react/ui/Avatar';
import Label, {
LabelTypography,
LabelColors,
} from '@sendbird/uikit-react/ui/Label';
import styled from 'styled-components';

import BetaLogo from './BetaLogo';
Expand All @@ -25,12 +29,7 @@ const SubContainer = styled.div`
align-items: center;
`;

const Title = styled.div`
font-weight: 700;
font-size: 16px;
line-height: 20px;
letter-spacing: -0.2px;
color: rgba(0, 0, 0, 0.88);
const Title = styled(Label)`
max-width: 200px;
overflow: hidden;
white-space: nowrap;
Expand Down Expand Up @@ -83,7 +82,9 @@ export default function CustomChannelHeader(props: Props) {
height="34px"
width="34px"
/>
<Title>{botUser?.nickname || channel.name}</Title>
<Title type={LabelTypography.H_2} color={LabelColors.ONBACKGROUND_1}>
{botUser?.nickname || channel.name}
</Title>
{!isMobile && betaMark && <BetaLogo>{customBetaMarkText}</BetaLogo>}
</SubContainer>
<RenewButtonContainer>
Expand Down
12 changes: 10 additions & 2 deletions src/components/CustomMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { User } from '@sendbird/chat';
import { Member } from '@sendbird/chat/groupChannel';
import { UserMessage } from '@sendbird/chat/message';
import { useChannelContext } from '@sendbird/uikit-react/Channel/context';
import TypingIndicatorBubble from '@sendbird/uikit-react/ui/TypingIndicatorBubble';
// eslint-disable-next-line import/no-unresolved
import { EveryMessage } from 'SendbirdUIKitGlobal';

Expand All @@ -10,11 +12,11 @@ import CurrentUserMessage from './CurrentUserMessage';
import CustomMessageBody from './CustomMessageBody';
import FormMessage from './FormMessage';
import ParsedBotMessageBody from './ParsedBotMessageBody';
import PendingMessage from './PendingMessage';
import SuggestedReplyMessageBody from './SuggestedReplyMessageBody';
import UserMessageWithBodyInput from './UserMessageWithBodyInput';
import { LOCAL_MESSAGE_CUSTOM_TYPE } from '../const';
import { useConstantState } from '../context/ConstantContext';
import botMessageImage from '../icons/bot-message-image.png';
import {
isNotLocalMessageCustomType,
MessageTextParser,
Expand Down Expand Up @@ -76,7 +78,13 @@ export default function CustomMessage(props: Props) {
<div>
{<CurrentUserMessage message={message as UserMessage} />}
{activeSpinnerId === message.messageId && (
<PendingMessage botProfileUrl={botUser?.profileUrl} />
<TypingIndicatorBubble
typingMembers={[
{
profileUrl: botUser?.profileUrl || botMessageImage,
} as Member,
]}
/>
)}
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/CustomMessageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const Root = styled.div`
padding: 8px 12px;
gap: 8px;
border-radius: 16px;
background-color: #eeeeee;
background-color: ${({ theme }) => theme.bgColor.incomingMessage};
&:hover {
background-color: #e0e0e0;
background-color: ${({ theme }) => theme.bgColor.hover.incomingMessage};
}
//max-width: 600px;
`;
Expand Down
4 changes: 0 additions & 4 deletions src/components/CustomMessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ const InputComponent = styled.textarea<InputProps>`
props.isActive ? 'none' : 'width 0.5s'};
transition-timing-function: ease;
padding: 8px 16px;
font-size: 14px;
font-family: 'Roboto', sans-serif;
line-height: 20px;
color: rgba(0, 0, 0, 0.88);
resize: none;
border: none;
outline: none;
Expand Down
8 changes: 4 additions & 4 deletions src/components/DynamicRepliesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const ReplyItem = styled.div<SuggestedReplyItemProps>`
border: ${(props: SuggestedReplyItemProps) =>
props.isActive ? '1px solid #6C32D5' : '1px solid #EEEEEE'};
border-radius: 18px;
background-color: #ffffff;
background-color: ${({ theme }) => theme.bgColor.suggestedReply};
cursor: ${(props: SuggestedReplyItemProps) =>
props.isActive ? 'pointer' : 'not-allowed'};
&:hover {
${(props: SuggestedReplyItemProps) => {
if (props.isActive) {
return 'background-color: #E6E0FF;';
${({ isActive, theme }: SuggestedReplyItemProps) => {
if (isActive) {
return `background-color: ${theme.bgColor.hover.suggestedReply};`;
}
}};
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/LoadingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Container = styled.div`
justify-content: center;
align-items: center;
z-index: 100;
background-color: white;
background-color: transparent;
`;

const IconContainer = styled.div`
Expand Down
4 changes: 2 additions & 2 deletions src/components/ParsedBotMessageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const LazyCodeBlock = lazy(() =>

const Root = styled.div`
display: flex;
background-color: #eeeeee;
background-color: ${({ theme }) => theme.bgColor.incomingMessage};
&:hover {
background-color: #e0e0e0;
background-color: ${({ theme }) => theme.bgColor.hover.incomingMessage};
}
//max-width: 600px;
flex-direction: column;
Expand Down
10 changes: 8 additions & 2 deletions src/components/SourceContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const RootTitle = styled.div`
font-weight: 700;
font-size: 14px;
line-height: 20px;
color: rgba(0, 0, 0, 0.5);
color: ${({ theme }) => theme.textColor.incomingMessage};
padding-bottom: 4px;
`;

Expand All @@ -24,7 +24,7 @@ const SourceTitle = styled.a`
font-size: 14px;
line-height: 20px;
letter-spacing: -0.1px;
color: rgba(0, 0, 0, 0.88);
color: ${({ theme }) => theme.textColor.incomingMessage};
width: fit-content;
block-size: fit-content;
`;
Expand All @@ -43,6 +43,12 @@ const IconLink = styled.a`
align-items: center;
width: 15px;
padding: 0 1px;
svg {
path {
fill: ${({ theme }) => theme.textColor.incomingMessage};
}
}
`;

export interface Source {
Expand Down
Loading