2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2019-11-09 11:42:31 +00:00
|
|
|
<div class="chat-message--input">
|
|
|
|
<ChatInputArea v-model="userInput" :placeholder="placeholder" />
|
|
|
|
<ChatSendButton
|
|
|
|
:on-click="handleButtonClick"
|
|
|
|
:disabled="!userInput.length"
|
2020-01-13 06:40:40 +00:00
|
|
|
:color="widgetColor"
|
2019-11-09 11:42:31 +00:00
|
|
|
/>
|
2019-10-29 07:20:54 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-01-13 06:40:40 +00:00
|
|
|
import { mapGetters } from 'vuex';
|
2019-10-29 07:20:54 +00:00
|
|
|
import ChatSendButton from 'widget/components/ChatSendButton.vue';
|
|
|
|
import ChatInputArea from 'widget/components/ChatInputArea.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ChatInputWrap',
|
|
|
|
components: {
|
|
|
|
ChatSendButton,
|
|
|
|
ChatInputArea,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
placeholder: {
|
|
|
|
type: String,
|
|
|
|
default: 'Type your message',
|
|
|
|
},
|
|
|
|
onSendMessage: {
|
|
|
|
type: Function,
|
|
|
|
default: () => {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
userInput: '',
|
|
|
|
};
|
|
|
|
},
|
2019-11-09 11:42:31 +00:00
|
|
|
destroyed() {
|
|
|
|
document.removeEventListener('keypress', this.handleEnterKeyPress);
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('keypress', this.handleEnterKeyPress);
|
|
|
|
},
|
|
|
|
|
2020-01-13 06:40:40 +00:00
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
widgetColor: 'appConfig/getWidgetColor',
|
|
|
|
}),
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
methods: {
|
|
|
|
handleButtonClick() {
|
2019-11-09 11:42:31 +00:00
|
|
|
if (this.userInput && this.userInput.trim()) {
|
2019-10-29 07:20:54 +00:00
|
|
|
this.onSendMessage(this.userInput);
|
|
|
|
}
|
|
|
|
this.userInput = '';
|
|
|
|
},
|
2019-11-09 11:42:31 +00:00
|
|
|
handleEnterKeyPress(e) {
|
|
|
|
if (e.keyCode === 13 && !e.shiftKey) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.handleButtonClick();
|
|
|
|
}
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
@import '~widget/assets/scss/variables.scss';
|
|
|
|
|
2019-11-09 11:42:31 +00:00
|
|
|
.chat-message--input {
|
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
2019-10-29 07:20:54 +00:00
|
|
|
}
|
|
|
|
</style>
|