ISSUE-017 - Basic animated mounting added.
This commit is contained in:
1 parent
61b60b9819
commit
1ba5e99532
7 files changed
+85
-13
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import { useSelector } from "react-redux";
|
||||
import { useTransition, animated } from "@react-spring/web";
|
||||
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
|
||||
import { OverlayItemContainer } from "./styles";
|
||||
@@ -6,18 +8,37 @@ import { OverlayItemContainer } from "./styles";
|
||||
export function OverlayDisplay() {
|
||||
const { currentOverlayItem, visible } = useSelector(overlayToolSelector);
|
||||
|
||||
if (currentOverlayItem == null) return null;
|
||||
const xPos = currentOverlayItem?.position.x ?? 0;
|
||||
const yPos = currentOverlayItem?.position.y ?? 0;
|
||||
const transition = useTransition(visible, {
|
||||
from: { left: xPos, top: yPos + 50, opacity: 0 },
|
||||
enter: {
|
||||
left: xPos,
|
||||
top: yPos,
|
||||
opacity: currentOverlayItem?.opacity ?? 1,
|
||||
},
|
||||
leave: { left: xPos, top: yPos + 50, opacity: 0 },
|
||||
});
|
||||
|
||||
if (currentOverlayItem == null) {
|
||||
return null; // Exit - There is no overlay item yet!
|
||||
}
|
||||
|
||||
const { id, position } = currentOverlayItem;
|
||||
|
||||
return (
|
||||
<OverlayItemContainer
|
||||
position={position}
|
||||
visible={visible}
|
||||
>
|
||||
{id}
|
||||
<br />
|
||||
({position.x}px {position.y}px)
|
||||
</OverlayItemContainer>
|
||||
transition((style, visible) =>
|
||||
visible ? (
|
||||
<animated.div
|
||||
style={{ ...style, position: "absolute" }}
|
||||
>
|
||||
<OverlayItemContainer position={position} visible={visible}>
|
||||
{id}
|
||||
<br />
|
||||
(x:{position.x}px, y:{position.y}px)
|
||||
</OverlayItemContainer>
|
||||
</animated.div>
|
||||
) : null,
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import styled from "styled-components";
|
||||
|
||||
import { OverlayPosition } from "../../../types/state";
|
||||
|
||||
export type OverlayItemContainerProps = {
|
||||
@@ -15,11 +16,11 @@ export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(
|
||||
display: visible ? undefined : "none",
|
||||
},
|
||||
}))<OverlayItemContainerProps>`
|
||||
position: absolute;
|
||||
|
||||
/* Temporary. Overlay will be transparent and based on an image. */
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
background-color: white;
|
||||
box-shadow: 0px 7px 11px 1px black;
|
||||
`;
|
||||
OverlayItemContainer.displayName = "OverlayItemContainer";
|
||||
|
||||
Reference in new issue
Block a user