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"
|
|
|
|
/>
|
2019-10-29 07:20:54 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
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>
|