Skip to content

An open-source, self-hosted system for apps built with web technologies.

Adopt React UI Panel across Desktop shells

zohayrslileh426d965237b0
diff --git a/scripts/contracts/panel.tsx b/scripts/contracts/panel.tsx
new file mode 100644
index 0000000..8ab5dd9
--- /dev/null
+++ b/scripts/contracts/panel.tsx
@@ -0,0 +1,48 @@
+import assert from "node:assert/strict"
+import type { ReactNode } from "react"
+import { renderToStaticMarkup } from "react-dom/server"
+import { standardAppearance } from "@phreshos/core"
+import { AppearanceProvider } from "@phreshos/react-ui"
+import CredentialsForm from "@client/view/structure/authentication/credentials-form"
+import TaskbarSurface from "@client/view/structure/desktop/taskbar/taskbar-surface"
+import Launcher from "@client/view/structure/desktop/taskbar/launcher/launcher"
+import Window from "@client/view/structure/desktop/windows/window"
+
+function markup(children: ReactNode) {
+ return renderToStaticMarkup(<AppearanceProvider appearance={standardAppearance} theme="light">{children}</AppearanceProvider>)
+}
+
+function panel(html: string) {
+ assert.equal(html.match(/data-surface-material=""/g)?.length, 2)
+ assert.match(html, /grid-template-rows:auto minmax\(0, 1fr\)/)
+ assert.match(html, /margin:6px;margin-top:0/)
+}
+
+const taskbar = markup(<TaskbarSurface label="Title" labelId="title"><button>Action</button></TaskbarSurface>)
+panel(taskbar)
+assert.match(taskbar, /<h2 id="title"/)
+assert.match(taskbar, /<button>Action<\/button>/)
+
+const window = markup(<Window icon="/icon.svg" title="Window"><iframe title="Content" /></Window>)
+panel(window)
+assert.match(window, /data-window-container/)
+assert.match(window, /<iframe title="Content"/)
+
+const bare = markup(<Window bare icon="/icon.svg" title="Bare"><iframe title="Content" /></Window>)
+assert.doesNotMatch(bare, /data-surface-material/)
+assert.doesNotMatch(bare, /grid-template-rows:auto minmax\(0, 1fr\)/)
+
+const authentication = markup(<CredentialsForm title="Sign in" description="Welcome" submitLabel="Continue" passwordAutocomplete="current-password" pending={false} onSubmit={() => {}} />)
+panel(authentication)
+assert.equal(authentication.match(/<form\b/g)?.length, 1)
+assert.match(authentication, /name="username"/)
+assert.match(authentication, /name="password"/)
+assert.match(authentication, /type="submit"/)
+
+const launcher = markup(<Launcher label="Menu" trigger="Open">{() => <button>Action</button>}</Launcher>)
+panel(launcher)
+// Native popover visibility belongs to the outer host, not Panel's grid.
+const popover = launcher.match(/<div[^>]*popover="auto"[^>]*>/)?.[0]
+assert(popover)
+assert.doesNotMatch(popover, /style=/)
+assert.match(launcher, /popovertarget=/i)
diff --git a/source/client/view/structure/authentication/credentials-form.tsx b/source/client/view/structure/authentication/credentials-form.tsx
index 7351a9e..8cc77ac 100644
--- a/source/client/view/structure/authentication/credentials-form.tsx
+++ b/source/client/view/structure/authentication/credentials-form.tsx
@@ -1,7 +1,7 @@
import { type AuthenticationState } from "@server/core/authentication/authentication"
import { enterSurface, prepareSurfaceEntrance, restSurface } from "../../appearance/surface-presence"
import { useReducedMotion } from "@libs/react-motion"
-import { Surface } from "@phreshos/react-ui"
+import { Panel } from "@phreshos/react-ui"
import Spinner from "../../components/spinner"
import Alert from "../../components/alert"
import { type SyntheticEvent, useLayoutEffect, useRef } from "react"
@@ -45,7 +45,7 @@ export default function CredentialsForm({ title, description, submitLabel, passw
ref={surface}
- className="relative isolate m-auto grid w-[min(24rem,calc(100%-2rem))] grid-rows-[auto_minmax(0,1fr)] text-slate-800"
+ className="relative m-auto w-[min(24rem,calc(100%-2rem))]"
aria-busy={pending}
@@ -53,17 +53,13 @@ export default function CredentialsForm({ title, description, submitLabel, passw
>
- <Surface aria-hidden="true" className="pointer-events-none absolute inset-0" />
-
- <div className="relative grid gap-1 px-5 py-4">
+ <Panel header={<div className="relative grid gap-1 px-5 py-4">
<h1 className="text-xl font-semibold">{title}</h1>
<p className="text-sm leading-5 text-slate-600/90">{description}</p>
- </div>
-
- <Surface className="relative m-1.5 mt-0 grid gap-5 p-5">
+ </div>} contentProps={{ className: "grid gap-5 p-5" }}>
<div className="grid gap-4">
@@ -145,7 +141,7 @@ export default function CredentialsForm({ title, description, submitLabel, passw
</button>
- </Surface>
+ </Panel>
</form>
diff --git a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
index da8dc5f..f198809 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
@@ -1,7 +1,6 @@
-import { ReactNode, useCallback, useEffect, useId, useRef, useState } from "react"
+import { type ComponentPropsWithoutRef, ReactNode, useCallback, useEffect, useId, useRef, useState } from "react"
import { enterSurface, prepareSurfaceEntrance, restSurface } from "@client/view/appearance/surface-presence"
import { useReducedMotion } from "@libs/react-motion"
-import { type SurfaceProps } from "@phreshos/react-ui"
import TaskbarSurface, { taskbarSurfaceClassName } from "../taskbar-surface"
import TaskbarButton from "../taskbar-button"
@@ -68,7 +67,7 @@ export default function ({ label, trigger, children, className, ...props }: Laun
</TaskbarButton>
- <TaskbarSurface
+ <div
{...props}
@@ -82,12 +81,6 @@ export default function ({ label, trigger, children, className, ...props }: Laun
aria-labelledby={`${id}-label`}
- label={label}
-
- labelId={`${id}-label`}
-
- contentClassName=""
-
tabIndex={-1}
className={`${taskbarSurfaceClassName} hidden open:block ${className ?? ""}`}
@@ -118,14 +111,18 @@ export default function ({ label, trigger, children, className, ...props }: Laun
>
- {children(close)}
+ <TaskbarSurface label={label} labelId={`${id}-label`}>
+
+ {children(close)}
+
+ </TaskbarSurface>
- </TaskbarSurface>
+ </div>
</>
}
-export interface LauncherProps extends Omit<SurfaceProps, "children" | "id" | "onBeforeToggle" | "onToggle" | "popover"> {
+export interface LauncherProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "id" | "onBeforeToggle" | "onToggle" | "popover"> {
label: string
diff --git a/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx b/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
index 8f0e3f8..e9c0c00 100644
--- a/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
+++ b/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
@@ -1,25 +1,18 @@
import { forwardRef, ReactNode } from "react"
-import { Surface, type SurfaceProps } from "@phreshos/react-ui"
+import { Panel, type PanelProps } from "@phreshos/react-ui"
/** The window-material shell shared by surfaces opened from the taskbar. */
export const taskbarSurfaceClassName = "m-0 isolate border-0 bg-transparent p-0 outline-none"
export default forwardRef<HTMLDivElement, TaskbarSurfaceProps>(function TaskbarSurface({ label, labelId, contentClassName = "", className, children, ...props }, ref) {
- return <Surface {...props} ref={ref} className={`grid min-h-0 max-h-[inherit] grid-rows-[auto_minmax(0,1fr)] ${className ?? ""}`}>
-
- <h2 id={labelId} className="relative grid h-10 items-center px-3.5 text-window-title font-medium select-none">{label}</h2>
-
- <Surface className={`relative m-1.5 mt-0 min-h-0 overflow-hidden ${contentClassName}`}>
-
- {children}
-
- </Surface>
-
- </Surface>
+ return <Panel {...props} ref={ref} className={className}
+ header={<h2 id={labelId} className="relative grid h-10 items-center px-3.5 text-window-title font-medium select-none">{label}</h2>}
+ contentProps={{ className: contentClassName }}
+ >{children}</Panel>
})
-interface TaskbarSurfaceProps extends Omit<SurfaceProps, "children"> {
+interface TaskbarSurfaceProps extends Omit<PanelProps, "children" | "header" | "contentProps"> {
label: string
diff --git a/source/client/view/structure/desktop/windows/window-surface.tsx b/source/client/view/structure/desktop/windows/window-surface.tsx
index 11af1a7..3b627f2 100644
--- a/source/client/view/structure/desktop/windows/window-surface.tsx
+++ b/source/client/view/structure/desktop/windows/window-surface.tsx
@@ -4,8 +4,6 @@ import { useLayoutEffect, useRef } from "react"
import { type LocalSurfaceState } from "@client/view/components/desktop-host/local-window"
import gsap, { motionDuration, motionDurations, motionEase } from "@client/view/appearance/motion"
-const paintSelector = "[data-surface-backdrop], [data-surface-border], [data-surface-material]"
-
/** Projects one representation-local target and animates explicit replacements. */
export default function WindowSurface({ state, onComplete }: WindowSurfaceProps) {
@@ -17,23 +15,12 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)
const reducedMotion = useReducedMotion()
- // The configured material and border opacity remain the visible targets;
- // visibility animation must not replace those values with a root opacity.
- const visibleOpacity = useRef(new Map<Element, number>())
-
useLayoutEffect(function () {
const surface = element.current
if (!surface) return
- const layers = [...surface.querySelectorAll(paintSelector)]
-
- for (const layer of layers) {
-
- if (!visibleOpacity.current.has(layer)) visibleOpacity.current.set(layer, Number(getComputedStyle(layer).opacity))
- }
-
const revision = transition?.revision ?? null
const changed = revision !== null
@@ -46,29 +33,28 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)
const duration = transaction?.duration ?? motionDurations.presence
- gsap.killTweensOf(layers)
+ // Desktop owns visibility of the whole Surface; React UI owns its
+ // material. Never capture or overwrite opacity on internal paint layers.
+ gsap.killTweensOf(surface)
if (!transaction || !changed || reducedMotion || duration === 0) {
- for (const layer of layers) gsap.set(layer, { opacity: visible ? visibleOpacity.current.get(layer) : 0 })
+ gsap.set(surface, { opacity: visible ? 1 : 0 })
if (transaction && changed) onComplete(revision!)
return
}
- const animation = gsap.timeline({
- onComplete: () => onComplete(revision!)
- })
-
- for (const layer of layers) animation.fromTo(layer, {
- opacity: initial && visible ? 0 : Number(getComputedStyle(layer).opacity)
+ const animation = gsap.fromTo(surface, {
+ opacity: initial && visible ? 0 : Number(getComputedStyle(surface).opacity)
}, {
- opacity: visible ? visibleOpacity.current.get(layer) : 0,
+ opacity: visible ? 1 : 0,
duration: motionDuration(duration),
ease: motionEase(transaction.easing),
- overwrite: "auto"
- }, 0)
+ overwrite: "auto",
+ onComplete: () => onComplete(revision!)
+ })
return function () {
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index 9d7a0c9..aa78f49 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -1,7 +1,7 @@
import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useLayoutEffect, useRef, useState } from "react"
import { useReducedMotion } from "@libs/react-motion"
import { enterSurface, prepareSurfaceEntrance, restSurface } from "@client/view/appearance/surface-presence"
-import { Surface, useAppearance, useResolveTheme } from "@phreshos/react-ui"
+import { Panel } from "@phreshos/react-ui"
import { absoluteWindowGeometry, resolveWindowGeometry, resolveWindowValue, wholeWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
import { type Position, type Size, type WindowGeometry } from "@phreshos/core"
import WindowHeader from "./window-header"
@@ -60,10 +60,6 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
const reducedMotion = useReducedMotion()
- const appearance = useAppearance()
-
- const foreground = useResolveTheme(appearance.foreground)
-
const [gesture, setGesture] = useState<Gesture | null>(null)
const [renderedGeometry, setRenderedGeometry] = useState<WindowGeometry>({ position, size })
@@ -707,28 +703,21 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
Bare, there is no difference: the frame fills the box, so
the window is exactly as large as it asked to be and its
boundaries are the ones its own content draws. */}
- <div data-window-container ref={surfaceElement} style={bare ? undefined : { ...paintedInsets, color: foreground }} className={`absolute isolate grid ${bare ? "inset-0 grid-rows-1" : "grid-rows-[auto_minmax(0,1fr)]"}`}>
-
- {/* Material is paint, not the interaction container. Keeping
- it as a sibling behind the window contents prevents plain
- overlays such as the inactive-window click catcher from
- entering the Surface tree or receiving its effects. */}
- {!bare && <Surface
-
- data-window-frame-surface
+ {bare ? <div data-window-container ref={surfaceElement} className="absolute isolate inset-0 grid grid-rows-1">
- aria-hidden="true"
+ {/* A bare Client controls its own host surface, separate from
+ its content and without the header/content Panel shell. */}
+ {localSurface && <WindowSurface state={localSurface} onComplete={revision => onLocalAnimationComplete?.("surface", revision)} />}
- className="pointer-events-none absolute inset-0 -z-1"
+ <div data-window-content className="relative min-h-0">{children}</div>
- />}
-
- {/* A bare Client controls its own host surface. It remains a
- sibling behind the frame, with its own radius and no
- clipping parent. */}
- {bare && localSurface && <WindowSurface state={localSurface} onComplete={revision => onLocalAnimationComplete?.("surface", revision)} />}
-
- {!bare && <WindowHeader
+ </div> : <Panel
+ data-window-container
+ ref={surfaceElement}
+ style={paintedInsets}
+ className="absolute"
+ contentProps={{ className: "p-px" }}
+ header={<WindowHeader
title={title}
@@ -751,24 +740,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
stopping={stopping || closing}
/>}
-
- {/* Where the program is. Bare, it is the whole of the
- box and wears none of the system's own edges. */}
- {bare
-
- ? <div data-window-content className="relative min-h-0">
-
- {children}
-
- </div>
-
- : <Surface data-window-content className="relative m-1.5 mt-0 min-h-0 overflow-hidden p-px">
-
- {children}
-
- </Surface>}
-
- </div>
+ >{children}</Panel>}
{!bare && edges.map(handle => <div
diff --git a/vite.client.ts b/vite.client.ts
index bac1a52..139599e 100644
--- a/vite.client.ts
+++ b/vite.client.ts
@@ -18,6 +18,7 @@ export default defineConfig({
dedupe: ["react", "react-dom"]
},
build: {
+ chunkSizeWarningLimit: 2000,
emptyOutDir: true,
outDir: resolve(import.meta.dirname, "dist/client")
}