-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filament): added coluns to infolists (#675)
- Loading branch information
Showing
38 changed files
with
879 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns\Filament\Enums; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* Trait HasColorOrEmoji. | ||
*/ | ||
trait HasColorOrEmoji | ||
{ | ||
/** | ||
* Get the enum as an array formatted for a select, but styled. | ||
* | ||
* @param bool|null $hasColor | ||
* @param bool|null $hasEmoji | ||
* @param string|null $locale | ||
* @return array | ||
*/ | ||
public static function asSelectArrayStyled(?bool $hasColor = true, ?bool $hasEmoji = true, ?string $locale = null): array | ||
{ | ||
$selectArray = []; | ||
|
||
/** @var static $case */ | ||
foreach (static::cases() as $case) { | ||
$selectArray[$case->value] = $case->localizeStyled($hasColor, $hasEmoji, $locale); | ||
} | ||
|
||
return $selectArray; | ||
} | ||
|
||
/** | ||
* Localize the enum, but styled. | ||
* | ||
* @param bool|null $hasColor | ||
* @param bool|null $hasEmoji | ||
* @param string|null $locale | ||
* @return string | ||
*/ | ||
public function localizeStyled(?bool $hasColor = true, ?bool $hasEmoji = true, ?string $locale = null): string | ||
{ | ||
$localizedName = $this->getLocalizedName($locale) ?? $this->getPrettyName(); | ||
|
||
$name = Str::of(''); | ||
|
||
if ($hasColor) { | ||
$color = $this->getColor(); | ||
$name = $name->append("<p style='color: rgb($color);'>"); | ||
} | ||
|
||
if ($hasEmoji) { | ||
$emoji = $this->getEmoji(); | ||
$name = $name->append("$emoji "); | ||
} | ||
|
||
$name = $name->append($localizedName); | ||
|
||
if ($hasColor) { | ||
$name = $name->append('</p>'); | ||
} | ||
|
||
return $name->__toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Components\Infolist; | ||
|
||
use App\Filament\Resources\BaseResource; | ||
use App\Models\BaseModel; | ||
use Filament\Infolists\Components\TextEntry as ComponentsTextEntry; | ||
use Filament\Support\Enums\FontWeight; | ||
|
||
/** | ||
* Class TextEntry. | ||
*/ | ||
class TextEntry extends ComponentsTextEntry | ||
{ | ||
/** | ||
* Used for entry relationships. | ||
* | ||
* @param class-string<BaseResource> $resourceRelated | ||
* @param string $relation | ||
* @return static | ||
*/ | ||
public function urlToRelated(string $resourceRelated, string $relation): static | ||
{ | ||
return $this | ||
->weight(FontWeight::SemiBold) | ||
->html() | ||
->formatStateUsing(fn ($state) => "<p style='color: rgb(64, 184, 166);'>$state</p>") | ||
->url(function (BaseModel $record) use ($resourceRelated, $relation) { | ||
foreach (explode('.', $relation) as $element) { | ||
$record = $record->$element; | ||
} | ||
|
||
return $record !== null ? (new $resourceRelated)::getUrl('edit', ['record' => $record]) : null; | ||
}); | ||
} | ||
|
||
/** | ||
* Make the entry copyable. | ||
* | ||
* @param bool $condition | ||
* @return static | ||
*/ | ||
public function copyableWithMessage(bool $condition = true): static | ||
{ | ||
return $this | ||
->copyable($condition) | ||
->copyMessage(__('filament.actions.base.copied')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.