2.0.2 • Published 5 years ago

vuetify-upload-button v2.0.2

Weekly downloads
1,221
License
MIT
Repository
github
Last release
5 years ago

vuetify-upload-button

A Vue component for Vuetify.

This component is a file upload input with the base functionality of a Vuetify button.

Installation

npm i vuetify-upload-button

Browser

Include the script file, then install the component with Vue.use(UploadButton); e.g.:

<script type="text/javascript" src="node_modules/vuejs/dist/vue.min.js"></script>
<script type="text/javascript" src="node_modules/vuetify-upload-button/dist/upload-button.min.js"></script>
<script type="text/javascript">
  Vue.use(UploadButton);
</script>

Module

  import UploadButton from 'vuetify-upload-button';

  export default {
    components: {
      'upload-btn': UploadButton
    }
  }

IMPORTANT NOTE

In order for the ripple directive to work properly, you must import the Ripple directive.

// plugins/vuetify.js
import Vue from 'vue'
import Vuetify from 'vuetify/lib'
import { Ripple } from 'vuetify/lib/directives'

Vue.use(Vuetify, {
  // other stuff
  directives: {
    Ripple
  }
})

Usage

Once installed, it can be used in a template as simply as:

Simple Upload button

<upload-btn></upload-btn>

Upon file change, the Upload Button component emit a file-update event with the file or files as the argument, see the following example:

<template>
  <upload-btn
    @file-update="update"
  >

  </upload-btn>
</template>

<script>
  import UploadButton from 'vuetify-upload-button'

  export default {
    methods: {
      update (file) {
        // handle file here. File will be an object.
        // If multiple prop is true, it will return an object array of files.
      }
    },
    components: {
      'upload-btn': UploadButton
    }
  }
</script>

Button with icon. The 'icon' slot defaults to the right:

<upload-btn
  title="Button With Icon"
>
  <template slot="icon">
    <v-icon>add</v-icon>
  </template>
</upload-btn>

Button with left icon:

<upload-btn
  title="Button With Icon"
>
  <template slot="icon-left">
    <v-icon left>add</v-icon>
  </template>
</upload-btn>

Button as icon

<upload-btn icon>
  <template slot="icon">
    <v-icon>add</v-icon>
  </template>
</upload-btn>

You can clear the file input using a ref

<upload-btn ref="button" title="Button" />

<button @click="$refs.button.clear()" />

Props

You can use the following props

NameDescriptionTypeDefault
acceptHTML input accept attributestring*
blockblockboolfalse
depressedremove box shadowboolfalse
colorvuetify color, e.g. 'primary'string'primary'
disabledsets disabled property for input/buttonboolfalse
fixedWidthsets a fixed width for the buttonstringnull
flatsets button flatboolfalse
hoverbutton has hoverable effectbooltrue
iconbutton is icon buttonboolfalse
labelClassclass to apply to the label such as text colorstring''
largebutton is largeboolfalse
loadingloading state for buttonboolfalse
maxWidthallows the button to grow based on filename length to a maxstring100%
multipleallows multiple files to be uploaded, returns an array instead of single objectboolfalse
nameapplies HTML name attributestringuploadFile
outlinebutton is outlineboolfalse
ripplebutton has ripple effectbooltrue
roundbutton is roundboolfalse
smallbutton is smallboolfalse
titletext of buttonstring'Upload'
noTitleUpdatedisabled dynamic updating of titleboolfalse

*Removed uniqueID as a prop because it should ALWAYS have a unique id

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago