2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2021-09-02 06:43:53 +00:00
|
|
|
<div
|
|
|
|
class="chat-message--input"
|
|
|
|
:class="{ 'is-focused': isFocused }"
|
|
|
|
@keydown.esc="hideEmojiPicker"
|
|
|
|
>
|
2020-06-18 09:47:45 +00:00
|
|
|
<resizable-text-area
|
2021-09-02 06:43:53 +00:00
|
|
|
id="chat-input"
|
|
|
|
ref="chatInput"
|
2020-05-06 08:08:36 +00:00
|
|
|
v-model="userInput"
|
2021-09-02 06:43:53 +00:00
|
|
|
:aria-label="$t('CHAT_PLACEHOLDER')"
|
2020-05-06 08:08:36 +00:00
|
|
|
:placeholder="$t('CHAT_PLACEHOLDER')"
|
2020-06-18 09:47:45 +00:00
|
|
|
class="form-input user-message-input"
|
2020-11-26 18:47:55 +00:00
|
|
|
@typing-off="onTypingOff"
|
|
|
|
@typing-on="onTypingOn"
|
2021-09-02 06:43:53 +00:00
|
|
|
@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"
|
|
|
|
/>
|
2021-09-02 06:43:53 +00:00
|
|
|
<button
|
|
|
|
v-if="hasEmojiPickerEnabled"
|
|
|
|
class="emoji-toggle"
|
|
|
|
aria-label="Emoji picker"
|
|
|
|
@click="toggleEmojiPicker()"
|
|
|
|
>
|
|
|
|
<i
|
|
|
|
class="icon ion-happy-outline"
|
|
|
|
:class="{ active: showEmojiPicker }"
|
|
|
|
/>
|
|
|
|
</button>
|
2020-04-29 08:24:56 +00:00
|
|
|
<emoji-input
|
|
|
|
v-if="showEmojiPicker"
|
|
|
|
v-on-clickaway="hideEmojiPicker"
|
|
|
|
:on-click="emojiOnClick"
|
2021-09-02 06:43:53 +00:00
|
|
|
@keydown.esc="hideEmojiPicker"
|
2020-04-29 08:24:56 +00:00
|
|
|
/>
|
|
|
|
<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 { 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-09-13 17:19:01 +00:00
|
|
|
import EmojiInput from 'shared/components/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,
|
2021-09-02 06:43:53 +00:00
|
|
|
isFocused: 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;
|
|
|
|
},
|
2021-09-02 06:43:53 +00:00
|
|
|
isOpen() {
|
|
|
|
return this.$store.state.events.isOpen;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
isOpen(isOpen) {
|
|
|
|
if (isOpen) {
|
|
|
|
this.focusInput();
|
|
|
|
}
|
|
|
|
},
|
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);
|
2021-09-02 06:43:53 +00:00
|
|
|
if (this.isOpen) {
|
|
|
|
this.focusInput();
|
|
|
|
}
|
2019-11-09 11:42:31 +00:00
|
|
|
},
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
methods: {
|
2021-09-02 06:43:53 +00:00
|
|
|
onBlur() {
|
|
|
|
this.isFocused = false;
|
|
|
|
},
|
|
|
|
onFocus() {
|
|
|
|
this.isFocused = true;
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
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 = '';
|
2021-09-02 06:43:53 +00:00
|
|
|
this.focusInput();
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
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;
|
|
|
|
},
|
2021-09-02 06:43:53 +00:00
|
|
|
hideEmojiPicker(e) {
|
2020-04-29 08:24:56 +00:00
|
|
|
if (this.showEmojiPicker) {
|
2021-09-02 06:43:53 +00:00
|
|
|
e.stopPropagation();
|
2020-04-29 08:24:56 +00:00
|
|
|
this.toggleEmojiPicker();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
emojiOnClick(emoji) {
|
2020-09-13 17:19:01 +00:00
|
|
|
this.userInput = `${this.userInput}${emoji} `;
|
2020-04-29 08:24:56 +00:00
|
|
|
},
|
2020-11-26 18:47:55 +00:00
|
|
|
onTypingOff() {
|
2020-06-18 09:47:45 +00:00
|
|
|
this.toggleTyping('off');
|
|
|
|
},
|
2020-11-26 18:47:55 +00:00
|
|
|
onTypingOn() {
|
2020-06-18 09:47:45 +00:00
|
|
|
this.toggleTyping('on');
|
|
|
|
},
|
|
|
|
toggleTyping(typingStatus) {
|
|
|
|
this.$store.dispatch('conversation/toggleUserTyping', { typingStatus });
|
|
|
|
},
|
2021-09-02 06:43:53 +00:00
|
|
|
focusInput() {
|
|
|
|
this.$refs.chatInput.focus();
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
@import '~widget/assets/scss/variables.scss';
|
2021-09-02 06:43:53 +00:00
|
|
|
@import '~widget/assets/scss/mixins.scss';
|
2019-10-29 07:20:54 +00:00
|
|
|
|
2019-11-09 11:42:31 +00:00
|
|
|
.chat-message--input {
|
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
2021-09-02 06:43:53 +00:00
|
|
|
padding: 0 $space-small 0 $space-slab;
|
|
|
|
border-radius: 7px;
|
|
|
|
|
|
|
|
&.is-focused {
|
|
|
|
box-shadow: 0 0 0 1px $color-woot, 0 0 2px 3px $color-primary-light;
|
|
|
|
}
|
2019-10-29 07:20:54 +00:00
|
|
|
}
|
2020-04-29 08:24:56 +00:00
|
|
|
|
|
|
|
.emoji-toggle {
|
2021-09-02 06:43:53 +00:00
|
|
|
@include button-size;
|
|
|
|
|
2020-04-29 08:24:56 +00:00
|
|
|
font-size: $font-size-large;
|
|
|
|
color: $color-gray;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.emoji-dialog {
|
|
|
|
right: $space-one;
|
|
|
|
}
|
|
|
|
|
|
|
|
.button-wrap {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2021-09-02 06:43:53 +00:00
|
|
|
padding-left: $space-small;
|
2020-04-29 08:24:56 +00:00
|
|
|
}
|
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;
|
2021-09-02 06:43:53 +00:00
|
|
|
padding: 0;
|
2020-06-18 09:47:45 +00:00
|
|
|
padding-top: $space-small;
|
2021-09-02 06:43:53 +00:00
|
|
|
margin-top: $space-small;
|
|
|
|
margin-bottom: $space-small;
|
2020-06-18 09:47:45 +00:00
|
|
|
}
|
2019-10-29 07:20:54 +00:00
|
|
|
</style>
|