Skip to content

Commit

Permalink
fix(attachment): adding button download (#499)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeroen Claassens <support@favware.tech>
  • Loading branch information
eumarciel404 and favna authored Nov 2, 2024
1 parent c7f3584 commit 056368b
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const DiscordMediaAttachmentStyles = css`
max-width: 100%;
display: flex;
flex-direction: column;
position: relative;
}
.discord-media-attachment-mosaic-item-media {
Expand Down Expand Up @@ -65,4 +66,32 @@ export const DiscordMediaAttachmentStyles = css`
.discord-media-attachment-duration-time-separator {
margin: 0 2px;
}
.discord-media-attachment-non-visual-media-item-container:hover .discord-button-download-attachment {
display: block !important;
}
.discord-button-download-attachment {
display: none;
position: absolute;
top: -8px;
right: -8px;
border-radius: 5px;
outline: color-mix(in oklab, hsl(220 calc(1 * 6.5%) 18% / 1) 100%, black 0%);
background-color: color-mix(in oklab, hsl(223 calc(1 * 6.7%) 20.6% / 1) 100%, black 0%);
}
.discord-link-download-attachment {
color: color-mix(in oklab, hsl(215 calc(1 * 8.8%) 73.3% / 1) 100%, black 0%);
display: flex;
}
.discord-icon-download {
padding: 6px;
}
.discord-button-download-attachment {
top: 5px !important;
right: 8px !important;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DiscordPlaybackControlStyles } from '../_private/DiscordPlaybackControl
import { DiscordVolumeControlStyles } from '../_private/DiscordVolumeControlStyles.js';
import '../discord-link/DiscordLink.js';
import { messagesLightTheme } from '../discord-messages/DiscordMessages.js';
import AttachmentDownloadButton from '../svgs/AttachmentDownloadButton.js';
import MediaPauseIcon from '../svgs/MediaPauseIcon.js';
import MediaPlayIcon from '../svgs/MediaPlayIcon.js';
import MediaRestartIcon from '../svgs/MediaRestartIcon.js';
Expand Down Expand Up @@ -304,6 +305,19 @@ export class DiscordAudioAttachment extends DiscordMediaLifecycle implements Lig
</div>
</div>
</div>
<div class="discord-button-download-attachment">
<a
class="discord-link-download-attachment"
aria-label="Download"
href="${ifDefined(this.href)}"
rel="noreferrer noopener"
target="_blank"
role="button"
tabindex="0"
>
${AttachmentDownloadButton()}
</a>
</div>
</div>`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { when } from 'lit/directives/when.js';
import '../discord-link/DiscordLink.js';
import type { LightTheme } from '../../types.js';
import { messagesLightTheme } from '../discord-messages/DiscordMessages.js';
import AttachmentDownloadButton from '../svgs/AttachmentDownloadButton.js';
import FileAttachment from '../svgs/FileAttachment.js';

@customElement('discord-file-attachment')
Expand Down Expand Up @@ -35,11 +36,35 @@ export class DiscordFileAttachment extends LitElement implements LightTheme {
align-self: start;
}
.discord-file-attachment-non-visual-media-item-container:hover .discord-button-download-attachment {
display: block !important;
}
.discord-button-download-attachment {
display: none;
position: absolute;
top: -8px;
right: -8px;
border-radius: 5px;
outline: color-mix(in oklab, hsl(220 calc(1 * 6.5%) 18% / 1) 100%, black 0%);
background-color: color-mix(in oklab, hsl(223 calc(1 * 6.7%) 20.6% / 1) 100%, black 0%);
}
.discord-link-download-attachment {
color: color-mix(in oklab, hsl(215 calc(1 * 8.8%) 73.3% / 1) 100%, black 0%);
display: flex;
}
.discord-icon-download {
padding: 6px;
}
.discord-file-attachment-non-visual-media-item-container {
margin-top: 8px;
max-width: 100%;
display: flex;
flex-direction: column;
position: relative;
}
.discord-file-attachment-non-visual-media-item {
Expand Down Expand Up @@ -211,6 +236,19 @@ export class DiscordFileAttachment extends LitElement implements LightTheme {
</div>
</div>
</div>
<div class="discord-button-download-attachment">
<a
class="discord-link-download-attachment"
aria-label="Download"
href="${ifDefined(this.href)}"
rel="noreferrer noopener"
target="_blank"
role="button"
tabindex="0"
>
${AttachmentDownloadButton()}
</a>
</div>
</div>`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DiscordPlaybackControlStyles } from '../_private/DiscordPlaybackControl
import { DiscordVolumeControlStyles } from '../_private/DiscordVolumeControlStyles.js';
import '../discord-link/DiscordLink.js';
import { messagesLightTheme } from '../discord-messages/DiscordMessages.js';
import AttachmentDownloadButton from '../svgs/AttachmentDownloadButton.js';
import MediaPauseIcon from '../svgs/MediaPauseIcon.js';
import MediaPlayIcon from '../svgs/MediaPlayIcon.js';
import MediaRestartIcon from '../svgs/MediaRestartIcon.js';
Expand Down Expand Up @@ -50,6 +51,11 @@ export class DiscordVideoAttachment extends DiscordMediaLifecycle implements Lig
--volume-slider-opacity: 0;
}
:host .discord-button-download-attachment {
top: 5px !important;
right: 8px !important;
}
.discord-video-attachment-one-by-one-grid {
max-width: 100%;
border-radius: 8px;
Expand Down Expand Up @@ -439,6 +445,19 @@ export class DiscordVideoAttachment extends DiscordMediaLifecycle implements Lig
</div>
</div>
</div>
<div class="discord-button-download-attachment">
<a
class="discord-link-download-attachment"
aria-label="Download"
href="${ifDefined(this.href)}"
rel="noreferrer noopener"
target="_blank"
role="button"
tabindex="0"
>
${AttachmentDownloadButton()}
</a>
</div>
</div>`;
}
}
Expand Down
25 changes: 25 additions & 0 deletions packages/core/src/components/svgs/AttachmentDownloadButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { html, svg } from 'lit';
import { spread } from '../../spread.js';

const svgContent = svg`
<path
fill="currentColor"
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"
/>
`;

export default function AttachmentDownloadButton(props: Record<string, unknown> = {}) {
return html`<svg
${spread(props)}
class="discord-icon-download"
aria-hidden="true"
role="img"
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
fill="none"
viewBox="0 0 24 24"
>
${svgContent}
</svg>`;
}

0 comments on commit 056368b

Please sign in to comment.