2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2019-11-09 11:42:31 +00:00
|
|
|
<div class="chat-message--input">
|
2020-06-18 09:47:45 +00:00
|
|
|
<resizable-text-area
|
2020-05-06 08:08:36 +00:00
|
|
|
v-model="userInput"
|
|
|
|
:placeholder="$t('CHAT_PLACEHOLDER')"
|
2020-06-18 09:47:45 +00:00
|
|
|
class="form-input user-message-input"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
2020-05-06 08:08:36 +00:00
|
|
|
/>
|
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
|
2020-08-05 12:16:17 +00:00
|
|
|
v-if="hasEmojiPickerEnabled"
|
2020-04-29 08:24:56 +00:00
|
|
|
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';
|
2020-06-18 09:47:45 +00:00
|
|
|
import ResizableTextArea from 'shared/components/ResizableTextArea';
|
2020-04-29 08:24:56 +00:00
|
|
|
import EmojiInput from 'dashboard/components/widgets/emoji/EmojiInput';
|
2020-08-05 12:16:17 +00:00
|
|
|
import configMixin from '../mixins/configMixin';
|
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,
|
2020-04-29 08:24:56 +00:00
|
|
|
EmojiInput,
|
2020-06-18 09:47:45 +00:00
|
|
|
ResizableTextArea,
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2020-08-05 12:16:17 +00:00
|
|
|
mixins: [clickaway, configMixin],
|
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() {
|
2020-08-05 12:16:17 +00:00
|
|
|
return this.hasAttachmentsEnabled && this.userInput.length === 0;
|
2020-04-29 08:24:56 +00:00
|
|
|
},
|
|
|
|
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} `
|
|
|
|
);
|
|
|
|
},
|
2020-06-18 09:47:45 +00:00
|
|
|
|
|
|
|
onBlur() {
|
|
|
|
this.toggleTyping('off');
|
|
|
|
},
|
|
|
|
onFocus() {
|
|
|
|
this.toggleTyping('on');
|
|
|
|
},
|
|
|
|
toggleTyping(typingStatus) {
|
|
|
|
this.$store.dispatch('conversation/toggleUserTyping', { typingStatus });
|
|
|
|
},
|
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;
|
|
|
|
}
|
2020-06-18 09:47:45 +00:00
|
|
|
|
|
|
|
.user-message-input {
|
|
|
|
border: 0;
|
|
|
|
height: $space-large;
|
|
|
|
min-height: $space-large;
|
|
|
|
max-height: 2.4 * $space-mega;
|
|
|
|
resize: none;
|
|
|
|
padding-top: $space-small;
|
|
|
|
}
|
2019-10-29 07:20:54 +00:00
|
|
|
</style>
|