├── .gitignore ├── src ├── index.js ├── DialogButton.vue ├── Dropzone.vue └── FileSelector.vue ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export { default as FileSelector } from './FileSelector.vue' 2 | export { default as Dropzone } from './Dropzone.vue' 3 | export { default as DialogButton } from './DialogButton.vue' 4 | -------------------------------------------------------------------------------- /src/DialogButton.vue: -------------------------------------------------------------------------------- 1 | 6 | 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue3-file-selector", 3 | "version": "1.0.3", 4 | "description": "A Vue 3 headless file selector component", 5 | "main": "dist/vue3-file-selector.common.js", 6 | "scripts": { 7 | "build": "vue-cli-service build --target lib src/index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+ssh://git@github.com/cyon/vue3-file-selector.git" 13 | }, 14 | "keywords": [ 15 | "vue", 16 | "vue", 17 | "3", 18 | "file", 19 | "selector", 20 | "headless" 21 | ], 22 | "author": "Max Gfeller ", 23 | "license": "ISC", 24 | "bugs": { 25 | "url": "https://github.com/cyon/vue3-file-selector/issues" 26 | }, 27 | "homepage": "https://github.com/cyon/vue3-file-selector#readme", 28 | "devDependencies": { 29 | "@vue/cli-service": "^4.5.11", 30 | "@vue/compiler-sfc": "^3.0.7", 31 | "vue": "^3.0.7" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Dropzone.vue: -------------------------------------------------------------------------------- 1 | 10 | 45 | -------------------------------------------------------------------------------- /src/FileSelector.vue: -------------------------------------------------------------------------------- 1 | 5 | 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue3-file-selector 2 | 3 | A Vue 3 headless File Selector component. 4 | 5 | ## How to use 6 | 7 | This library includes a few headless components for a drag and drop supported 8 | file selector. 9 | 10 | Here's the parts: 11 | 12 | - `FileSelector`: The main container, needs to be used 13 | - `Dropzone`: Handles the drag and drop logic, does not need to be used 14 | - `DialogButton`: Unstyled button that opens the file dialog on click, does not need to be used 15 | 16 | ## Basic example 17 | 18 | [See it in action.](https://codesandbox.io/s/sweet-fog-f5wgd?file=/src/App.vue) 19 | 20 | Here's a basic example with drag and drop and a list of the selected files. 21 | 22 | ```vue 23 | 42 | 61 | ``` 62 | 63 | ## BYOB (Bring Your Own Button) 64 | 65 | This library provides an unstyled button component, which already implements the logic of opening 66 | the file selector dialog. However, if you already have a button component in your project, it would 67 | probably make more sense to use this one. 68 | 69 | This can be done as follows: 70 | 71 | ```vue 72 | 77 | ``` 78 | 79 | ## The `File` interface 80 | 81 | The `v-model` of `FileSelector` is an Array of [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) 82 | objects as they are returned from a file `` element or the drag and drop `DataTransfer` object. 83 | 84 | Here's how you could create a little preview of uploaded images: 85 | 86 | ```vue 87 | 95 | 129 | ``` 130 | --------------------------------------------------------------------------------