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

feat(blade): chat message component #2513

Open
wants to merge 65 commits into
base: master
Choose a base branch
from

Conversation

tewarig
Copy link
Contributor

@tewarig tewarig commented Jan 31, 2025

Description

feat: add chat bubble component

Changes

Additional Information

Component Checklist

  • Update Component Status Page
  • Perform Manual Testing in Other Browsers
  • Add KitchenSink Story
  • Add Interaction Tests (if applicable)
  • Add changeset

Copy link

changeset-bot bot commented Jan 31, 2025

🦋 Changeset detected

Latest commit: aa1186d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@razorpay/blade Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jan 31, 2025

✅ PR title follows Conventional Commits specification.

@tewarig tewarig changed the title Feat: chat bubble component feat: chat bubble component Feb 1, 2025
@tewarig tewarig changed the title feat: chat bubble component feat(blade): chat bubble component Feb 2, 2025
Copy link

codesandbox-ci bot commented Feb 2, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit aa1186d:

Sandbox Source
razorpay/blade: basic Configuration

@rzpcibot
Copy link
Collaborator

rzpcibot commented Feb 2, 2025

Bundle Size Report

Updated Components
Status Component Base Size (kb) Current Size (kb) Diff
ChatMessage 0.000 3.205 +3.205 KB
Move 1.092 1.094 +0.002 KB
Slide 1.264 1.268 +0.004 KB
Stagger 0.936 0.937 +0.001 KB

Generated by 🚫 dangerJS against 955b47c

ref: React.Ref<BladeElementRef>,
): React.ReactElement => {
const childrenToRender = (): React.ReactElement => {
// their can be a case where childrens are passed like "{' '} some text" so we need to check if children is string or not
Copy link
Member

Choose a reason for hiding this comment

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

use getStringFromReactText

Copy link
Contributor Author

@tewarig tewarig Feb 4, 2025

Choose a reason for hiding this comment

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

already using getStringFromReactText inside childrenToRender, since we expect both string and Card component as children, we need to check if we need to wrap it in Text component

isError={validationState === 'error'}
onClick={onClick}
errorText={errorText}
children={childrenToRender()}
Copy link
Member

Choose a reason for hiding this comment

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

Check once: May cause unnecessary rerenders

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems fine to me.. refactored a bit

cursor={isError ? 'pointer' : 'default'}
>
<BaseBox
maxWidth="240px"
Copy link
Member

Choose a reason for hiding this comment

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

is this maxWidth set from design side? Shouldn't this be controlled by the consumer and our chatbubble be fluid to accommodate any UI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, maxWidth is set from the design for now. It should be, but currently, Bubble should only be used in specific UIs

Copy link
Member

@anuraghazra anuraghazra Feb 4, 2025

Choose a reason for hiding this comment

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

I don't think adding maxWidth is a good idea, we did the same thing with Accordion and it backfired causing a lot of issues because:

Once you add maxWidth removing it in future becomes kind of a styling breakage for consumers. Like now if consumers wants to make Accordion fullWidth they have to explicitly override maxWidth to 100% which isn't intuitive.

It should be fluid and expose maxWidth so consumers can add it.

Copy link
Member

Choose a reason for hiding this comment

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

It should still have a default maxWidth and then expose to consumers right? otherwise the messages will overflow till the end of chatbox

Copy link
Contributor Author

@tewarig tewarig Feb 4, 2025

Choose a reason for hiding this comment

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

checked with design, we can remove maxWidth, allow consumers to pass it. i think instead of having default, message should take what everspace is available

Copy link
Member

@anuraghazra anuraghazra Feb 4, 2025

Choose a reason for hiding this comment

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

It should still have a default maxWidth and then expose to consumers right?

No. That's what caused the unintuitive issues that consumers faced.

It should still have a default maxWidth and then expose to consumers right? otherwise the messages will overflow till the end of chatbox

<Box width="500px">
  <ChatBubble /> // it's like a block element
</Box>

ChatBubble should fluidly take it's parent's width.

onClick,
}: DefaultMessageBubbleProps): React.ReactElement => {
return (
<BaseBox maxWidth="296px" onClick={onClick}>
Copy link
Member

Choose a reason for hiding this comment

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

same: button if onClick

onClick,
}: DefaultMessageBubbleProps): React.ReactElement => {
return (
<BaseBox maxWidth="296px" onClick={onClick}>
Copy link
Member

Choose a reason for hiding this comment

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

lets move these px values to common file with token.ts and explain where these values come from? like why is it 296px here and div below is 256px?

Copy link
Contributor Author

@tewarig tewarig Feb 4, 2025

Choose a reason for hiding this comment

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

i think we don't need 296px onces. it was for wrapper.
chatMessage have a set width of 240px from design

Comment on lines 19 to 29
<m.div
style={{
display: 'flex',
}}
animate={{ rotate: animate ? 90 : 0 }}
transition={{
duration: msToSeconds(theme.motion.duration.gentle),
repeat: Infinity,
ease: cssBezierToArray(castWebType(theme.motion.easing.emphasized)),
delay: msToSeconds(theme.motion.delay.gentle),
}}
Copy link
Member

Choose a reason for hiding this comment

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

nice 🏅

cursor={isError ? 'pointer' : 'default'}
>
<BaseBox
maxWidth="240px"
Copy link
Member

Choose a reason for hiding this comment

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

Expected for this to have different maxWidth than responder's message?

Copy link
Contributor Author

@tewarig tewarig Feb 4, 2025

Choose a reason for hiding this comment

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

yes
for default message -
Screenshot 2025-02-04 at 10 12 12 AM
for self message
Screenshot 2025-02-04 at 10 12 31 AM

Copy link
Member

Choose a reason for hiding this comment

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

@tewarig can you check with design if this is expected? what is the reason to have 2 different max-widths?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

checked with design . We need two different max-width values, but we are removing max-width from the token. We will allow consumers to pass it instead

packages/blade/src/components/ChatBubble/index.ts Outdated Show resolved Hide resolved
Comment on lines 33 to 41
return onClick ? (
<ChatMessageButton {...props} onClick={onClick} ref={ref as never}>
{children}
</ChatMessageButton>
) : (
<BaseBox {...props} ref={ref as never}>
{children}
</BaseBox>
);
Copy link
Member

Choose a reason for hiding this comment

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

You can also just do this I believe 🤔

Suggested change
return onClick ? (
<ChatMessageButton {...props} onClick={onClick} ref={ref as never}>
{children}
</ChatMessageButton>
) : (
<BaseBox {...props} ref={ref as never}>
{children}
</BaseBox>
);
return (
<BaseBox as={onClick ? 'button' : undefined} onClick={onClick} {...props} ref={ref as never}>
{children}
</BaseBox>
);

Comment on lines 1 to 11
const chatMessageToken = {
default: {
maxWidth: '256px',
},
self: {
maxWidth: '240px',
padding: 'spacing.4',
borderTopLeftRadius: 'large',
borderTopRightRadius: 'large',
borderBottomLeftRadius: 'large',
borderBottomRightRadiusForLastMessage: 'none',
borderBottomRightRadius: 'large',
backgroundColor: {
default: 'surface.background.primary.subtle',
Copy link
Member

Choose a reason for hiding this comment

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

nice 🔥

@tewarig tewarig force-pushed the feat/chat-bubble-component branch from 036ecfe to f3bb245 Compare February 5, 2025 08:36
@snitin315
Copy link
Member

snitin315 commented Feb 6, 2025

footerActions are not aligned correctly by default like children.

Screenshot 2025-02-06 at 9 23 21 AM

@tewarig
Copy link
Contributor Author

tewarig commented Feb 6, 2025

footerActions are not aligned correctly by default like children.

Screenshot 2025-02-06 at 9 23 21 AM

you can follow this story, https://61c19ee8d3d282003ac1d81c-lbirdazznk.chromatic.com/?path=/story/components-chatmessage--chat-message-with-footer-actions

you need to wrap footer actions in box . then you can style them as you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants