Skip to content

Commit e372560

Browse files
authored
Merge pull request #4 from devklick/dev
Refactor FileBrowser popup, context menus for FSObjects
2 parents 4bf191d + f650285 commit e372560

31 files changed

Lines changed: 889 additions & 314 deletions

src/common/keyCode.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const KeyCodes = {
2+
Escape: "Escape",
3+
Enter: "Enter",
4+
NumpadEnter: "NumpadEnter",
5+
} as const;
6+
7+
export const allKeyCodes = Object.values(KeyCodes);
8+
9+
export type KeyCode = (typeof KeyCodes)[keyof typeof KeyCodes];
10+
11+
export function isKeyCode(value: unknown): value is KeyCode {
12+
return (
13+
typeof value === "string" && Object.values<string>(KeyCodes).includes(value)
14+
);
15+
}

src/components/FullAppPrompt/FullAppPrompt.scss renamed to src/components/AppPopup/AppPopup.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
.full-app-prompt {
2-
backdrop-filter: brightness(80%) blur(1px);
1+
.app-popup {
2+
backdrop-filter: brightness(80%);
33
position: fixed;
44
z-index: 9999;
55
display: flex;
66
justify-content: center;
77
align-items: center;
88

9-
&-content {
9+
&__content {
1010
width: 300px;
1111
display: flex;
1212
flex-direction: column;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React, { useEffect, useRef, useState } from "react";
2+
import { Rect } from "../../hooks/useDragToResize";
3+
import useDetectMouseDownOutside from "../../hooks/useDetectMouseDownOutside";
4+
import useSystemSettings from "../../stores/systemSettingsStore";
5+
6+
import "./AppPopup.scss";
7+
8+
interface AppPopupProps<Element extends HTMLElement> {
9+
appRef: React.RefObject<Element>;
10+
close: () => void;
11+
}
12+
13+
function AppPopup<Element extends HTMLElement>({
14+
appRef,
15+
children,
16+
close,
17+
}: React.PropsWithChildren<AppPopupProps<Element>>) {
18+
const thisRef = useRef<HTMLDivElement>(null);
19+
const settings = useSystemSettings();
20+
const [rect, setRect] = useState<Rect>({
21+
height: 0,
22+
left: 0,
23+
top: 0,
24+
width: 0,
25+
});
26+
27+
useDetectMouseDownOutside({ elementRef: thisRef, onMouseDown: close });
28+
29+
useEffect(() => {
30+
if (appRef.current) {
31+
const bounds = appRef.current.getBoundingClientRect();
32+
setRect({
33+
height: bounds.height ?? 0,
34+
left: bounds.left ?? 0,
35+
top: bounds.top ?? 0,
36+
width: bounds.width ?? 0,
37+
});
38+
}
39+
}, [appRef]);
40+
41+
function handleContextMenu(e: React.MouseEvent) {
42+
e.stopPropagation();
43+
e.preventDefault();
44+
}
45+
46+
return (
47+
<div
48+
className="app-popup"
49+
ref={thisRef}
50+
style={{ ...rect }}
51+
onContextMenu={handleContextMenu}
52+
onClick={(e) => e.stopPropagation()}
53+
onDoubleClick={(e) => e.stopPropagation()}
54+
>
55+
<div
56+
className="app-popup__content"
57+
style={{ backgroundColor: settings.mainColor }}
58+
>
59+
{children}
60+
</div>
61+
</div>
62+
);
63+
}
64+
65+
export default AppPopup;

src/components/AppPopup/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import AppPopup from "./AppPopup";
2+
3+
export default AppPopup;

src/components/Box/Box.scss

Whitespace-only changes.

src/components/Box/Box.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import "./Box.scss";
2+
3+
interface BoxProps {
4+
flow?: "horizontal" | "vertical";
5+
gap?: number;
6+
}
7+
8+
function Box({
9+
flow = "vertical",
10+
gap = 10,
11+
children,
12+
}: React.PropsWithChildren<BoxProps>) {
13+
return (
14+
<div
15+
className="box"
16+
style={{
17+
display: "flex",
18+
alignItems: "center",
19+
flexDirection: flow == "horizontal" ? "row" : "column",
20+
gap,
21+
padding: gap,
22+
boxSizing: "border-box",
23+
}}
24+
>
25+
{children}
26+
</div>
27+
);
28+
}
29+
30+
export default Box;

src/components/Box/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Box from "./Box";
2+
3+
export default Box;

src/components/Button/Button.scss

Whitespace-only changes.

src/components/Button/Button.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import "./Button.scss";
2+
3+
interface ButtonProps {
4+
name: string;
5+
onClick: () => void;
6+
width?: string | number;
7+
}
8+
9+
function Button({ name, width = "100%", onClick }: ButtonProps) {
10+
return (
11+
<button style={{ width }} onClick={onClick}>
12+
{name}
13+
</button>
14+
);
15+
}
16+
export default Button;

src/components/Button/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Button from "./Button";
2+
export default Button;

0 commit comments

Comments
 (0)