ISSUE-017 - Initial work on the Overlay Tool.
Have basic state management in place and a number of simple prototypes in place to practice floating a div above the interface.
This commit is contained in:
1 parent
110d00d7bb
commit
506491eed9
14 files changed
+265
-14
No files matched your search
@@ -0,0 +1,82 @@
|
||||
import { useState } from "react";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { PadBox } from "@bedrock-layout/padbox";
|
||||
|
||||
import { appDimensionsSelector } from "../../../features/pageDimensions/pageDimensionsSelector";
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
import {
|
||||
initNewOverlayItem,
|
||||
setCurrentOverlayId,
|
||||
setPosition,
|
||||
setVisibility,
|
||||
} from "../../../features/overlayTool/overlayToolSlice";
|
||||
|
||||
import { Toggle } from "../../Common/Inputs/Toggle";
|
||||
|
||||
|
||||
export function OverlayControl() {
|
||||
const dispatch = useDispatch();
|
||||
const { visible, currentOverlayItem } = useSelector(overlayToolSelector);
|
||||
|
||||
|
||||
|
||||
|
||||
/* For prototyping use only */
|
||||
const { width: appWidth, height: appHeight } = useSelector(appDimensionsSelector);
|
||||
const [overlayId, setOverlayId] = useState("foo_1.00000");
|
||||
const { width, height } = useSelector(appDimensionsSelector);
|
||||
|
||||
const getRandomArbitrary = (min: number, max: number) =>
|
||||
Math.random() * (max - min) + min;
|
||||
|
||||
const posRandomizer = () => {
|
||||
dispatch(setPosition({
|
||||
x: Math.floor(getRandomArbitrary(50, width - 50)),
|
||||
y: Math.floor(getRandomArbitrary(50, height - 50)),
|
||||
}));
|
||||
};
|
||||
const idRandomizer = () => {
|
||||
const newId = `id_${getRandomArbitrary(1, 10)}`.slice(0, 10);
|
||||
setOverlayId(newId);
|
||||
dispatch(setCurrentOverlayId(newId));
|
||||
};
|
||||
/* For prototyping use only */
|
||||
|
||||
|
||||
|
||||
const onToggle = (value: boolean) => {
|
||||
if (currentOverlayItem == null) {
|
||||
dispatch(initNewOverlayItem({
|
||||
overlayId,
|
||||
appDimensions: { height: appHeight, width: appWidth },
|
||||
}));
|
||||
}
|
||||
dispatch(setVisibility(value));
|
||||
};
|
||||
|
||||
return (
|
||||
<PadBox padding="sm">
|
||||
<Toggle
|
||||
label="Show Overlay"
|
||||
toggled={visible}
|
||||
onToggle={onToggle}
|
||||
/>
|
||||
|
||||
{/* For prototyping use only */}
|
||||
<br />
|
||||
<a
|
||||
onClick={posRandomizer}
|
||||
>
|
||||
Random Location
|
||||
</a>
|
||||
<br />
|
||||
<a
|
||||
onClick={idRandomizer}
|
||||
>
|
||||
Id: {overlayId}
|
||||
</a>
|
||||
{/* For prototyping use only */}
|
||||
|
||||
</PadBox>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useSelector } from "react-redux";
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
|
||||
import { OverlayItemContainer } from "./styles";
|
||||
|
||||
export function OverlayDisplay() {
|
||||
const { currentOverlayItem } = useSelector(overlayToolSelector);
|
||||
if (currentOverlayItem == null) return null;
|
||||
const { id, position } = currentOverlayItem;
|
||||
return (
|
||||
<OverlayItemContainer position={position}>
|
||||
{id}
|
||||
<br />
|
||||
({position.x}px {position.y}px)
|
||||
</OverlayItemContainer>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import styled from "styled-components";
|
||||
import { OverlayPosition } from "../../../types/state";
|
||||
|
||||
export type OverlayItemContainerProps = {
|
||||
position: OverlayPosition,
|
||||
};
|
||||
export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(({
|
||||
position: { x, y },
|
||||
}) => ({
|
||||
style: {
|
||||
top: y,
|
||||
left: x,
|
||||
},
|
||||
}))<OverlayItemContainerProps>`
|
||||
position: absolute;
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
background-color: white;
|
||||
box-shadow: 0px 7px 11px 1px black;
|
||||
`;
|
||||
@@ -0,0 +1,2 @@
|
||||
export { OverlayDisplay } from "./OverlayDisplay/OverlayDisplay";
|
||||
export { OverlayControl } from "./OverlayControl/OverlayControl";
|
||||
Reference in new issue
Block a user