diff --git a/resources/boost/skills/saucebase-themes-development/SKILL.md b/resources/boost/skills/saucebase-themes-development/SKILL.md index 4d22999..71f0cfb 100644 --- a/resources/boost/skills/saucebase-themes-development/SKILL.md +++ b/resources/boost/skills/saucebase-themes-development/SKILL.md @@ -30,7 +30,7 @@ A developer-facing visual theming system for Saucebase. Lets the SaaS owner desi - Theme picker with circle-reveal transition (`@saucebase/core/lib/themeReveal`) - Preview persists in `localStorage` key `sb-theme-theme` (this browser only) - Footer: Delete (saved presets) · Reset · **Set as default** (`writable`) · Save menu (Save / Save as) -- Filament admin theme: a separate settings page (`AdminThemeSettings`), colours/font/radius for the admin panel via `ThemesPlugin` +- Filament admin theme: a separate settings page (`AdminThemeSettings`), colours/font/radius for the admin panel via `ThemesPlugin`. A palette picker on top offers the shipped themes (`AdminThemeSettings::presets()`, read from `resources/themes/*.json`: each theme's light `primary`, and its `sidebar` as the base; the `default` theme is keyed `app-default`, since `default` is the no-colour option, labelled Neutral), or Custom, which shows the colour pickers. The palette isn't stored: picking one fills the colour settings, and `AdminTheme::presetFor()` reads it back from them. Every colour goes through `AdminTheme::generate()`, not Filament's `generatePalette()`: that one keeps only the hue, with a fixed vivid chroma and a light 600, so muted colours came out vivid and buttons pale. `generate()` uses Filament's Indigo shade curve with the chroma scaled to the colour's own, and reads lightness as `0.52` or `52%`. --- diff --git a/src/Admin/AdminTheme.php b/src/Admin/AdminTheme.php index eb21416..c424529 100644 --- a/src/Admin/AdminTheme.php +++ b/src/Admin/AdminTheme.php @@ -14,6 +14,42 @@ class AdminTheme { public const COLORS = ['primary', 'gray', 'danger', 'warning', 'success', 'info']; + /** + * The palette the colours are: a preset's key, `default` with none set, else `custom`. + * + * @param array $colors keyed by Filament colour name + * @param array $presets + */ + public static function presetFor(array $colors, array $presets): string + { + $set = array_filter(array_intersect_key($colors, array_flip(self::COLORS))); + + if ($set === []) { + return 'default'; + } + + foreach ($presets as $key => $preset) { + if ($set === ['primary' => $preset['primary'], 'gray' => $preset['gray']]) { + return $key; + } + } + + return 'custom'; + } + + /** + * Every colour a palette sets: the preset's, null for the rest (and all null for `default`). + * + * @param array $presets + * @return array + */ + public static function presetColors(string $palette, array $presets): array + { + $preset = $presets[$palette] ?? []; + + return array_combine(self::COLORS, array_map(fn (string $color): ?string => $preset[$color] ?? null, self::COLORS)); + } + /** A plain CSS length. The radius is printed into a