Skip to content

Commit

Permalink
Split up component
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Jun 27, 2024
1 parent 19f6690 commit 325cec1
Show file tree
Hide file tree
Showing 18 changed files with 309 additions and 263 deletions.
Binary file removed img.png
Binary file not shown.
11 changes: 11 additions & 0 deletions resources/views/components/simple-alert-entry.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry">
<x-filament-simple-alert::simple-alert
:icon="$getIcon()"
:color="$getColor()"
:title="$getTitle()"
:description="$getDescription()"
:link="$getLink()"
:link-label="$getLinkLabel()"
:link-blank="$getLinkBlank()"
/>
</x-dynamic-component>
11 changes: 11 additions & 0 deletions resources/views/components/simple-alert-field.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
<x-filament-simple-alert::simple-alert
:icon="$getIcon()"
:color="$getColor()"
:title="$getTitle()"
:description="$getDescription()"
:link="$getLink()"
:link-label="$getLinkLabel()"
:link-blank="$getLinkBlank()"
/>
</x-dynamic-component>
51 changes: 51 additions & 0 deletions resources/views/components/simple-alert.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@props([
'icon' => null,
'color' => null,
'title' => null,
'description' => null,
'link' => null,
'linkLabel' => null,
'linkBlank' => false,
])

@php
use function Filament\Support\get_color_css_variables;
$colors = \Illuminate\Support\Arr::toCssStyles([
get_color_css_variables($color, shades: [50, 400, 500, 600, 700, 800]),
]);
@endphp

<div
x-data="{}"
class="filament-simple-alert rounded-md bg-custom-50 p-4 dark:bg-gray-900 dark:ring-white/10"
style="{{ $colors }}">
<div class="flex">
@if($icon)
<div class="flex-shrink-0 self-center">
<x-filament::icon
icon="{{ $icon }}"
class="h-5 w-5 h-5 w-5 text-custom-400"
/>
</div>
@endif
<div class="ml-3 flex-1 md:flex md:justify-between">
<div>
<p class="text-sm font-medium text-custom-800 dark:text-white">
{!! $title !!}
</p>
<p class="text-sm text-custom-700 dark:text-white">
{!! $description !!}
</p>
</div>
@if($link)
<p class="mt-3 text-sm md:ml-6 md:mt-0 self-center">
<a href="{{ $link }}" {{ $linkBlank ? 'target="_blank"' : '' }} class="whitespace-nowrap font-medium text-custom-400 hover:text-custom-500">
{{ $linkLabel }}
<span aria-hidden="true"> &rarr;</span>
</a>
</p>
@endif
</div>
</div>
</div>
40 changes: 0 additions & 40 deletions resources/views/simple-alert.blade.php

This file was deleted.

22 changes: 22 additions & 0 deletions src/Components/Concerns/HasColor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace CodeWithDennis\SimpleAlert\Components\Concerns;

use Closure;

trait HasColor
{
protected string $color = 'gray';

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

return $this;
}

public function getColor(): string
{
return $this->evaluate($this->color);
}
}
22 changes: 22 additions & 0 deletions src/Components/Concerns/HasDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace CodeWithDennis\SimpleAlert\Components\Concerns;

use Closure;

trait HasDescription
{
protected Closure|string|null $description = null;

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

return $this;
}

public function getDescription(): ?string
{
return $this->evaluate($this->description);
}
}
22 changes: 22 additions & 0 deletions src/Components/Concerns/HasIcon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace CodeWithDennis\SimpleAlert\Components\Concerns;

use Closure;

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

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

return $this;
}

public function getIcon(): ?string
{
return $this->evaluate($this->icon);
}
}
50 changes: 50 additions & 0 deletions src/Components/Concerns/HasLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace CodeWithDennis\SimpleAlert\Components\Concerns;

use Closure;

trait Haslink
{
protected Closure|string|null $link = null;

protected Closure|string $linkLabel = 'Details';

protected Closure|bool|null $linkBlank = false;

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

return $this;
}

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

return $this;
}

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

return $this;
}

public function getLink(): ?string
{
return $this->evaluate($this->link);
}

public function getLinkLabel(): string
{
return $this->evaluate($this->linkLabel);
}

public function getLinkBlank(): bool
{
return $this->evaluate($this->linkBlank);
}
}
38 changes: 38 additions & 0 deletions src/Components/Concerns/HasSimple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace CodeWithDennis\SimpleAlert\Components\Concerns;

trait HasSimple
{
public function danger(): static
{
$this->color = 'danger';
$this->icon = 'heroicon-s-x-circle';

return $this;
}

public function info(): static
{
$this->color = 'info';
$this->icon = 'heroicon-s-information-circle';

return $this;
}

public function success(): static
{
$this->color = 'success';
$this->icon = 'heroicon-s-check-circle';

return $this;
}

public function warning(): static
{
$this->color = 'warning';
$this->icon = 'heroicon-s-exclamation-triangle';

return $this;
}
}
22 changes: 22 additions & 0 deletions src/Components/Concerns/HasTitle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace CodeWithDennis\SimpleAlert\Components\Concerns;

use Closure;

trait HasTitle
{
protected Closure|string|null $title = null;

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

return $this;
}

public function getTitle(): ?string
{
return $this->evaluate($this->title);
}
}
30 changes: 30 additions & 0 deletions src/Components/Forms/SimpleAlert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace CodeWithDennis\SimpleAlert\Components\Forms;

use CodeWithDennis\SimpleAlert\Components\Concerns\HasColor;
use CodeWithDennis\SimpleAlert\Components\Concerns\HasDescription;
use CodeWithDennis\SimpleAlert\Components\Concerns\HasIcon;
use CodeWithDennis\SimpleAlert\Components\Concerns\Haslink;
use CodeWithDennis\SimpleAlert\Components\Concerns\HasSimple;
use CodeWithDennis\SimpleAlert\Components\Concerns\HasTitle;
use Filament\Forms\Components\Field;

class SimpleAlert extends Field
{
use HasColor;
use HasDescription;
use HasIcon;
use Haslink;
use HasSimple;
use HasTitle;

protected string $view = 'filament-simple-alert::components.simple-alert-field';

protected function setUp(): void
{
parent::setUp();

$this->hiddenLabel();
}
}
30 changes: 30 additions & 0 deletions src/Components/Infolists/SimpleAlert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace CodeWithDennis\SimpleAlert\Components\Infolists;

use CodeWithDennis\SimpleAlert\Components\Concerns\HasColor;
use CodeWithDennis\SimpleAlert\Components\Concerns\HasDescription;
use CodeWithDennis\SimpleAlert\Components\Concerns\HasIcon;
use CodeWithDennis\SimpleAlert\Components\Concerns\Haslink;
use CodeWithDennis\SimpleAlert\Components\Concerns\HasSimple;
use CodeWithDennis\SimpleAlert\Components\Concerns\HasTitle;
use Filament\Infolists\Components\Entry;

class SimpleAlert extends Entry
{
use HasColor;
use HasDescription;
use HasIcon;
use Haslink;
use HasSimple;
use HasTitle;

protected string $view = 'filament-simple-alert::components.simple-alert-entry';

protected function setUp(): void
{
parent::setUp();

$this->hiddenLabel();
}
}
Loading

0 comments on commit 325cec1

Please sign in to comment.