Created
March 27, 2018 08:07
-
-
Save rhymes/1b0658e891956287de5aff833a7815a6 to your computer and use it in GitHub Desktop.
buefy app input file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="container"> | |
<b-field> | |
<b-tooltip | |
:label="tooltipLabel" | |
position="is-right" | |
type="is-dark" | |
animated> | |
<b-field> | |
<b-upload | |
:name="name" | |
v-model="files" | |
:accept="accept" | |
@input="onFileSelect"> | |
<a class="button is-info"> | |
<b-icon icon="upload" /> | |
<span v-if="hasFile"> | |
{{ fileName }} | |
</span> | |
<span v-else>{{ label }}</span> | |
</a> | |
</b-upload> | |
<p | |
v-if="hasFile" | |
class="control"> | |
<button | |
title="Clear selected file" | |
class="button reset is-info is-outlined" | |
@click="onClearFileClick"> | |
<b-icon icon="close" /> | |
</button> | |
</p> | |
</b-field> | |
</b-tooltip> | |
</b-field> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'AppInputFile', | |
props: { | |
name: { | |
type: String, | |
required: true, | |
}, | |
accept: { | |
type: String, | |
default: null, | |
}, | |
label: { | |
type: String, | |
default: 'Choose a file...', | |
}, | |
tooltipLabel: { | |
type: String, | |
default: '', | |
}, | |
}, | |
data() { | |
return { | |
files: [], | |
} | |
}, | |
computed: { | |
hasFile() { | |
return this.files && this.files.length > 0 | |
}, | |
fileName() { | |
if (this.hasFile) { | |
return this.files[0].name | |
} | |
return '' | |
}, | |
}, | |
methods: { | |
emitInputEvent(value) { | |
// send images to the parent component | |
this.$emit('input', value) | |
}, | |
/* event handlers */ | |
onClearFileClick() { | |
this.files = [] | |
this.emitInputEvent(this.files) | |
}, | |
onFileSelect() { | |
this.emitInputEvent(this.files) | |
}, | |
}, | |
} | |
</script> | |
<style scoped> | |
.container { | |
margin-bottom: 0.5rem; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment