This commit is contained in:
Gabe Yuan
2023-09-12 11:00:54 +08:00
parent c57a0a11fa
commit f4e4c84712
2 changed files with 25 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
import { limitNumber } from "../../libs/utils";
import { isMobile } from "../../libs/mobile";
import { setFab } from "../../libs/storage";
import Paper from "@mui/material/Paper";
const getEdgePosition = (
{ x: left, y: top, edge },
@@ -58,6 +59,17 @@ const getHidePosition = (
return { x: left, y: top, edge, hide: true };
};
function DraggableWrapper({ children, usePaper, ...props }) {
if (usePaper) {
return (
<Paper {...props} elevation={4}>
{children}
</Paper>
);
}
return <div {...props}>{children}</div>;
}
export default function Draggable({
windowSize,
width,
@@ -70,6 +82,7 @@ export default function Draggable({
onMove,
handler,
children,
usePaper,
}) {
const [origin, setOrigin] = useState({
x: left,
@@ -181,7 +194,8 @@ export default function Draggable({
};
return (
<div
<DraggableWrapper
usePaper={usePaper}
style={{
opacity,
position: "fixed",
@@ -202,6 +216,6 @@ export default function Draggable({
{handler}
</div>
<div>{children}</div>
</div>
</DraggableWrapper>
);
}

View File

@@ -1,4 +1,3 @@
import Paper from "@mui/material/Paper";
import Fab from "@mui/material/Fab";
import TranslateIcon from "@mui/icons-material/Translate";
import ThemeProvider from "../../hooks/Theme";
@@ -9,6 +8,8 @@ import Popup from "../Popup";
import { debounce } from "../../libs/utils";
import { isGm } from "../../libs/client";
import Header from "../Popup/Header";
import Box from "@mui/material/Box";
import Divider from "@mui/material/Divider";
import {
DEFAULT_SHORTCUTS,
OPT_SHORTCUT_TRANSLATE,
@@ -178,17 +179,17 @@ export default function Action({ translator, fab }) {
show={showPopup}
onStart={handleStart}
onMove={handleMove}
usePaper
handler={
<Paper style={{ cursor: "move" }} elevation={3}>
<Box style={{ cursor: "move" }}>
<Header setShowPopup={setShowPopup} />
</Paper>
<Divider />
</Box>
}
>
<Paper>
{showPopup && (
<Popup setShowPopup={setShowPopup} translator={translator} />
)}
</Paper>
{showPopup && (
<Popup setShowPopup={setShowPopup} translator={translator} />
)}
</Draggable>
<Draggable
key="fab"