Skip to content

Commit 88471c9

Browse files
committed
(feat) add download/view icons on image hover
1 parent 8a15623 commit 88471c9

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ colors="{
164164
pencil: '#1976d2',
165165
pencilEdited: '#9e9e9e',
166166
trash: '#f44336',
167-
checkmark: '#0696c7'
167+
checkmark: '#0696c7',
168+
eye: '#9ca6af'
168169
}
169170
}"
170171
```

src/ChatWindow/ChatMessage.vue

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<div
2525
class="message-card"
2626
:class="{
27-
'message-highlight': setMessageElevation(message),
27+
'message-highlight': isMessageHover(message),
2828
'message-current': message.sender_id === 'me',
2929
'message-deleted': message.deleted,
3030
'slide-up':
@@ -57,10 +57,26 @@
5757
}"
5858
:style="{ background: `url(${message.file.url})` }"
5959
></div>
60+
<transition name="fade">
61+
<div class="image-buttons" v-if="imageHover">
62+
<div
63+
class="svg-button button-view"
64+
@click.stop="openFile(message.file)"
65+
>
66+
<svg-icon name="eye" />
67+
</div>
68+
<div
69+
class="svg-button button-download"
70+
@click.stop="openFile(message.file)"
71+
>
72+
<svg-icon name="document" />
73+
</div>
74+
</div>
75+
</transition>
6076
<span>{{ message.content }}</span>
6177
</div>
6278

63-
<div v-else :class="{ 'file-message': message.file && !isImage }">
79+
<div v-else class="file-message">
6480
<div
6581
class="svg-button icon-file"
6682
@click.stop="openFile(message.file)"
@@ -113,7 +129,8 @@ export default {
113129
return {
114130
openMessageId: {},
115131
hoverMessageId: null,
116-
imageLoading: false
132+
imageLoading: false,
133+
imageHover: false
117134
}
118135
},
119136
@@ -148,7 +165,7 @@ export default {
148165
},
149166
150167
methods: {
151-
setMessageElevation() {
168+
isMessageHover() {
152169
return (
153170
this.editedMessage._id === this.message._id ||
154171
this.hoverMessageId === this.message._id ||
@@ -165,12 +182,14 @@ export default {
165182
}
166183
},
167184
onHoverMessage() {
185+
this.imageHover = true
168186
if (this.canEditMessage()) this.hoverMessageId = this.message._id
169187
},
170188
canEditMessage() {
171189
return this.message.sender_id === 'me' && !this.message.deleted
172190
},
173191
onLeaveMessage() {
192+
this.imageHover = false
174193
this.openMessageId.toggle = false
175194
this.hoverMessageId = null
176195
},
@@ -371,13 +390,15 @@ export default {
371390
.action-buttons {
372391
position: relative;
373392
393+
svg {
394+
height: 18px;
395+
width: 18px;
396+
}
397+
374398
.button-delete,
375399
.button-edit {
376-
max-width: 18px;
377400
right: 5px;
378-
z-index: 0;
379401
position: absolute;
380-
width: 100%;
381402
}
382403
383404
.button-delete {
@@ -387,11 +408,47 @@ export default {
387408
.button-edit {
388409
bottom: 2px;
389410
}
411+
}
390412
413+
.image-buttons {
391414
svg {
392-
height: 18px;
393-
width: 18px;
415+
height: 20px;
416+
width: 20px;
417+
}
418+
419+
.button-view,
420+
.button-download {
421+
position: absolute;
422+
bottom: 2px;
423+
left: 5px;
394424
}
425+
426+
:first-child {
427+
left: 30px;
428+
}
429+
430+
.button-view {
431+
max-width: 18px;
432+
bottom: 4px;
433+
434+
svg {
435+
height: 18px;
436+
width: 18px;
437+
}
438+
}
439+
}
440+
441+
.fade-enter {
442+
opacity: 0;
443+
}
444+
445+
.fade-enter-active {
446+
transition: opacity 1.5s;
447+
}
448+
449+
.fade-leave-active {
450+
transition: opacity 0.5s;
451+
opacity: 0;
395452
}
396453
397454
.icon-check {

src/ChatWindow/SvgIcon.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export default {
8686
{
8787
name: 'checkmark',
8888
path: 'M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z'
89+
},
90+
{
91+
name: 'eye',
92+
path:
93+
'M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z'
8994
}
9095
]
9196
}
@@ -157,4 +162,8 @@ export default {
157162
#chat-icon-checkmark {
158163
fill: var(--chat-icon-color-checkmark);
159164
}
165+
166+
#chat-icon-eye {
167+
fill: var(--chat-icon-color-eye);
168+
}
160169
</style>

src/themes/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export const defaultThemeColors = {
3535
pencil: '#1976d2',
3636
pencilEdited: '#9e9e9e',
3737
trash: '#f44336',
38-
checkmark: '#0696c7'
38+
checkmark: '#0696c7',
39+
eye: '#9ca6af'
3940
}
4041
},
4142
dark: {
@@ -74,7 +75,8 @@ export const defaultThemeColors = {
7475
pencil: '#1976d2',
7576
pencilEdited: '#ebedf2',
7677
trash: '#f44336',
77-
checkmark: '#f0d90a'
78+
checkmark: '#f0d90a',
79+
eye: '#fff'
7880
}
7981
}
8082
}
@@ -136,6 +138,7 @@ export const cssThemeVars = ({
136138
'--chat-icon-color-pencil': iconsColor.pencil,
137139
'--chat-edited-icon-color-pencil': iconsColor.pencilEdited,
138140
'--chat-icon-color-trash': iconsColor.trash,
139-
'--chat-icon-color-checkmark': iconsColor.checkmark
141+
'--chat-icon-color-checkmark': iconsColor.checkmark,
142+
'--chat-icon-color-eye': iconsColor.eye
140143
}
141144
}

0 commit comments

Comments
 (0)