Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MudDropZone: New Drag and Drop component #3860

Merged
merged 50 commits into from
Feb 3, 2022
Merged

MudDropZone: New Drag and Drop component #3860

merged 50 commits into from
Feb 3, 2022

Conversation

Garderoben
Copy link
Member

@Garderoben Garderoben commented Feb 1, 2022

New component / feature adds Drag and Drop

It's been built with great customization capability's in mind and comes with 0 styling.
Just so it can be used in way more things than just the classic drag and drop lists.

Made by me @Garderoben and @just-the-benno

Components:

  • MudDropZone
  • MudDropContainer
  • MudDynamicDropItem

Description

resolves #1045 #668

Basic Usage

BasicUsage

Can be used in combination with other components (in some cases)

WorksWithList

Drop Rules

CanDrop can be set globally or per drop zone.
DropRules

Drop Rule Styling

CanDrop and NoDrop styling.
DropRuleStyling

Dragging Styles

The style of the drop zone or the drop item can be changed on drag as well and in combination of both.
DraggingStyles

Disabled Items

Items can be disabled and prevent dragging from happening

DisabledItems

Misc, show case examples

KanBan Example
KanBan
Chess Board
ChessExample

How Has This Been Tested?

Manually while making this and the docs examples.
Unit tests.
Tested by several people.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@codecov
Copy link

codecov bot commented Feb 1, 2022

Codecov Report

Merging #3860 (b17b7d3) into dev (a8a910a) will increase coverage by 0.40%.
The diff coverage is 98.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #3860      +/-   ##
==========================================
+ Coverage   90.59%   91.00%   +0.40%     
==========================================
  Files         332      348      +16     
  Lines       10519    11419     +900     
==========================================
+ Hits         9530    10392     +862     
- Misses        989     1027      +38     
Impacted Files Coverage Δ
...MudBlazor/Components/DropZone/MudDropZone.razor.cs 97.75% <97.75%> (ø)
src/MudBlazor/Attributes/CategoryAttribute.cs 96.22% <100.00%> (+0.30%) ⬆️
...dBlazor/Components/DropZone/MudDropContainer.razor 100.00% <100.00%> (ø)
...azor/Components/DropZone/MudDropContainer.razor.cs 100.00% <100.00%> (ø)
...rc/MudBlazor/Components/DropZone/MudDropZone.razor 100.00% <100.00%> (ø)
...lazor/Components/DropZone/MudDynamicDropItem.razor 100.00% <100.00%> (ø)
...or/Components/DropZone/MudDynamicDropItem.razor.cs 100.00% <100.00%> (ø)
...dBlazor/Components/TextField/MudTextField.razor.cs 71.42% <0.00%> (-1.30%) ⬇️
...lazor/Components/MessageBox/MudMessageBox.razor.cs 20.40% <0.00%> (-0.43%) ⬇️
src/MudBlazor/Components/Menu/MudMenu.razor 100.00% <0.00%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8a910a...b17b7d3. Read the comment docs.

@mikes-gh mikes-gh added the new component A completely new component label Feb 2, 2022
Copy link
Member

@JonBunator JonBunator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. This looks great @just-the-benno, @Garderoben
Good job :D
The only thing that could be added in my opinion:

  • allow for reordering inside the drop zone
    or
  • have a function that determines the order of the items in the drop zone

Comment on lines 120 to 121
.AddClass(DraggingClass, string.IsNullOrWhiteSpace(DraggingClass) == false && _dragOperationIsInProgress == true)
.AddClass(DisabledClass, Disabled == true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.AddClass(DraggingClass, string.IsNullOrWhiteSpace(DraggingClass) == false && _dragOperationIsInProgress == true)
.AddClass(DisabledClass, Disabled == true)
.AddClass(DraggingClass, _dragOperationIsInProgress)
.AddClass(DisabledClass, Disabled)

I think string.IsNullOrWhiteSpace(DraggingClass) is not necessary here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a look at the CSSBuilder

public CssBuilder AddClass(string value) => AddValue(" " + value);

If the value is null or empty a "space" will be appended, which triggers also the change attribute process within Blazor and later the browser too. That is the reason, why I added this a condition for when.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok got it. Maybe it would even be better if we move the IsNullOrWhiteSpace check inside the AddClass function. We use AddClass without a null check quite often.




etc.

Copy link
Contributor

@just-the-benno just-the-benno Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'll remove the check from this component. After it is accepted/merged, I'll create a new PR to propose a change to AddClass method of the CSSBuilder.

src/MudBlazor/Components/DropZone/MudDropContainer.razor Outdated Show resolved Hide resolved
@just-the-benno
Copy link
Contributor

  • have a function that determines the order of the items in the drop zone

It is maybe not obvious, but the items are rendered in the same sequence as they appear in the source list. So, you can control the order (also within the drop zone) by sorting your source list.

  • allow for reordering inside the drop zone

That would be a nice feature but require js, or maybe I could reuse the resize observer. However, we thought it was valuable even without this feature. But that doesn't mean we can't do it later ;)

@Garderoben Garderoben merged commit 6581f4a into MudBlazor:dev Feb 3, 2022
@Garderoben Garderoben added this to the 6.0.6 milestone Feb 3, 2022
mikes-gh pushed a commit to mikes-gh/MudBlazor that referenced this pull request Feb 3, 2022
Co-authored-by: Benjamin Kappel <b.kappel90@outlook.de>
mikes-gh pushed a commit to mikes-gh/MudBlazor that referenced this pull request Feb 3, 2022
Recommited by Mike Surcouf
Authored-by: Jonny Larsson
Co-authored-by: Benjamin Kappel
@porkopek
Copy link
Contributor

porkopek commented Feb 3, 2022

The chess example made want to use it! 😍

@peterthorpe81
Copy link
Contributor

This looks great 😍

allow for reordering inside the drop zone
That would be a nice feature but require js, or maybe I could reuse the resize observer. However, we thought it was valuable even without this feature. But that doesn't mean we can't do it later

Before I saw this was coming I was looking to use this library https://github.com/Postlagerkarte/blazor-dragdrop. They seem to have managed this without javascript by passing indexes around. Maybe something for the future.

@bar10dr
Copy link

bar10dr commented Feb 6, 2022

Very nice implementation, but needs support for reordering for it to be useful for my use case I think.

@Garderoben Garderoben deleted the feature/dropzone branch March 17, 2022 07:30
jammerware pushed a commit to jammerware/MudBlazor that referenced this pull request Sep 20, 2022
Recommited by Mike Surcouf
Authored-by: Jonny Larsson
Co-authored-by: Benjamin Kappel
jammerware pushed a commit to jammerware/MudBlazor that referenced this pull request Sep 20, 2022
Recommited by Mike Surcouf
Authored-by: Jonny Larsson
Co-authored-by: Benjamin Kappel
jammerware pushed a commit to jammerware/MudBlazor that referenced this pull request Sep 20, 2022
Recommited by Mike Surcouf
Authored-by: Jonny Larsson
Co-authored-by: Benjamin Kappel
jammerware pushed a commit to jammerware/MudBlazor that referenced this pull request Sep 20, 2022
Recommited by Mike Surcouf
Authored-by: Jonny Larsson
Co-authored-by: Benjamin Kappel
3dots pushed a commit to 3dots/MudBlazor that referenced this pull request Mar 23, 2023
Recommited by Mike Surcouf
Authored-by: Jonny Larsson
Co-authored-by: Benjamin Kappel
ferraridavide pushed a commit to ferraridavide/MudBlazor that referenced this pull request May 30, 2023
Recommited by Mike Surcouf
Authored-by: Jonny Larsson
Co-authored-by: Benjamin Kappel
ilovepilav pushed a commit to ilovepilav/MudBlazor that referenced this pull request Nov 25, 2023
Recommited by Mike Surcouf
Authored-by: Jonny Larsson
Co-authored-by: Benjamin Kappel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change API that needs approval enhancement New feature or request legendary new component A completely new component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drag and drop
9 participants