/
ChatTile.vue
163 lines (152 loc) · 3.16 KB
/
ChatTile.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<template>
<div :class="chatIsOpen ? 'chat-wrapper open' : 'chat-wrapper'">
<div>
<button class="chat" @click="handleChatClick">
<template v-if="chatIsOpen">
<img class="icon" :src="close" alt="" />
</template>
<template v-else>
<img class="icon" :src="chat" alt="" />
</template>
</button>
</div>
<div class="chat-container">
<div class="messages">
<p
v-for="({ name = '', message = '' }, i) in messages"
:key="i"
class="chat-message"
>
<span class="chat-name">{{ name }}: </span>{{ message }}
</p>
</div>
<form @submit="submitForm">
<div class="input">
<label for="message">Type a message...</label>
<textarea
id="message"
v-model="text"
type="text"
placeholder="Type a message..."
@keydown.enter="submitForm"
/>
</div>
<button class="submit-button" type="submit">
<img :src="send" alt="" />
</button>
</form>
</div>
</div>
</template>
<script>
import close from "../assets/x.svg";
import chat from "../assets/chat.svg";
import send from "../assets/send.svg";
export default {
name: "ChatTile",
props: ["sendMessage", "messages"],
data() {
return {
chatIsOpen: false,
close,
chat,
send,
text: "",
};
},
methods: {
// Toggle chat's view (open/closed)
handleChatClick() {
this.chatIsOpen = !this.chatIsOpen;
},
// Send chat message using prop method from CallTile.vue
submitForm(e) {
e.preventDefault();
this.sendMessage(this.text);
this.text = "";
},
},
};
</script>
<style scoped>
@import url("https://fonts.googleapis.com/css2?family=Ropa+Sans&display=swap");
.chat-wrapper {
position: absolute;
right: 0;
top: 0;
width: 348px;
height: 100%;
transition: right 0.5s ease-out;
right: -300px;
display: flex;
align-items: center;
}
.chat-wrapper.open {
right: 0;
}
.chat-container {
background-color: #fff;
width: 300px;
display: flex;
flex-direction: column;
padding: 24px;
height: calc(100% - 48px);
}
button.chat {
background-color: #fff;
border: none;
cursor: pointer;
border-radius: 16px 0 0 16px;
padding: 16px 14px 13px 18px;
}
.messages {
flex: 1;
padding-right: 32px;
}
.input {
display: flex;
flex-direction: column;
flex: 1;
align-items: flex-start;
}
label {
color: #fff;
}
.input textarea {
width: 100%;
border: none;
resize: none;
font-family: "Ropa Sans", sans-serif;
font-size: 16px;
}
.input textarea::placeholder {
font-family: "Ropa Sans", sans-serif;
font-size: 16px;
}
form {
display: flex;
border-bottom: 2px solid #c8d1dc;
}
.submit-button {
padding: 4px;
margin: 0 0 0 16px;
border: none;
background-color: #fff;
}
.chat-message {
color: #121a24;
text-align: left;
font-size: 14px;
line-height: 18px;
margin: 0 0 20px;
}
.chat-message .chat-name {
color: #6b7785;
}
@media screen and (max-width: 700px) {
.chat-container {
width: calc(100% - 104px);
right: calc((100% + 56px) * -1);
}
}
</style>