Skip to content

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

refactor: share system identity header

zohayrslileh1de4ef17e39e
diff --git a/source/client/view/components/system-header.tsx b/source/client/view/components/system-header.tsx
new file mode 100644
index 0000000..3624bd8
--- /dev/null
+++ b/source/client/view/components/system-header.tsx
@@ -0,0 +1,22 @@
+import logo from "@/assets/bundled/logo.png"
+
+/** The System identity header shared by System-owned panels. */
+export default function SystemHeader({ labelId, name, version }: Readonly<{
+
+ labelId?: string
+
+ name: string
+
+ version: string
+}>) {
+
+ return <div className="relative grid h-10 shrink-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 px-3.5 select-none">
+
+ <img src={logo} alt="" draggable={false} className="size-4 rounded-sm object-contain" />
+
+ <h2 id={labelId} className="m-0 truncate text-window-title font-medium">{name}</h2>
+
+ <span className="text-xs tabular-nums opacity-60" aria-label={`System version ${version}`}>v{version}</span>
+
+ </div>
+}
diff --git a/source/client/view/structure/authentication/credentials-form.tsx b/source/client/view/structure/authentication/credentials-form.tsx
index 4b076eb..24d4779 100644
--- a/source/client/view/structure/authentication/credentials-form.tsx
+++ b/source/client/view/structure/authentication/credentials-form.tsx
@@ -2,16 +2,18 @@ import { type AuthenticationState } from "@server/core/authentication/authentica
import { surfacePresencePose, surfacePresenceTransition } from "../../appearance/surface-presence"
import { useReducedMotion } from "@libs/react-motion"
import { motion } from "motion/react"
-import { Panel, useAppearance } from "@phreshos/react-ui"
-import Spinner from "../../components/spinner"
+import { Button, Input, Panel, useAppearance } from "@phreshos/react-ui"
import Alert from "../../components/alert"
import { type SyntheticEvent } from "react"
+import { ApplicationContext } from "../../contexts"
+import SystemHeader from "../../components/system-header"
/** The common username-and-password surface for registration and sign-in. */
export default function CredentialsForm({ title, description, submitLabel, passwordAutocomplete, requirements, error, pending, onSubmit }: CredentialsFormProps) {
const reducedMotion = useReducedMotion()
const transaction = useAppearance().transaction
+ const application = ApplicationContext.useValue()
function submit(event: SyntheticEvent<HTMLFormElement, SubmitEvent>) {
@@ -24,7 +26,7 @@ export default function CredentialsForm({ title, description, submitLabel, passw
onSubmit(String(data.get("username") ?? ""), String(data.get("password") ?? ""))
}
- return <div className="absolute inset-0 grid backdrop-blur-md">
+ return <div className="absolute inset-0 grid">
<motion.form
@@ -42,93 +44,57 @@ export default function CredentialsForm({ title, description, submitLabel, passw
>
- <Panel header={<div className="relative grid gap-1 px-5 py-4">
+ <Panel header={<SystemHeader name={application.displayName} version={application.version} />} contentProps={{ className: "grid gap-5 p-5" }}>
- <h1 className="text-xl font-semibold">{title}</h1>
+ <div className="grid gap-1">
- <p className="text-sm leading-5 text-slate-600/90">{description}</p>
+ <h1 className="text-xl font-semibold">{title}</h1>
- </div>} contentProps={{ className: "grid gap-5 p-5" }}>
+ <p className="text-sm leading-5 opacity-60">{description}</p>
- <div className="grid gap-4">
-
- <label className="grid gap-1.5 text-sm font-medium">
-
- Username
-
- <input
-
- name="username"
-
- type="text"
-
- autoComplete="username"
-
- minLength={requirements?.username.minimumLength}
-
- maxLength={requirements?.username.maximumLength}
-
- required
-
- disabled={pending}
-
- autoFocus
-
- className="h-10 rounded-lg border border-white/70 bg-white/70 px-3 font-normal shadow-window-content outline-none focus:border-sky-400 focus:ring-2 focus:ring-sky-200/80"
-
- />
-
- </label>
-
- <label className="grid gap-1.5 text-sm font-medium">
-
- Password
-
- <input
-
- name="password"
-
- type="password"
-
- autoComplete={passwordAutocomplete}
-
- minLength={requirements?.password.minimumLength}
-
- maxLength={requirements?.password.maximumLength}
-
- required
-
- disabled={pending}
-
- className="h-10 rounded-lg border border-white/70 bg-white/70 px-3 font-normal shadow-window-content outline-none focus:border-sky-400 focus:ring-2 focus:ring-sky-200/80"
-
- />
-
- {requirements && <span className="font-normal text-slate-500">
-
- Use at least {requirements.password.minimumLength} characters.
+ </div>
- </span>}
+ <div className="grid gap-4">
- </label>
+ <Input
+ label="Username"
+ name="username"
+ type="text"
+ autoComplete="username"
+ minLength={requirements?.username.minimumLength}
+ maxLength={requirements?.username.maximumLength}
+ required
+ disabled={pending}
+ autoFocus
+ />
+
+ <Input
+ label="Password"
+ name="password"
+ type="password"
+ autoComplete={passwordAutocomplete}
+ minLength={requirements?.password.minimumLength}
+ maxLength={requirements?.password.maximumLength}
+ required
+ disabled={pending}
+ description={requirements ? `Use at least ${requirements.password.minimumLength} characters.` : undefined}
+ />
</div>
- {error && <Alert className="border-red-200/70 bg-red-50/70 text-sm text-red-700">{error}</Alert>}
+ {error && <Alert className="text-sm">{error}</Alert>}
- <button
+ <Button
type="submit"
disabled={pending}
- className="h-10 cursor-pointer rounded-lg border border-sky-700/35 from-sky-500 to-sky-600 px-4 font-medium text-white shadow-taskbar-control outline-none hover:from-sky-400 hover:to-sky-500 focus-visible:ring-2 focus-visible:ring-white/90"
-
- >
+ pending={pending}
- {pending ? <Spinner className="m-auto size-5" /> : submitLabel}
+ style={{ width: "100%" }}
- </button>
+ >{pending ? `${submitLabel}…` : submitLabel}</Button>
</Panel>
diff --git a/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx b/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx
index 73ba61c..068b4cb 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx
@@ -1,6 +1,6 @@
import { type ReactNode } from "react"
import { Surface } from "@phreshos/react-ui"
-import logo from "@/assets/bundled/logo.png"
+import SystemHeader from "../../../../components/system-header"
/** Start menu shell: one outer material and two independently scrolling halves. */
export default function StartMenuPanel({ labelId, name, version, left, right, footer }: Readonly<{ labelId: string, name: string, version: string, left: ReactNode, right: ReactNode, footer: ReactNode }>) {
@@ -9,15 +9,7 @@ export default function StartMenuPanel({ labelId, name, version, left, right, fo
return <Surface style={{ display: "grid", gridTemplateRows: "auto minmax(0, 1fr)", minHeight: 0, height: "100%", maxHeight: "inherit", overflow: "hidden" }}>
- <div className="relative grid h-10 shrink-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 px-3.5 select-none">
-
- <img src={logo} alt="" draggable={false} className="size-4 rounded-sm object-contain" />
-
- <h2 id={labelId} className="m-0 truncate text-window-title font-medium">{name}</h2>
-
- <span className="text-xs tabular-nums opacity-60" aria-label={`System version ${version}`}>v{version}</span>
-
- </div>
+ <SystemHeader labelId={labelId} name={name} version={version} />
<div className="grid min-h-0 min-w-0" style={{ gridTemplateRows: "minmax(0, 1fr) auto", gap: spacing, padding: spacing, paddingTop: 0 }}>
diff --git a/tests/panel.test.tsx b/tests/panel.test.tsx
index 7f45647..6d17d09 100644
--- a/tests/panel.test.tsx
+++ b/tests/panel.test.tsx
@@ -8,15 +8,27 @@ import TaskbarSurface, { taskbarSurfaceClassName } from "@client/view/structure/
import Launcher from "@client/view/structure/desktop/taskbar/launcher/launcher"
import Window from "@client/view/structure/desktop/windows/window"
import StartMenuPanel from "@client/view/structure/desktop/taskbar/launcher/start-menu-panel"
+import { ApplicationContext } from "@client/view/contexts"
+import Application from "@client/core/application"
import { test } from "vitest"
test("panel contract", async () => {
+ const application = new Application("phreshos", "Example System", "1.2.3", {
+ link: "/link",
+ proxy: "/proxy",
+ storage: "/storage",
+ uploads: "/uploads",
+ program: "/program"
+ })
+
function markup(children: ReactNode) {
- return renderToStaticMarkup(<AppearanceProvider appearance={defaultAppearance} theme="light">{children}</AppearanceProvider>)
+ return renderToStaticMarkup(<ApplicationContext.Provider value={application}>
+ <AppearanceProvider appearance={defaultAppearance} theme="light">{children}</AppearanceProvider>
+ </ApplicationContext.Provider>)
}
- function panel(html: string) {
- assert.equal(html.match(/data-material=""/g)?.length, 2)
+ function panel(html: string, materials = 2) {
+ assert.equal(html.match(/data-material=""/g)?.length, materials)
assert.match(html, /grid-template-rows:auto minmax\(0, 1fr\)/)
assert.match(html, /margin:6px;margin-top:0/)
}
@@ -41,11 +53,14 @@ test("panel contract", async () => {
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)
+ panel(authentication, 5)
assert.equal(authentication.match(/<form\b/g)?.length, 1)
assert.match(authentication, /name="username"/)
assert.match(authentication, /name="password"/)
assert.match(authentication, /type="submit"/)
+ assert.match(authentication, /<h2[^>]*>Example System<\/h2>/)
+ assert.match(authentication, /System version 1.2.3/)
+ assert.doesNotMatch(authentication, /backdrop-blur/)
const launcher = markup(<Launcher label="Example System" trigger="Open">{(_close, labelId) => <StartMenuPanel labelId={labelId} name="Example System" version="1.2.3" left={<button>Programs</button>} right={<p>Processes</p>} footer={<input type="search" aria-label="Search Programs and Processes" />} />}</Launcher>)
assert.equal(launcher.match(/data-material=""/g)?.length, 4)