diff --git a/CHANGELOG.md b/CHANGELOG.md index e1c9810b5..7d7b4d9b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,8 +35,8 @@ Extension SDK `2.0.0-beta.5`. * Adds the `server.files.editor` and `server.files.manager` views, `useNavigationBlocker`, `serverResourcesQueryOptions`, `useServerResources`, `useSendServerPower` and `useSendServerCommand` to the SDK. * Adds themes: extensions with `"type": "theme"` that rebuild the panel stylesheet, skin the UI kit and override views through `defineTheme` (`@pterodactyl/sdk/theme`), with typed settings written as tokens and `` attributes, dark and light schemes with a user switch, and child themes through `theme.extends`. * Adds the admin Themes page (activate, preview for me, reset, settings with a live preview), `p:theme:activate`, `p:theme:reset`, `p:theme:list`, safe mode (`?safe_mode=1`), and a fallback to classic when a theme fails to load. -* Adds the theme workbench (`/panel/theme-workbench`), which renders every view and UI primitive from fixtures, and the view inspector (`Alt+Shift+I`, `?inspect=1`). -* Adds the theme toolchain: `p:extension:make --theme`, `defineThemeConfig`, the `pterodactyl-theme` CLI (`list`, `eject`, `skins`), `renderView`, `renderPrimitive` and `preloadTheme` in `@pterodactyl/sdk/testing`, and the SDK's themes guide, `THEMES.md`. +* Adds the theme toolchain: `p:extension:make --theme` (`--css-only` for a theme without JavaScript), `defineThemeConfig`, the `pterodactyl-theme` CLI (`list`, `eject`, `skins`), `renderView`, `renderPrimitive` and `preloadTheme` in `@pterodactyl/sdk/testing`, and the SDK's themes guide, `THEMES.md`. +* `renderView` and `createViewTestHost` throw a `ViewLayerError` when a theme or extension layer fails, unless `strict` is false, and `renderView` mounts test components in slots with `slots`. * Adds layout, terminal, selection, scrollbar and browser chrome theme tokens, a sidebar sub-navigation mode (`data-sub-navigation="side"`), and `onThemeChange`, `notifyThemeChange` and `readThemeToken`. * Scaffolded extensions set `preserveSymlinks` so a linked SDK resolves its peer types from the extension. diff --git a/app/Console/Commands/Extensions/MakeCommand.php b/app/Console/Commands/Extensions/MakeCommand.php index b90d58f4a..729206acd 100644 --- a/app/Console/Commands/Extensions/MakeCommand.php +++ b/app/Console/Commands/Extensions/MakeCommand.php @@ -20,6 +20,7 @@ use Pterodactyl\Services\Extensions\Scaffolding\ExtensionScaffolder; {--prefix= : Tailwind prefix for the classes of the extension: 2-12 lowercase letters (defaults to one derived from the id).} {--no-ui : Skip the frontend scaffold (backend-only extension).} {--theme : Scaffold a theme: stylesheet, a layout override, a skin, settings and a test.} + {--css-only : With --theme: a theme of CSS alone, with no JavaScript entry.} {--out= : Parent directory: the package is created in / (defaults to the extensions directory).} {--path= : The package directory itself, created exactly as given (instead of --out).} {--force : Overwrite the target directory if it already exists.}')] @@ -39,6 +40,7 @@ class MakeCommand extends Command implements PromptsForMissingInput prefix: $this->option('prefix'), theme: (bool) $this->option('theme'), path: $this->option('path'), + cssOnly: (bool) $this->option('css-only'), ); } catch (InvalidExtensionException $invalidExtensionException) { $this->components->error($invalidExtensionException->getMessage()); diff --git a/app/Services/Extensions/Scaffolding/ExtensionScaffolder.php b/app/Services/Extensions/Scaffolding/ExtensionScaffolder.php index 4e2d1af9b..8ff6c654d 100644 --- a/app/Services/Extensions/Scaffolding/ExtensionScaffolder.php +++ b/app/Services/Extensions/Scaffolding/ExtensionScaffolder.php @@ -41,6 +41,7 @@ class ExtensionScaffolder ?string $prefix = null, bool $theme = false, ?string $path = null, + bool $cssOnly = false, ): string { $this->files = []; @@ -50,6 +51,8 @@ class ExtensionScaffolder throw_if($path !== null && $outDir !== null, InvalidExtensionException::class, 'Pass --path (the package directory) or --out (the directory it is created in), not both.'); + throw_if($cssOnly && ! $theme, InvalidExtensionException::class, '--css-only scaffolds a theme: pass it with --theme.'); + $prefix ??= ExtensionManifest::defaultUiPrefix($id); throw_unless($theme || ExtensionManifest::isUsableUiPrefix($prefix), InvalidExtensionException::class, "Tailwind prefix \"{$prefix}\" must match ".ExtensionManifest::UI_PREFIX_REGEX.' and must not be a Tailwind variant, theme namespace or panel name.'); @@ -74,7 +77,7 @@ class ExtensionScaffolder ]; if ($theme) { - $this->scaffoldTheme($target, $id, $replacements); + $this->scaffoldTheme($target, $id, $replacements, $cssOnly); $this->validator->fromDirectory($target); return $target; @@ -148,12 +151,12 @@ class ExtensionScaffolder /** * A theme with a stylesheet for both schemes, a skin, a layout override, four settings and a - * test, laid out as the SDK's THEMES.md describes. It needs no PHP; a provider can be - * added like an extension's. + * test, laid out as the SDK's THEMES.md describes; with `cssOnly`, the stylesheet and settings + * alone, with no `ui` entry. It needs no PHP; a provider can be added like an extension's. * * @param array $replacements stub placeholder => literal substitution */ - private function scaffoldTheme(string $target, string $id, array $replacements): void + private function scaffoldTheme(string $target, string $id, array $replacements, bool $cssOnly): void { $manifest = array_filter([ '$schema' => './node_modules/@pterodactyl/sdk/manifest.schema.json', @@ -165,7 +168,7 @@ class ExtensionScaffolder 'description' => $replacements['{{description}}'] ?: null, 'author' => $replacements['{{author}}'] ?: null, 'icon' => 'palette', - 'ui' => ['entry' => ExtensionManifest::UI_ENTRY], + 'ui' => $cssOnly ? null : ['entry' => ExtensionManifest::UI_ENTRY], 'theme' => [ 'extends' => ThemeRepository::CLASSIC, 'stylesheet' => ThemeDefinition::STYLESHEET, @@ -183,7 +186,14 @@ class ExtensionScaffolder $this->files[] = ExtensionManifest::FILENAME; $replacements['{{artisan}}'] = $this->artisanPath($target); - foreach ([ + $stubs = $cssOnly ? [ + 'theme-css-package.stub' => 'package.json', + 'theme-css-vite.config.stub' => 'vite.config.mjs', + 'postcss.config.stub' => 'postcss.config.mjs', + 'theme-css.stub' => 'src/theme.css', + 'gitignore.stub' => '.gitignore', + 'theme-css-readme.stub' => 'README.md', + ] : [ 'theme-package.stub' => 'package.json', 'theme-vite.config.stub' => 'vite.config.mjs', 'postcss.config.stub' => 'postcss.config.mjs', @@ -196,7 +206,8 @@ class ExtensionScaffolder 'theme-test.stub' => 'src/theme.spec.tsx', 'gitignore.stub' => '.gitignore', 'theme-readme.stub' => 'README.md', - ] as $stub => $relative) { + ]; + foreach ($stubs as $stub => $relative) { $this->stub($target, $stub, $relative, $replacements); } } diff --git a/app/Services/Extensions/Scaffolding/stubs/theme-css-package.stub b/app/Services/Extensions/Scaffolding/stubs/theme-css-package.stub new file mode 100644 index 000000000..0b9b48a07 --- /dev/null +++ b/app/Services/Extensions/Scaffolding/stubs/theme-css-package.stub @@ -0,0 +1,20 @@ +{ + "name": "{{id}}", + "private": true, + "version": "1.0.0", + "type": "module", + "scripts": { + "build": "vite build", + "dev": "vite build --watch", + "doctor": "php {{artisan}} p:extension:doctor .", + "pack": "php {{artisan}} p:extension:pack . --force" + }, + "devDependencies": { + "@pterodactyl/sdk": "{{sdkDependency}}", + "vite": "^8", + "tailwindcss": "^4.3.0", + "@tailwindcss/forms": "^0.5.2", + "@tailwindcss/postcss": "^4", + "postcss": "^8.5.6" + } +} diff --git a/app/Services/Extensions/Scaffolding/stubs/theme-css-readme.stub b/app/Services/Extensions/Scaffolding/stubs/theme-css-readme.stub new file mode 100644 index 000000000..7767e4fa8 --- /dev/null +++ b/app/Services/Extensions/Scaffolding/stubs/theme-css-readme.stub @@ -0,0 +1,33 @@ +# {{name}} + +A Pterodactyl panel theme of CSS alone, scaffolded by `p:extension:make --theme --css-only`. Level 1 of +the themes guide, `node_modules/@pterodactyl/sdk/THEMES.md`, covers it: colours, fonts, radius and +spacing, for dark and light. Skins and views (levels 2 to 4) need a theme scaffolded without `--css-only`. + +## Files + +| File | | +| --- | --- | +| `extension.json` | The manifest. `"type": "theme"` and its `theme` section declare the stylesheet, the colour schemes and the settings. | +| `src/theme.css` | The panel stylesheet with this theme's tokens and classes. Plain Tailwind, no prefix. | + +## Scripts + +| Script | | +| --- | --- | +| `npm run build` | `dist/theme.css` and `dist/theme.json`. | +| `npm run dev` | Rebuilds on change; `p:extension:dev --watch` runs it. | +| `npm run doctor` | The panel's checks: manifest, build, budgets and remote URLs. | +| `npm run pack` | Packs a `.pteroext` archive to install on another panel. | + +## Develop + +```sh +npm install +php {{artisan}} p:extension:dev . --enable +php {{artisan}} p:theme:activate {{id}} +php {{artisan}} p:extension:dev . --watch +``` + +The first command builds, installs and enables the theme. While the last one runs on a panel with +`APP_DEBUG=true`, a change to `src/theme.css` swaps into open pages without a reload. diff --git a/app/Services/Extensions/Scaffolding/stubs/theme-css-vite.config.stub b/app/Services/Extensions/Scaffolding/stubs/theme-css-vite.config.stub new file mode 100644 index 000000000..cd8f0c9d7 --- /dev/null +++ b/app/Services/Extensions/Scaffolding/stubs/theme-css-vite.config.stub @@ -0,0 +1,4 @@ +import { defineThemeConfig } from '@pterodactyl/sdk/vite'; + +// A theme of CSS alone: no entry, so the build writes dist/theme.css and dist/theme.json. +export default defineThemeConfig({ stylesheet: 'src/theme.css' }); diff --git a/docs-notes/theme-fixes.md b/docs-notes/theme-fixes.md deleted file mode 100644 index f8e25a3f5..000000000 --- a/docs-notes/theme-fixes.md +++ /dev/null @@ -1,163 +0,0 @@ -# Theme fixes from the first dogfood: doc notes - -Notes for the THEMES.md and README chapters. Each section says what changed and what the docs should say. - -## The app shell knows the area (`layout.app` model `area`) - -`AppLayoutModel.area` says where the user is and carries the model of that area's own layout: - -```ts -type AppArea = - | { kind: 'dashboard' } // the dashboard and any page outside the areas below - | ({ kind: 'account' } & AccountLayoutModel) // { nav } - | ({ kind: 'server' } & ServerLayoutModel) // { name, identifier, uuid, internalId, state, conflict, adminLink, nav, server } - | ({ kind: 'admin' } & AdminLayoutModel); // { nav, user } -``` - -- `nav.items` are the same items the area's layout gets: filtered by subuser permissions and egg rules. - Render them with ``, which applies extension screen gates and badges. -- A sidebar theme draws every navigation in `layout.app` and overrides `layout.server`, `layout.account` - and `layout.admin` with thin layouts, e.g. `({ children }) =>
{children}
`. - Render the area's slots (`server.navigation.before/after` with `data={area.server}`, - `account.navigation.*`, `panel.navigation.*`) where the shell draws that navigation. The dev-mode - "renders none of its slots" check counts slots a view's enclosing views render, so a thin layout does - not warn when the shell renders its slots. -- Fixtures: `layout.app` has `accountArea`, `serverArea` and `adminArea` besides the dashboard ones - (`user`, `admin`, `schemes`, `logo`). - -Recipe (sidebar part): - -```tsx -function AreaNav({ area }: { area: AppArea }) { - if (area.kind === 'dashboard') return null; - const items = area.kind === 'server' && area.adminLink ? [...area.nav.items, area.adminLink] : area.nav.items; - - return ( - - ); -} -``` - -## Server power state on `layout.server` (`state`, `uuid`) - -`ServerLayoutModel` gained `uuid` and `state: ServerRunState | null` (`'offline' | 'starting' | 'running' | -'stopping'`, as `server.power` and `server.stats` name it). It is the cached resources query, fetched once -when the server opens and kept live by the server's websocket, which now writes every `status` event into -that cache (so dashboard cards returning from a server show the latest state too). Fixtures: `owner`, -`subuser`, `admin` are `running`; new `offline`; `installing` and `suspended` are `offline`. - -## `
` - -- Exactly one `
` renders, from the outermost `
`; nested ones render their children in place. -- A nested `
` now keeps its classes on a `
` around its children instead of dropping - them. A nested `
` without a class adds no element. - -## Failing layers - -- A theme or extension layer that throws falls back to the layer below once. If a layer below the failed - one throws too (classic included), the panel's standard error notice renders for that view, with a - Retry that tries the failed layer again. Nothing re-renders in a loop (before, an effect throwing in - classic under a failed theme layer re-mounted forever, e.g. `server.graphs` without `ResizeObserver`). -- Each failure logs one `console.error`: `[extensions] "" failed in view "": `. -- The inspector is gone (see below); the console line is how to spot a failing layer. - -## Strict test renderers - -- `renderView(name, options)` throws when the view fails to render, and when any theme or extension - layer throws: `The "theme" layer of view "server.graphs" failed: ` (a `ViewLayerError` with - `view`, `layer` and `cause`). Nested views count. `{ strict: false }` lets layers fall back as in the - panel. Failures after the first render (say on a click) are thrown by `unmount()`. -- `createViewTestHost(name, options)` is strict too: the layer under test or a nested layer that throws - fails the render (the error propagates out of RTL's `render`/`act`). `{ strict: false }` opts out. -- `ViewLayerError` is exported from `@pterodactyl/sdk/testing`. -- `renderView(name, { slots: { 'server.navigation.before': () => probe } })` mounts - components in slots as an extension's `slots.register` would, typed per slot; they are removed on - unmount. Use it to test that a view renders the slots it replaces. -- The SDK's Vitest setup (`pterodactylTestSetup`) now provides `ResizeObserver`, `IntersectionObserver` - (inert) and `matchMedia` (matches nothing) besides `PointerEvent` and `scrollTo`. Theme tests need no - stubs; `vi.stubGlobal` still replaces them where a test drives them. -- `usePanelLocation()` works in views rendered from fixtures (tests): outside a route it returns the - path with empty `params` and `search` instead of throwing. - -## Navigation details - -- Every core nav item has an `icon` (lucide name for `NamedIcon`): - - account: Account `user-round`, API Credentials `key-round`, SSH Keys `terminal`, Activity `history`; - - server: Console `square-terminal`, Files `folder`, Databases `database`, Schedules `calendar-clock`, - Users `users`, Backups `archive`, Network `network`, Startup `rocket`, Settings `settings`, - Activity `history`; the admin link stays `external-link`; - - admin: Activity is now `history` (the rest had icons already). - - `AppLayoutLink.icon`: dashboard `layers`, admin `user-cog`, account `user-round`. - Classic still shows its account and server tabs as text (extension screens keep their icons), through - `views/layout/tabLabel.tsx`, which `eject` copies with those layouts; its admin sidebar now shows the - history icon for Activity instead of the fallback puzzle. -- `DropdownMenu.Item` takes `destination` (a `PanelDestination`): the item renders as a link (``, - `role="menuitem"`, same skin parts) that navigates and closes the menu. - `Account` -- Closing a drawer on navigation: an effect on the path, which also works in tests. - - ```tsx - const { pathname } = usePanelLocation(); - useEffect(() => setOpen(false), [pathname]); - ``` - - No `useOnNavigate` hook was added; this is two lines and needs no new concept. - -## Layout spacing tokens - -- `--layout-gutter` (default `calc(var(--spacing) * 4)`): page content's side margin until it centres. -- `--layout-content-width` (existing): its maximum width (`max-w-panel`). -- `page-width` utility: the geometry `PageContentBlock` and `ServerContentBlock` use (max width - `--layout-content-width`, `--layout-gutter` at the sides, centred from `xl`). Put it on a layout's own - header to line up with the pages below: `
`. - Core renders exactly as before. - -## Palette - -`text-white`, `bg-black/15` etc. work in theme builds again: `--color-white` and `--color-black` are -defined after the palette reset. `transparent`, `current` and `inherit` always worked. The rest of -Tailwind's default palette stays removed; add colours in `@theme` as before. Core's compiled CSS is -unchanged. - -## Packaging - -- `defineThemeConfig({ …, sourcemap })`: off by default for themes, because a map embeds the sources. - `sourcemap: true` turns it on (e.g. for a private build). Extensions keep `sourcemap: true`. -- `p:extension:pack` leaves `*.map` files out of the archive unless given `--sourcemaps`. -- The theme scaffold's `npm run pack` passes `--force`, so re-packing replaces the archive, and its - `.gitignore` (shared with extensions) ignores `*.pteroext`. - -## Scaffold paths - -- `p:extension:make --path=` creates the package in exactly ``. -- `--out=` (unchanged) is the parent: the package goes in `/`. `--help` says so. -- Passing both fails before writing anything. - -## Removed: the theme workbench - -`/panel/theme-workbench`, `page.admin.themeWorkbench`, the workbench components, the UI-kit gallery -(`themes/gallery.tsx`), preview frames and the portal-container context that sent overlays into them, -and the Workbench button on the Themes page are gone. View fixtures, `renderView`, `renderPrimitive` -(same primitive names), `createViewTestHost` and `preloadTheme` remain; tests are the way to render views -without a backend. Docs should drop the workbench section, its URL parameters (`view`, `fixture`, `scheme`, -`width`, `ui`) and the scaffold README's mention (done in the stub). `Portal` renders into -`#modal-portal`, or the body where there is none (as in tests), so `createViewTestHost` no longer adds a -`#modal-portal` for the file manager. Dialogs, menus, selects and tooltips portal into the body again. -The planned `useViewDocument()` hook and the `width=` URL parameter fix were dropped with the workbench. - -## Removed: the inspector - -The Alt-click inspector, its floating button, the `data-view` wrappers, the view probes -(`ViewInspectionContext`), `?inspect=1` and `SiteConfiguration.theme.inspect` (server payload and client -type) are gone. Failing layers log a `console.error` naming the view and the layer instead. diff --git a/packages/sdk/README.md b/packages/sdk/README.md index 7a87642f1..94e71f613 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -240,11 +240,14 @@ shows while the extension is disabled, and `p:extension:pack` adds it to the arc ## Author tooling and configuration -Use `p:extension:doctor `, `p:extension:dev --watch`, and +`p:extension:make ` scaffolds a package in `extensions/`; `--out=` creates it in +`/` and `--path=` in exactly ``. Use `p:extension:doctor `, `p:extension:dev --watch`, and `p:extension:pack ` for preflight checks, successful-build publishing with browser reload in debug mode, and -runtime-only archives. Scaffolds include tests, CI, OpenAPI generation, and styling. +runtime-only archives; pack leaves `*.map` files out unless given `--sourcemaps`, since a map can embed +your sources. Scaffolds include tests, CI, OpenAPI generation, and styling. `@pterodactyl/sdk/testing` supplies `createExtensionTestHost` and `createTestServer`; -`@pterodactyl/sdk/vitest` supplies aliases and setup for the real runtime. Unmount the +`@pterodactyl/sdk/vitest` supplies aliases and setup for the real runtime, including the +`ResizeObserver`, `IntersectionObserver` and `matchMedia` jsdom lacks. Unmount the wrapper and dispose the host after each test. The test host shares the real cache; create one host at a time within a test environment. @@ -924,9 +927,9 @@ export default function Browser({ model, parts }: ViewProps<'server.files.manage ### Loading and failure -While a bundle that declares a view loads, the view shows its placeholder; mounts of one page share that decision. After five seconds, or when the import or the layer fails, the layers below render instead, and a late bundle cannot replace a view already shown. A layer that throws while rendering is reported against its package and replaced by the layer below. Core state remains outside the layer. Use local Suspense for extension-owned asynchronous rendering and `useExtensionAction` for callbacks. +While a bundle that declares a view loads, the view shows its placeholder; mounts of one page share that decision. After five seconds, or when the import or the layer fails, the layers below render instead, and a late bundle cannot replace a view already shown. A layer that throws while rendering falls back to the layer below once; if that one throws too, the view shows the panel's error notice with a Retry. Each failure logs `[extensions] "" failed in view "": ` to the browser console. Core state remains outside the layer. Use local Suspense for extension-owned asynchronous rendering and `useExtensionAction` for callbacks. -The testing entry exports `createViewTestHost(name, { model?, fixture?, input?, extensionId?, prefix? })`, which resolves to a `Wrapper`, the typed `props` of a layer above classic, and `dispose`, plus the model fixtures `createTestServerCard`, `createTestFileDetails`, `createTestFileEditor`, `createTestFileManager` and `createTestFileManagerEntry`. It exercises classic's layers and parts without issuing core queries; nested views read their fixtures. Pass `vi.fn()` callbacks in the model to assert on `save`, `change` or an action, and call `dispose()` after unmounting. +The testing entry exports `createViewTestHost(name, { model?, fixture?, input?, extensionId?, prefix?, strict? })`, which resolves to a `Wrapper`, the typed `props` of a layer above classic, and `dispose`, plus the model fixtures `createTestServerCard`, `createTestFileDetails`, `createTestFileEditor`, `createTestFileManager` and `createTestFileManagerEntry`. It exercises classic's layers and parts without issuing core queries; nested views read their fixtures. Pass `vi.fn()` callbacks in the model to assert on `save`, `change` or an action, and call `dispose()` after unmounting. The render fails with a `ViewLayerError` when your layer or a nested view's layer throws; `strict: false` lets it fall back as in the panel. `renderView` and its `slots` option, which mounts test components in slots, are described under [Testing](THEMES.md#testing). ## UI kit diff --git a/packages/sdk/THEMES.md b/packages/sdk/THEMES.md index 4df09654e..1c1586ae4 100644 --- a/packages/sdk/THEMES.md +++ b/packages/sdk/THEMES.md @@ -44,7 +44,8 @@ classic the stock panel ``` Render `` to keep what is below and add to it; leave it out to replace it. A layer that -throws is reported and the layer below renders instead. Whatever you do not override stays classic. +throws gives way to the layer below ([Fallback](#fallback-and-safe-mode)). Whatever you do not override +stays classic. | I want to … | Go to | | --- | --- | @@ -64,14 +65,17 @@ From the panel's root directory, five commands scaffold a theme, build and insta and rebuild it on every change: ```sh -php artisan p:extension:make sunrise --theme +php artisan p:extension:make sunrise --theme --css-only cd extensions/sunrise && npm install php ../../artisan p:extension:dev . --enable php ../../artisan p:theme:activate sunrise php ../../artisan p:extension:dev . --watch ``` -While the last one runs on a panel with `APP_DEBUG=true`, a stylesheet change swaps into open pages +`--css-only` leaves out the JavaScript that levels 2 to 4 need. The package goes in +`extensions/sunrise`; `--path=` puts it in exactly ``, and `--out=` in `/sunrise`. + +While the last command runs on a panel with `APP_DEBUG=true`, a stylesheet change swaps into open pages without a reload, and any other change reloads them. To try a theme without switching everyone to it, skip `p:theme:activate` and choose **Preview for me** on **Admin > Themes**. @@ -86,8 +90,9 @@ A **token** is a CSS custom property the panel's classes read. Set one and every changes: `--primary` colours primary buttons and selected items, `--radius` sets every rounded corner, and `--spacing` scales every padding, margin and gap. [Tokens](#tokens) lists them all. -The colour classes are roles such as `bg-card` and `text-muted-foreground`; Tailwind's palette is not -there. Add a colour of your own in `@theme`: `--color-brand: oklch(0.7 0.2 300);` gives `bg-brand`. +The colour classes are roles such as `bg-card` and `text-muted-foreground`. Of Tailwind's palette only +`white` and `black` remain (`text-white`, `bg-black/15`). Add a colour of your own in `@theme`: +`--color-brand: oklch(0.7 0.2 300);` gives `bg-brand`. ### Dark and light @@ -102,9 +107,6 @@ Ship font files with the theme and reference them relative to the stylesheet; th beside `dist/theme.css`. Set `--font-sans` (body) and `--font-header` (headings) in `@theme`. Fonts from another origin, such as a CDN, are refused. -The build warns that `/assets/fonts/ibm-plex-sans-latin-wght-normal.woff2` did not resolve. That is the -panel's own font, served by the panel, and the warning is expected. - ### A complete level 1 theme @@ -177,15 +179,18 @@ panel's own font, served by the panel, and the warning is expected. ``` -This theme has no JavaScript: its manifest has no `ui` and its `vite.config.mjs` no `entry`. The -scaffold also writes `src/theme.tsx`, with a skin and a layout layer, for the later levels; the build -ignores it once those two lines are gone. [`docs-samples/level1-css`](docs-samples/level1-css) in the -panel repository holds the files. +The manifest has no `ui` and `vite.config.mjs` no `entry`, so the build writes only the stylesheet; +`--css-only` scaffolds a theme this way. [`docs-samples/level1-css`](docs-samples/level1-css) in the panel +repository holds the files. You now have a theme. ## Level 2: restyle components +From this level on, a theme has JavaScript: `src/theme.tsx`, built to the `dist/client.js` that the +manifest's `ui.entry` names. Scaffold without `--css-only` to get it, with a skin, a layout and a test +to start from; a level 1 theme moves over by copying its `src/theme.css` into the new package. + The panel draws its interface with a UI kit of 28 **primitives**, such as `Button`, `Card` and `Dialog`. Extensions use them too, so restyling a primitive restyles it everywhere. @@ -364,14 +369,14 @@ that does not exist logs a warning, and a recipe that throws renders no classes. ## Level 3: change the layout -A **view** is a named piece of the interface, rendered by a stack of layers. A **layout** view frames -the pages of an area: +A **view** is a named piece of the interface, rendered by a stack of layers. A **layout** view frames a +set of pages: | Layout | Frames | Its model has | | --- | --- | --- | -| `layout.app` | Every signed-in page | `brand`, `links`, `user`, the scheme, `signOut` | +| `layout.app` | Every signed-in page | `brand`, `links`, `area`, `user`, the scheme, `signOut` | | `layout.account` | The account pages, inside `layout.app` | `nav` | -| `layout.server` | A server's pages, inside `layout.app` | `name`, `nav`, `conflict`, `server` | +| `layout.server` | A server's pages, inside `layout.app` | `name`, `state`, `nav`, `conflict`, `server` | | `layout.admin` | The admin area, inside `layout.app` | `nav`, `user` | | `layout.auth` | The sign-in pages | `brand` | @@ -381,117 +386,191 @@ types these props. Register views by name: ```tsx -import { defineTheme, lazyView } from '@pterodactyl/sdk/theme'; +import type { ReactNode } from 'react'; +import { Main, defineTheme, lazyView } from '@pterodactyl/sdk/theme'; + +/** The shell draws every area's navigation, so an area's layout only places its pages. */ +function AreaLayout({ children }: { children?: ReactNode }) { + return
{children}
; +} export default defineTheme({ views: { 'layout.app': lazyView(() => import('./views/Shell')), - 'layout.account': lazyView(() => import('./views/AccountLayout')), + 'layout.server': AreaLayout, + 'layout.account': AreaLayout, + 'layout.admin': AreaLayout, }, }); ``` `lazyView` loads a view's code the first time it renders (see [Level 4](#loading-with-lazyview)). +[The shell knows the area](#the-shell-knows-the-area) explains `AreaLayout`. ### `
` A layout places `children` inside `
`, which renders `
`: the target of the skip link, which the engine focuses after each navigation while it announces the new page title. -Layouts nest, and only the outermost `
` renders the element. In development, a layout that never -renders `
` logs a warning. +Layouts nest, and only the outermost `
` renders the element; a nested one renders its children in +place, in a `
` when it has a `className`. In development, a layout that never renders `
` logs +a warning. ### Navigation and the brand `layout.app` has `model.links` (the dashboard, the admin area for root admins, and the account) and `model.brand`, the panel's `name` and a `logoUrl` (see [Branding](#branding)). -The other layouts have `model.nav.items`: the area's `NavItem`s, filtered by subuser permissions and egg -rules, extension screens included. `` calls its child with each item and `{ active, badge }`, -and keeps an extension screen hidden until its runtime condition allows it. `NavigationLink` links to -an item and carries `data-status="active"` while the item is active. +The other layouts each frame an **area**, a part of the panel with navigation of its own: the account, a +server, or the admin area. They have `model.nav.items`: the area's `NavItem`s, filtered by subuser +permissions and egg rules, extension screens included. Links and items have an `icon`, a lucide name for +``. +`` calls its child with each item and `{ active, badge }`, and keeps an extension screen +hidden until its runtime condition allows it. `NavigationLink` links to an item and carries +`data-status="active"` while the item is active. [`AreaNav`](#the-shell-knows-the-area) below uses both. - +`useNavigation('account' | 'server' | 'admin')` returns an area's items outside its layout. Classic's tab +bar, which folds items that do not fit into a menu, is `SubNavigation` with `SubNavigationLayout` from +`@pterodactyl/sdk`. In a menu of your own, `` is a +link that navigates and closes the menu. + +### The shell knows the area + +`model.area` of `layout.app` says which area the user is in: `kind` is `account`, `server` or `admin`, +with the model of that area's layout beside it, or `dashboard` on the dashboard and any page outside an +area. So `layout.app` can draw every area's navigation itself, in one sidebar. The theme then overrides +`layout.account`, `layout.server` and `layout.admin` with a **thin layout**, which places the page in +`
` and nothing else (`AreaLayout` above). + +A layer that replaces a view renders the view's slots, listed in the [catalogue](#view-catalogue), or +the extensions mounted there disappear. The area layouts' slots sit in their navigation, so the shell +renders them where it draws that navigation (`AreaSlot` below). In development, a layer that renders +none of its view's slots logs a warning after three seconds; slots an enclosing view renders count, so +the thin layouts do not warn. + + ```tsx -/** The account pages with a vertical menu. `model.nav` lists them, extension screens included. */ -export default function AccountLayout({ model, children }: ViewProps<'layout.account'>) { +import { Badge, NamedIcon } from '@pterodactyl/sdk'; +import { Navigation, NavigationLink, Slot, type AppArea } from '@pterodactyl/sdk/theme'; + +type Area = Exclude; + +const link = [ + 'flex items-center gap-3 rounded-lg px-3 py-2 text-sm text-muted-foreground no-underline', + 'hover:bg-popover hover:text-foreground data-[status=active]:bg-primary/15 data-[status=active]:text-foreground', +].join(' '); + +/** The slots of the area's navigation, which its own layout would render if it drew the navigation. */ +function AreaSlot({ area, at }: { area: Area; at: 'before' | 'after' }) { + if (area.kind === 'server') return ; + if (area.kind === 'account') return ; + return ; +} + +/** The pages of the area the user is in: a server's, the account's or the admin area's. */ +export default function AreaNav({ area }: { area: AppArea }) { + if (area.kind === 'dashboard') return null; + + const items = area.kind === 'server' && area.adminLink ? [...area.nav.items, area.adminLink] : area.nav.items; + const label = { server: 'Server', account: 'Account', admin: 'Administration' }[area.kind]; + return ( -
- -
{children}
-
+ ); } ``` -`useNavigation('account' | 'server' | 'admin')` returns an area's items outside its layout. Classic's tab -bar, which folds items that do not fit into a menu, is `SubNavigation` with `SubNavigationLayout` from -`@pterodactyl/sdk`. +The fixtures `accountArea`, `serverArea` and `adminArea` of `layout.app` render the shell in each area. ### A sidebar shell -A complete `layout.app`: the brand, the links between their slots, the panel's search, the user, the -scheme switch, sign-out, and the page in `
`. `w-sidebar` reads `--layout-sidebar-width` and -`bg-sidebar` reads `--sidebar`. +A complete `layout.app`: the brand, the links between their slots, the area's navigation, the panel's +search, the user, the scheme switch, sign-out, and the page in `
`. `w-sidebar` reads +`--layout-sidebar-width` and `bg-sidebar` reads `--sidebar`. Below the `lg` breakpoint the sidebar is a +drawer, which an effect on `usePanelLocation().pathname` closes when one of its links navigates. ```tsx -import { LayoutGrid, LogOut, Moon, Shield, Sun, UserRound, type LucideIcon } from 'lucide-react'; -import { Avatar, PanelLink, SpinnerOverlay } from '@pterodactyl/sdk'; -import { Main, Slot, View, type AppLayoutLink, type ViewProps } from '@pterodactyl/sdk/theme'; - -const icons: Record = { dashboard: LayoutGrid, admin: Shield, account: UserRound }; +import { useEffect, useState } from 'react'; +import { LogOut, Menu, Moon, Sun } from 'lucide-react'; +import { Avatar, NamedIcon, PanelLink, SpinnerOverlay, cn, usePanelLocation } from '@pterodactyl/sdk'; +import { Main, Slot, View, type ViewProps } from '@pterodactyl/sdk/theme'; +import AreaNav from './AreaNav'; const item = [ 'flex items-center gap-3 rounded-lg px-3 py-2 text-sm text-muted-foreground no-underline', 'hover:bg-popover hover:text-foreground data-[status=active]:bg-primary/15 data-[status=active]:text-foreground', ].join(' '); -/** A sidebar on large screens and a top bar below them, with the page beside it. */ +/** A sidebar beside the page on large screens, and a drawer behind a menu button below them. */ export default function Shell({ model, children }: ViewProps<'layout.app'>) { const { brand, user, scheme, setScheme } = model; + const SchemeIcon = scheme === 'dark' ? Sun : Moon; + const [open, setOpen] = useState(false); + const { pathname } = usePanelLocation(); + + // Close the drawer when one of its links navigates. + useEffect(() => setOpen(false), [pathname]); return ( -
+
-