Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: styling loading #11

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions resources/dist/palette-select-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.choices__inner .palette-select-option {
display: flex;
gap: 0.5rem;
align-items: center;
line-height: 1;
height: 1rem;
position: absolute;
top: calc(50% - 0.5rem);
}

.choices__list--dropdown .palette-select-option {
display: flex;
gap: 0.5rem;
align-items: center;
line-height: 1;
height: 1rem;
}

.palette-select-option span {
display: block;
height: 1rem;
line-height: 1;
}

.palette-select-option span:first-child {
width: 1rem;
height: 1rem;
border-radius: 100%;
flex-shrink: 0;
}
28 changes: 2 additions & 26 deletions resources/views/forms/components/select-option.blade.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
<div class="palette-select-option">
@if ($color['type'] === 'class')
<span class="{{ $color['value'] }}" style="display: block; border-radius: 100%; width: 1rem; height: 1rem; flex-shrink: 0;"></span>
<span class="{{ $color['value'] }}"></span>
@else
<span style="display: block; border-radius: 100%; width: 1rem; height: 1rem; flex-shrink: 0; background-color: {{ $color['type'] === 'rgb' ? 'rgba(' . $color['value'] . ', 1)' : $color['value'] }};"></span>
<span style="background-color: {{ $color['type'] === 'rgb' ? 'rgba(' . $color['value'] . ', 1)' : $color['value'] }};"></span>
@endif
<span style="line-height: 1; display: block; height: 1rem;">{{ $color['label'] }}</span>
</div>

@once
@push('styles')
<style>
.choices__inner .palette-select-option {
display: flex;
gap: 0.5rem;
align-items: center;
line-height: 1;
height: 1rem;
position: absolute;
top: calc(50% - 0.5rem);
}

.choices__list--dropdown .palette-select-option {
display: flex;
gap: 0.5rem;
align-items: center;
line-height: 1;
height: 1rem;
}
</style>
@endpush
@endonce
7 changes: 7 additions & 0 deletions src/Forms/Components/ColorPickerSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Filament\Forms\Components\Select;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Blade;
use Js;

class ColorPickerSelect extends Select
{
Expand All @@ -22,7 +23,13 @@ protected function setUp(): void
{
parent::setUp();

$styles = Js::from(\Filament\Support\Facades\FilamentAsset::getStyleHref('palette-select-styles', 'awcodes/palette'));

$this
->extraAttributes([
'x-data' => '',
'x-load-css' => '[' . $styles . ']',
])
->afterStateHydrated(function (ColorPickerSelect $component, string | array | null $state) {
if (! $state) {
return;
Expand Down
9 changes: 9 additions & 0 deletions src/PaletteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Awcodes\Palette;

use Awcodes\Palette\Testing\TestsPalette;
use Filament\Support\Assets\Css;
use Filament\Support\Facades\FilamentAsset;
use Livewire\Features\SupportTesting\Testable;
use ReflectionException;
use Spatie\LaravelPackageTools\Package;
Expand All @@ -27,6 +29,13 @@ public function configurePackage(Package $package): void
*/
public function packageBooted(): void
{
FilamentAsset::register([
Css::make(
id: 'palette-select-styles',
path: __DIR__ . '/../resources/dist/palette-select-styles.css'
)->loadedOnRequest(),
], 'awcodes/palette');

Testable::mixin(new TestsPalette);
}
}