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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/waspello/src/cards/Main.css
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ button.open-add-list {

background-color: #ebecf0;
border-radius: 3px;

transition: transform 200ms ease-in-out;
}

.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.

transform: rotate(2deg);
}

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

.list-header {
Expand Down Expand Up @@ -418,6 +428,15 @@ textarea.card-composer-textarea {
margin-bottom: 8px;
padding: 6px 8px 2px;
box-shadow: 0 1px 0 rgb(9 30 66 / 25%);
transition: transform 200ms ease-in-out;
}

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

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

.list-card-title {
Expand Down
31 changes: 27 additions & 4 deletions examples/waspello/src/cards/MainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ const List = ({ list, index, cards }) => {
)
}

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

return (
<Draggable
key={list.id}
Expand All @@ -248,7 +259,7 @@ const List = ({ list, index, cards }) => {
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<div className='list'>
<div className={getListClassName(snapshot)}>
<div className='list-header'>
{isHeaderTargetShown ? (
<div
Expand Down Expand Up @@ -324,19 +335,31 @@ const Cards = ({ cards }) => {
}

const Card = ({ card, index }) => {
const getListCardClassName = (snapshot) => {
const classes = ['list-card']
if (snapshot.isDragging) {
classes.push('list-card--dragging')
}
if (snapshot.isDropAnimating) {
classes.push('list-card--drop-animating')
}
return classes.join(' ')
}

return (
<Draggable
key={card.id}
draggableId={`${card.id}`}
index={index}
>
{(provided, snapshot) => (
<div className='list-card'
ref={provided.innerRef}
<div ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<span className='list-card-title'>{ card.title }</span>
<div className={getListCardClassName(snapshot)}>
<span className='list-card-title'>{card.title}</span>
</div>
</div>
)}
</Draggable>
Expand Down