## Description Core features of Auto Layout and mobile responsiveness, hidden under a feature flag. > Add a TL;DR when description is extra long (helps content team) Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? > Manual regression and sanity tests for all fixed canvas functionality. - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] PR is being merged under a feature flag --------- Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Arsalan <arsalanyaldram0211@outlook.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { Layers } from "constants/Layers";
|
|
|
|
import { useMemo } from "react";
|
|
import { AppState } from "@appsmith/reducers";
|
|
import { isWidgetSelected } from "selectors/widgetSelectors";
|
|
import { useSelector } from "react-redux";
|
|
|
|
export const usePositionedContainerZIndex = (
|
|
droppableWidget: boolean,
|
|
widgetId: string,
|
|
focused?: boolean,
|
|
selected?: boolean,
|
|
) => {
|
|
const isDragging = useSelector(
|
|
(state: AppState) => state.ui.widgetDragResize.isDragging,
|
|
);
|
|
const isSelected = useSelector(isWidgetSelected(widgetId));
|
|
const isThisWidgetDragging = isDragging && isSelected;
|
|
|
|
const zIndex = useMemo(() => {
|
|
if (isDragging) {
|
|
// dragging mode use cases
|
|
if (!isThisWidgetDragging && droppableWidget) {
|
|
return Layers.positionedWidget + 1;
|
|
} else {
|
|
// all non container widgets should go last into the background to not interfere with mouse move
|
|
// since it is not technically dragged but just drawn on canvas as the mouse moves.
|
|
return -1;
|
|
}
|
|
} else {
|
|
// common use case when nothing is dragged
|
|
|
|
return focused
|
|
? Layers.focusedWidget
|
|
: selected
|
|
? Layers.selectedWidget
|
|
: Layers.positionedWidget;
|
|
}
|
|
}, [isDragging, isThisWidgetDragging, droppableWidget, selected, focused]);
|
|
|
|
const zIndicesObj = useMemo(() => {
|
|
const onHoverZIndex = isDragging ? zIndex : Layers.positionedWidget + 1;
|
|
return { zIndex, onHoverZIndex };
|
|
}, [isDragging, zIndex, Layers.positionedWidget]);
|
|
|
|
return zIndicesObj;
|
|
};
|