Skip to content

Commit

Permalink
Output custom color classes
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Jan 29, 2025
1 parent 648902b commit 7427b60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/support/resources/views/assets.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
:root {
@foreach ($cssVariables ?? [] as $cssVariableName => $cssVariableValue) --{{ $cssVariableName }}:{{ $cssVariableValue }}; @endforeach
}
@foreach ($customColors ?? [] as $customColorName => $customColorShades) .fi-color-{{ $customColorName }} { @foreach ($customColorShades as $customColorShade) --color-{{ $customColorShade }}:var(--{{ $customColorName }}-{{ $customColorShade }}); @endforeach } @endforeach
</style>
15 changes: 12 additions & 3 deletions packages/support/src/Assets/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Filament\Support\Assets;

use Exception;
use Filament\Support\Colors\ColorManager;
use Filament\Support\Facades\FilamentColor;
use Illuminate\Support\Arr;

Expand Down Expand Up @@ -265,11 +266,18 @@ public function getCssVariables(?array $packages = null): array
*/
public function renderStyles(?array $packages = null): string
{
$variables = $this->getCssVariables($packages);
$cssVariables = $this->getCssVariables($packages);
$customColors = [];

$defaultColorNames = array_keys(ColorManager::DEFAULT_COLORS);

foreach (FilamentColor::getColors() as $name => $palette) {
foreach (array_keys($palette) as $shade) {
$variables["{$name}-{$shade}"] = $this->resolveColorShadeFromPalette($palette, $shade);
$cssVariables["{$name}-{$shade}"] = $this->resolveColorShadeFromPalette($palette, $shade);
}

if (! in_array($name, $defaultColorNames)) {
$customColors[$name] = array_keys($palette);
}
}

Expand All @@ -281,7 +289,8 @@ public function renderStyles(?array $packages = null): string
$this->getFonts($packages),
),
],
'cssVariables' => $variables,
'cssVariables' => $cssVariables,
'customColors' => $customColors,
])->render();
}

Expand Down

0 comments on commit 7427b60

Please sign in to comment.