Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jsakamoto/Toolbelt.Blazor.FileDropZone

Surround an "input type=file" element by this Blazor component to making a zone that accepts drag and drops files.
https://github.com/jsakamoto/Toolbelt.Blazor.FileDropZone

blazor dragdrop drop dropfile

Last synced: 3 months ago
JSON representation

Surround an "input type=file" element by this Blazor component to making a zone that accepts drag and drops files.

Awesome Lists containing this project

README

        

# Blazor File Drop Zone [![NuGet Package](https://img.shields.io/nuget/v/Toolbelt.Blazor.FileDropZone.svg)](https://www.nuget.org/packages/Toolbelt.Blazor.FileDropZone/)

## Summary

Surround an `` element by this `` Blazor component to making a zone that accepts drag and drops files.

- Live demo site - https://jsakamoto.github.io/Toolbelt.Blazor.FileDropZone/

![fig.1](https://raw.githubusercontent.com/jsakamoto/Toolbelt.Blazor.FileDropZone/master/.assets/fig.001.png)

## Usage

**Step 1.** Add the NuGet package of this Blazor component to your Blazor app project.

```shell
> dotnet add package Toolbelt.Blazor.FileDropZone
```

**Step 2.** Surround `` component by the `` component.

Before:

```html

```

After:

```html

@using Toolbelt.Blazor.FileDropZone
...

```

**Step 3.** Styling the `` component as you want to see.

**[Tips]**

The `` component will render just a single & plain `

` element outside of child content.

That means the `` component doesn't provide any UI styles.

Instead, `` the component adds/removes the `"hover"` CSS class to that `

` element when the mouse cursor enters/leaves the component area.

```css
/* "Foo.razor.css" */

::deep .drop-zone {
padding: 32px;
border: dashed 2px transparent;
transition: border linear 0.2s;
}
::deep .drop-zone.hover {
border: dashed 2px darkorange;
}
```

After doing the above steps, you will get a drag & drop file feature like the following image.

![movie](https://raw.githubusercontent.com/jsakamoto/Toolbelt.Blazor.FileDropZone/master/.assets/movie.001.gif)

When any files are dropped into the `div` element that the `` component rendered, the `` component finds a `` element from an inside of its child content.

And then, the component dispatches the file object that the user dropped to the input element that the component found.

## Supported version

- .NET 5 or later is required.
- Both Blazor WebAssembly and Blazor Server are supported.

## Release Note

[Release notes](https://github.com/jsakamoto/Toolbelt.Blazor.FileDropZone/blob/master/RELEASE-NOTES.txt)

## License

[Mozilla Public License Version 2.0](https://github.com/jsakamoto/Toolbelt.Blazor.FileDropZone/blob/master/LICENSE)