From 9ae0337820155769e5ecdea36aa4d24691633cbe Mon Sep 17 00:00:00 2001 From: robert dennis <31261583+robertdrakedennis@users.noreply.github.com> Date: Mon, 12 Oct 2026 16:20:31 -0400 Subject: [PATCH] theme docs --- CHANGELOG.md | 13 +- docs-notes/skins.md | 111 - package.json | 6 +- packages/sdk/README.md | 2063 +++++++++++++++++ packages/sdk/docs-samples/aurora/src/skins.ts | 6 +- .../aurora/src/views/ServerCard.tsx | 25 +- .../aurora/src/views/ServerGrid.tsx | 14 +- .../docs-samples/aurora/src/views/Stats.tsx | 21 +- .../aurora/src/views/Terminal.tsx | 7 +- .../sdk/docs-samples/snippets/extension.tsx | 5 +- packages/sdk/docs-samples/snippets/skins.tsx | 2 +- .../admin/themes/workbench/PreviewFrame.tsx | 1 + .../admin/themes/workbench/ViewPreview.tsx | 5 +- resources/scripts/themes/gallery.tsx | 8 +- resources/scripts/views/slotCheck.spec.tsx | 5 +- resources/scripts/views/slotCheck.tsx | 1 + 16 files changed, 2141 insertions(+), 152 deletions(-) delete mode 100644 docs-notes/skins.md diff --git a/CHANGELOG.md b/CHANGELOG.md index f46535a26..b32fabeb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This file is a running track of new features and fixes to each version of the pa This project follows [Semantic Versioning](http://semver.org) guidelines. ## v2.0.0 (unreleased) -Extension SDK `2.0.0-beta.4`. +Extension SDK `2.0.0-beta.5`. ### Fixed * Extension web routes under `/extensions/` are now matched before the SPA catch-all route, which previously answered them. @@ -19,6 +19,11 @@ Extension SDK `2.0.0-beta.4`. * Each extension builds Tailwind with its own prefix, declared as `ui.prefix` in the manifest (2-12 lowercase letters; `hw` gives `hw:flex`, `hw:lg:hidden` and theme variables under `--hw-*`). Tailwind variant names, theme namespaces and panel names are reserved, two enabled extensions cannot share a prefix, and `p:extension:doctor`, `p:extension:pack`, install and enable reject a build whose utilities or theme variables do not carry the declared prefix. `p:extension:make` derives a prefix from the id or takes `--prefix`. * `@pterodactyl/sdk/theme.css` points prefixed extension builds at the panel's live `--spacing` and font tokens; the panel imports the shared mapping from `packages/sdk/theme-tokens.css`. * Class names passed to core components resolve the prefixed utilities of every enabled extension against the panel utility they replace; the SDK test hosts take the `prefix` to do the same. +* The stock UI is the built-in `classic` theme, written on the public theme API. Every layout, page and block is a named view with an engine model, rendered through a chain of layers (classic, the active theme and its parents, then extension overrides) in which each layer can render the one below and a failing layer falls back to it. +* Extensions override views with `views.override` and the manifest's `ui.views`, replacing `components.replace` and `ui.components`, and add views of their own with `views.define`. +* Core components take their classes from UI kit skins and mark their parts with `data-ui`, `data-part` and their state. +* The extension and theme Vite presets emit fonts and images with URLs relative to the file that uses them, so they load from the published build. +* Removed the `themes/` directory, `ThemeService` and the old `p:theme:apply` behaviour. ### Added * Adds `ReadsFileContents`, `ListsDirectories`, `ReadsServerLogs`, `ReadsServerState`, `ChangesServerEgg` and `CompletesLogins` action contracts. @@ -27,7 +32,11 @@ Extension SDK `2.0.0-beta.4`. * `OperationCompleted` now also reports `delete`, `suspend`, `unsuspend` and `transfer`. * Adds public extension settings (`->frontend()->public()`) and the `color`, `textarea`, `multiselect`, `list` and `file` setting fields, with uploads served from `/extension-files//`. * Adds conditional extension screens (`ui.screens[].when` and a runtime `visible` predicate), live navigation badges, `NamedIcon` and `@pterodactyl/sdk/icons.json`. -* Adds the replaceable `server.files.editor` and `server.files.manager` components, `useNavigationBlocker`, `serverResourcesQueryOptions`, `useServerResources`, `useSendServerPower` and `useSendServerCommand` to the SDK. +* 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 Themes chapter of the SDK README. * 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/docs-notes/skins.md b/docs-notes/skins.md deleted file mode 100644 index f4b6916b8..000000000 --- a/docs-notes/skins.md +++ /dev/null @@ -1,111 +0,0 @@ -# Skin reference (data for the docs lane) - -Source of truth: `resources/scripts/themes/primitives.ts` (`UiPrimitives`, `UI_PRIMITIVES`), the registry in -`resources/scripts/themes/skins.ts`, classic's recipes in `resources/scripts/themes/classic/skins/*.ts`. - -## API (`@pterodactyl/sdk/theme`) - -- `defineTheme({ ui })`: `ui` is `ThemeSkins`, keyed by primitive name. -- `skin(name, skin)` types a skin; `skin(name, (parent) => skin)` extends the layers below. The function form must go - through `skin()`: a bare function is read as a replacement component. -- Skin: `{ [part]: recipe }`. A recipe is a string, a cva recipe `{ base, variants, compoundVariants, defaultVariants }`, - or `(state) => string`. Variant keys are state keys; booleans use `'true'`/`'false'`. -- `parent` in the function form has every part resolved: `parent.root(state)` returns the classes below. -- `useSkin(name, state)` returns a binding: `ui(part, className?, partState?)` gives - `{ className, 'data-ui', 'data-part', data-* }` to spread; `ui.classes(part, className?, partState?)` gives the string. -- Types: `ThemeSkins`, `Skin`, `CompleteSkin`, `CompleteSkins`, `SkinRecipe`, `SkinRecipeConfig`, - `SkinCompoundVariant`, `ResolvedSkin`, `SkinExtension`, `SkinDefinition`, `SkinBinding`, - `SkinPartProps`, `SkinClassName`, `SkinPart`, `PrimitiveName`, `PrimitiveState`, `PrimitiveProps`, - `ReplaceableName`, `UiPrimitives`, `UiTone`, `NoState`, `SkinStateMap`, `SkinStateValue`, `PrimitiveMeta`; - value `UI_PRIMITIVES` (parts and `replaceable` per primitive). - -## Rules - -- Layers: classic, then the theme chain parent first. For each part the topmost recipe wins and replaces the one below - wholesale; nothing merges. Parts a skin leaves out keep the recipe below. -- The call-site `className` is appended with `cn()` (tailwind-merge), so it wins conflicts. -- Every part renders `data-ui=""` and `data-part=""`. The root also renders a `data-` per state - value (camelCase keys become kebab case: `richLabel` → `data-rich-label`). `true` renders as an empty attribute, - `false`/unset render nothing. A part given its own state (Dialog `icon`, Empty `media`, Pagination `page`) renders - that state on itself. -- Parts marked "classes only" below are passed as `className` to another primitive or element and carry no attributes. -- Presentational primitives can be replaced by a component receiving the identical props. The topmost replacement wins; - skins of all layers still resolve for the core components. A replacement must not render the primitive it replaces. -- Base UI primitives (and the other skin-only ones) cannot be replaced: a component there is a type error, and at - runtime it is ignored with a dev warning. Unknown primitive names and unknown parts are ignored with a dev warning. -- Resolution is memoised per primitive per layer stack; a recipe or extension that throws is skipped and logged. - -## Primitives - -`root` gets the bound state as `data-*`. Replaceable = may be a component. - -| Primitive | Parts | State (→ `data-*`) | Replaceable | -|---|---|---|---| -| Alert | root, icon, body, title, content | `type`: success, info, warning, danger | yes | -| Avatar | root | `variant`: beam, marble, pixel, sunset, ring, bauhaus | yes | -| Badge | root | `tone`: neutral, success, warning, danger, info, accent; `size`: sm, md; `variant`: solid, soft | yes | -| Button | root, spinner, label | `color`: primary, grey, green, red, orange; `size`: xsmall, small, large, xlarge; `secondary`; `loading` | yes | -| Card | root, header, title, icon, actions, body | `titled` (has a header); `actions`; `loading` | yes | -| Checkbox | root, indicator | none (Base UI sets `data-checked`, `data-indeterminate`, `data-disabled`) | no | -| Code | root | `dark` | no | -| CopyOnClick | root (toast), status, message, target (classes only, added to the clicked child) | `status`: copied, failed | no | -| Dialog | backdrop, viewport, container, root (popup), body, content, header, heading, title, description, spacer, footer, close, closeButton (classes only, on a Button), closeIcon, icon, iconGlyph | `described`; `type` on `icon`: danger, warning, success, info | no | -| DropdownMenu | trigger, positioner, root (popup) | `context` (ContextDropdownMenu) | no | -| DropdownMenuItem | root, icon, glyph, text, label, description | `danger`; `described` | no | -| Empty | root, header, media, title, description, content | `size`: default, compact; `variant` on `media`: default, icon | yes (root) | -| FileInput | root | none | no | -| Input | root | `light`; `error` | no | -| Label | root | `light` | no | -| ListRow | root | `interactive` | yes | -| NewButton | root (classes only, on the Button), content, icon | `link` (NewLinkButton) | no | -| NumberInput | root (NumberField), input | `light`; `error` | no | -| PageHeading | root, text, title, description, actions | none | yes | -| Pagination | root, page (classes only, on each page Button) | `current` on `page` | no | -| ProgressBar | root (track), indicator | `variant`: meter, page; `tone`: as Badge | yes | -| Select | root (input group), input, trigger, positioner, popup, list, item, itemLabel, indicator, empty, group, groupLabel, summary, preview | `error`; `multiple`; `selected`; `richLabel`; `searching` | no | -| Spinner | root, container (when centered) | `size`: small, base, large; `blue`; `centered` | yes | -| SpinnerOverlay | root, text | `fixed` | no | -| Switch | root, control, thumb, text, label (classes only, on the Label), description | `described`; `position`: start, end | no | -| Table | root, empty, scroller, table, head, headerRow, headerCell, body, row, cell | `fetching` | no | -| TextArea | root | `light`; `error` | no | -| Tooltip | root, arrow | `side`: top, right, bottom, left; `arrow` | no | - -## Components and props (`@pterodactyl/sdk`) - -Button (`ButtonProps`, `ButtonColor`, `ButtonSize`; `Button.Text`, `Button.Danger`), LinkButton, RouterLinkButton, -NewButton/NewLinkButton (`NewButtonProps`, `NewLinkButtonProps`), Input (`InputProps`), TextArea (`TextAreaProps`), -NumberInput (`NumberInputProps`), FileInput (`FileInputProps`), Select (`SelectProps`), Checkbox (`CheckboxProps`), -Switch (`SwitchProps`), Label (`LabelProps`), Dialog (`DialogProps`, `DialogIconProps`; `Dialog.Footer`, `Dialog.Icon`, -`Dialog.Confirm`), Alert (`AlertProps`, `AlertType`), Tooltip (`TooltipProps`), DropdownMenu / DropdownMenuItem / -ContextDropdownMenu (`DropdownMenuProps`, `DropdownMenuItemProps`, `ContextDropdownMenuProps`), Table (`TableProps`), -Pagination (`PaginationProps`), Empty + EmptyHeader/EmptyMedia/EmptyTitle/EmptyDescription/EmptyContent (`EmptyProps`, -`EmptySize`, `EmptyMediaVariant`), Spinner (`SpinnerProps`), SpinnerOverlay (`SpinnerOverlayProps`), Avatar -(`AvatarProps`), ProgressBar (`ProgressBarProps`), Code (`CodeProps`), CopyOnClick (`CopyOnClickProps`), Card -(`CardProps`), ListRow (`ListRowProps`), Badge (`BadgeProps`), PageHeading (`PageHeadingProps`). ContentBox and -TitledGreyBox remain as thin wrappers over Card. - -## Recipes - -```tsx -export default defineTheme({ - ui: { - // Replaces Button's root recipe; spinner and label keep classic's. - Button: skin('Button', { - root: { - base: 'inline-flex h-9 items-center rounded-full px-4 font-medium', - variants: { color: { primary: 'bg-primary text-primary-foreground hover:bg-primary/90' } }, - compoundVariants: [{ secondary: true, color: 'primary', class: 'bg-transparent text-primary' }], - }, - }), - // Builds on the classes below. - Card: skin('Card', (parent) => ({ root: (state) => `${parent.root(state)} backdrop-blur-xl bg-card/60` })), - // Presentational primitives can be components with the same props. - Badge: AuroraBadge, - }, -}); -``` - -Classic's normalised variants: plain `hover:`/`active:` guarded with `not-disabled:` on Button -(`hover:not-disabled:bg-primary/80`), `data-checked:`/`data-highlighted:`/`data-starting-style:` instead of -`data-[…]:`, `z-9999`, and `(--var)` shorthands. Rendered classes are otherwise unchanged -(`resources/scripts/themes/classicClasses.spec.tsx`). diff --git a/package.json b/package.json index 8ff9f7402..fbe65dd51 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "test": "vitest run", "test:watch": "vitest", "tsc": "tsc --noEmit && tsc --project tools/oxlint/rules && npm --prefix packages/hello-world run typecheck", - "lint": "oxfmt --check resources/scripts packages/hello-world tools/oxlint && oxlint --type-aware resources/scripts packages/hello-world/src/client tools/oxlint", + "lint": "oxfmt --check resources/scripts packages/hello-world packages/sdk/docs-samples tools/oxlint && oxlint --type-aware resources/scripts packages/hello-world/src/client tools/oxlint", "api:generate": "openapi-ts", "extension:api:generate": "node scripts/generate-extension-api.mjs", "api:refresh": "APP_URL=http://localhost PTERODACTYL_EXTENSIONS_ENABLED=false composer docs:openapi:verify && npm run api:generate", @@ -107,8 +107,8 @@ "build:production": "npm run build --", "build:vite": "npm run build && npm --prefix packages/hello-world run build", "serve": "vite", - "sdk:generate": "node scripts/generate-sdk-types.mjs && node scripts/generate-sdk-icons.mjs && node scripts/generate-sdk-views.mjs && node scripts/generate-core-classes.mjs", - "sdk:check": "node scripts/generate-sdk-types.mjs --check && node scripts/generate-sdk-icons.mjs --check && node scripts/generate-sdk-views.mjs --check && npm run sdk:testing && vitest run packages/sdk/types-drift.spec.ts", + "sdk:generate": "node scripts/generate-sdk-types.mjs && node scripts/generate-sdk-icons.mjs && node scripts/generate-sdk-views.mjs && node scripts/generate-core-classes.mjs && node scripts/generate-sdk-docs.mjs", + "sdk:check": "node scripts/generate-sdk-types.mjs --check && node scripts/generate-sdk-icons.mjs --check && node scripts/generate-sdk-views.mjs --check && node scripts/generate-sdk-docs.mjs --check && tsc --project packages/sdk/docs-samples && npm run sdk:testing && vitest run packages/sdk/types-drift.spec.ts", "sdk:testing": "node scripts/build-sdk-testing.mjs", "pretest": "npm run sdk:testing" }, diff --git a/packages/sdk/README.md b/packages/sdk/README.md index 6bf64c857..ae1ade60a 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -757,9 +757,35 @@ panel does not have. ``` +```tsx +/** A layer over the server card: it keeps the layers below and adds a note. */ +function ServerCard({ Default, model }: ViewProps<'dashboard.serverCard'>) { + return ( + <> + + {model.state.kind === 'unavailable' &&

Ask support about {model.name}.

} + + ); +} +``` +```tsx +views.override('dashboard.serverCard', ServerCard); +views.override('server.files.details', { load: () => import('./FileDetails') }); +views.define('billing.balance', { + context: 'app', + use: useBalance, + Default: Balance, + fixtures: { + funded: () => ({ credits: 120, topUp: () => {} }), + empty: () => ({ credits: 0, topUp: () => {} }), + }, +}); +// Wherever classic has no place for it yet, a slot places the view. +slots.register('dashboard.after', () => ); +``` `packages/hello-world` overrides the server card, the file details and the file editor, each with @@ -789,6 +815,27 @@ with ``; a theme that may run without the extensi with `optional`, which renders nothing while no installed package defines it. +```tsx +interface BalanceModel { + readonly credits: number; + readonly topUp: () => void; +} + +function useBalance(): BalanceModel { + return { credits: 120, topUp: () => window.open('/billing', '_self') }; +} + +/** The bottom layer of the extension's own view; themes restyle or move it. Built from the UI kit, it takes their skins. */ +function Balance({ model, className }: ExtensionViewProps) { + return ( + {model.credits} credits}> + + + ); +} +``` ### Slots inside views @@ -879,3 +926,2019 @@ primitive in every variant under the active theme. A `className` passed to a primitive is appended to its skin's classes, and a conflicting utility replaces the skin's: `