Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions resources/views/partials/head.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@
@endforeach

<style>
:root {
{{ \Statamic\CP\Color::cssVariables() }}
}
@if (\Statamic\CP\Color::isUsingThemeFile())
{{ \Statamic\CP\Color::themeCss() }}
@else
:root {
{{ \Statamic\CP\Color::cssVariables() }}
}
@endif
</style>

@stack('head')
18 changes: 17 additions & 1 deletion src/CP/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Statamic\CP;

use Statamic\Facades\File;

class Color
{
public const Slate = [
Expand Down Expand Up @@ -400,10 +402,14 @@ public static function defaults(): array
];
}

public static function theme(): array
public static function theme(): array|string
{
$config = config('statamic.cp.theme', []);

if (is_string($config) && File::exists(resource_path('themes/'.$config.'.css'))) {
return $config;
}

foreach ($config['grays'] ?? [] as $shade => $value) {
$config["gray-{$shade}"] = $value;
}
Expand All @@ -413,6 +419,16 @@ public static function theme(): array
->all();
}

public static function isUsingThemeFile(): bool
{
return is_string(static::theme()) && File::exists(resource_path('themes/'.static::theme().'.css'));
}

public static function themeCss(): string
{
return File::get(resource_path('themes/'.static::theme().'.css'));
}

public static function cssVariables(): string
{
return collect(static::theme())
Expand Down