Skip to content

Commit

Permalink
Merge pull request #26 from dissto/extend-icon
Browse files Browse the repository at this point in the history
The icon method now includes more options.
  • Loading branch information
CodeWithDennis authored Oct 13, 2024
2 parents ff09405 + 8abc883 commit 06b8406
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ SimpleAlert::make('example')

### Icon

By default, all simple alerts will have an icon. If you would like to change the icon, you can use the `icon` method.
By default, simple alerts come with an icon. For example, the `->danger()` method includes a `heroicon-s-x-circle` icon. If you want to use a different icon, you can use the icon method.

```php
use CodeWithDennis\SimpleAlert\Components\Infolists\SimpleAlert;
//use Illuminate\Support\HtmlString;

SimpleAlert::make('example')
->color('purple')
->icon('heroicon-s-users')
//->icon(new HtmlString('🤓'))
//->icon(new HtmlString(Blade::render('my-custom-icon-component')))
```

### Title
Expand Down
7 changes: 4 additions & 3 deletions resources/views/components/simple-alert.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$colors = \Illuminate\Support\Arr::toCssStyles([
get_color_css_variables($color, shades: [50, 100, 400, 500, 600, 700, 800]),
]);
@endphp

<div
Expand All @@ -27,14 +28,14 @@
style="{{ $colors }}">
<div class="flex">
@if($icon)
<div class="flex-shrink-0 self-center">
<div class="flex-shrink-0 self-center mr-3">
<x-filament::icon
icon="{{ $icon }}"
:icon="$icon"
class="h-5 w-5 text-custom-400"
/>
</div>
@endif
<div class="ml-3 items-center flex-1 md:flex md:justify-between">
<div class="items-center flex-1 md:flex md:justify-between">
@if($title || $description)
<div>
@if($title)
Expand Down
7 changes: 4 additions & 3 deletions src/Components/Concerns/HasIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
namespace CodeWithDennis\SimpleAlert\Components\Concerns;

use Closure;
use Illuminate\Contracts\Support\Htmlable;

trait HasIcon
{
protected Closure|string|null $icon = null;
protected string|Htmlable|Closure|null $icon = null;

public function icon(Closure|string $icon): static
public function icon(string|Htmlable|Closure|null $icon): static
{
$this->icon = $icon;

return $this;
}

public function getIcon(): ?string
public function getIcon(): string|Htmlable|null
{
return $this->evaluate($this->icon);
}
Expand Down

0 comments on commit 06b8406

Please sign in to comment.