chatscope / chat-ui-kit-react

Build your own chat UI with React components in few minutes. Chat UI Kit from chatscope is an open source UI toolkit for developing web chat applications.
https://chatscope.io
MIT License
1.34k stars 116 forks source link

add voice button #7

Closed roxana-ahmadi closed 3 years ago

roxana-ahmadi commented 3 years ago

hi, how can i add a custom button like voice recording in MessageInput component? tnx.

supersnager commented 3 years ago

@roxana-ahmadi Adding buttons (and other components) directly do MessageInput is on my roadmap, but it's not possible yet. However there is a simple workaroud. You can wrap MessageInput into div, mark this div as MessageInput (because ChatContainer need to know where to place MessageInput) and add whatever you want into your wrapper. This approach need some css tweaking, but it's simple thing. You can also remove sendButton from MessageInput by setting sendButton={false} and add your own button.

const [msg, setMsg] = useState("");
const handleSend = () => {
  // send message to recipient
  send(msg);
}

<ChatContainer>
  <MessageList></MessageList>
  <div as="MessageInput">
     <MessageInput sentButton={false}  onChange={msg => setMsg(msg)} value={msg}/>
     <button onClick={handleSend}>Send</button><button>Record</button>
  </div>
</ChatContainer>

Please ensure you are using the latest version of the library https://github.com/chatscope/chat-ui-kit-react/releases/tag/v1.2.2 as there is a fix for aliasing other elements as library components.

Also please check this recipe in storybook: https://chatscope.io/storybook/react/?path=/docs/documentation-recipes--page#changing-component-type-to-allow-place-it-in-container-slot

And onsure you are using "as" prop instead of "is" (recipe is not updated yet).

supersnager commented 3 years ago

@roxana-ahmadi I have updated recipe here: https://chatscope.io/storybook/react/?path=/docs/documentation-recipes--page#changing-component-type-to-allow-place-it-in-container-slot and added example story: https://chatscope.io/storybook/react/?path=/docs/components-chatcontainer--wrapped-message-input#wrapped-messageinput

roxana-ahmadi commented 3 years ago

problem solved! tnx

ranwang0417 commented 7 months ago

Hi, sorry for the stupid question but how can I see the implementation of in https://chatscope.io/storybook/react/?path=/story/components-chatcontainer--wrapped-message-input? I am trying to add more buttons to the right of the send button but could not achieve the same style. Many thanks!

supersnager commented 7 months ago

@ranwang0417 Components->Chat Container->Docs and scroll down to the Wrapped MessageInput story :)

ranwang0417 commented 7 months ago

@ranwang0417 Components->Chat Container->Docs and scroll down to the Wrapped MessageInput story :)

Thank you so so much!