Skip to content

Commit d01f01a

Browse files
committed
(UI) improve media preview
1 parent 1acee91 commit d01f01a

File tree

6 files changed

+62
-26
lines changed

6 files changed

+62
-26
lines changed

src/components/SvgIcon/SvgIcon.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
fill: var(--chat-icon-color-close-outline);
3535
}
3636

37+
#vac-icon-close-outline-preview {
38+
fill: var(--chat-icon-color-close-preview);
39+
}
40+
3741
#vac-icon-send {
3842
fill: var(--chat-icon-color-send);
3943
}

src/lib/ChatWindow.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
background: var(--chat-content-bg-color);
66
color: var(--chat-color);
77
overflow-wrap: break-word;
8-
position: relative;
98
white-space: normal;
109
border: var(--chat-container-border);
1110
border-radius: var(--chat-container-border-radius);

src/lib/ChatWindow.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@
7979
</room>
8080
</div>
8181
<media-preview
82-
v-if="showMediaModal"
82+
v-if="showMediaPreview"
8383
:file="filePreview"
84-
@close-file-modal="showMediaModal = false"
84+
@close-media-preview="showMediaPreview = false"
8585
/>
8686
</div>
8787
</template>
@@ -194,7 +194,7 @@ export default {
194194
loadingMoreRooms: false,
195195
showRoomsList: true,
196196
isMobile: false,
197-
showMediaModal: false,
197+
showMediaPreview: false,
198198
filePreview: {
199199
url: ''
200200
}
@@ -341,7 +341,7 @@ export default {
341341
openFile({ message, file }) {
342342
if (this.mediaModalPreview && file.action === 'preview') {
343343
this.filePreview = file.file
344-
this.showMediaModal = true
344+
this.showMediaPreview = true
345345
} else {
346346
this.$emit('open-file', { message, file })
347347
}
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
.vac-room-file-preview {
1+
.vac-media-preview {
22
position: absolute;
33
top: 0;
44
left: 0;
5-
width: 100%;
6-
height: 100%;
7-
z-index: 11;
8-
background-color: rgba(0, 0, 0, 0.5);
5+
z-index: 99;
6+
width: 100vw;
7+
height: 100vh;
8+
background-color: rgba(0, 0, 0, 0.8);
9+
outline: none;
910

10-
.vac-room-file-preview-container {
11+
.vac-media-preview-container {
1112
width: 100%;
1213
height: 100%;
1314
}
1415

1516
.vac-image-preview {
1617
width: 100%;
1718
height: 100%;
18-
background-size: contain !important;
19+
background-size: contain;
1920
background-repeat: no-repeat;
2021
background-position: center;
2122
}
23+
24+
.vac-svg-button {
25+
position: absolute;
26+
top: 30px;
27+
right: 30px;
28+
transform: scale(1.4);
29+
}
30+
31+
@media only screen and (max-width: 768px) {
32+
.vac-svg-button {
33+
top: 20px;
34+
right: 20px;
35+
transform: scale(1.2);
36+
}
37+
}
2238
}

src/lib/MediaPreview/MediaPreview.vue

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
<template>
2-
<div class="vac-room-file-preview">
3-
<div
4-
v-if="isImage"
5-
class="vac-room-file-preview-container"
6-
@click.stop="$emit('close-file-modal')"
7-
@keypress.esc="$emit('close-file-modal')"
8-
>
2+
<div
3+
ref="modal"
4+
tabindex="0"
5+
class="vac-media-preview"
6+
@click.stop="closeModal"
7+
@keydown.esc="closeModal"
8+
>
9+
<div v-if="isImage" class="vac-media-preview-container">
910
<div
1011
class="vac-image-preview"
1112
:style="{
1213
'background-image': `url('${file.url}')`
1314
}"
14-
@keypress.esc="$emit('close-file-modal')"
15+
@keypress.esc="closeModal"
1516
/>
1617
</div>
1718

1819
<div
1920
v-else-if="isVideo"
2021
class="vac-video-preview"
21-
@keypress.esc="$emit('close-file-modal')"
22+
@keypress.esc="closeModal"
2223
>
2324
<video width="100%" height="100%" controls>
2425
<source :src="file.url" />
2526
</video>
2627
</div>
27-
<button @click="$emit('close-file-modal')">
28-
Close
29-
</button>
28+
29+
<div class="vac-svg-button" @click="closeModal">
30+
<slot name="preview-close-icon">
31+
<svg-icon name="close-outline" param="preview" size="10" />
32+
</slot>
33+
</div>
3034
</div>
3135
</template>
3236
<script>
33-
// import SvgIcon from '../../../components/SvgIcon/SvgIcon'
37+
import SvgIcon from '../../components/SvgIcon/SvgIcon'
3438
3539
const { isImageFile, isVideoFile } = require('../../utils/media-file')
3640
3741
export default {
3842
name: 'RoomFilePreview',
3943
components: {
40-
// SvgIcon,
44+
SvgIcon
4145
},
4246
4347
props: {
@@ -54,6 +58,16 @@ export default {
5458
if (this.file.url) return isVideoFile(this.file)
5559
else return false
5660
}
61+
},
62+
63+
mounted() {
64+
this.$refs.modal.focus()
65+
},
66+
67+
methods: {
68+
closeModal() {
69+
this.$emit('close-media-preview')
70+
}
5771
}
5872
}
5973
</script>

src/themes/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const defaultThemeStyles = {
119119
file: '#1976d2',
120120
paperclip: '#1976d2',
121121
closeOutline: '#000',
122+
closePreview: '#fff',
122123
send: '#1976d2',
123124
sendDisabled: '#9ca6af',
124125
emoji: '#1976d2',
@@ -259,6 +260,7 @@ export const defaultThemeStyles = {
259260
file: '#1976d2',
260261
paperclip: '#fff',
261262
closeOutline: '#fff',
263+
closePreview: '#fff',
262264
send: '#fff',
263265
sendDisabled: '#646a70',
264266
emoji: '#fff',
@@ -407,6 +409,7 @@ export const cssThemeVars = ({
407409
'--chat-icon-color-file': icons.file,
408410
'--chat-icon-color-paperclip': icons.paperclip,
409411
'--chat-icon-color-close-outline': icons.closeOutline,
412+
'--chat-icon-color-close-preview': icons.closePreview,
410413
'--chat-icon-color-send': icons.send,
411414
'--chat-icon-color-send-disabled': icons.sendDisabled,
412415
'--chat-icon-color-emoji': icons.emoji,

0 commit comments

Comments
 (0)