Skip to content

Commit 70795cf

Browse files
committed
(feat) add icon to scroll to bottom
1 parent 309a795 commit 70795cf

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ colors="{
215215
pencil: '#9e9e9e',
216216
checkmark: '#0696c7',
217217
eye: '#fff',
218-
dropdown: '#fff'
218+
dropdown: '#fff',
219+
dropdownScroll: '#0a0a0a'
219220
}
220221
}"
221222
```

src/ChatWindow/MessagesList.vue

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
</div>
6767
</transition-group>
6868
</div>
69+
<transition name="bounce">
70+
<div class="icon-scroll" v-if="scrollIcon" @click="scrollToBottom">
71+
<svg-icon name="dropdown" param="scroll" />
72+
</div>
73+
</transition>
6974
</div>
7075
<div ref="roomFooter" class="room-footer">
7176
<transition name="slide-up-fade">
@@ -200,14 +205,23 @@ export default {
200205
file: null,
201206
imageFile: null,
202207
menuOpened: false,
203-
emojiOpened: false
208+
emojiOpened: false,
209+
scrollIcon: true
204210
}
205211
},
206212
207213
mounted() {
208214
window.addEventListener('keypress', e => {
209215
if (e.keyCode === 13 && !e.shiftKey) this.sendMessage()
210216
})
217+
218+
document
219+
.getElementsByClassName('container-scroll')[0]
220+
.addEventListener('scroll', e => {
221+
this.scrollIcon =
222+
e.target.scrollHeight > 500 &&
223+
e.target.scrollHeight - e.target.scrollTop > 1000
224+
})
211225
},
212226
213227
watch: {
@@ -335,6 +349,10 @@ export default {
335349
336350
setTimeout(() => this.resizeTextarea(this.$refs['roomTextarea']), 0)
337351
},
352+
scrollToBottom() {
353+
const element = document.getElementsByClassName('container-scroll')[0]
354+
element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' })
355+
},
338356
autoGrow(el) {
339357
this.resizeTextarea(el.srcElement)
340358
},
@@ -508,6 +526,24 @@ export default {
508526
margin-bottom: 20px;
509527
}
510528
529+
.icon-scroll {
530+
position: absolute;
531+
bottom: 80px;
532+
right: 20px;
533+
padding: 8px;
534+
background: #fff;
535+
border-radius: 50%;
536+
box-shadow: 0 1px 1px -1px rgba(0, 0, 0, 0.2), 0 1px 1px 0 rgba(0, 0, 0, 0.14),
537+
0 1px 2px 0 rgba(0, 0, 0, 0.12);
538+
display: flex;
539+
cursor: pointer;
540+
541+
svg {
542+
height: 25px;
543+
width: 25px;
544+
}
545+
}
546+
511547
.room-footer {
512548
position: absolute;
513549
bottom: 0;
@@ -664,4 +700,24 @@ textarea {
664700
transform: translateY(10px);
665701
opacity: 0;
666702
}
703+
704+
.bounce-enter-active {
705+
animation: bounce-in 0.5s;
706+
}
707+
708+
.bounce-leave-active {
709+
animation: bounce-in 0.3s reverse;
710+
}
711+
712+
@keyframes bounce-in {
713+
0% {
714+
transform: scale(0);
715+
}
716+
50% {
717+
transform: scale(1.05);
718+
}
719+
100% {
720+
transform: scale(1);
721+
}
722+
}
667723
</style>

src/ChatWindow/SvgIcon.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,8 @@ export default {
162162
#chat-icon-dropdown {
163163
fill: var(--chat-icon-color-dropdown);
164164
}
165+
166+
#chat-icon-dropdown-sroll {
167+
fill: var(--chat-icon-color-dropdown-scroll);
168+
}
165169
</style>

src/themes/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export const defaultThemeColors = {
4343
pencil: '#9e9e9e',
4444
checkmark: '#0696c7',
4545
eye: '#fff',
46-
dropdown: '#fff'
46+
dropdown: '#fff',
47+
dropdownScroll: '#0a0a0a'
4748
}
4849
},
4950
dark: {
@@ -90,7 +91,8 @@ export const defaultThemeColors = {
9091
pencil: '#ebedf2',
9192
checkmark: '#f0d90a',
9293
eye: '#fff',
93-
dropdown: '#fff'
94+
dropdown: '#fff',
95+
dropdownScroll: '#0a0a0a'
9496
}
9597
}
9698
}
@@ -168,6 +170,7 @@ export const cssThemeVars = ({
168170
'--chat-icon-color-pencil': iconsColor.pencil,
169171
'--chat-icon-color-checkmark': iconsColor.checkmark,
170172
'--chat-icon-color-eye': iconsColor.eye,
171-
'--chat-icon-color-dropdown': iconsColor.dropdown
173+
'--chat-icon-color-dropdown': iconsColor.dropdown,
174+
'--chat-icon-color-dropdown-scroll': iconsColor.dropdownScroll
172175
}
173176
}

0 commit comments

Comments
 (0)