Skip to content

Drop Zone

Drop Zone area, where you can drop files.

🎬 Usage

<script>
    import {drop_zone} from "sveltecore"

    let is_over_drop_zone = false

    let files_data = []

    function on_drop(files) {
        files_data = []
        if (files) {
            files_data = files.map((file) => ({
                name: file.name,
                size: file.size,
                type: file.type,
                last_modified: file.lastModified,
            }))
        }
    }

    function on_drop_zone(el) {
        const result = drop_zone(el, on_drop)
        result.subscribe((x) => {
            is_over_drop_zone = x
        })
    }

</script>
<div use:on_drop_zone></div>

👩‍💻API

Arguments

Name Description Type Required
target DOM element to attach drop zone to HTMLElement Yes
on_drop Callback function to handle drop (files: File[] | null) => void Yes

Returns

A subscribable store that contains the current drop zone state.

🧪 Playground


Last update: 2022-11-13