You've already forked AstralRinth
forked from didirus/AstralRinth
Create StatelessFileInput, use in version.vue (#537)
This commit is contained in:
93
components/ui/StatelessFileInput.vue
Normal file
93
components/ui/StatelessFileInput.vue
Normal file
@@ -0,0 +1,93 @@
|
||||
<template>
|
||||
<div class="columns">
|
||||
<label class="button" @drop.prevent="handleDrop" @dragover.prevent>
|
||||
<span>
|
||||
<UploadIcon />
|
||||
{{ prompt }}
|
||||
</span>
|
||||
<input
|
||||
type="file"
|
||||
:multiple="multiple"
|
||||
:accept="accept"
|
||||
@change="handleChange"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import UploadIcon from '~/assets/images/utils/upload.svg?inline'
|
||||
|
||||
export default {
|
||||
name: 'StatelessFileInput',
|
||||
components: {
|
||||
UploadIcon,
|
||||
},
|
||||
props: {
|
||||
prompt: {
|
||||
type: String,
|
||||
default: 'Select file',
|
||||
},
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
accept: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
onChange(addedFiles) {
|
||||
this.$emit('change', addedFiles)
|
||||
},
|
||||
addFiles(filesToAdd) {
|
||||
if (!filesToAdd) return
|
||||
|
||||
if (!this.multiple && filesToAdd.length > 0) {
|
||||
this.onChange([filesToAdd[0]])
|
||||
return
|
||||
}
|
||||
|
||||
this.onChange(filesToAdd)
|
||||
},
|
||||
handleDrop(e) {
|
||||
this.addFiles(e.dataTransfer.files)
|
||||
},
|
||||
handleChange(e) {
|
||||
this.addFiles(e.target.files)
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
label {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
padding: var(--spacing-card-sm) var(--spacing-card-md);
|
||||
margin-bottom: var(--spacing-card-sm);
|
||||
}
|
||||
|
||||
span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
gap: 0.5rem;
|
||||
border: 2px dashed var(--color-divider-dark);
|
||||
border-radius: var(--size-rounded-control);
|
||||
padding: var(--spacing-card-md) var(--spacing-card-lg);
|
||||
|
||||
svg {
|
||||
height: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
input {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -511,7 +511,7 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<SmartFileInput
|
||||
<StatelessFileInput
|
||||
v-if="mode === 'edit' || mode === 'create'"
|
||||
multiple
|
||||
class="choose-files"
|
||||
@@ -527,7 +527,7 @@
|
||||
<script>
|
||||
import Multiselect from 'vue-multiselect'
|
||||
import ConfirmPopup from '~/components/ui/ConfirmPopup'
|
||||
import SmartFileInput from '~/components/ui/SmartFileInput'
|
||||
import StatelessFileInput from '~/components/ui/StatelessFileInput'
|
||||
|
||||
import InfoIcon from '~/assets/images/utils/info.svg?inline'
|
||||
import TrashIcon from '~/assets/images/utils/trash.svg?inline'
|
||||
@@ -557,7 +557,7 @@ export default {
|
||||
CheckIcon,
|
||||
Multiselect,
|
||||
PlusIcon,
|
||||
SmartFileInput,
|
||||
StatelessFileInput,
|
||||
InfoIcon,
|
||||
},
|
||||
beforeRouteLeave(to, from, next) {
|
||||
|
||||
Reference in New Issue
Block a user