chat-ui-kit-react icon indicating copy to clipboard operation
chat-ui-kit-react copied to clipboard

Custom components for message

Open no-1ne opened this issue 5 years ago • 11 comments

Hello thank you for sharing your work...

Coming to the issue/feature request, currently message seems to take only string, it would be nice to add custom components like image, video file attachments etc something like this https://chatui.io/components/file-card

no-1ne avatar Dec 03 '20 02:12 no-1ne

Hello @startupgurukul thank you for your feedback.

We have this feature on our roadmap. I'd like to hear from you, what approach would be better (and why)?

  1. Dedicated component for each kind of message e.g. ImageMessage, FileMessage
  2. One parametrized Message component

supersnager avatar Dec 04 '20 09:12 supersnager

Thank you for the reply.

Keeping message structure fixed with keys: type & payload. While rendering logic changes based on type of message . Few message types like image video and file can be pre handled by library while still giving an option to customise for other message types

For example , type: image and payload: path to image type: text and payload: message text type: video, file and payload: path

This keeps message structure simple and based on type of message render components accordingly this enables users to extend it to any type of message they like

Here is how alibabas chat ui handles it

const initialMessages = [ { type: 'text', content: { text: 'message text' }, user: { avatar: '//gw.alicdn.com/tfs/TB1DYHLwMHqK1RjSZFEXXcGMXXa-56-62.svg' }, }, { type: 'image', content: { picUrl: '//img.alicdn.com/tfs/TB1p_nirYr1gK0jSZR0XXbP8XXa-300-300.png', }, }, ];

switch (type) {
  case 'text':
    return <Bubble content={content.text} />;
  case 'image':
    return (
      <Bubble type="image">
        <img src={content.picUrl} alt="" />
      </Bubble>
    );
  default:
    return null;
}

Source: https://chatui.io/components/chat

no-1ne avatar Dec 05 '20 04:12 no-1ne

@startupgurukul Thank you for your explains. I will add support for new kind of messages. This will be probably divided into few small update steps.

First the <Message /> component should be modified to allow to pass any content as children, or from model.content property - for any custom content messages. Note to myself: add <Message.Content /> Component. For backward compatiblity current message type should have default set to "text" or "default" (or maybe "html" because now it uses dangerouslysetinnerhtml internally) Maybe: new <Message.Content /> component should be typed instead of <Message />?

Next add predefined components for common types like image, video, etc

supersnager avatar Dec 07 '20 11:12 supersnager

When are you releasing this feature @supersnager ?

GhazanfarKhan avatar Dec 18 '20 10:12 GhazanfarKhan

@GhazanfarKhan Today/tommorow depending on your timezone ;)

supersnager avatar Dec 20 '20 17:12 supersnager

32439f703361ac951522f8892a01982b8e16ccf8 https://github.com/chatscope/chat-ui-kit-react/releases/tag/v1.1.0

I will add some documentation later.

supersnager avatar Dec 20 '20 23:12 supersnager

Awesome and thank you :)

no-1ne avatar Dec 21 '20 04:12 no-1ne

Awesome work.

GhazanfarKhan avatar Dec 22 '20 18:12 GhazanfarKhan

Added some examples to Storybook: https://chatscope.io/storybook/react/?path=/docs/components-message--html-content https://chatscope.io/storybook/react/?path=/docs/components-message--text-content https://chatscope.io/storybook/react/?path=/docs/components-message--image-content https://chatscope.io/storybook/react/?path=/docs/components-message--custom-content

supersnager avatar Dec 29 '20 18:12 supersnager

it would be perfect if there is an onclick listener for message (to be exact, on click of image thumbnail the flexibility of doing something)

no-1ne avatar Dec 30 '20 21:12 no-1ne

@startupgurukul I will add it.

supersnager avatar Jan 04 '21 12:01 supersnager