2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2019-11-09 11:42:31 +00:00
|
|
|
<div class="chat-message--input">
|
2020-05-06 08:08:36 +00:00
|
|
|
<chat-input-area
|
|
|
|
v-model="userInput"
|
|
|
|
:placeholder="$t('CHAT_PLACEHOLDER')"
|
|
|
|
/>
|
2020-04-29 08:24:56 +00:00
|
|
|
<div class="button-wrap">
|
|
|
|
<chat-attachment-button
|
|
|
|
v-if="showAttachment"
|
|
|
|
:on-attach="onSendAttachment"
|
|
|
|
/>
|
|
|
|
<emoji-input
|
|
|
|
v-if="showEmojiPicker"
|
|
|
|
v-on-clickaway="hideEmojiPicker"
|
|
|
|
:on-click="emojiOnClick"
|
|
|
|
/>
|
|
|
|
<i
|
|
|
|
class="emoji-toggle icon ion-happy-outline"
|
|
|
|
:class="{ active: showEmojiPicker }"
|
|
|
|
@click="toggleEmojiPicker()"
|
|
|
|
/>
|
|
|
|
<chat-send-button
|
|
|
|
v-if="showSendButton"
|
|
|
|
:on-click="handleButtonClick"
|
|
|
|
:color="widgetColor"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-10-29 07:20:54 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-01-13 06:40:40 +00:00
|
|
|
import { mapGetters } from 'vuex';
|
2020-04-29 08:24:56 +00:00
|
|
|
import emojione from 'emojione';
|
|
|
|
import { mixin as clickaway } from 'vue-clickaway';
|
2019-10-29 07:20:54 +00:00
|
|
|
import ChatSendButton from 'widget/components/ChatSendButton.vue';
|
2020-04-02 06:58:38 +00:00
|
|
|
import ChatAttachmentButton from 'widget/components/ChatAttachment.vue';
|
2019-10-29 07:20:54 +00:00
|
|
|
import ChatInputArea from 'widget/components/ChatInputArea.vue';
|
2020-04-29 08:24:56 +00:00
|
|
|
import EmojiInput from 'dashboard/components/widgets/emoji/EmojiInput';
|
2019-10-29 07:20:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ChatInputWrap',
|
|
|
|
components: {
|
2020-04-02 06:58:38 +00:00
|
|
|
ChatAttachmentButton,
|
2019-10-29 07:20:54 +00:00
|
|
|
ChatSendButton,
|
|
|
|
ChatInputArea,
|
2020-04-29 08:24:56 +00:00
|
|
|
EmojiInput,
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2020-04-29 08:24:56 +00:00
|
|
|
mixins: [clickaway],
|
2019-10-29 07:20:54 +00:00
|
|
|
props: {
|
|
|
|
onSendMessage: {
|
|
|
|
type: Function,
|
|
|
|
default: () => {},
|
|
|
|
},
|
2020-03-30 06:45:06 +00:00
|
|
|
onSendAttachment: {
|
|
|
|
type: Function,
|
|
|
|
default: () => {},
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
userInput: '',
|
2020-04-29 08:24:56 +00:00
|
|
|
showEmojiPicker: false,
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|
|
|
|
},
|
2020-04-02 06:58:38 +00:00
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
widgetColor: 'appConfig/getWidgetColor',
|
|
|
|
}),
|
2020-04-29 08:24:56 +00:00
|
|
|
showAttachment() {
|
|
|
|
return this.userInput.length === 0;
|
|
|
|
},
|
|
|
|
showSendButton() {
|
|
|
|
return this.userInput.length > 0;
|
|
|
|
},
|
2020-04-02 06:58:38 +00:00
|
|
|
},
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
},
|
2020-04-29 08:24:56 +00:00
|
|
|
toggleEmojiPicker() {
|
|
|
|
this.showEmojiPicker = !this.showEmojiPicker;
|
|
|
|
},
|
|
|
|
hideEmojiPicker() {
|
|
|
|
if (this.showEmojiPicker) {
|
|
|
|
this.toggleEmojiPicker();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
emojiOnClick(emoji) {
|
|
|
|
this.userInput = emojione.shortnameToUnicode(
|
|
|
|
`${this.userInput}${emoji.shortname} `
|
|
|
|
);
|
|
|
|
},
|
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
|
|
|
}
|
2020-04-29 08:24:56 +00:00
|
|
|
|
|
|
|
.emoji-toggle {
|
|
|
|
font-size: $font-size-large;
|
|
|
|
color: $color-gray;
|
|
|
|
padding-right: $space-smaller;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.emoji-dialog {
|
|
|
|
right: $space-one;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-uploads {
|
|
|
|
margin-right: $space-small;
|
|
|
|
}
|
|
|
|
|
|
|
|
.button-wrap {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
2019-10-29 07:20:54 +00:00
|
|
|
</style>
|