Chatwoot/app/javascript/widget/components/ChatInputWrap.vue
Nithin David Thomas 7fcd2d0e85
Feature: Support file type messages on widget and dashboard (#659)
- Adds support for file upload

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
Co-authored-by: Sojan <sojan@pepalo.com>
2020-04-02 12:28:38 +05:30

85 lines
1.7 KiB
Vue
Executable file

<template>
<div class="chat-message--input">
<chat-attachment-button :on-attach="onSendAttachment" />
<ChatInputArea v-model="userInput" :placeholder="placeholder" />
<ChatSendButton
:on-click="handleButtonClick"
:disabled="!userInput.length"
:color="widgetColor"
/>
</div>
</template>
<script>
import { mapGetters } from 'vuex';
import ChatSendButton from 'widget/components/ChatSendButton.vue';
import ChatAttachmentButton from 'widget/components/ChatAttachment.vue';
import ChatInputArea from 'widget/components/ChatInputArea.vue';
export default {
name: 'ChatInputWrap',
components: {
ChatAttachmentButton,
ChatSendButton,
ChatInputArea,
},
props: {
placeholder: {
type: String,
default: 'Type your message',
},
onSendMessage: {
type: Function,
default: () => {},
},
onSendAttachment: {
type: Function,
default: () => {},
},
},
data() {
return {
userInput: '',
};
},
computed: {
...mapGetters({
widgetColor: 'appConfig/getWidgetColor',
}),
},
destroyed() {
document.removeEventListener('keypress', this.handleEnterKeyPress);
},
mounted() {
document.addEventListener('keypress', this.handleEnterKeyPress);
},
methods: {
handleButtonClick() {
if (this.userInput && this.userInput.trim()) {
this.onSendMessage(this.userInput);
}
this.userInput = '';
},
handleEnterKeyPress(e) {
if (e.keyCode === 13 && !e.shiftKey) {
e.preventDefault();
this.handleButtonClick();
}
},
},
};
</script>
<style scoped lang="scss">
@import '~widget/assets/scss/variables.scss';
.chat-message--input {
align-items: center;
display: flex;
}
</style>