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

Waspello: Tilt cards when dragging #2413

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dabrorius
Copy link
Contributor

@dabrorius dabrorius commented Dec 12, 2024

Description

This PR implements tilting while dragging for both full lists and individual cards. Fixes #338

Note:

Waspello.Tilt.Drag.mp4

Select what type of change this PR introduces:

  1. Just code/docs improvement (no functional change).
  2. Bug fix (non-breaking change which fixes an issue).
  3. New feature (non-breaking change which adds functionality).
  4. Breaking change (fix or feature that would cause existing functionality to not work as expected).

Update Waspc ChangeLog and version if needed

If you did a bug fix, new feature, or breaking change, that affects waspc, make sure you satisfy the following:

  1. I updated ChangeLog.md with description of the change this PR introduces.
  2. I bumped waspc version in waspc.cabal to reflect changes I introduced, with regards to the version of the latest wasp release, if the bump was needed.

Update example apps if needed

If you did code changes and added a new feature or modified an existing feature, make sure you satisfy the following:

  1. I updated waspc/examples/todoApp as needed (updated modified feature or added new feature) and manually checked it works correctly.
  2. I updated waspc/headless-test/examples/todoApp and its e2e tests as needed (updated modified feature and its tests or added new feature and new tests for it).

@infomiho infomiho self-requested a review December 13, 2024 12:40
Copy link
Contributor

@infomiho infomiho left a comment

Choose a reason for hiding this comment

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

Good job!

I've added some comments to maybe improve it a bit :)

@@ -235,6 +235,10 @@ button.open-add-list {
border-radius: 3px;
}

.list--dragging {
Copy link
Contributor

@infomiho infomiho Dec 17, 2024

Choose a reason for hiding this comment

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

I think we should add transitions to make this look smoother:

.list {
  ...
  transition: transform 200ms ease-in-out;
}

.list--dragging {
  transform: rotate(2deg);
}

.list--drop-animating {
  transform: rotate(0deg);
}

I'd do the same for the .list-card component.

Also, potential improvement in readability is to maybe declare CSS vars for the angle e.g. --list-rotate-angle: 2deg and then use it var(--list-rotate-angle).

I've explained the --drop-animating class here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added suggested changes. I didn't extract the 2deg to a separate variable as it is used only once (when dragging the whole list 4 degs are used), moving its definition to a different place could make the code harder to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

P.S. I still need to test the whole list dragging, but it won't work until #2414 is resolved and merged.

@@ -248,7 +248,7 @@ const List = ({ list, index, cards }) => {
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<div className='list'>
<div className={`list ${snapshot.isDragging && 'list--dragging'}`}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd implement a helper function for this e.g.

function getListClassName(snapshot) {
  const classes = ['list']
  if (snapshot.isDragging) {
    classes.push('list--dragging')
  }
  if (snapshot.isDropAnimating) {
    classes.push('list--drop-animating')
  }
  return classes.join(' ')
}

This way:

  1. There is no space after list if list--dragging is not present.
  2. It's easier to compose multiple classes

You'll notice I used isDropAnimating as well, this enables us to have a smooth start:

(no rotation) -> (rotation)

and a smooth end:

(rotation) -> (no rotation)
without.mov
with.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just noticed that classnames npm package is included and used in other places. Should have used that 🤦
I'll update the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[example/Waspello] Make list tilt while dragged'n'dropped like in Trello
2 participants