Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s

- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

View file

@ -0,0 +1,179 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Illuminate\Contracts\Database\Query\Expression;
trait CanAggregateRelatedModels
{
protected string | Expression | Closure | null $columnToAvg = null;
/**
* @var string | array<int | string, string | Closure> | Closure | null
*/
protected string | array | Closure | null $relationshipToAvg = null;
/**
* @var string | array<int | string, string | Closure> | Closure | null
*/
protected string | array | Closure | null $relationshipsToCount = null;
/**
* @var string | array<int | string, string | Closure> | Closure | null
*/
protected string | array | Closure | null $relationshipsToExistenceCheck = null;
protected string | Expression | Closure | null $columnToMax = null;
/**
* @var string | array<int | string, string | Closure> | Closure | null
*/
protected string | array | Closure | null $relationshipToMax = null;
protected string | Expression | Closure | null $columnToMin = null;
/**
* @var string | array<int | string, string | Closure> | Closure | null
*/
protected string | array | Closure | null $relationshipToMin = null;
protected string | Expression | Closure | null $columnToSum = null;
/**
* @var string | array<int | string, string | Closure> | Closure | null
*/
protected string | array | Closure | null $relationshipToSum = null;
/**
* @param string | array<int | string, string | Closure> | Closure | null $relationship
*/
public function avg(string | array | Closure | null $relationship, string | Expression | Closure | null $column): static
{
$this->columnToAvg = $column;
$this->relationshipToAvg = $relationship;
return $this;
}
/**
* @param string | array<int | string, string | Closure> | Closure | null $relationships
*/
public function counts(string | array | Closure | null $relationships): static
{
$this->relationshipsToCount = $relationships;
return $this;
}
/**
* @param string | array<int | string, string | Closure> | Closure | null $relationships
*/
public function exists(string | array | Closure | null $relationships): static
{
$this->relationshipsToExistenceCheck = $relationships;
return $this;
}
/**
* @param string | array<int | string, string | Closure> | Closure | null $relationship
*/
public function max(string | array | Closure | null $relationship, string | Expression | Closure | null $column): static
{
$this->columnToMax = $column;
$this->relationshipToMax = $relationship;
return $this;
}
/**
* @param string | array<int | string, string | Closure> | Closure | null $relationship
*/
public function min(string | array | Closure | null $relationship, string | Expression | Closure | null $column): static
{
$this->columnToMin = $column;
$this->relationshipToMin = $relationship;
return $this;
}
/**
* @param string | array<int | string, string | Closure> | Closure | null $relationship
*/
public function sum(string | array | Closure | null $relationship, string | Expression | Closure | null $column): static
{
$this->columnToSum = $column;
$this->relationshipToSum = $relationship;
return $this;
}
public function getColumnToAvg(): string | Expression | null
{
return $this->evaluate($this->columnToAvg);
}
/**
* @return string | array<int | string, string | Closure> | null
*/
public function getRelationshipToAvg(): string | array | null
{
return $this->evaluate($this->relationshipToAvg);
}
/**
* @return string | array<int | string, string | Closure> | null
*/
public function getRelationshipsToCount(): string | array | null
{
return $this->evaluate($this->relationshipsToCount);
}
/**
* @return string | array<int | string, string | Closure> | null
*/
public function getRelationshipsToExistenceCheck(): string | array | null
{
return $this->evaluate($this->relationshipsToExistenceCheck);
}
public function getColumnToMax(): string | Expression | null
{
return $this->evaluate($this->columnToMax);
}
/**
* @return string | array<int | string, string | Closure> | null
*/
public function getRelationshipToMax(): string | array | null
{
return $this->evaluate($this->relationshipToMax);
}
public function getColumnToMin(): string | Expression | null
{
return $this->evaluate($this->columnToMin);
}
/**
* @return string | array<int | string, string | Closure> | null
*/
public function getRelationshipToMin(): string | array | null
{
return $this->evaluate($this->relationshipToMin);
}
public function getColumnToSum(): string | Expression | null
{
return $this->evaluate($this->columnToSum);
}
/**
* @return string | array<int | string, string | Closure> | null
*/
public function getRelationshipToSum(): string | array | null
{
return $this->evaluate($this->relationshipToSum);
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait CanBeContained
{
protected bool | Closure $isContained = true;
protected bool $isContainedCache;
public function contained(bool | Closure $condition = true): static
{
$this->isContained = $condition;
return $this;
}
public function isContained(): bool
{
return $this->isContainedCache ??= (bool) $this->evaluate($this->isContained);
}
}

View file

@ -0,0 +1,77 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait CanBeCopied
{
protected bool | Closure $isCopyable = false;
protected string | Closure | null $copyableState = null;
protected string | Closure | null $copyMessage = null;
protected int | Closure | null $copyMessageDuration = null;
public function copyable(bool | Closure $condition = true): static
{
$this->isCopyable = $condition;
return $this;
}
public function copyableState(string | Closure | null $state): static
{
$this->copyableState = $state;
return $this;
}
public function copyMessage(string | Closure | null $message): static
{
$this->copyMessage = $message;
return $this;
}
public function copyMessageDuration(int | Closure | null $duration): static
{
$this->copyMessageDuration = $duration;
return $this;
}
public function isCopyable(mixed $state): bool
{
return (bool) $this->evaluate($this->isCopyable, [
'state' => $state,
]);
}
public function getCopyableState(mixed $state): ?string
{
return $this->evaluate($this->copyableState, [
'state' => $state,
]);
}
public function getCopyMessage(mixed $state): string
{
return $this->evaluate($this->copyMessage, [
'state' => $state,
]) ?? __('filament::components/copyable.messages.copied');
}
public function getCopyMessageDuration(mixed $state): int
{
return $this->evaluate($this->copyMessageDuration, [
'state' => $state,
]) ?? 2000;
}
public function hasCopyable(): bool
{
return $this->isCopyable !== false;
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace Filament\Support\Concerns;
use Illuminate\Contracts\View\View;
trait CanBeLazy
{
protected static bool $isLazy = true;
protected ?string $placeholderHeight = null;
public static function isLazy(): bool
{
return static::$isLazy;
}
public function placeholder(): View
{
return view(
'filament::components.loading-section',
[
'height' => $this->getPlaceholderHeight(),
...$this->getPlaceholderData(),
],
);
}
/**
* @return array<string, mixed>
*/
public function getPlaceholderData(): array
{
return [
//
];
}
public function getPlaceholderHeight(): ?string
{
return $this->placeholderHeight;
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Filament\Support\Concerns;
trait CanCallHooks
{
protected function callHook(string $hook): void
{
if (method_exists($this, $hook)) {
$this->{$hook}();
}
$calledTraitHooks = [];
foreach (class_uses_recursive($this) as $trait) {
$method = $hook . class_basename($trait);
if (method_exists($this, $method) && (! in_array($method, $calledTraitHooks, strict: true))) {
$this->{$method}();
$calledTraitHooks[] = $method;
}
}
}
}

View file

@ -0,0 +1,55 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use League\CommonMark\Extension\ExtensionInterface;
trait CanConfigureCommonMark
{
/**
* @var array<string, mixed> | Closure | null
*/
protected array | Closure | null $commonMarkOptions = null;
/**
* @var array<array-key, ExtensionInterface> | Closure | null
*/
protected array | Closure | null $commonMarkExtensions = null;
/**
* @param array<string, mixed> | Closure | null $commonMarkOptions
*/
public function commonMarkOptions(array | Closure | null $commonMarkOptions): static
{
$this->commonMarkOptions = $commonMarkOptions;
return $this;
}
/**
* @return array<string, mixed>
*/
public function getCommonMarkOptions(): array
{
return $this->evaluate($this->commonMarkOptions) ?? [];
}
/**
* @param array<array-key, ExtensionInterface> | Closure | null $commonMarkExtensions
*/
public function commonMarkExtensions(array | Closure | null $commonMarkExtensions): static
{
$this->commonMarkExtensions = $commonMarkExtensions;
return $this;
}
/**
* @return array<array-key, ExtensionInterface>
*/
public function getCommonMarkExtensions(): array
{
return $this->evaluate($this->commonMarkExtensions) ?? [];
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait CanGrow
{
protected bool | Closure | null $canGrow = null;
public function grow(bool | Closure | null $condition = true): static
{
$this->canGrow = $condition;
return $this;
}
public function canGrow(bool $default = true): bool
{
return (bool) ($this->evaluate($this->canGrow) ?? $default);
}
}

View file

@ -0,0 +1,90 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait CanOrderColumns
{
/**
* @var array<string | int, int | Closure | null> | null
*/
protected ?array $columnOrder = null;
/**
* @param array<string, int | Closure | null> | int | Closure | null $order
*/
public function columnOrder(array | int | Closure | null $order): static
{
if ($order instanceof Closure) {
$this->columnOrder[] = $order;
return $this;
}
if (! is_array($order)) {
$order = [
'lg' => $order,
];
}
$this->columnOrder = [
...($this->columnOrder ?? []),
...$order,
];
return $this;
}
/**
* @return array<string, ?int> | int | null
*/
public function getColumnOrder(int | string | null $breakpoint = null): array | int | null
{
$order = $this->columnOrder ?? [
'default' => null,
'sm' => null,
'md' => null,
'lg' => null,
'xl' => null,
'2xl' => null,
];
foreach ($this->columnOrder ?? [] as $columnOrderBreakpoint => $columnOrder) {
$columnOrder = $this->evaluate($columnOrder);
if (is_array($columnOrder)) {
$order = [
...$order,
...$columnOrder,
];
unset($order[$columnOrderBreakpoint]);
continue;
}
if (blank($columnOrderBreakpoint)) {
unset($order[$columnOrderBreakpoint]);
continue;
}
if (! is_string($columnOrderBreakpoint)) {
$order['default'] = $columnOrder;
unset($order[$columnOrderBreakpoint]);
continue;
}
$order[$columnOrderBreakpoint] = $columnOrder;
}
if ($breakpoint !== null) {
return $this->evaluate($order[$breakpoint] ?? null);
}
return $order;
}
}

View file

@ -0,0 +1,180 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait CanSpanColumns
{
/**
* @var array<string | int, int | string | Closure | null> | null
*/
protected ?array $columnSpan = null;
/**
* @var array<string | int, int | string | Closure | null> | null
*/
protected ?array $columnStart = null;
/**
* @param array<string, int | string | Closure | null> | int | string | Closure | null $span
*/
public function columnSpan(array | int | string | Closure | null $span): static
{
if ($span instanceof Closure) {
$this->columnSpan[] = $span;
return $this;
}
if (! is_array($span)) {
$span = [
'default' => 1,
'lg' => $span,
];
}
$this->columnSpan = [
...($this->columnSpan ?? []),
...$span,
];
return $this;
}
public function columnSpanFull(): static
{
$this->columnSpan(['default' => 'full']);
return $this;
}
/**
* @param array<string, int | string | Closure | null> | int | string | Closure | null $start
*/
public function columnStart(array | int | string | Closure | null $start): static
{
if ($start instanceof Closure) {
$this->columnStart[] = $start;
return $this;
}
if (! is_array($start)) {
$start = [
'lg' => $start,
];
}
$this->columnStart = [
...($this->columnStart ?? []),
...$start,
];
return $this;
}
/**
* @return array<string, int | string | null> | int | string | null
*/
public function getColumnSpan(int | string | null $breakpoint = null): array | int | string | null
{
$span = $this->columnSpan ?? [
'default' => 1,
'sm' => null,
'md' => null,
'lg' => null,
'xl' => null,
'2xl' => null,
];
foreach ($this->columnSpan ?? [] as $columnSpanBreakpoint => $columnSpan) {
$columnSpan = $this->evaluate($columnSpan);
if (is_array($columnSpan)) {
$span = [
...$span,
...$columnSpan,
];
unset($span[$columnSpanBreakpoint]);
continue;
}
if (blank($columnSpanBreakpoint)) {
unset($span[$columnSpanBreakpoint]);
continue;
}
if (! is_string($columnSpanBreakpoint)) {
$span['default'] = $columnSpan;
unset($span[$columnSpanBreakpoint]);
continue;
}
$span[$columnSpanBreakpoint] = $columnSpan;
}
if ($breakpoint !== null) {
return $this->evaluate($span[$breakpoint] ?? null);
}
return $span;
}
/**
* @return array<string, int | string | null> | int | string | null
*/
public function getColumnStart(int | string | null $breakpoint = null): array | int | string | null
{
$start = $this->columnStart ?? [
'default' => null,
'sm' => null,
'md' => null,
'lg' => null,
'xl' => null,
'2xl' => null,
];
foreach ($this->columnStart ?? [] as $columnStartBreakpoint => $columnStart) {
$columnStart = $this->evaluate($columnStart);
if (is_array($columnStart)) {
$start = [
...$start,
...$columnStart,
];
unset($start[$columnStartBreakpoint]);
continue;
}
if (blank($columnStartBreakpoint)) {
unset($start[$columnStartBreakpoint]);
continue;
}
if (! is_string($columnStartBreakpoint)) {
$start['default'] = $columnStart;
unset($start[$columnStartBreakpoint]);
continue;
}
$start[$columnStartBreakpoint] = $columnStart;
}
if ($breakpoint !== null) {
return $this->evaluate($start[$breakpoint] ?? null);
}
return $start;
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait CanWrap
{
protected bool | Closure | null $canWrap = null;
public function wrap(bool | Closure | null $condition = true): static
{
$this->canWrap = $condition;
return $this;
}
public function canWrap(): bool
{
return (bool) ($this->evaluate($this->canWrap) ?? $this->canWrapByDefault());
}
public function canWrapByDefault(): bool
{
return false;
}
public function hasWrap(): bool
{
return $this->canWrap !== null || $this->canWrapByDefault();
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait CanWrapHeader
{
protected bool | Closure $canHeaderWrap = false;
public function wrapHeader(bool | Closure $condition = true): static
{
$this->canHeaderWrap = $condition;
return $this;
}
public function canHeaderWrap(): bool
{
return (bool) $this->evaluate($this->canHeaderWrap);
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\Components\ComponentManager;
trait Configurable
{
public static function configureUsing(Closure $modifyUsing, ?Closure $during = null, bool $isImportant = false): mixed
{
return ComponentManager::resolve()->configureUsing(
static::class,
$modifyUsing,
$during,
$isImportant,
);
}
public function configure(): static
{
ComponentManager::resolve()->configure(
$this,
$this->setUp(...),
);
return $this;
}
protected function setUp(): void {}
}

View file

@ -0,0 +1,166 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\Model;
use ReflectionFunction;
use ReflectionNamedType;
use ReflectionParameter;
trait EvaluatesClosures
{
protected string $evaluationIdentifier;
/**
* @template T
*
* @param T | callable(): T $value
* @param array<string, mixed> $namedInjections
* @param array<string, mixed> $typedInjections
* @return T
*/
public function evaluate(mixed $value, array $namedInjections = [], array $typedInjections = []): mixed
{
if (! $value instanceof Closure) {
return $value;
}
$dependencies = [];
foreach ((new ReflectionFunction($value))->getParameters() as $parameter) {
$dependencies[] = $this->resolveClosureDependencyForEvaluation($parameter, $namedInjections, $typedInjections);
}
return $value(...$dependencies);
}
/**
* @param array<string, mixed> $namedInjections
* @param array<string, mixed> $typedInjections
*/
protected function resolveClosureDependencyForEvaluation(ReflectionParameter $parameter, array $namedInjections, array $typedInjections): mixed
{
$parameterName = $parameter->getName();
if (array_key_exists($parameterName, $namedInjections)) {
return value($namedInjections[$parameterName]);
}
$typedParameterClassName = $this->getTypedReflectionParameterClassName($parameter);
if (filled($typedParameterClassName) && array_key_exists($typedParameterClassName, $typedInjections)) {
return value($typedInjections[$typedParameterClassName]);
}
// Dependencies are wrapped in an array to differentiate between null and no value.
$defaultWrappedDependencyByName = $this->resolveDefaultClosureDependencyForEvaluationByName($parameterName);
if (count($defaultWrappedDependencyByName)) {
// Unwrap the dependency if it was resolved.
return $defaultWrappedDependencyByName[0];
}
if (filled($typedParameterClassName)) {
// Dependencies are wrapped in an array to differentiate between null and no value.
$defaultWrappedDependencyByType = $this->resolveDefaultClosureDependencyForEvaluationByType($typedParameterClassName);
if (count($defaultWrappedDependencyByType)) {
// Unwrap the dependency if it was resolved.
return $defaultWrappedDependencyByType[0];
}
}
if (
(
isset($this->evaluationIdentifier) &&
($parameterName === $this->evaluationIdentifier)
) ||
(is_string($typedParameterClassName) && is_a($this, $typedParameterClassName))
) {
return $this;
}
if (
filled($typedParameterClassName)
&& (! is_subclass_of($typedParameterClassName, Model::class) || app()->bound($typedParameterClassName))
) {
return app()->make($typedParameterClassName);
}
if ($parameter->isDefaultValueAvailable()) {
return $parameter->getDefaultValue();
}
if ($parameter->isOptional() || $parameter->allowsNull()) {
return null;
}
$staticClass = static::class;
throw new BindingResolutionException("An attempt was made to evaluate a closure for [{$staticClass}], but [\${$parameterName}] was unresolvable.");
}
protected function evaluationValueIsFunctionAndHasParameter(mixed $value, string $parameterName): bool
{
if (! $value instanceof Closure) {
return false;
}
foreach ((new ReflectionFunction($value))->getParameters() as $parameter) {
if ($parameter->getName() === $parameterName) {
return true;
}
}
return false;
}
/**
* @return array<mixed>
*/
protected function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array
{
return [];
}
/**
* @return array<mixed>
*/
protected function resolveDefaultClosureDependencyForEvaluationByType(string $parameterType): array
{
return [];
}
protected function getTypedReflectionParameterClassName(ReflectionParameter $parameter): ?string
{
$type = $parameter->getType();
if (! $type instanceof ReflectionNamedType) {
return null;
}
if ($type->isBuiltin()) {
return null;
}
$name = $type->getName();
$class = $parameter->getDeclaringClass();
if (is_null($class)) {
return $name;
}
if ($name === 'self') {
return $class->getName();
}
if ($name === 'parent' && ($parent = $class->getParentClass())) {
return $parent->getName();
}
return $name;
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\Enums\Alignment;
trait HasAlignment
{
protected Alignment | string | Closure | null $alignment = null;
public function alignment(Alignment | string | Closure | null $alignment): static
{
$this->alignment = $alignment;
return $this;
}
public function alignStart(bool | Closure $condition = true): static
{
return $this->alignment(fn (): ?Alignment => $this->evaluate($condition) ? Alignment::Start : null);
}
public function alignCenter(bool | Closure $condition = true): static
{
return $this->alignment(fn (): ?Alignment => $this->evaluate($condition) ? Alignment::Center : null);
}
public function alignEnd(bool | Closure $condition = true): static
{
return $this->alignment(fn (): ?Alignment => $this->evaluate($condition) ? Alignment::End : null);
}
public function alignJustify(bool | Closure $condition = true): static
{
return $this->alignment(fn (): ?Alignment => $this->evaluate($condition) ? Alignment::Justify : null);
}
public function alignBetween(bool | Closure $condition = true): static
{
return $this->alignment(fn (): ?Alignment => $this->evaluate($condition) ? Alignment::Between : null);
}
public function alignLeft(bool | Closure $condition = true): static
{
return $this->alignment(fn (): ?Alignment => $this->evaluate($condition) ? Alignment::Left : null);
}
public function alignRight(bool | Closure $condition = true): static
{
return $this->alignment(fn (): ?Alignment => $this->evaluate($condition) ? Alignment::Right : null);
}
public function getAlignment(): Alignment | string | null
{
$alignment = $this->evaluate($this->alignment);
if (! is_string($alignment)) {
return $alignment;
}
return Alignment::tryFrom($alignment) ?? $alignment;
}
public function hasDynamicAlignment(): bool
{
return $this->alignment instanceof Closure;
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait HasBadge
{
protected string | Closure | null $badge = null;
/**
* @var string | array<string> | Closure | null
*/
protected string | array | Closure | null $badgeColor = null;
public function badge(string | int | float | Closure | null $badge): static
{
if (is_int($badge) || is_float($badge)) {
$badge = (string) $badge;
}
$this->badge = $badge;
return $this;
}
/**
* @deprecated Use `badge()` instead.
*/
public function indicator(string | int | float | Closure | null $indicator): static
{
return $this->badge($indicator);
}
/**
* @param string | array<string> | Closure | null $color
*/
public function badgeColor(string | array | Closure | null $color): static
{
$this->badgeColor = $color;
return $this;
}
/**
* @deprecated Use `badgeColor()` instead.
*/
public function indicatorColor(string | Closure | null $color): static
{
return $this->badgeColor($color);
}
public function getBadge(): ?string
{
return $this->evaluate($this->badge);
}
/**
* @return string | array<string> | null
*/
public function getBadgeColor(?string $badge = null): string | array | null
{
return $this->evaluate($this->badgeColor, [
'badge' => $badge,
]);
}
public function hasBadge(): bool
{
return $this->badge !== null;
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Illuminate\Contracts\Support\Htmlable;
trait HasBadgeTooltip
{
protected string | Htmlable | Closure | null $badgeTooltip = null;
public function badgeTooltip(string | Htmlable | Closure | null $tooltip): static
{
$this->badgeTooltip = $tooltip;
return $this;
}
public function getBadgeTooltip(?string $badge = null): string | Htmlable | null
{
return $this->evaluate($this->badgeTooltip, [
'badge' => $badge,
]);
}
}

View file

@ -0,0 +1,605 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Forms\Components\RichEditor\Models\Contracts\HasRichContent;
use Filament\Support\ArrayRecord;
use Filament\Tables\Columns\Column;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Stringable;
use LogicException;
use Znck\Eloquent\Relations\BelongsToThrough;
trait HasCellState
{
protected mixed $defaultState = null;
protected mixed $getStateUsing = null;
protected string | Closure | null $separator = null;
protected bool | Closure $isDistinctList = false;
protected ?string $inverseRelationshipName = null;
/**
* @var array<string, mixed>
*/
protected array $cachedState = [];
protected ?bool $hasMultipleRelationshipCache = null;
protected ?Relation $relationshipCache = null;
protected ?bool $hasRelationshipCache = null;
protected ?string $relationshipNameCache = null;
protected ?string $fullAttributeNameCache = null;
protected ?string $attributeNameCache = null;
protected ?bool $hasNestedMorphToRelationshipCache = null;
public function inverseRelationship(?string $name): static
{
$this->inverseRelationshipName = $name;
return $this;
}
public function distinctList(bool | Closure $condition = true): static
{
$this->isDistinctList = $condition;
return $this;
}
public function getStateUsing(mixed $callback): static
{
$this->getStateUsing = $callback;
return $this;
}
public function state(mixed $state): static
{
$this->getStateUsing($state);
return $this;
}
public function default(mixed $state): static
{
$this->defaultState = $state;
return $this;
}
public function isDistinctList(): bool
{
return (bool) $this->evaluate($this->isDistinctList);
}
public function getDefaultState(): mixed
{
return $this->evaluate($this->defaultState);
}
public function getState(): mixed
{
return $this->cacheState(function (): mixed {
$state = ($this->getStateUsing !== null) ?
$this->evaluate($this->getStateUsing) :
$this->getStateFromRecord();
if (is_string($state) && ($separator = $this->getSeparator())) {
$state = explode($separator, $state);
$state = (count($state) === 1 && blank($state[0])) ?
[] :
$state;
}
if (blank($state)) {
$state = $this->getDefaultState();
}
return $state;
});
}
public function getStateFromRecord(): mixed
{
$record = $this->getRecord();
if ($record instanceof Model) {
$relationship = $this->getRelationship($record);
if ($relationship) {
$relationshipAttribute = $this->getFullAttributeName($record);
$state = collect($this->getRelationshipResults($record))
->reduce(
function (Collection $carry, Model $record) use ($relationshipAttribute): Collection {
if (
($record instanceof HasRichContent) &&
$record->hasRichContentAttribute($relationshipAttribute)
) {
$state = $record->getRichContentAttribute($relationshipAttribute);
} else {
$state = data_get($record, $relationshipAttribute);
}
if (blank($state)) {
return $carry;
}
return $carry->push($state);
},
initial: collect(),
)
->when($this->isDistinctList(), fn (Collection $state) => $state->unique())
->values();
if (! $state->count()) {
return null;
}
if (($state->count() < 2) && (! $this->hasMultipleRelationship($record))) {
return $state->first();
}
return $state->all();
}
}
$name = $this->getName();
if (
($record instanceof HasRichContent) &&
$record->hasRichContentAttribute($name)
) {
$state = $record->getRichContentAttribute($name);
} else {
$state = data_get($record, $name);
}
return $state;
}
public function clearCachedState(): void
{
$this->cachedState = [];
}
public function separator(string | Closure | null $separator = ','): static
{
$this->separator = $separator;
return $this;
}
public function getSeparator(): ?string
{
return $this->evaluate($this->separator);
}
public function hasRelationship(Model $record): bool
{
if (isset($this->hasRelationshipCache)) {
return $this->hasRelationshipCache;
}
$name = $this->getName();
if (! str($name)->contains('.')) {
return $this->hasRelationshipCache = false;
}
if ($record->hasAttribute((string) str($name)->before('.'))) {
return $this->hasRelationshipCache = false;
}
return $this->hasRelationshipCache = $record->isRelation((string) str($name)->before('.'));
}
/**
* @deprecated Use `hasRelationship()` instead.
*/
public function queriesRelationships(Model $record): bool
{
return $this->hasRelationship($record);
}
public function getRelationship(Model $record, ?string $relationshipName = null): ?Relation
{
$hasNestedMorphToRelationship = $this->hasNestedMorphToRelationship($record);
if ($this->relationshipCache && (! $hasNestedMorphToRelationship)) {
return $this->relationshipCache;
}
if (isset($relationshipName)) {
$nameParts = explode('.', $relationshipName);
} else {
$name = $this->getName();
if (! str($name)->contains('.')) {
return null;
}
$nameParts = explode('.', $name);
array_pop($nameParts);
}
$relationship = null;
foreach ($nameParts as $namePart) {
if ($record->hasAttribute($namePart)) {
break;
}
if (! $record->isRelation($namePart)) {
break;
}
$relationship = $record->{$namePart}();
$record = $relationship->getRelated();
}
if ($hasNestedMorphToRelationship) {
return $relationship;
}
return $this->relationshipCache = $relationship;
}
public function hasMultipleRelationship(Model $record): bool
{
$hasNestedMorphToRelationship = $this->hasNestedMorphToRelationship($record);
if (isset($this->hasMultipleRelationshipCache) && (! $hasNestedMorphToRelationship)) {
return $this->hasMultipleRelationshipCache;
}
$hasMultipleRelationship = false;
$relationships = explode('.', $this->getRelationshipName($record));
while (count($relationships)) {
$currentRelationshipName = array_shift($relationships);
$currentRelationshipValue = $record->getRelationValue($currentRelationshipName);
if ($currentRelationshipValue instanceof Collection) {
$hasMultipleRelationship = true;
break;
}
if (! $currentRelationshipValue instanceof Model) {
break;
}
if (! count($relationships)) {
break;
}
$record = $currentRelationshipValue;
}
if ($hasNestedMorphToRelationship) {
return $hasMultipleRelationship;
}
return $this->hasMultipleRelationshipCache = $hasMultipleRelationship;
}
/**
* @param array<string> | null $relationships
* @return array<Model>
*/
public function getRelationshipResults(Model $record, ?array $relationships = null): array
{
$results = [];
$relationships ??= explode('.', $this->getRelationshipName($record));
while (count($relationships)) {
$currentRelationshipName = array_shift($relationships);
$currentRelationshipValue = $record->getRelationValue($currentRelationshipName);
if ($currentRelationshipValue instanceof Collection) {
if (! count($relationships)) {
$results = [
...$results,
...$currentRelationshipValue->all(),
];
continue;
}
foreach ($currentRelationshipValue as $valueRecord) {
$results = [
...$results,
...$this->getRelationshipResults(
$valueRecord,
$relationships,
),
];
}
break;
}
if (! $currentRelationshipValue instanceof Model) {
break;
}
if (! count($relationships)) {
$results[] = $currentRelationshipValue;
break;
}
$record = $currentRelationshipValue;
}
return $results;
}
public function getAttributeName(Model $record): string
{
$hasNestedMorphToRelationship = $this->hasNestedMorphToRelationship($record);
if (($this->attributeNameCache !== null) && (! $hasNestedMorphToRelationship)) {
return $this->attributeNameCache;
}
$name = $this->getName();
if (! str($name)->contains('.')) {
return $this->attributeNameCache = $name;
}
$nameParts = explode('.', $name);
$lastPart = array_pop($nameParts);
foreach ($nameParts as $namePart) {
if ($record->hasAttribute($namePart)) {
break;
}
if (! $record->isRelation($namePart)) {
break;
}
array_shift($nameParts);
$record = $record->{$namePart}()->getRelated();
}
$attributeName = Arr::first([...$nameParts, $lastPart]);
if ($hasNestedMorphToRelationship) {
return $attributeName;
}
return $this->attributeNameCache = $attributeName;
}
public function getFullAttributeName(Model $record): string
{
$hasNestedMorphToRelationship = $this->hasNestedMorphToRelationship($record);
if (($this->fullAttributeNameCache !== null) && (! $hasNestedMorphToRelationship)) {
return $this->fullAttributeNameCache;
}
$name = $this->getName();
if (! str($name)->contains('.')) {
return $this->fullAttributeNameCache = $name;
}
$nameParts = explode('.', $name);
$lastPart = array_pop($nameParts);
foreach ($nameParts as $namePart) {
if ($record->hasAttribute($namePart)) {
break;
}
if (! $record->isRelation($namePart)) {
break;
}
array_shift($nameParts);
$record = $record->{$namePart}()->getRelated();
}
$fullAttributeName = implode('.', [...$nameParts, $lastPart]);
if ($hasNestedMorphToRelationship) {
return $fullAttributeName;
}
return $this->fullAttributeNameCache = $fullAttributeName;
}
public function getInverseRelationshipName(Model $record): string
{
if (filled($this->inverseRelationshipName)) {
return $this->inverseRelationshipName;
}
$nameParts = explode('.', $this->getName());
array_pop($nameParts);
$inverseRelationshipParts = [];
foreach ($nameParts as $namePart) {
if ($record->hasAttribute($namePart)) {
break;
}
if (! $record->isRelation($namePart)) {
break;
}
$relationship = $record->{$namePart}();
$record = $relationship->getRelated();
$inverseNestedRelationshipName = (string) str(class_basename($relationship->getParent()::class))
->when(
($relationship instanceof BelongsTo ||
$relationship instanceof BelongsToMany ||
$relationship instanceof BelongsToThrough),
fn (Stringable $name) => $name->plural(),
)
->camel();
if ($record->hasAttribute($inverseNestedRelationshipName) || (! $record->isRelation($inverseNestedRelationshipName))) {
// The conventional relationship doesn't exist, but we can
// attempt to use the original relationship name instead.
if ($record->hasAttribute($namePart) || (! $record->isRelation($namePart))) {
$recordClass = $record::class;
throw new LogicException("When trying to guess the inverse relationship for column [{$this->getName()}], relationship [{$inverseNestedRelationshipName}] was not found on model [{$recordClass}]. Please define a custom [inverseRelationship()] for this column.");
}
$inverseNestedRelationshipName = $namePart;
}
array_unshift($inverseRelationshipParts, $inverseNestedRelationshipName);
}
return $this->inverseRelationshipName = implode('.', $inverseRelationshipParts);
}
public function getRelationshipName(Model $record): ?string
{
$hasNestedMorphToRelationship = $this->hasNestedMorphToRelationship($record);
if (($this->relationshipNameCache !== null) && (! $hasNestedMorphToRelationship)) {
return $this->relationshipNameCache;
}
$name = $this->getName();
if (! str($name)->contains('.')) {
return null;
}
$nameParts = explode('.', $name);
array_pop($nameParts);
$relationshipParts = [];
foreach ($nameParts as $namePart) {
if ($record->hasAttribute($namePart)) {
break;
}
if (! $record->isRelation($namePart)) {
break;
}
$relationshipParts[] = $namePart;
$record = $record->{$namePart}()->getRelated();
}
$relationshipName = implode('.', $relationshipParts);
if ($hasNestedMorphToRelationship) {
return $relationshipName;
}
return $this->relationshipNameCache = $relationshipName;
}
/**
* When the name of a cell traverses a `MorphTo` relationship and then continues deeper,
* the remainder of the path resolves against the concrete related model of each record,
* which may differ between records and is unknown while the query is being built. In
* that case, the relationship and attribute names cannot be cached across records and
* must be resolved fresh for each one.
*/
public function hasNestedMorphToRelationship(Model $record): bool
{
if (isset($this->hasNestedMorphToRelationshipCache)) {
return $this->hasNestedMorphToRelationshipCache;
}
$name = $this->getName();
if (! str($name)->contains('.')) {
return $this->hasNestedMorphToRelationshipCache = false;
}
$nameParts = explode('.', $name);
array_pop($nameParts);
$lastNamePartIndex = count($nameParts) - 1;
foreach ($nameParts as $namePartIndex => $namePart) {
if ($record->hasAttribute($namePart)) {
break;
}
if (! $record->isRelation($namePart)) {
break;
}
$relationship = $record->{$namePart}();
if ($relationship instanceof MorphTo) {
return $this->hasNestedMorphToRelationshipCache = ($namePartIndex < $lastNamePartIndex);
}
$record = $relationship->getRelated();
}
return $this->hasNestedMorphToRelationshipCache = false;
}
protected function cacheState(Closure $state): mixed
{
$record = $this->getRecord();
if (! $record) {
return null;
}
if ($this instanceof Column) {
$recordKey = $this->getLivewire()->getTableRecordKey($record);
} elseif (is_array($record)) { /** @phpstan-ignore function.impossibleType */
$recordKey = (string) ($record[ArrayRecord::getKeyName()] ?? null); /** @phpstan-ignore nullCoalesce.offset */
} else {
$recordKey = (string) $record->getKey();
}
if (blank($recordKey)) {
return $state();
}
if (array_key_exists($recordKey, $this->cachedState)) {
return $this->cachedState[$recordKey];
}
return $this->cachedState[$recordKey] = $state();
}
public function getGetStateUsingCallback(): mixed
{
return $this->getStateUsing;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait HasColor
{
/**
* @var string | array<string> | Closure | null
*/
protected string | array | Closure | null $color = null;
/**
* @var string | array<string> | Closure | null
*/
protected string | array | Closure | null $defaultColor = null;
/**
* @param string | array<string> | Closure | null $color
*/
public function color(string | array | Closure | null $color): static
{
$this->color = $color;
return $this;
}
/**
* @param string | array<string> | Closure | null $color
*/
public function defaultColor(string | array | Closure | null $color): static
{
$this->defaultColor = $color;
return $this;
}
/**
* @return string | array<string> | null
*/
public function getColor(): string | array | null
{
return $this->evaluate($this->color) ?? $this->evaluate($this->defaultColor);
}
public function hasColor(): bool
{
return $this->color !== null || $this->defaultColor !== null;
}
}

View file

@ -0,0 +1,120 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait HasDefaultDataFormattingSettings
{
protected string | Closure $defaultCurrency = 'usd';
protected string | Closure $defaultDateDisplayFormat = 'M j, Y';
protected string | Closure $defaultIsoDateDisplayFormat = 'L';
protected string | Closure $defaultDateTimeDisplayFormat = 'M j, Y H:i:s';
protected string | Closure $defaultIsoDateTimeDisplayFormat = 'LLL';
protected string | Closure | null $defaultNumberLocale = null;
protected string | Closure $defaultTimeDisplayFormat = 'H:i:s';
protected string | Closure $defaultIsoTimeDisplayFormat = 'LT';
public function defaultDateDisplayFormat(string | Closure $format): static
{
$this->defaultDateDisplayFormat = $format;
return $this;
}
public function defaultDateTimeDisplayFormat(string | Closure $format): static
{
$this->defaultDateTimeDisplayFormat = $format;
return $this;
}
public function defaultTimeDisplayFormat(string | Closure $format): static
{
$this->defaultTimeDisplayFormat = $format;
return $this;
}
public function defaultIsoDateDisplayFormat(string | Closure $format): static
{
$this->defaultIsoDateDisplayFormat = $format;
return $this;
}
public function defaultIsoDateTimeDisplayFormat(string | Closure $format): static
{
$this->defaultIsoDateTimeDisplayFormat = $format;
return $this;
}
public function defaultIsoTimeDisplayFormat(string | Closure $format): static
{
$this->defaultIsoTimeDisplayFormat = $format;
return $this;
}
public function defaultNumberLocale(string | Closure | null $locale): static
{
$this->defaultNumberLocale = $locale;
return $this;
}
public function defaultCurrency(string | Closure $currency): static
{
$this->defaultCurrency = $currency;
return $this;
}
public function getDefaultDateDisplayFormat(): string
{
return $this->evaluate($this->defaultDateDisplayFormat);
}
public function getDefaultDateTimeDisplayFormat(): string
{
return $this->evaluate($this->defaultDateTimeDisplayFormat);
}
public function getDefaultTimeDisplayFormat(): string
{
return $this->evaluate($this->defaultTimeDisplayFormat);
}
public function getDefaultIsoDateDisplayFormat(): string
{
return $this->evaluate($this->defaultIsoDateDisplayFormat);
}
public function getDefaultIsoDateTimeDisplayFormat(): string
{
return $this->evaluate($this->defaultIsoDateTimeDisplayFormat);
}
public function getDefaultIsoTimeDisplayFormat(): string
{
return $this->evaluate($this->defaultIsoTimeDisplayFormat);
}
public function getDefaultNumberLocale(): ?string
{
return $this->evaluate($this->defaultNumberLocale);
}
public function getDefaultCurrency(): string
{
return $this->evaluate($this->defaultCurrency);
}
}

View file

@ -0,0 +1,55 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
use Illuminate\View\ComponentAttributeBag;
trait HasExtraAlpineAttributes
{
/**
* @var array<array<mixed> | Closure>
*/
protected array $extraAlpineAttributes = [];
/**
* @param array<mixed> | Closure $attributes
*/
public function extraAlpineAttributes(array | Closure $attributes, bool $merge = false): static
{
// Security: Attribute values are not escaped when rendered. Never
// pass unsanitized user input as attribute names or values.
if ($merge) {
if (($attributes instanceof Closure) && in_array($attributes, $this->extraAlpineAttributes, strict: true)) {
return $this;
}
$this->extraAlpineAttributes[] = $attributes;
} else {
$this->extraAlpineAttributes = [$attributes];
}
return $this;
}
/**
* @return array<mixed>
*/
public function getExtraAlpineAttributes(): array
{
$temporaryAttributeBag = new FilamentComponentAttributeBag;
foreach ($this->extraAlpineAttributes as $extraAlpineAttributes) {
$temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraAlpineAttributes), escape: false);
}
return $temporaryAttributeBag->getAttributes();
}
public function getExtraAlpineAttributeBag(): ComponentAttributeBag
{
return new FilamentComponentAttributeBag($this->getExtraAlpineAttributes());
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
use Illuminate\View\ComponentAttributeBag;
trait HasExtraAttributes
{
/**
* @var array<array<mixed> | Closure>
*/
protected array $extraAttributes = [];
/**
* @param array<mixed> | Closure $attributes
*/
public function extraAttributes(array | Closure $attributes, bool $merge = false): static
{
// Security: Attribute values are not escaped when rendered. Never
// pass unsanitized user input as attribute names or values.
if ($merge) {
if (($attributes instanceof Closure) && in_array($attributes, $this->extraAttributes, strict: true)) {
return $this;
}
$this->extraAttributes[] = $attributes;
} else {
$this->extraAttributes = [$attributes];
}
return $this;
}
/**
* @return array<mixed>
*/
public function getExtraAttributes(): array
{
$temporaryAttributeBag = new FilamentComponentAttributeBag;
foreach ($this->extraAttributes as $extraAttributes) {
$temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraAttributes), escape: false);
}
return $temporaryAttributeBag->getAttributes();
}
public function getExtraAttributeBag(): ComponentAttributeBag
{
return new FilamentComponentAttributeBag($this->getExtraAttributes());
}
public function hasExtraAttributes(): bool
{
return ! empty($this->extraAttributes);
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\Enums\FontFamily;
trait HasFontFamily
{
protected FontFamily | string | Closure | null $fontFamily = null;
public function fontFamily(FontFamily | string | Closure | null $family): static
{
$this->fontFamily = $family;
return $this;
}
public function getFontFamily(mixed $state = null): FontFamily | string | null
{
$family = $this->evaluate($this->fontFamily, [
'state' => $state,
]);
if (is_string($family)) {
$family = FontFamily::tryFrom($family) ?? $family;
}
return $family;
}
public function hasFontFamily(): bool
{
return $this->fontFamily !== null;
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait HasFromBreakpoint
{
protected string | Closure | null $fromBreakpoint = null;
public function from(string | Closure | null $breakpoint): static
{
$this->fromBreakpoint = $breakpoint;
return $this;
}
public function getFromBreakpoint(): ?string
{
return $this->evaluate($this->fromBreakpoint);
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Filament\Support\Concerns;
use BackedEnum;
use Closure;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\HtmlString;
trait HasIcon
{
protected string | BackedEnum | Htmlable | Closure | false | null $icon = null;
public function icon(string | BackedEnum | Htmlable | Closure | null $icon): static
{
// Security: Icon strings are escaped when rendered as URLs, but
// invalid icon names from user input will cause rendering errors.
// Validate against a known allowlist if user-controlled.
$this->icon = filled($icon) ? $icon : false;
return $this;
}
public function getIcon(string | BackedEnum | Htmlable | null $default = null): string | BackedEnum | Htmlable | null
{
$icon = $this->evaluate($this->icon);
// https://github.com/filamentphp/filament/pull/13512
if ($icon instanceof Renderable) {
return new HtmlString($icon->render());
}
if ($icon === false) {
return null;
}
return $icon ?? $default;
}
public function hasIcon(): bool
{
return $this->icon !== null && $this->icon !== false;
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait HasIconColor
{
/**
* @var string | array<string> | Closure | null
*/
protected string | array | Closure | null $iconColor = null;
/**
* @param string | array<string> | Closure | null $color
*/
public function iconColor(string | array | Closure | null $color): static
{
$this->iconColor = $color;
return $this;
}
/**
* @return string | array<string> | null
*/
public function getIconColor(): string | array | null
{
return $this->evaluate($this->iconColor);
}
public function hasIconColor(): bool
{
return $this->iconColor !== null;
}
}

View file

@ -0,0 +1,38 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\Enums\IconPosition;
trait HasIconPosition
{
protected IconPosition | string | Closure | null $iconPosition = null;
public function iconPosition(IconPosition | string | Closure | null $position): static
{
$this->iconPosition = $position;
return $this;
}
public function getIconPosition(): IconPosition
{
$position = $this->evaluate($this->iconPosition);
if ($position instanceof IconPosition) {
return $position;
}
if (blank($position)) {
return IconPosition::Before;
}
return IconPosition::tryFrom($position) ?? IconPosition::Before;
}
public function hasIconPosition(): bool
{
return $this->iconPosition !== null;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\Enums\IconSize;
trait HasIconSize
{
protected IconSize | string | Closure | null $iconSize = null;
public function iconSize(IconSize | string | Closure | null $size): static
{
$this->iconSize = $size;
return $this;
}
public function getIconSize(): IconSize | string | null
{
return $this->evaluate($this->iconSize);
}
public function hasIconSize(): bool
{
return $this->iconSize !== null;
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait HasLineClamp
{
protected int | Closure | null $lineClamp = null;
public function lineClamp(int | Closure | null $lineClamp): static
{
$this->lineClamp = $lineClamp;
return $this;
}
public function getLineClamp(): ?int
{
return $this->evaluate($this->lineClamp);
}
public function hasLineClamp(): bool
{
return $this->lineClamp !== null;
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Illuminate\Contracts\Support\Htmlable;
trait HasPlaceholder
{
protected string | Htmlable | Closure | null $placeholder = null;
public function placeholder(string | Htmlable | Closure | null $placeholder): static
{
$this->placeholder = $placeholder;
return $this;
}
public function getPlaceholder(): string | Htmlable | null
{
return $this->evaluate($this->placeholder);
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait HasReorderAnimationDuration
{
protected int | Closure $reorderAnimationDuration = 300;
public function reorderAnimationDuration(int | Closure $animation): static
{
$this->reorderAnimationDuration = $animation;
return $this;
}
public function getReorderAnimationDuration(): int
{
return $this->evaluate($this->reorderAnimationDuration);
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Illuminate\Contracts\Support\Htmlable;
trait HasTooltip
{
protected string | Htmlable | Closure | null $tooltip = null;
public function tooltip(string | Htmlable | Closure | null $tooltip): static
{
$this->tooltip = $tooltip;
return $this;
}
public function getTooltip(): string | Htmlable | null
{
return $this->evaluate($this->tooltip);
}
public function hasTooltip(): bool
{
return $this->tooltip !== null;
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\Enums\VerticalAlignment;
trait HasVerticalAlignment
{
protected VerticalAlignment | string | Closure | null $verticalAlignment = null;
public function verticalAlignment(VerticalAlignment | string | Closure | null $alignment): static
{
$this->verticalAlignment = $alignment;
return $this;
}
public function verticallyAlignStart(bool | Closure $condition = true): static
{
return $this->verticalAlignment(fn (): ?VerticalAlignment => $this->evaluate($condition) ? VerticalAlignment::Start : null);
}
public function verticallyAlignCenter(bool | Closure $condition = true): static
{
return $this->verticalAlignment(fn (): ?VerticalAlignment => $this->evaluate($condition) ? VerticalAlignment::Center : null);
}
public function verticallyAlignEnd(bool | Closure $condition = true): static
{
return $this->verticalAlignment(fn (): ?VerticalAlignment => $this->evaluate($condition) ? VerticalAlignment::End : null);
}
public function getVerticalAlignment(): VerticalAlignment | string | null
{
$alignment = $this->evaluate($this->verticalAlignment);
if (! is_string($alignment)) {
return $alignment;
}
return VerticalAlignment::tryFrom($alignment) ?? $alignment;
}
public function hasDynamicVerticalAlignment(): bool
{
return $this->verticalAlignment instanceof Closure;
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
use Filament\Support\Enums\FontWeight;
trait HasWeight
{
protected FontWeight | string | Closure | null $weight = null;
public function weight(FontWeight | string | Closure | null $weight): static
{
$this->weight = $weight;
return $this;
}
public function getWeight(mixed $state = null): FontWeight | string | null
{
$weight = $this->evaluate($this->weight, [
'state' => $state,
]);
if (! is_string($weight)) {
return $weight;
}
return FontWeight::tryFrom($weight) ?? $weight;
}
public function hasWeight(): bool
{
return $this->weight !== null;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Filament\Support\Concerns;
use Closure;
trait HasWidth
{
protected int | string | Closure | null $width = null;
public function width(int | string | Closure | null $width): static
{
$this->width = $width;
return $this;
}
public function getWidth(): ?string
{
$width = $this->evaluate($this->width);
if (is_int($width)) {
$width = "{$width}px";
}
return $width;
}
}

View file

@ -0,0 +1,111 @@
<?php
namespace Filament\Support\Concerns;
use BadMethodCallException;
use Closure;
use ReflectionClass;
use ReflectionMethod;
trait Macroable
{
/**
* @var array<string, array<class-string, Closure>>
*/
protected static array $macros = [];
public static function macro(string $name, callable $macro): void
{
static::$macros[$name][static::class] = $macro;
}
public static function mixin(object $mixin, bool $replace = true): void
{
$methods = (new ReflectionClass($mixin))->getMethods(
ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED,
);
foreach ($methods as $method) {
if ($replace || (! isset(static::$macros[$method->name][static::class]))) {
static::macro($method->name, $method->invoke($mixin));
}
}
}
public static function flushMacros(): void
{
static::$macros = [];
}
public static function hasMacro(string $name): bool
{
return (bool) static::getMacro($name);
}
/**
* @param array<array-key> $parameters
*/
public static function __callStatic(string $method, array $parameters): mixed
{
$macro = static::getMacro($method);
if ($macro === null) {
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.',
static::class,
$method,
));
}
if ($macro instanceof Closure) {
$macro = $macro->bindTo(null, static::class);
}
return $macro(...$parameters);
}
/**
* @param array<array-key> $parameters
*/
public function __call(string $method, array $parameters): mixed
{
$macro = static::getMacro($method);
if ($macro === null) {
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.',
static::class,
$method,
));
}
if ($macro instanceof Closure) {
$macro = $macro->bindTo($this, static::class);
}
return $macro(...$parameters);
}
protected static function getMacro(string $method): ?callable
{
$macros = static::$macros[$method] ?? [];
if (! count($macros)) {
return null;
}
if (array_key_exists(static::class, $macros)) {
return $macros[static::class];
}
foreach (class_parents(static::class) as $parent) {
if (! array_key_exists($parent, $macros)) {
continue;
}
return $macros[$parent];
}
return null;
}
}