2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2021-09-02 06:43:53 +00:00
|
|
|
<div
|
2022-04-01 15:29:03 +00:00
|
|
|
class="chat-message--input is-focused"
|
|
|
|
:class="$dm('bg-white ', 'dark:bg-slate-600')"
|
2021-09-02 06:43:53 +00:00
|
|
|
@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')"
|
2022-04-01 15:29:03 +00:00
|
|
|
class="form-input user-message-input is-focused"
|
|
|
|
:class="inputColor"
|
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"
|
2022-04-01 15:29:03 +00:00
|
|
|
:class="$dm('text-black-900', 'dark:text-slate-100')"
|
2020-04-29 08:24:56 +00:00
|
|
|
:on-attach="onSendAttachment"
|
|
|
|
/>
|
2021-09-02 06:43:53 +00:00
|
|
|
<button
|
|
|
|
v-if="hasEmojiPickerEnabled"
|
2021-11-18 09:48:51 +00:00
|
|
|
class="icon-button flex justify-center items-center"
|
2021-09-02 06:43:53 +00:00
|
|
|
aria-label="Emoji picker"
|
2021-11-18 09:48:51 +00:00
|
|
|
@click="toggleEmojiPicker"
|
2021-09-02 06:43:53 +00:00
|
|
|
>
|
2022-04-01 15:29:03 +00:00
|
|
|
<fluent-icon icon="emoji" :class="emojiIconColor" />
|
2021-09-02 06:43:53 +00:00
|
|
|
</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';
|
2021-11-18 09:48:51 +00:00
|
|
|
|
2020-04-02 06:58:38 +00:00
|
|
|
import ChatAttachmentButton from 'widget/components/ChatAttachment.vue';
|
2021-11-18 09:48:51 +00:00
|
|
|
import ChatSendButton from 'widget/components/ChatSendButton.vue';
|
2020-08-05 12:16:17 +00:00
|
|
|
import configMixin from '../mixins/configMixin';
|
2021-11-18 09:48:51 +00:00
|
|
|
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
|
|
|
|
import ResizableTextArea from 'shared/components/ResizableTextArea';
|
2022-04-01 15:29:03 +00:00
|
|
|
import darkModeMixin from 'widget/mixins/darkModeMixin.js';
|
2019-10-29 07:20:54 +00:00
|
|
|
|
2022-12-06 00:00:42 +00:00
|
|
|
const EmojiInput = () => import('shared/components/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,
|
2020-04-29 08:24:56 +00:00
|
|
|
EmojiInput,
|
2021-11-18 09:48:51 +00:00
|
|
|
FluentIcon,
|
2020-06-18 09:47:45 +00:00
|
|
|
ResizableTextArea,
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2022-04-01 15:29:03 +00:00
|
|
|
mixins: [clickaway, configMixin, darkModeMixin],
|
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',
|
2022-01-12 10:55:27 +00:00
|
|
|
isWidgetOpen: 'appConfig/getIsWidgetOpen',
|
2020-04-02 06:58:38 +00:00
|
|
|
}),
|
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;
|
|
|
|
},
|
2022-04-01 15:29:03 +00:00
|
|
|
inputColor() {
|
|
|
|
return `${this.$dm('bg-white', 'dark:bg-slate-600')}
|
|
|
|
${this.$dm('text-black-900', 'dark:text-slate-50')}`;
|
|
|
|
},
|
|
|
|
emojiIconColor() {
|
|
|
|
return this.showEmojiPicker
|
|
|
|
? `text-woot-500 ${this.$dm('text-black-900', 'dark:text-slate-100')}`
|
|
|
|
: `${this.$dm('text-black-900', 'dark:text-slate-100')}`;
|
|
|
|
},
|
2021-09-02 06:43:53 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2022-01-12 10:55:27 +00:00
|
|
|
isWidgetOpen(isWidgetOpen) {
|
|
|
|
if (isWidgetOpen) {
|
2021-09-02 06:43:53 +00:00
|
|
|
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);
|
2022-01-12 10:55:27 +00:00
|
|
|
if (this.isWidgetOpen) {
|
2021-09-02 06:43:53 +00:00
|
|
|
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-dialog {
|
2022-12-06 00:00:42 +00:00
|
|
|
right: 0;
|
|
|
|
top: -302px;
|
2022-10-25 02:59:36 +00:00
|
|
|
max-width: 100%;
|
2022-09-06 05:11:39 +00:00
|
|
|
|
|
|
|
&::before {
|
|
|
|
right: $space-one;
|
|
|
|
}
|
2020-04-29 08:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.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;
|
2022-10-14 03:43:11 +00:00
|
|
|
padding: $space-smaller 0;
|
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>
|