-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
175 additions
and
47 deletions.
There are no files selected for viewing
32 changes: 17 additions & 15 deletions
32
packages/blade/src/components/ChatBubble/ChatBubble.stories.tsx
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 |
---|---|---|
@@ -1,24 +1,26 @@ | ||
// import chatBubble and create a basic story | ||
import { ChatBubble } from './ChatBubble'; | ||
// import chatBubble and create a basic story | ||
import React from 'react'; | ||
import { Story } from '@storybook/react'; | ||
import { ChatBubbleProps } from './ChatBubble.types'; | ||
import { ChatBubble } from './ChatBubble'; | ||
import type { ChatBubbleProps } from './ChatBubble'; | ||
import { Box } from '~components/Box'; | ||
|
||
export default { | ||
title: 'ChatBubble', | ||
component: ChatBubble, | ||
}; | ||
|
||
const Template: Story<ChatBubbleProps> = (args) => <ChatBubble {...args} />; | ||
const Template = (args) => ( | ||
<Box display="flex" flexDirection="column" gap={'spacing.10'}> | ||
<ChatBubble> Demo</ChatBubble> | ||
<ChatBubble isLastMessage> this is a demo message </ChatBubble> | ||
<ChatBubble isUserMessage isLastMessage> | ||
message | ||
</ChatBubble> | ||
<ChatBubble isError onErrorTextClick={() => {}}> | ||
{' '} | ||
Hi, can you tell me how can i join fight club?{' '} | ||
</ChatBubble> | ||
</Box> | ||
); | ||
export const Default = Template.bind({}); | ||
Default.args = { | ||
message: 'Hello', | ||
isLastMessage: false, | ||
isUserMessage: false, | ||
isLoading: false, | ||
isError: false, | ||
cardBody: null, | ||
feedbackOptions: [], | ||
ErrorText: '', | ||
onErrorTextClick: () => {}, | ||
}; |
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 |
---|---|---|
@@ -1,22 +1,63 @@ | ||
import React from "react"; | ||
import { Box } from "~components/Box"; | ||
import React from 'react'; | ||
import { UserMessageBubble } from './UserMessageBubble'; | ||
import { Box } from '~components/Box'; | ||
import BaseBox from '~components/Box/BaseBox'; | ||
import { AlertCircleIcon } from '~components/Icons'; | ||
import { Text } from '~components/Typography'; | ||
|
||
type ChatBubbleProps = { | ||
message?: string; | ||
isLastMessage?: boolean; | ||
isUserMessage?: boolean; | ||
isLoading?: boolean; | ||
isError?: boolean; | ||
cardBody?: React.ReactNode; | ||
feedbackOptions?: Array<{icon: React.ReactNode, onClick: Function}>; | ||
ErrorText?: string; | ||
onErrorTextClick?: Function; | ||
} | ||
const ChatBubble = ({ message, isLastMessage,isUserMessage,isLoading,isError,cardBody,feedbackOptions,ErrorText,onErrorTextClick }:ChatBubbleProps) => { | ||
console.log({ message, isLastMessage,isUserMessage,isLoading,isError,cardBody,feedbackOptions,ErrorText,onErrorTextClick }); | ||
return <Box maxWidth="240px"></Box>; | ||
export type ChatBubbleProps = { | ||
isLastMessage?: boolean; | ||
isUserMessage?: boolean; | ||
isLoading?: boolean; | ||
isError?: boolean; | ||
feedbackOptions?: Array<{ icon: React.ReactNode; onClick: () => void }>; | ||
errorText?: string; | ||
onErrorTextClick?: () => void; | ||
children: React.ReactNode | string; | ||
avatarIcon?: React.ReactNode; | ||
}; | ||
const ChatBubble = ({ | ||
isLastMessage, | ||
isUserMessage, | ||
isLoading, | ||
isError, | ||
feedbackOptions, | ||
errorText, | ||
onErrorTextClick, | ||
children, | ||
avatarIcon, | ||
}: ChatBubbleProps): React.ReactElement => { | ||
console.log({ | ||
isLastMessage, | ||
isUserMessage, | ||
isLoading, | ||
isError, | ||
feedbackOptions, | ||
errorText, | ||
onErrorTextClick, | ||
children, | ||
avatarIcon, | ||
}); | ||
const childrenToRender = (): React.ReactElement => { | ||
if (typeof children === 'string') { | ||
return ( | ||
<Text color="surface.text.gray.normal" weight="regular" variant="body" size="medium"> | ||
{children} | ||
</Text> | ||
); | ||
} | ||
return children; | ||
}; | ||
return ( | ||
<UserMessageBubble | ||
isError={isError} | ||
onErrorTextClick={onErrorTextClick} | ||
isLastMessage={isLastMessage} | ||
isUserMessage={isUserMessage} | ||
errorText={errorText} | ||
children={childrenToRender()} | ||
/> | ||
); | ||
}; | ||
|
||
|
||
|
||
export { ChatBubble }; | ||
export { ChatBubble }; |
68 changes: 68 additions & 0 deletions
68
packages/blade/src/components/ChatBubble/UserMessageBubble.tsx
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,68 @@ | ||
import React from 'react'; | ||
import BaseBox from '~components/Box/BaseBox'; | ||
import { AlertCircleIcon } from '~components/Icons'; | ||
import { Text } from '~components/Typography'; | ||
|
||
const UserMessageBubble = ({ | ||
children, | ||
isError, | ||
onErrorTextClick, | ||
isLastMessage, | ||
isUserMessage, | ||
errorText = 'Message not sent. Tap to retry.', | ||
}: { | ||
children: React.ReactNode | string; | ||
isError?: boolean; | ||
onErrorTextClick?: () => void; | ||
isLastMessage?: boolean; | ||
isUserMessage?: boolean; | ||
errorText?: string; | ||
}): React.ReactElement => { | ||
return ( | ||
<BaseBox | ||
display="flex" | ||
gap="10px" | ||
flexDirection="column" | ||
onClick={isError ? onErrorTextClick : () => {}} | ||
cursor={isError ? 'pointer' : 'default'} | ||
> | ||
<BaseBox | ||
maxWidth="240px" | ||
backgroundColor={ | ||
isError ? 'feedback.background.negative.subtle' : 'surface.background.primary.subtle' | ||
} | ||
padding="spacing.4" | ||
borderTopLeftRadius="large" | ||
borderTopRightRadius="large" | ||
borderBottomLeftRadius="large" | ||
borderBottomRightRadius={isLastMessage && isUserMessage ? 'none' : 'large'} | ||
width="fit-content" | ||
height="auto" | ||
word-break="break-word" | ||
> | ||
{children} | ||
</BaseBox> | ||
{isError && ( | ||
<BaseBox | ||
maxWidth="240px" | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
gap="4px" | ||
> | ||
<AlertCircleIcon size="small" color="feedback.icon.negative.intense" /> | ||
<Text | ||
color="feedback.text.negative.intense" | ||
weight="regular" | ||
variant="caption" | ||
size="medium" | ||
> | ||
{errorText} | ||
</Text> | ||
</BaseBox> | ||
)} | ||
</BaseBox> | ||
); | ||
}; | ||
|
||
export { UserMessageBubble }; |
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