Skip to content

Commit 056368b

Browse files
eumarciel404favna
andauthored
fix(attachment): adding button download (#499)
Co-authored-by: Jeroen Claassens <support@favware.tech>
1 parent c7f3584 commit 056368b

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

packages/core/src/components/_private/DiscordMediaAttachmentStyles.ts

+29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const DiscordMediaAttachmentStyles = css`
1111
max-width: 100%;
1212
display: flex;
1313
flex-direction: column;
14+
position: relative;
1415
}
1516
1617
.discord-media-attachment-mosaic-item-media {
@@ -65,4 +66,32 @@ export const DiscordMediaAttachmentStyles = css`
6566
.discord-media-attachment-duration-time-separator {
6667
margin: 0 2px;
6768
}
69+
70+
.discord-media-attachment-non-visual-media-item-container:hover .discord-button-download-attachment {
71+
display: block !important;
72+
}
73+
74+
.discord-button-download-attachment {
75+
display: none;
76+
position: absolute;
77+
top: -8px;
78+
right: -8px;
79+
border-radius: 5px;
80+
outline: color-mix(in oklab, hsl(220 calc(1 * 6.5%) 18% / 1) 100%, black 0%);
81+
background-color: color-mix(in oklab, hsl(223 calc(1 * 6.7%) 20.6% / 1) 100%, black 0%);
82+
}
83+
84+
.discord-link-download-attachment {
85+
color: color-mix(in oklab, hsl(215 calc(1 * 8.8%) 73.3% / 1) 100%, black 0%);
86+
display: flex;
87+
}
88+
89+
.discord-icon-download {
90+
padding: 6px;
91+
}
92+
93+
.discord-button-download-attachment {
94+
top: 5px !important;
95+
right: 8px !important;
96+
}
6897
`;

packages/core/src/components/discord-audio-attachment/DiscordAudioAttachment.ts

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DiscordPlaybackControlStyles } from '../_private/DiscordPlaybackControl
1212
import { DiscordVolumeControlStyles } from '../_private/DiscordVolumeControlStyles.js';
1313
import '../discord-link/DiscordLink.js';
1414
import { messagesLightTheme } from '../discord-messages/DiscordMessages.js';
15+
import AttachmentDownloadButton from '../svgs/AttachmentDownloadButton.js';
1516
import MediaPauseIcon from '../svgs/MediaPauseIcon.js';
1617
import MediaPlayIcon from '../svgs/MediaPlayIcon.js';
1718
import MediaRestartIcon from '../svgs/MediaRestartIcon.js';
@@ -304,6 +305,19 @@ export class DiscordAudioAttachment extends DiscordMediaLifecycle implements Lig
304305
</div>
305306
</div>
306307
</div>
308+
<div class="discord-button-download-attachment">
309+
<a
310+
class="discord-link-download-attachment"
311+
aria-label="Download"
312+
href="${ifDefined(this.href)}"
313+
rel="noreferrer noopener"
314+
target="_blank"
315+
role="button"
316+
tabindex="0"
317+
>
318+
${AttachmentDownloadButton()}
319+
</a>
320+
</div>
307321
</div>`;
308322
}
309323
}

packages/core/src/components/discord-file-attachment/DiscordFileAttachment.ts

+38
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { when } from 'lit/directives/when.js';
77
import '../discord-link/DiscordLink.js';
88
import type { LightTheme } from '../../types.js';
99
import { messagesLightTheme } from '../discord-messages/DiscordMessages.js';
10+
import AttachmentDownloadButton from '../svgs/AttachmentDownloadButton.js';
1011
import FileAttachment from '../svgs/FileAttachment.js';
1112

1213
@customElement('discord-file-attachment')
@@ -35,11 +36,35 @@ export class DiscordFileAttachment extends LitElement implements LightTheme {
3536
align-self: start;
3637
}
3738
39+
.discord-file-attachment-non-visual-media-item-container:hover .discord-button-download-attachment {
40+
display: block !important;
41+
}
42+
43+
.discord-button-download-attachment {
44+
display: none;
45+
position: absolute;
46+
top: -8px;
47+
right: -8px;
48+
border-radius: 5px;
49+
outline: color-mix(in oklab, hsl(220 calc(1 * 6.5%) 18% / 1) 100%, black 0%);
50+
background-color: color-mix(in oklab, hsl(223 calc(1 * 6.7%) 20.6% / 1) 100%, black 0%);
51+
}
52+
53+
.discord-link-download-attachment {
54+
color: color-mix(in oklab, hsl(215 calc(1 * 8.8%) 73.3% / 1) 100%, black 0%);
55+
display: flex;
56+
}
57+
58+
.discord-icon-download {
59+
padding: 6px;
60+
}
61+
3862
.discord-file-attachment-non-visual-media-item-container {
3963
margin-top: 8px;
4064
max-width: 100%;
4165
display: flex;
4266
flex-direction: column;
67+
position: relative;
4368
}
4469
4570
.discord-file-attachment-non-visual-media-item {
@@ -211,6 +236,19 @@ export class DiscordFileAttachment extends LitElement implements LightTheme {
211236
</div>
212237
</div>
213238
</div>
239+
<div class="discord-button-download-attachment">
240+
<a
241+
class="discord-link-download-attachment"
242+
aria-label="Download"
243+
href="${ifDefined(this.href)}"
244+
rel="noreferrer noopener"
245+
target="_blank"
246+
role="button"
247+
tabindex="0"
248+
>
249+
${AttachmentDownloadButton()}
250+
</a>
251+
</div>
214252
</div>`;
215253
}
216254
}

packages/core/src/components/discord-video-attachment/DiscordVideoAttachment.ts

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DiscordPlaybackControlStyles } from '../_private/DiscordPlaybackControl
1212
import { DiscordVolumeControlStyles } from '../_private/DiscordVolumeControlStyles.js';
1313
import '../discord-link/DiscordLink.js';
1414
import { messagesLightTheme } from '../discord-messages/DiscordMessages.js';
15+
import AttachmentDownloadButton from '../svgs/AttachmentDownloadButton.js';
1516
import MediaPauseIcon from '../svgs/MediaPauseIcon.js';
1617
import MediaPlayIcon from '../svgs/MediaPlayIcon.js';
1718
import MediaRestartIcon from '../svgs/MediaRestartIcon.js';
@@ -50,6 +51,11 @@ export class DiscordVideoAttachment extends DiscordMediaLifecycle implements Lig
5051
--volume-slider-opacity: 0;
5152
}
5253
54+
:host .discord-button-download-attachment {
55+
top: 5px !important;
56+
right: 8px !important;
57+
}
58+
5359
.discord-video-attachment-one-by-one-grid {
5460
max-width: 100%;
5561
border-radius: 8px;
@@ -439,6 +445,19 @@ export class DiscordVideoAttachment extends DiscordMediaLifecycle implements Lig
439445
</div>
440446
</div>
441447
</div>
448+
<div class="discord-button-download-attachment">
449+
<a
450+
class="discord-link-download-attachment"
451+
aria-label="Download"
452+
href="${ifDefined(this.href)}"
453+
rel="noreferrer noopener"
454+
target="_blank"
455+
role="button"
456+
tabindex="0"
457+
>
458+
${AttachmentDownloadButton()}
459+
</a>
460+
</div>
442461
</div>`;
443462
}
444463
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { html, svg } from 'lit';
2+
import { spread } from '../../spread.js';
3+
4+
const svgContent = svg`
5+
<path
6+
fill="currentColor"
7+
d="M12 2a1 1 0 0 1 1 1v10.59l3.3-3.3a1 1 0 1 1 1.4 1.42l-5 5a1 1 0 0 1-1.4 0l-5-5a1 1 0 1 1 1.4-1.42l3.3 3.3V3a1 1 0 0 1 1-1ZM3 20a1 1 0 1 0 0 2h18a1 1 0 1 0 0-2H3Z"
8+
/>
9+
`;
10+
11+
export default function AttachmentDownloadButton(props: Record<string, unknown> = {}) {
12+
return html`<svg
13+
${spread(props)}
14+
class="discord-icon-download"
15+
aria-hidden="true"
16+
role="img"
17+
xmlns="http://www.w3.org/2000/svg"
18+
width="20"
19+
height="20"
20+
fill="none"
21+
viewBox="0 0 24 24"
22+
>
23+
${svgContent}
24+
</svg>`;
25+
}

0 commit comments

Comments
 (0)