Skip to content

Commit 23bb0b6

Browse files
committed
fix: ts type
1 parent 7b98cf7 commit 23bb0b6

File tree

5 files changed

+33
-50
lines changed

5 files changed

+33
-50
lines changed

.yarnrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
re
Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<div v-bind="getRootProps()">
4-
<input v-bind="getInputProps()" >
4+
<input v-bind="getInputProps()">
55
<p v-if="isDragActive">Drop the files here ...</p>
66
<p v-else>Drag 'n' drop some files here, or click to select files</p>
77
<div v-if="isFocused" id="focus">
@@ -11,51 +11,34 @@
1111
isDragReject: {{ isDragReject }}
1212
</div>
1313
</div>
14-
<button @click="onClick">open</button>
14+
<button @click="open">open</button>
1515
</div>
1616
</template>
1717

18-
<script lang="ts">
19-
import { defineComponent, reactive } from 'vue'
18+
<script lang="ts" setup>
19+
import { reactive } from 'vue'
2020
import { useDropzone } from 'vue3-dropzone/src'
21-
export default defineComponent({
22-
name: 'HelloWorld',
23-
props: {
24-
msg: String
25-
},
26-
methods: {
27-
onClick() {
28-
if (this.open) {
29-
this.open()
30-
}
31-
},
32-
toggleMulti() {
33-
this.options.multiple = !this.options.multiple
34-
}
35-
},
36-
setup() {
37-
function onDrop(acceptedFiles, rejectReasons) {
38-
console.log('acceptedFiles', acceptedFiles)
39-
console.log('rejectReasons', rejectReasons)
40-
}
21+
import type { FileRejectReason } from 'vue3-dropzone/src/useDropzone'
4122
42-
const options = reactive({
43-
multiple: false,
44-
onDrop,
45-
accept: '.jpg',
46-
})
23+
function onDrop(acceptedFiles: File[], rejectReasons: FileRejectReason[]) {
24+
console.log('acceptedFiles', acceptedFiles)
25+
console.log('rejectReasons', rejectReasons)
26+
}
4727
48-
const {
49-
getRootProps,
50-
getInputProps,
51-
...rest
52-
} = useDropzone(options)
53-
return {
54-
options,
55-
getRootProps,
56-
getInputProps,
57-
...rest
58-
}
59-
}
28+
const options = reactive({
29+
multiple: false,
30+
onDrop,
31+
accept: '.jpg',
6032
})
33+
34+
const {
35+
getRootProps,
36+
getInputProps,
37+
isDragActive,
38+
isFocused,
39+
isDragReject,
40+
open
41+
} = useDropzone(options)
42+
43+
6144
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue3-dropzone",
3-
"version": "0.0.7",
3+
"version": "2.0.0",
44
"description": "",
55
"main": "dist/index.common.js",
66
"unpkg": "dist/index.umd.js",

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export { useDropzone } from './useDropzone'
1+
export { useDropzone } from './useDropzone'
2+
export type { FileUploadOptions, FileRejectReason } from './useDropzone'

src/useDropzone.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type FileRejectionError = { code: FileErrorCode, message: string } | null | bool
1616

1717
type InputFile = (FileWithPath | DataTransferItem) & { size?: number }
1818

19-
type FileRejectReason = { file: InputFile; errors: FileRejectionError[] }
19+
export type FileRejectReason = { file: InputFile; errors: FileRejectionError[] }
2020

2121
export interface FileUploadOptions {
2222
accept: FileAccept
@@ -29,7 +29,7 @@ export interface FileUploadOptions {
2929
onDragEnter: FileHandler
3030
onDragLeave: FileHandler
3131
onDragOver: FileHandler
32-
onDrop: (acceptedFiles: InputFile[], rejectReasons: FileRejectReason[], event: Event) => void
32+
onDrop: (acceptedFiles: any[], rejectReasons: FileRejectReason[], event: Event) => void
3333
onDropAccepted: (acceptedFiles: InputFile[], event: Event) => void
3434
onDropRejected: (rejectReasons: FileRejectReason[], event: Event) => void
3535
onFileDialogCancel: () => void
@@ -527,11 +527,11 @@ export function useDropzone(options: Partial<FileUploadOptions> = {}) {
527527
dispatch({ type: 'reset' })
528528
}
529529

530-
const composeHandler = (fn: ComposeFunction) => (optionsRef.value.disabled ? null : fn)
530+
const composeHandler = (fn: ComposeFunction) => (optionsRef.value.disabled ? undefined : fn)
531531

532-
const composeKeyboardHandler = (fn: ComposeFunction) => (optionsRef.value.noKeyboard ? null : composeHandler(fn))
532+
const composeKeyboardHandler = (fn: ComposeFunction) => (optionsRef.value.noKeyboard ? undefined : composeHandler(fn))
533533

534-
const composeDragHandler = (fn: ComposeFunction) => (optionsRef.value.noDrag ? null : composeHandler(fn))
534+
const composeDragHandler = (fn: ComposeFunction) => (optionsRef.value.noDrag ? undefined : composeHandler(fn))
535535

536536
const getRootProps = ({
537537
onKeyDown,
@@ -572,7 +572,7 @@ export function useDropzone(options: Partial<FileUploadOptions> = {}) {
572572
...rest
573573
}: { onChange?: () => void; onClick?: () => void } = {}) {
574574
const inputProps = {
575-
accept: optionsRef.value.accept,
575+
accept: optionsRef.value.accept as string,
576576
multiple: optionsRef.value.multiple,
577577
style: 'display: none',
578578
type: 'file',

0 commit comments

Comments
 (0)