daedalOS/components/system/Window/index.tsx
Dustin Brett 24c17c0088
Some checks failed
Tests / tests (push) Has been cancelled
Add memo to everything
2025-07-01 09:10:22 -07:00

56 lines
1.8 KiB
TypeScript

import { memo, useCallback } from "react";
import { type ComponentProcessProps } from "components/system/Apps/RenderComponent";
import StyledPeekViewport from "components/system/Taskbar/TaskbarEntry/Peek/StyledPeekViewport";
import RndWindow from "components/system/Window/RndWindow";
import StyledWindow from "components/system/Window/StyledWindow";
import Titlebar from "components/system/Window/Titlebar";
import useFocusable from "components/system/Window/useFocusable";
import useWindowTransitions from "components/system/Window/useWindowTransitions";
import { useProcesses } from "contexts/process";
import { useSession } from "contexts/session";
const Window: FC<ComponentProcessProps> = ({ children, id }) => {
const {
linkElement,
processes: { [id]: process },
} = useProcesses();
const {
backgroundBlur,
backgroundColor,
Component,
hideTitlebar,
peekElement,
} = process || {};
const { foregroundId } = useSession();
const isForeground = id === foregroundId;
const { zIndex, ...focusableProps } = useFocusable(id);
const windowTransitions = useWindowTransitions(id);
const linkViewportEntry = useCallback(
(viewportEntry: HTMLDivElement) => {
if (Component && !peekElement && viewportEntry) {
linkElement(id, "peekElement", viewportEntry);
}
},
[Component, id, linkElement, peekElement]
);
return (
<RndWindow id={id} zIndex={zIndex}>
<StyledWindow
$backgroundBlur={backgroundBlur}
$backgroundColor={backgroundColor}
$isForeground={isForeground}
{...focusableProps}
{...windowTransitions}
>
<StyledPeekViewport ref={linkViewportEntry}>
{!hideTitlebar && <Titlebar id={id} />}
{children}
</StyledPeekViewport>
</StyledWindow>
</RndWindow>
);
};
export default memo(Window);