1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fixing hotbar drag-n-drop animation issues (#2704)

This commit is contained in:
Alex Andreev 2021-05-06 00:37:06 +03:00 committed by GitHub
parent 1044c544ad
commit 768e1d14ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 12 deletions

View File

@ -207,6 +207,21 @@ describe("HotbarStore", () => {
expect(hotbarStore.getActive().items[0].entity.uid).toEqual("test"); expect(hotbarStore.getActive().items[0].entity.uid).toEqual("test");
}); });
it("new items takes first empty cell", () => {
const hotbarStore = HotbarStore.createInstance();
const test = new CatalogEntityItem(testCluster);
const minikube = new CatalogEntityItem(minikubeCluster);
const aws = new CatalogEntityItem(awsCluster);
hotbarStore.load();
hotbarStore.addToHotbar(test);
hotbarStore.addToHotbar(aws);
hotbarStore.restackItems(0, 3);
hotbarStore.addToHotbar(minikube);
expect(hotbarStore.getActive().items[0].entity.uid).toEqual("minikube");
});
it("throws if invalid arguments provided", () => { it("throws if invalid arguments provided", () => {
// Prevent writing to stderr during this render. // Prevent writing to stderr during this render.
const err = console.error; const err = console.error;

View File

@ -6,6 +6,8 @@
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
transition: none; transition: none;
text-shadow: 0 0 4px #0000008f;
position: relative;
div.MuiAvatar-colorDefault { div.MuiAvatar-colorDefault {
font-weight:500; font-weight:500;
@ -25,7 +27,9 @@
} }
&:hover { &:hover {
box-shadow: 0 0 0px 3px var(--clusterMenuBackground), 0 0 0px 6px #ffffff30; &:not(.active) {
box-shadow: 0 0 0px 3px var(--clusterMenuBackground), 0 0 0px 6px #ffffff30;
}
} }
&.isDragging { &.isDragging {

View File

@ -46,12 +46,32 @@
position: relative; position: relative;
&.isDraggingOver { &.isDraggingOver {
box-shadow: 0 0 0px 3px $clusterMenuBackground, 0 0 0px 6px #fff; background-color: #3e4148;
box-shadow: 0 0 0px 3px var(--clusterMenuBackground), 0 0 0px 6px #ffffff30;
&:not(.isDraggingOwner) {
z-index: 50;
> div:not(:empty) {
border-radius: 6px;
box-shadow: 0 0 9px #00000042;
}
&.animateUp {
> div {
transform: translate(0px, -40px)!important;
}
}
&.animateDown {
> div {
transform: translate(0px, 40px);
}
}
}
} }
&.animating { &.animating {
transform: translateZ(0); // Remove flickering artifacts
&:empty { &:empty {
animation: shake .6s cubic-bezier(.36,.07,.19,.97) both; animation: shake .6s cubic-bezier(.36,.07,.19,.97) both;
transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0);
@ -60,7 +80,9 @@
} }
&:not(:empty) { &:not(:empty) {
animation: outline 1s cubic-bezier(0.19, 1, 0.22, 1); .HotbarIcon {
animation: click .1s;
}
} }
} }
} }
@ -85,13 +107,12 @@
} }
} }
// TODO: Use theme-aware colors @keyframes click {
@keyframes outline {
0% { 0% {
box-shadow: 0 0 0px 11px $clusterMenuBackground, 0 0 0px 15px #ffffff00; margin-top: 0;
} }
100% { 100% {
box-shadow: 0 0 0px 3px $clusterMenuBackground, 0 0 0px 6px #ffffff; margin-top: 2px;
} }
} }

View File

@ -48,9 +48,16 @@ export class HotbarMenu extends React.Component<Props> {
HotbarStore.getInstance().restackItems(from, to); HotbarStore.getInstance().restackItems(from, to);
} }
getMoveAwayDirection(entityId: string, cellIndex: number) {
const draggableItemIndex = this.hotbar.items.findIndex(item => item?.entity.uid == entityId);
return draggableItemIndex > cellIndex ? "animateDown" : "animateUp";
}
renderGrid() { renderGrid() {
return this.hotbar.items.map((item, index) => { return this.hotbar.items.map((item, index) => {
const entity = this.getEntity(item); const entity = this.getEntity(item);
const isActive = !entity ? false : this.isActive(entity);
return ( return (
<Droppable droppableId={`${index}`} key={index}> <Droppable droppableId={`${index}`} key={index}>
@ -59,11 +66,14 @@ export class HotbarMenu extends React.Component<Props> {
index={index} index={index}
key={entity ? entity.getId() : `cell${index}`} key={entity ? entity.getId() : `cell${index}`}
innerRef={provided.innerRef} innerRef={provided.innerRef}
className={cssNames({ isDraggingOver: snapshot.isDraggingOver })} className={cssNames({
isDraggingOver: snapshot.isDraggingOver,
isDraggingOwner: snapshot.draggingOverWith == entity?.getId(),
}, this.getMoveAwayDirection(snapshot.draggingOverWith, index))}
{...provided.droppableProps} {...provided.droppableProps}
> >
{entity && ( {entity && (
<Draggable draggableId={item.entity.uid} key={item.entity.uid} index={0}> <Draggable draggableId={item.entity.uid} key={item.entity.uid} index={0} >
{(provided, snapshot) => { {(provided, snapshot) => {
const style = { const style = {
zIndex: defaultHotbarCells - index, zIndex: defaultHotbarCells - index,
@ -83,7 +93,7 @@ export class HotbarMenu extends React.Component<Props> {
key={index} key={index}
index={index} index={index}
entity={entity} entity={entity}
isActive={this.isActive(entity)} isActive={isActive}
onClick={() => entity.onRun(catalogEntityRunContext)} onClick={() => entity.onRun(catalogEntityRunContext)}
className={cssNames({ isDragging: snapshot.isDragging })} className={cssNames({ isDragging: snapshot.isDragging })}
/> />