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:
parent
1044c544ad
commit
768e1d14ca
@ -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;
|
||||||
|
|||||||
@ -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,8 +27,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
|
&:not(.active) {
|
||||||
box-shadow: 0 0 0px 3px var(--clusterMenuBackground), 0 0 0px 6px #ffffff30;
|
box-shadow: 0 0 0px 3px var(--clusterMenuBackground), 0 0 0px 6px #ffffff30;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.isDragging {
|
&.isDragging {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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,7 +66,10 @@ 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 && (
|
||||||
@ -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 })}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user