mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 17:14:50 +00:00
* fix: add download attribute to fix JAR files saving as ZIP in Chromium - JAR files were downloading with a `.zip` extension in Chromium-based browsers (Chrome, Edge, Arc, Brave, Opera, Vivaldi) - Root cause: JAR files are ZIP archives internally, so Chromium sniffs the `Content-Type` as `application/zip` and overrides the filename extension when no `download` attribute is present - Fix: add `download="<filename>"` to all file download `<a>` tags so the browser uses the original filename from the API * fix: add download attribute to remaining download links Missed in initial pass: changelog page button, versions overflow menu, settings/versions overflow menu. Also adds `download` prop to Button and OverflowMenu to support dropdown link items. Adds missing `getPrimaryFile` definition in changelog.vue. --------- Co-authored-by: Mr_chank <180248271+chank-op@users.noreply.github.com> Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
143 lines
2.7 KiB
Vue
143 lines
2.7 KiB
Vue
<script setup>
|
|
import { ExternalIcon, UnknownIcon } from '@modrinth/assets'
|
|
import { computed } from 'vue'
|
|
|
|
const props = defineProps({
|
|
link: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
external: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
download: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
action: {
|
|
type: Function,
|
|
default: null,
|
|
},
|
|
color: {
|
|
type: String,
|
|
default: 'default',
|
|
},
|
|
iconOnly: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
large: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
outline: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
transparent: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
hoverFilled: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
hoverFilledOnly: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
disabled: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
})
|
|
|
|
const accentedButton = computed(() =>
|
|
['danger', 'primary', 'red', 'orange', 'green', 'blue', 'purple', 'gray'].includes(props.color),
|
|
)
|
|
|
|
const classes = computed(() => {
|
|
const color = props.color
|
|
return {
|
|
'icon-only': props.iconOnly,
|
|
'btn-large': props.large,
|
|
'btn-danger': color === 'danger',
|
|
'btn-primary': color === 'primary',
|
|
'btn-secondary': color === 'secondary',
|
|
'btn-highlight': color === 'highlight',
|
|
'btn-red': color === 'red',
|
|
'btn-orange': color === 'orange',
|
|
'btn-green': color === 'green',
|
|
'btn-blue': color === 'blue',
|
|
'btn-purple': color === 'purple',
|
|
'btn-gray': color === 'gray',
|
|
'btn-transparent': props.transparent,
|
|
'btn-hover-filled': props.hoverFilled,
|
|
'btn-hover-filled-only': props.hoverFilledOnly,
|
|
'btn-outline': props.outline,
|
|
'color-accent-contrast': accentedButton,
|
|
disabled: props.disabled,
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<router-link
|
|
v-if="link && link.startsWith('/')"
|
|
class="btn"
|
|
:class="classes"
|
|
:to="disabled ? '' : link"
|
|
:target="external ? '_blank' : '_self'"
|
|
@click="
|
|
(event) => {
|
|
if (disabled) {
|
|
event.preventDefault()
|
|
return
|
|
}
|
|
if (action) {
|
|
action(event)
|
|
}
|
|
}
|
|
"
|
|
>
|
|
<slot />
|
|
<ExternalIcon v-if="external && !iconOnly" class="external-icon" />
|
|
<UnknownIcon v-if="!$slots.default" />
|
|
</router-link>
|
|
<a
|
|
v-else-if="link"
|
|
class="btn"
|
|
:class="classes"
|
|
:href="disabled ? undefined : link"
|
|
:download="download || undefined"
|
|
:target="external ? '_blank' : '_self'"
|
|
@click="
|
|
(event) => {
|
|
if (disabled) {
|
|
event.preventDefault()
|
|
return
|
|
}
|
|
if (action) {
|
|
action(event)
|
|
}
|
|
}
|
|
"
|
|
>
|
|
<slot />
|
|
<ExternalIcon v-if="external && !iconOnly" class="external-icon" />
|
|
<UnknownIcon v-if="!$slots.default" />
|
|
</a>
|
|
<button v-else class="btn" :class="classes" :disabled="disabled" @click="action">
|
|
<slot />
|
|
<UnknownIcon v-if="!$slots.default" />
|
|
</button>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
:where(button) {
|
|
background: none;
|
|
color: var(--color-base);
|
|
}
|
|
</style>
|