Skip to content

Commit

Permalink
Merge pull request #17 from pemudakoding/main
Browse files Browse the repository at this point in the history
V3 Support
  • Loading branch information
pemudakoding authored Aug 4, 2023
2 parents 91bc82b + 043721f commit 0a0e758
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": "^8.1",
"spatie/laravel-package-tools": "^1.13",
"filament/filament": "^2.16"
"filament/filament": "^3.0"
},
"require-dev": {
"laravel/pint": "^1.3",
Expand Down Expand Up @@ -40,7 +40,7 @@
]
}
},
"minimum-stability": "stable",
"minimum-stability": "dev",
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
Expand Down
16 changes: 8 additions & 8 deletions resources/views/components/base-alert-box.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

@php
$backgroundClass = match($type) {
'primary' => 'bg-primary-500',
'success' => 'bg-success-500',
'warning' => 'bg-warning-500',
'danger' => 'bg-danger-500',
'secondary' => 'bg-gray-500',
'primary' => '--c-300: var(--primary-300);--c-400: var(--primary-400);--c-500: var(--primary-500);--c-600: var(--primary-600);',
'success' => '--c-300: var(--success-300);--c-400: var(--success-400);--c-500: var(--success-500);--c-600: var(--success-600);',
'warning' => '--c-300: var(--warning-300);--c-400: var(--warning-400);--c-500: var(--warning-500);--c-600: var(--warning-600);',
'danger' => '--c-300: var(--danger-300);--c-400: var(--danger-400);--c-500: var(--danger-500);--c-600: var(--danger-600);',
'secondary' => '--c-300: var(--gray-300);--c-400: var(--gray-400);--c-500: var(--gray-500);--c-600: var(--gray-600);',
};
$textColor = 'text-gray-50';
@endphp
<div {{ $attributes
->merge($extraAttributes)
->style(styleList: $backgroundClass)
->class(
[
'filament-forms-text-input-component flex items-center space-x-2 rtl:space-x-reverse group p-5 rounded-lg',
$backgroundClass,
$textColor
'filament-forms-text-input-component flex items-center space-x-2 rtl:space-x-reverse group p-4 rounded-lg bg-custom-600',
'text-white'
]
)
}}
Expand Down
4 changes: 2 additions & 2 deletions resources/views/widgets/filament-alertbox.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<x-filament::widget class="filament-alert-box-widget">
<x-filament-widgets::widget class="filament-alert-box-widget">
<x-filament-alertbox::base-alert-box
:type="$this->getType()"
:extraAttributes="$this->getExtraAttributes()"
:icon="$this->getIcon()"
:label="$this->getLabel()"
:helperText="$this->getHelperText()"
/>
</x-filament::widget>
</x-filament-widgets::widget>
2 changes: 1 addition & 1 deletion src/Concerns/Forms/HasType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function warning(): static
{
$this->type = 'warning';

$this->icon = 'heroicon-o-exclamation';
$this->icon = 'heroicon-o-exclamation-triangle';

return $this;
}
Expand Down
8 changes: 5 additions & 3 deletions src/FilamentAlertBoxServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace KoalaFacade\FilamentAlertBox;

use Filament\PluginServiceProvider;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class FilamentAlertBoxServiceProvider extends PluginServiceProvider
class FilamentAlertBoxServiceProvider extends PackageServiceProvider
{
public static string $name = 'filament-alertbox';

/**
* @var string[]
*/
Expand All @@ -17,7 +19,7 @@ class FilamentAlertBoxServiceProvider extends PluginServiceProvider
public function configurePackage(Package $package): void
{
$package
->name(name: 'filament-alertbox')
->name(name: static::$name)
->hasViews();
}
}
14 changes: 6 additions & 8 deletions src/Widgets/AlertBoxWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
use Filament\Support\Concerns\EvaluatesClosures;
use Filament\Support\Concerns\HasExtraAttributes;
use Filament\Tables\Columns\Concerns\HasLabel;
use Illuminate\Contracts\View\Factory;
use Filament\Widgets\ChartWidget;
use Illuminate\Contracts\View\View;
use KoalaFacade\FilamentAlertBox\Concerns\HasIcon;
use KoalaFacade\FilamentAlertBox\Concerns\HasType;
use Livewire\Component;

class AlertBoxWidget extends Component
class AlertBoxWidget extends ChartWidget
{
use EvaluatesClosures,
HasExtraAttributes,
Expand All @@ -23,12 +22,8 @@ class AlertBoxWidget extends Component

protected static string $view = 'filament-alertbox::widgets.filament-alertbox';

/** @var int | string | array<int, string> */
protected int | string | array $columnSpan = 1;

/**
* @return int | string | array<int, string>
*/
public function getColumnSpan(): int | string | array
{
return $this->columnSpan;
Expand All @@ -39,8 +34,11 @@ public static function canView(): bool
return true;
}

public function render(): Factory | View
public function render(): View
{
/**
* @phpstan-ignore-next-line
*/
return view(static::$view);
}
}
10 changes: 5 additions & 5 deletions tests/Livewire/Forms/AlertBoxBackgroundColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
];

livewire(name: CreatePost::class)
->assertSee(values: baseClassWith(backgroundColor: 'bg-success-500', textColor: 'text-gray-50'));
->assertSee(values: '--c-300: var(--success-300);--c-400: var(--success-400);--c-500: var(--success-500);--c-600: var(--success-600);');
});

it(description: 'can show success background color when type is warning')
Expand All @@ -27,19 +27,19 @@
];

livewire(name: CreatePost::class)
->assertSee(values: baseClassWith(backgroundColor: 'bg-warning-500', textColor: 'text-gray-50'));
->assertSee(values: '--c-300: var(--warning-300);--c-400: var(--warning-400);--c-500: var(--warning-500);--c-600: var(--warning-600);');
});

it(description: 'can show success background color when type is primary')
->tap(callable: function () {
CreatePost::$formSchema = [
AlertBox::make()
->helperText(text: 'tests')
->primary(),
->info(),
];

livewire(name: CreatePost::class)
->assertSee(values: baseClassWith(backgroundColor: 'bg-primary-500', textColor: 'text-gray-50'));
->assertSee(values: '--c-300: var(--primary-300);--c-400: var(--primary-400);--c-500: var(--primary-500);--c-600: var(--primary-600);');
});

it(description: 'can show success background color when type is danger')
Expand All @@ -51,5 +51,5 @@
];

livewire(name: CreatePost::class)
->assertSee(values: baseClassWith(backgroundColor: 'bg-danger-500', textColor: 'text-gray-50'));
->assertSee(values: '--c-300: var(--danger-300);--c-400: var(--danger-400);--c-500: var(--danger-500);--c-600: var(--danger-600);');
});
2 changes: 1 addition & 1 deletion tests/Livewire/Widget/WidgetOkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
->tap(callable: function () {
livewire(name: WidgetTestComponent::class)->assertOk()
->assertSee(values: ['Test', 'please shut u freakin mouth', 'icon px-3 mr-2'])
->assertSee(values: baseClassWith(backgroundColor: 'bg-success-500', textColor: 'text-gray-50'));
->assertSee(values: '--c-300: var(--success-300);--c-400: var(--success-400);--c-500: var(--success-500);--c-600: var(--success-600);');
})
->group('widget');
3 changes: 1 addition & 2 deletions tests/Livewire/Widget/WidgetTestComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

use Closure;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString;
use KoalaFacade\FilamentAlertBox\Widgets\AlertBoxWidget;

class WidgetTestComponent extends AlertBoxWidget
{
public string | Closure | null $icon = 'heroicon-o-exclamation';
public string | Closure | null $icon = 'heroicon-o-exclamation-triangle';

public string $type = 'success';

Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Filament\FilamentServiceProvider;
use Filament\Forms\FormsServiceProvider;
use Filament\Support\SupportServiceProvider;
use Filament\Widgets\WidgetsServiceProvider;
use Illuminate\Encryption\Encrypter;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
Expand All @@ -27,6 +28,7 @@ protected function getPackageProviders($app): array
return [
FilamentAlertBoxServiceProvider::class,
FilamentServiceProvider::class,
WidgetsServiceProvider::class,
ViewServiceProvider::class,
LivewireServiceProvider::class,
FormsServiceProvider::class,
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/AlertBoxIconTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
$alertBox = AlertBox::make()
->warning();

expect(value: $alertBox->getIcon())->toEqual(expected: 'heroicon-o-exclamation');
expect(value: $alertBox->getIcon())->toEqual(expected: 'heroicon-o-exclamation-triangle');
});

0 comments on commit 0a0e758

Please sign in to comment.