@ducor/react
Version:
admin template ui interface
41 lines (40 loc) • 1.61 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useState } from "react";
import { Button } from "../components";
const Move = ({ onChange }) => {
const [dragStart, setDragStart] = useState(false);
const handleChange = (x, y) => {
// Determine if the position is on the left side of the viewport
const isLeft = x < window.innerWidth / 2;
onChange(dragStart, isLeft, y);
const data = {
dragStart,
isLeft,
y,
timestamp: new Date().getTime(),
windowWidth: window.innerWidth,
windowHeight: window.innerHeight,
};
//save to localstorage
localStorage.setItem("customizerPosition", JSON.stringify(data));
};
useEffect(() => {
const data = localStorage.getItem("customizerPosition");
if (data) {
const parsedData = JSON.parse(data);
if (window.innerWidth === parsedData.windowWidth &&
window.innerHeight === parsedData.windowHeight &&
parsedData.isLeft &&
parsedData.y) {
onChange(parsedData.dragStart, parsedData.isLeft, parsedData.y);
}
}
}, []);
return (_jsx(Button, { color: 'default', variant: 'filled', active: true, round: 'none', draggable: true, onDragStart: (e) => {
setDragStart(true);
}, onDragEnd: (e) => {
setDragStart(false);
handleChange(e.clientX, e.clientY);
}, children: _jsx("i", { className: 'feather-more-horizontal' }) }));
};
export default Move;