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
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:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
175
vendor/filament/infolists/src/Components/CodeEntry.php
vendored
Normal file
175
vendor/filament/infolists/src/Components/CodeEntry.php
vendored
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanBeCopied;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Js;
|
||||
use Phiki\Grammar\Grammar;
|
||||
use Phiki\Phiki;
|
||||
use Phiki\Theme\Theme;
|
||||
|
||||
class CodeEntry extends Entry implements HasEmbeddedView
|
||||
{
|
||||
use CanBeCopied;
|
||||
|
||||
protected string | Grammar | Closure | null $grammar = null;
|
||||
|
||||
protected string | Theme | Closure | null $lightTheme = null;
|
||||
|
||||
protected string | Theme | Closure | null $darkTheme = null;
|
||||
|
||||
protected int | Closure $jsonFlags = JSON_PRETTY_PRINT;
|
||||
|
||||
public function grammar(string | Grammar | Closure | null $grammar): static
|
||||
{
|
||||
$this->grammar = $grammar;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGrammar(): string | Grammar | null
|
||||
{
|
||||
return $this->evaluate($this->grammar);
|
||||
}
|
||||
|
||||
public function lightTheme(string | Theme | Closure | null $theme): static
|
||||
{
|
||||
$this->lightTheme = $theme;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLightTheme(): string | Theme | null
|
||||
{
|
||||
return $this->evaluate($this->lightTheme);
|
||||
}
|
||||
|
||||
public function darkTheme(string | Theme | Closure | null $theme): static
|
||||
{
|
||||
$this->darkTheme = $theme;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDarkTheme(): string | Theme | null
|
||||
{
|
||||
return $this->evaluate($this->darkTheme);
|
||||
}
|
||||
|
||||
public function jsonFlags(int | Closure $flags): static
|
||||
{
|
||||
$this->jsonFlags = $flags;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getJsonFlags(): int
|
||||
{
|
||||
return $this->evaluate($this->jsonFlags);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$state = $this->getState();
|
||||
|
||||
if ($state instanceof Collection) {
|
||||
$state = $state->all();
|
||||
}
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-in-code',
|
||||
]);
|
||||
|
||||
if (blank($state)) {
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-tooltip' => filled($tooltip = $this->getEmptyTooltip())
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false);
|
||||
|
||||
$placeholder = $this->getPlaceholder();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($placeholder)) { ?>
|
||||
<p class="fi-in-placeholder">
|
||||
<?= e($placeholder) ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
$phiki = new Phiki;
|
||||
$grammar = $this->getGrammar();
|
||||
$lightTheme = $this->getLightTheme();
|
||||
$darkTheme = $this->getDarkTheme();
|
||||
|
||||
if (is_array($state)) {
|
||||
$state = json_encode($state, flags: $this->getJsonFlags());
|
||||
$grammar ??= Grammar::Json;
|
||||
}
|
||||
|
||||
$grammar ??= Grammar::Html;
|
||||
$lightTheme ??= Theme::GithubLight;
|
||||
$darkTheme ??= Theme::GithubDarkHighContrast;
|
||||
|
||||
$isCopyable = $this->isCopyable($state);
|
||||
|
||||
$copyableStateJs = $isCopyable
|
||||
? Js::from($this->getCopyableState($state) ?? $state)
|
||||
: null;
|
||||
$copyMessageJs = $isCopyable
|
||||
? Js::from($this->getCopyMessage($state))
|
||||
: null;
|
||||
$copyMessageDurationJs = $isCopyable
|
||||
? Js::from($this->getCopyMessageDuration($state))
|
||||
: null;
|
||||
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-on:click' => $isCopyable
|
||||
? <<<JS
|
||||
window.navigator.clipboard.writeText({$copyableStateJs})
|
||||
\$tooltip({$copyMessageJs}, {
|
||||
theme: \$store.theme,
|
||||
timeout: {$copyMessageDurationJs},
|
||||
})
|
||||
JS
|
||||
: null,
|
||||
'x-tooltip' => filled($tooltip = $this->getTooltip($state))
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-copyable' => $isCopyable,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?= (string) $phiki->codeToHtml($state, $grammar, [
|
||||
'light' => $lightTheme,
|
||||
'dark' => $darkTheme,
|
||||
]) ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
}
|
||||
144
vendor/filament/infolists/src/Components/ColorEntry.php
vendored
Normal file
144
vendor/filament/infolists/src/Components/ColorEntry.php
vendored
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanBeCopied;
|
||||
use Filament\Support\Concerns\CanWrap;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ColorEntry extends Entry implements HasEmbeddedView
|
||||
{
|
||||
use CanBeCopied;
|
||||
use CanWrap;
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$state = $this->getState();
|
||||
|
||||
if ($state instanceof Collection) {
|
||||
$state = $state->all();
|
||||
}
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-in-color',
|
||||
]);
|
||||
|
||||
if (blank($state)) {
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-tooltip' => filled($tooltip = $this->getEmptyTooltip())
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false);
|
||||
|
||||
$placeholder = $this->getPlaceholder();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($placeholder)) { ?>
|
||||
<p class="fi-in-placeholder">
|
||||
<?= e($placeholder) ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
$state = Arr::wrap($state);
|
||||
|
||||
$alignment = $this->getAlignment();
|
||||
|
||||
$attributes = $attributes
|
||||
->class([
|
||||
'fi-wrapped' => $this->canWrap(),
|
||||
($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : ''),
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php foreach ($state as $stateItem) { ?>
|
||||
<?php
|
||||
$isCopyable = $this->isCopyable($stateItem);
|
||||
|
||||
$copyableStateJs = $isCopyable
|
||||
? Js::from($this->getCopyableState($stateItem) ?? $stateItem)
|
||||
: null;
|
||||
$copyMessageJs = $isCopyable
|
||||
? Js::from($this->getCopyMessage($stateItem))
|
||||
: null;
|
||||
$copyMessageDurationJs = $isCopyable
|
||||
? Js::from($this->getCopyMessageDuration($stateItem))
|
||||
: null;
|
||||
|
||||
$tooltip = $this->getTooltip($stateItem);
|
||||
|
||||
$sanitizedColor = Str::sanitizeCssColor($stateItem);
|
||||
|
||||
// The colour value is the swatch's only information, so expose it (or the
|
||||
// developer's tooltip text) as an accessible name on the `role="img"` swatch.
|
||||
// Only the sanitized colour is used, so an invalid value is never announced.
|
||||
// The copyable swatch is an interactive control that needs separate treatment (an
|
||||
// accessible name and keyboard operability), so it is not named here — matching
|
||||
// `ColorColumn`.
|
||||
$accessibleLabel = $isCopyable
|
||||
? null
|
||||
: (filled($tooltip)
|
||||
? ($tooltip instanceof Htmlable ? strip_tags($tooltip->toHtml()) : $tooltip)
|
||||
: $sanitizedColor);
|
||||
?>
|
||||
|
||||
<div <?= (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'role' => filled($accessibleLabel) ? 'img' : null,
|
||||
'aria-label' => filled($accessibleLabel) ? e($accessibleLabel) : null,
|
||||
'x-on:click' => $isCopyable
|
||||
? <<<JS
|
||||
window.navigator.clipboard.writeText({$copyableStateJs})
|
||||
\$tooltip({$copyMessageJs}, {
|
||||
theme: \$store.theme,
|
||||
timeout: {$copyMessageDurationJs},
|
||||
})
|
||||
JS
|
||||
: null,
|
||||
'x-tooltip' => filled($tooltip)
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-in-color-item',
|
||||
'fi-copyable' => $isCopyable,
|
||||
])
|
||||
->style([
|
||||
'background-color: ' . e($sanitizedColor) => filled($sanitizedColor),
|
||||
])
|
||||
->toHtml() ?>></div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
public function canWrapByDefault(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
519
vendor/filament/infolists/src/Components/Concerns/CanFormatState.php
vendored
Normal file
519
vendor/filament/infolists/src/Components/Concerns/CanFormatState.php
vendored
Normal file
|
|
@ -0,0 +1,519 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Forms\Components\RichEditor\RichContentAttribute;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Support\Concerns\CanConfigureCommonMark;
|
||||
use Filament\Support\Contracts\HasLabel as LabelInterface;
|
||||
use Filament\Support\Enums\ArgumentValue;
|
||||
use Filament\Support\Facades\FilamentTimezone;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Number;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait CanFormatState
|
||||
{
|
||||
use CanConfigureCommonMark;
|
||||
|
||||
protected ?Closure $formatStateUsing = null;
|
||||
|
||||
protected int | Closure | null $characterLimit = null;
|
||||
|
||||
protected string | Closure | null $characterLimitEnd = null;
|
||||
|
||||
protected int | Closure | null $wordLimit = null;
|
||||
|
||||
protected string | Closure | null $wordLimitEnd = null;
|
||||
|
||||
protected string | Htmlable | Closure | null $prefix = null;
|
||||
|
||||
protected string | Htmlable | Closure | null $suffix = null;
|
||||
|
||||
protected string | Closure | null $timezone = null;
|
||||
|
||||
protected bool | Closure $isHtml = false;
|
||||
|
||||
protected bool | Closure $isMarkdown = false;
|
||||
|
||||
protected bool $isDate = false;
|
||||
|
||||
protected bool $isDateTime = false;
|
||||
|
||||
protected bool $isMoney = false;
|
||||
|
||||
protected bool $isNumeric = false;
|
||||
|
||||
protected bool $isTime = false;
|
||||
|
||||
public function markdown(bool | Closure $condition = true): static
|
||||
{
|
||||
// Security: Markdown is converted to HTML and then sanitized via
|
||||
// `Str::sanitizeHtml()`. Same inline `style` caveat as `html()`.
|
||||
|
||||
$this->isMarkdown = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function date(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->isDate = true;
|
||||
|
||||
$this->formatStateUsing(static function (TextEntry $component, $state) use ($format, $timezone): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::parse($state)
|
||||
->setTimezone($component->evaluate($timezone) ?? $component->getTimezone())
|
||||
->translatedFormat($component->evaluate($format) ?? $component->getContainer()->getDefaultDateDisplayFormat());
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dateTime(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->isDateTime = true;
|
||||
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultDateTimeDisplayFormat();
|
||||
|
||||
$this->date($format, $timezone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isoDate(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->isDate = true;
|
||||
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultIsoDateDisplayFormat();
|
||||
|
||||
$this->formatStateUsing(static function (TextEntry $component, $state) use ($format, $timezone): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::parse($state)
|
||||
->setTimezone($component->evaluate($timezone) ?? $component->getTimezone())
|
||||
->isoFormat($component->evaluate($format) ?? $component->getContainer()->getDefaultIsoDateDisplayFormat());
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isoDateTime(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->isDateTime = true;
|
||||
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultIsoDateTimeDisplayFormat();
|
||||
|
||||
$this->isoDate($format, $timezone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function since(string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->isDateTime = true;
|
||||
|
||||
$this->formatStateUsing(static function (TextEntry $component, $state) use ($timezone): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::parse($state)
|
||||
->setTimezone($component->evaluate($timezone) ?? $component->getTimezone())
|
||||
->diffForHumans();
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dateTooltip(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->tooltip(static function (TextEntry $component, mixed $state) use ($format, $timezone): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::parse($state)
|
||||
->setTimezone($component->evaluate($timezone) ?? $component->getTimezone())
|
||||
->translatedFormat($component->evaluate($format) ?? $component->getContainer()->getDefaultDateDisplayFormat());
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dateTimeTooltip(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultDateTimeDisplayFormat();
|
||||
|
||||
$this->dateTooltip($format, $timezone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function timeTooltip(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultTimeDisplayFormat();
|
||||
|
||||
$this->dateTooltip($format, $timezone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sinceTooltip(string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->tooltip(static function (TextEntry $component, mixed $state) use ($timezone): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::parse($state)
|
||||
->setTimezone($component->evaluate($timezone) ?? $component->getTimezone())
|
||||
->diffForHumans();
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isoDateTooltip(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultIsoDateDisplayFormat();
|
||||
|
||||
$this->tooltip(static function (TextEntry $component, mixed $state) use ($format, $timezone): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::parse($state)
|
||||
->setTimezone($component->evaluate($timezone) ?? $component->getTimezone())
|
||||
->isoFormat($component->evaluate($format) ?? $component->getContainer()->getDefaultIsoDateDisplayFormat());
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isoDateTimeTooltip(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultIsoDateTimeDisplayFormat();
|
||||
|
||||
$this->isoDateTooltip($format, $timezone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isoTimeTooltip(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultIsoTimeDisplayFormat();
|
||||
|
||||
$this->isoDateTooltip($format, $timezone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function money(string | BackedEnum | Closure | null $currency = null, int | Closure $divideBy = 0, string | BackedEnum | Closure | null $locale = null, int | Closure | null $decimalPlaces = null): static
|
||||
{
|
||||
$this->isMoney = true;
|
||||
|
||||
$this->formatStateUsing(static function (TextEntry $component, $state) use ($currency, $divideBy, $locale, $decimalPlaces): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! is_numeric($state)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
$currency = $component->evaluate($currency) ?? $component->getContainer()->getDefaultCurrency();
|
||||
$locale = $component->evaluate($locale) ?? $component->getContainer()->getDefaultNumberLocale() ?? config('app.locale');
|
||||
$decimalPlaces = $component->evaluate($decimalPlaces);
|
||||
|
||||
if ($divideBy = $component->evaluate($divideBy)) {
|
||||
$state /= $divideBy;
|
||||
}
|
||||
|
||||
if ($currency instanceof BackedEnum) {
|
||||
$currency = (string) $currency->value;
|
||||
}
|
||||
|
||||
if ($locale instanceof BackedEnum) {
|
||||
$locale = (string) $locale->value;
|
||||
}
|
||||
|
||||
return Number::currency($state, $currency, $locale, $decimalPlaces);
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function numeric(int | Closure | null $decimalPlaces = null, string | Closure | null | ArgumentValue $decimalSeparator = ArgumentValue::Default, string | Closure | null | ArgumentValue $thousandsSeparator = ArgumentValue::Default, int | Closure | null $maxDecimalPlaces = null, string | BackedEnum | Closure | null $locale = null): static
|
||||
{
|
||||
$this->isNumeric = true;
|
||||
|
||||
$this->formatStateUsing(static function (TextEntry $component, $state) use ($decimalPlaces, $decimalSeparator, $locale, $maxDecimalPlaces, $thousandsSeparator): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! is_numeric($state)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
$decimalPlaces = $component->evaluate($decimalPlaces);
|
||||
$decimalSeparator = $component->evaluate($decimalSeparator);
|
||||
$thousandsSeparator = $component->evaluate($thousandsSeparator);
|
||||
|
||||
if (
|
||||
($decimalSeparator !== ArgumentValue::Default) ||
|
||||
($thousandsSeparator !== ArgumentValue::Default)
|
||||
) {
|
||||
return number_format(
|
||||
$state,
|
||||
$decimalPlaces,
|
||||
$decimalSeparator === ArgumentValue::Default ? '.' : $decimalSeparator,
|
||||
$thousandsSeparator === ArgumentValue::Default ? ',' : $thousandsSeparator,
|
||||
);
|
||||
}
|
||||
|
||||
$locale = $component->evaluate($locale) ?? $component->getContainer()->getDefaultNumberLocale() ?? config('app.locale');
|
||||
|
||||
if ($locale instanceof BackedEnum) {
|
||||
$locale = (string) $locale->value;
|
||||
}
|
||||
|
||||
return Number::format($state, $decimalPlaces, $component->evaluate($maxDecimalPlaces), $locale);
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function time(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->isTime = true;
|
||||
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultTimeDisplayFormat();
|
||||
|
||||
$this->date($format, $timezone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isoTime(string | Closure | null $format = null, string | Closure | null $timezone = null): static
|
||||
{
|
||||
$this->isTime = true;
|
||||
|
||||
$format ??= fn (TextEntry $component): string => $component->getContainer()->getDefaultIsoTimeDisplayFormat();
|
||||
|
||||
$this->isoDate($format, $timezone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function timezone(string | Closure | null $timezone): static
|
||||
{
|
||||
$this->timezone = $timezone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limit(int | Closure | null $length = 100, string | Closure | null $end = '...'): static
|
||||
{
|
||||
$this->characterLimit = $length;
|
||||
$this->characterLimitEnd = $end;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function words(int | Closure | null $words = 100, string | Closure | null $end = '...'): static
|
||||
{
|
||||
$this->wordLimit = $words;
|
||||
$this->wordLimitEnd = $end;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function prefix(string | Htmlable | Closure | null $prefix): static
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function suffix(string | Htmlable | Closure | null $suffix): static
|
||||
{
|
||||
$this->suffix = $suffix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function html(bool | Closure $condition = true): static
|
||||
{
|
||||
// Security: Content is automatically sanitized via Symfony's
|
||||
// `HtmlSanitizer`. The default config permits inline `style`
|
||||
// attributes, which can enable CSS-based attacks (e.g.
|
||||
// `background: url(...)`). Configure a custom sanitizer
|
||||
// if rendering untrusted user content.
|
||||
|
||||
$this->isHtml = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function formatStateUsing(?Closure $callback): static
|
||||
{
|
||||
$this->formatStateUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function formatState(mixed $state): mixed
|
||||
{
|
||||
$isHtml = $this->isHtml();
|
||||
|
||||
$state = $this->evaluate($this->formatStateUsing ?? $state, [
|
||||
'state' => $state,
|
||||
]);
|
||||
|
||||
if (is_array($state)) {
|
||||
$state = json_encode($state);
|
||||
}
|
||||
|
||||
if ($state instanceof RichContentAttribute) {
|
||||
$isHtml = true;
|
||||
$state = Str::sanitizeHtml($state->toHtml());
|
||||
} elseif ($state instanceof Htmlable) {
|
||||
$isHtml = true;
|
||||
$state = $state->toHtml();
|
||||
} elseif ($isHtml) {
|
||||
if ($this->isMarkdown()) {
|
||||
$state = Str::markdown($state, $this->getCommonMarkOptions(), $this->getCommonMarkExtensions());
|
||||
}
|
||||
|
||||
$state = Str::sanitizeHtml($state);
|
||||
}
|
||||
|
||||
if ($state instanceof LabelInterface) {
|
||||
$state = $state->getLabel();
|
||||
}
|
||||
|
||||
if (! $isHtml) {
|
||||
if ($characterLimit = $this->getCharacterLimit()) {
|
||||
$state = Str::limit($state, $characterLimit, $this->getCharacterLimitEnd());
|
||||
}
|
||||
|
||||
if ($wordLimit = $this->getWordLimit()) {
|
||||
$state = Str::words($state, $wordLimit, $this->getWordLimitEnd());
|
||||
}
|
||||
}
|
||||
|
||||
$prefix = $this->getPrefix();
|
||||
$suffix = $this->getSuffix();
|
||||
|
||||
if (
|
||||
(($prefix instanceof Htmlable) || ($suffix instanceof Htmlable)) &&
|
||||
(! $isHtml)
|
||||
) {
|
||||
$isHtml = true;
|
||||
$state = e($state);
|
||||
}
|
||||
|
||||
if (filled($prefix)) {
|
||||
if ($prefix instanceof Htmlable) {
|
||||
$prefix = $prefix->toHtml();
|
||||
} elseif ($isHtml) {
|
||||
$prefix = e($prefix);
|
||||
}
|
||||
|
||||
$state = $prefix . $state;
|
||||
}
|
||||
|
||||
if (filled($suffix)) {
|
||||
if ($suffix instanceof Htmlable) {
|
||||
$suffix = $suffix->toHtml();
|
||||
} elseif ($isHtml) {
|
||||
$suffix = e($suffix);
|
||||
}
|
||||
|
||||
$state .= $suffix;
|
||||
}
|
||||
|
||||
return $isHtml ? new HtmlString($state) : $state;
|
||||
}
|
||||
|
||||
public function getCharacterLimit(): ?int
|
||||
{
|
||||
return $this->evaluate($this->characterLimit);
|
||||
}
|
||||
|
||||
public function getCharacterLimitEnd(): ?string
|
||||
{
|
||||
return $this->evaluate($this->characterLimitEnd);
|
||||
}
|
||||
|
||||
public function getWordLimit(): ?int
|
||||
{
|
||||
return $this->evaluate($this->wordLimit);
|
||||
}
|
||||
|
||||
public function getWordLimitEnd(): ?string
|
||||
{
|
||||
return $this->evaluate($this->wordLimitEnd);
|
||||
}
|
||||
|
||||
public function getTimezone(): string
|
||||
{
|
||||
return $this->evaluate($this->timezone) ?? ($this->isDateTime() ? FilamentTimezone::get() : config('app.timezone'));
|
||||
}
|
||||
|
||||
public function isHtml(): bool
|
||||
{
|
||||
return $this->evaluate($this->isHtml) || $this->isMarkdown() || $this->isProse();
|
||||
}
|
||||
|
||||
public function getPrefix(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->prefix);
|
||||
}
|
||||
|
||||
public function getSuffix(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->suffix);
|
||||
}
|
||||
|
||||
public function isMarkdown(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isMarkdown);
|
||||
}
|
||||
|
||||
public function isDate(): bool
|
||||
{
|
||||
return $this->isDate;
|
||||
}
|
||||
|
||||
public function isDateTime(): bool
|
||||
{
|
||||
return $this->isDateTime;
|
||||
}
|
||||
|
||||
public function isMoney(): bool
|
||||
{
|
||||
return $this->isMoney;
|
||||
}
|
||||
|
||||
public function isNumeric(): bool
|
||||
{
|
||||
return $this->isNumeric;
|
||||
}
|
||||
|
||||
public function isTime(): bool
|
||||
{
|
||||
return $this->isTime;
|
||||
}
|
||||
}
|
||||
127
vendor/filament/infolists/src/Components/Concerns/HasAffixes.php
vendored
Normal file
127
vendor/filament/infolists/src/Components/Concerns/HasAffixes.php
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait HasAffixes
|
||||
{
|
||||
/**
|
||||
* @var array<Action> | null
|
||||
*/
|
||||
protected ?array $cachedSuffixActions = null;
|
||||
|
||||
/**
|
||||
* @var array<Action | Closure>
|
||||
*/
|
||||
protected array $suffixActions = [];
|
||||
|
||||
/**
|
||||
* @var array<Action> | null
|
||||
*/
|
||||
protected ?array $cachedPrefixActions = null;
|
||||
|
||||
/**
|
||||
* @var array<Action | Closure>
|
||||
*/
|
||||
protected array $prefixActions = [];
|
||||
|
||||
public function prefixAction(Action | Closure $action): static
|
||||
{
|
||||
$this->prefixActions([$action]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | Closure> $actions
|
||||
*/
|
||||
public function prefixActions(array $actions): static
|
||||
{
|
||||
$this->prefixActions = [
|
||||
...$this->prefixActions,
|
||||
...$actions,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function suffixAction(Action | Closure $action): static
|
||||
{
|
||||
$this->suffixActions([$action]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | Closure> $actions
|
||||
*/
|
||||
public function suffixActions(array $actions): static
|
||||
{
|
||||
$this->suffixActions = [
|
||||
...$this->suffixActions,
|
||||
...$actions,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getPrefixActions(): array
|
||||
{
|
||||
return $this->cachedPrefixActions ?? $this->cachePrefixActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function cachePrefixActions(): array
|
||||
{
|
||||
$this->cachedPrefixActions = [];
|
||||
|
||||
foreach ($this->prefixActions as $prefixAction) {
|
||||
foreach (Arr::wrap($this->evaluate($prefixAction)) as $action) {
|
||||
$this->cachedPrefixActions[$action->getName()] = $this->prepareAction(
|
||||
$action
|
||||
->defaultSize(Size::Small)
|
||||
->defaultView(Action::ICON_BUTTON_VIEW),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cachedPrefixActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getSuffixActions(): array
|
||||
{
|
||||
return $this->cachedSuffixActions ?? $this->cacheSuffixActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function cacheSuffixActions(): array
|
||||
{
|
||||
$this->cachedSuffixActions = [];
|
||||
|
||||
foreach ($this->suffixActions as $suffixAction) {
|
||||
foreach (Arr::wrap($this->evaluate($suffixAction)) as $action) {
|
||||
$this->cachedSuffixActions[$action->getName()] = $this->prepareAction(
|
||||
$action
|
||||
->defaultSize(Size::Small)
|
||||
->defaultView(Action::ICON_BUTTON_VIEW),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cachedSuffixActions;
|
||||
}
|
||||
}
|
||||
75
vendor/filament/infolists/src/Components/Concerns/HasColor.php
vendored
Normal file
75
vendor/filament/infolists/src/Components/Concerns/HasColor.php
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Support\Contracts\HasColor as ColorInterface;
|
||||
|
||||
trait HasColor
|
||||
{
|
||||
/**
|
||||
* @var string | array<string> | bool | Closure | null
|
||||
*/
|
||||
protected string | array | bool | Closure | null $color = null;
|
||||
|
||||
/**
|
||||
* @param string | array<string> | bool | Closure | null $color
|
||||
*/
|
||||
public function color(string | array | bool | Closure | null $color): static
|
||||
{
|
||||
$this->color = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> | Closure $colors
|
||||
*/
|
||||
public function colors(array | Closure $colors): static
|
||||
{
|
||||
$this->color(function (Component $component, $state) use ($colors) {
|
||||
$colors = $component->evaluate($colors);
|
||||
|
||||
$color = null;
|
||||
|
||||
foreach ($colors as $conditionalColor => $condition) {
|
||||
if (is_numeric($conditionalColor)) {
|
||||
$color = $condition;
|
||||
} elseif ($condition instanceof Closure && $component->evaluate($condition)) {
|
||||
$color = $conditionalColor;
|
||||
} elseif ($condition === $state) {
|
||||
$color = $conditionalColor;
|
||||
}
|
||||
}
|
||||
|
||||
return $color;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string> | null
|
||||
*/
|
||||
public function getColor(mixed $state): string | array | null
|
||||
{
|
||||
$color = $this->evaluate($this->color, [
|
||||
'state' => $state,
|
||||
]);
|
||||
|
||||
if ($color === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (filled($color)) {
|
||||
return $color;
|
||||
}
|
||||
|
||||
if (! $state instanceof ColorInterface) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $state->getColor();
|
||||
}
|
||||
}
|
||||
55
vendor/filament/infolists/src/Components/Concerns/HasExtraEntryWrapperAttributes.php
vendored
Normal file
55
vendor/filament/infolists/src/Components/Concerns/HasExtraEntryWrapperAttributes.php
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
trait HasExtraEntryWrapperAttributes
|
||||
{
|
||||
/**
|
||||
* @var array<array<mixed> | Closure>
|
||||
*/
|
||||
protected array $extraEntryWrapperAttributes = [];
|
||||
|
||||
/**
|
||||
* @param array<mixed> | Closure $attributes
|
||||
*/
|
||||
public function extraEntryWrapperAttributes(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->extraEntryWrapperAttributes, strict: true)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->extraEntryWrapperAttributes[] = $attributes;
|
||||
} else {
|
||||
$this->extraEntryWrapperAttributes = [$attributes];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function getExtraEntryWrapperAttributes(): array
|
||||
{
|
||||
$temporaryAttributeBag = new FilamentComponentAttributeBag;
|
||||
|
||||
foreach ($this->extraEntryWrapperAttributes as $extraEntryWrapperAttributes) {
|
||||
$temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraEntryWrapperAttributes), escape: false);
|
||||
}
|
||||
|
||||
return $temporaryAttributeBag->getAttributes();
|
||||
}
|
||||
|
||||
public function getExtraEntryWrapperAttributesBag(): ComponentAttributeBag
|
||||
{
|
||||
return new FilamentComponentAttributeBag($this->getExtraEntryWrapperAttributes());
|
||||
}
|
||||
}
|
||||
26
vendor/filament/infolists/src/Components/Concerns/HasHelperText.php
vendored
Normal file
26
vendor/filament/infolists/src/Components/Concerns/HasHelperText.php
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasHelperText
|
||||
{
|
||||
public function helperText(string | Htmlable | Closure | null $text): static
|
||||
{
|
||||
$this->belowContent(function (Component $component) use ($text): ?Text {
|
||||
$content = $component->evaluate($text);
|
||||
|
||||
if (blank($content)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Text::make($content);
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
189
vendor/filament/infolists/src/Components/Concerns/HasHint.php
vendored
Normal file
189
vendor/filament/infolists/src/Components/Concerns/HasHint.php
vendored
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Infolists\Components\Entry;
|
||||
use Filament\Schemas\Components\Icon;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasHint
|
||||
{
|
||||
protected string | Htmlable | Closure | null $hint = null;
|
||||
|
||||
/**
|
||||
* @var array<Action | Closure>
|
||||
*/
|
||||
protected array $hintActions = [];
|
||||
|
||||
/**
|
||||
* @var string | array<string> | Closure | null
|
||||
*/
|
||||
protected string | array | Closure | null $hintColor = null;
|
||||
|
||||
protected string | BackedEnum | Htmlable | Closure | null $hintIcon = null;
|
||||
|
||||
protected string | Closure | null $hintIconTooltip = null;
|
||||
|
||||
protected function setUpHint(): void
|
||||
{
|
||||
$this->afterLabel(function (Entry $component): array {
|
||||
$components = [];
|
||||
|
||||
if ($component->hasHint()) {
|
||||
$components[] = Text::make(static function (Text $component): string | Htmlable | null {
|
||||
/** @var self $parentComponent */
|
||||
$parentComponent = $component->getContainer()->getParentComponent();
|
||||
|
||||
return $parentComponent->getHint();
|
||||
})
|
||||
->color(static function (Text $component): string | array | null {
|
||||
/** @var self $parentComponent */
|
||||
$parentComponent = $component->getContainer()->getParentComponent();
|
||||
|
||||
return $parentComponent->getHintColor();
|
||||
})
|
||||
->visible(static function (Text $component): bool {
|
||||
/** @var self $parentComponent */
|
||||
$parentComponent = $component->getContainer()->getParentComponent();
|
||||
|
||||
return filled($parentComponent->getHint());
|
||||
});
|
||||
}
|
||||
|
||||
if ($component->hasHintIcon()) {
|
||||
$components[] = Icon::make(static function (Icon $component): string | BackedEnum | Htmlable | null {
|
||||
/** @var self $parentComponent */
|
||||
$parentComponent = $component->getContainer()->getParentComponent();
|
||||
|
||||
return $parentComponent->getHintIcon();
|
||||
})
|
||||
->tooltip(static function (Icon $component): ?string {
|
||||
/** @var self $parentComponent */
|
||||
$parentComponent = $component->getContainer()->getParentComponent();
|
||||
|
||||
return $parentComponent->getHintIconTooltip();
|
||||
})
|
||||
->visible(static function (Icon $component): bool {
|
||||
/** @var self $parentComponent */
|
||||
$parentComponent = $component->getContainer()->getParentComponent();
|
||||
|
||||
return filled($parentComponent->getHintIcon());
|
||||
})
|
||||
->color(static function (Icon $component): string | array | null {
|
||||
/** @var self $parentComponent */
|
||||
$parentComponent = $component->getContainer()->getParentComponent();
|
||||
|
||||
return $parentComponent->getHintColor();
|
||||
});
|
||||
}
|
||||
|
||||
return [
|
||||
...$components,
|
||||
...$component->getHintActions(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function hint(string | Htmlable | Closure | null $hint): static
|
||||
{
|
||||
$this->hint = $hint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | Closure | null $color
|
||||
*/
|
||||
public function hintColor(string | array | Closure | null $color): static
|
||||
{
|
||||
$this->hintColor = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hintIcon(string | BackedEnum | Htmlable | Closure | null $icon, string | Closure | null $tooltip = null): static
|
||||
{
|
||||
$this->hintIcon = $icon;
|
||||
|
||||
if (func_num_args() >= 2) {
|
||||
$this->hintIconTooltip($tooltip);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hintIconTooltip(string | Closure | null $tooltip): static
|
||||
{
|
||||
$this->hintIconTooltip = $tooltip;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hintAction(Action | Closure $action): static
|
||||
{
|
||||
$this->hintActions([$action]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | Closure> $actions
|
||||
*/
|
||||
public function hintActions(array $actions): static
|
||||
{
|
||||
$this->hintActions = [
|
||||
...$this->hintActions,
|
||||
...$actions,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasHint(): bool
|
||||
{
|
||||
return filled($this->hint);
|
||||
}
|
||||
|
||||
public function getHint(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->hint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string> | null
|
||||
*/
|
||||
public function getHintColor(): string | array | null
|
||||
{
|
||||
return $this->evaluate($this->hintColor);
|
||||
}
|
||||
|
||||
public function hasHintIcon(): bool
|
||||
{
|
||||
return filled($this->hintIcon);
|
||||
}
|
||||
|
||||
public function getHintIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->hintIcon);
|
||||
}
|
||||
|
||||
public function getHintIconTooltip(): ?string
|
||||
{
|
||||
return $this->evaluate($this->hintIconTooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getHintActions(): array
|
||||
{
|
||||
return array_filter(array_map(
|
||||
fn (Action | Closure $hintAction): ?Action => $this->evaluate($hintAction),
|
||||
$this->hintActions,
|
||||
));
|
||||
}
|
||||
}
|
||||
93
vendor/filament/infolists/src/Components/Concerns/HasIcon.php
vendored
Normal file
93
vendor/filament/infolists/src/Components/Concerns/HasIcon.php
vendored
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Support\Contracts\HasIcon as IconInterface;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasIcon
|
||||
{
|
||||
protected string | BackedEnum | bool | Closure | null $icon = null;
|
||||
|
||||
protected IconPosition | string | Closure | null $iconPosition = null;
|
||||
|
||||
public function icon(string | BackedEnum | bool | Closure | null $icon): static
|
||||
{
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> | Closure $icons
|
||||
*/
|
||||
public function icons(array | Closure $icons): static
|
||||
{
|
||||
$this->icon(function (Component $component, $state) use ($icons) {
|
||||
$icons = $component->evaluate($icons);
|
||||
|
||||
$icon = null;
|
||||
|
||||
foreach ($icons as $conditionalIcon => $condition) {
|
||||
if (is_numeric($conditionalIcon)) {
|
||||
$icon = $condition;
|
||||
} elseif ($condition instanceof Closure && $component->evaluate($condition)) {
|
||||
$icon = $conditionalIcon;
|
||||
} elseif ($condition === $state) {
|
||||
$icon = $conditionalIcon;
|
||||
}
|
||||
}
|
||||
|
||||
return $icon;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function iconPosition(IconPosition | string | Closure | null $iconPosition): static
|
||||
{
|
||||
$this->iconPosition = $iconPosition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIcon(mixed $state): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
$icon = $this->evaluate($this->icon, [
|
||||
'state' => $state,
|
||||
]);
|
||||
|
||||
if ($icon === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (filled($icon)) {
|
||||
return $icon;
|
||||
}
|
||||
|
||||
if (! $state instanceof IconInterface) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $state->getIcon();
|
||||
}
|
||||
|
||||
public function getIconPosition(): IconPosition | string
|
||||
{
|
||||
$position = $this->evaluate($this->iconPosition);
|
||||
|
||||
if ($position instanceof IconPosition) {
|
||||
return $position;
|
||||
}
|
||||
|
||||
if (blank($position)) {
|
||||
return IconPosition::Before;
|
||||
}
|
||||
|
||||
return IconPosition::tryFrom($position) ?? $position;
|
||||
}
|
||||
}
|
||||
33
vendor/filament/infolists/src/Components/Concerns/HasIconColor.php
vendored
Normal file
33
vendor/filament/infolists/src/Components/Concerns/HasIconColor.php
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\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<int | string, string | int> | null
|
||||
*/
|
||||
public function getIconColor(mixed $state): string | array | null
|
||||
{
|
||||
return $this->evaluate($this->iconColor, [
|
||||
'state' => $state,
|
||||
]);
|
||||
}
|
||||
}
|
||||
39
vendor/filament/infolists/src/Components/Concerns/HasTooltip.php
vendored
Normal file
39
vendor/filament/infolists/src/Components/Concerns/HasTooltip.php
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasTooltip
|
||||
{
|
||||
protected string | Htmlable | Closure | null $tooltip = null;
|
||||
|
||||
protected string | Htmlable | Closure | null $emptyTooltip = null;
|
||||
|
||||
public function tooltip(string | Htmlable | Closure | null $tooltip): static
|
||||
{
|
||||
$this->tooltip = $tooltip;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTooltip(mixed $state = null): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->tooltip, [
|
||||
'state' => $state,
|
||||
]);
|
||||
}
|
||||
|
||||
public function emptyTooltip(string | Htmlable | Closure | null $tooltip): static
|
||||
{
|
||||
$this->emptyTooltip = $tooltip;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmptyTooltip(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->emptyTooltip);
|
||||
}
|
||||
}
|
||||
364
vendor/filament/infolists/src/Components/Entry.php
vendored
Normal file
364
vendor/filament/infolists/src/Components/Entry.php
vendored
Normal file
|
|
@ -0,0 +1,364 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Concerns\CanOpenUrl;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Components\Concerns\HasName;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Concerns\HasAlignment;
|
||||
use Filament\Support\Concerns\HasPlaceholder;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\View\ComponentSlot;
|
||||
use LogicException;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
|
||||
class Entry extends Component
|
||||
{
|
||||
use CanOpenUrl;
|
||||
use Concerns\HasExtraEntryWrapperAttributes;
|
||||
use Concerns\HasHelperText;
|
||||
use Concerns\HasHint;
|
||||
use Concerns\HasTooltip;
|
||||
use HasAlignment;
|
||||
use HasLabel {
|
||||
getLabel as getBaseLabel;
|
||||
}
|
||||
use HasName;
|
||||
use HasPlaceholder;
|
||||
|
||||
protected string $viewIdentifier = 'entry';
|
||||
|
||||
const ABOVE_LABEL_SCHEMA_KEY = 'above_label';
|
||||
|
||||
const BELOW_LABEL_SCHEMA_KEY = 'below_label';
|
||||
|
||||
const BEFORE_LABEL_SCHEMA_KEY = 'before_label';
|
||||
|
||||
const AFTER_LABEL_SCHEMA_KEY = 'after_label';
|
||||
|
||||
const ABOVE_CONTENT_SCHEMA_KEY = 'above_content';
|
||||
|
||||
const BELOW_CONTENT_SCHEMA_KEY = 'below_content';
|
||||
|
||||
const BEFORE_CONTENT_SCHEMA_KEY = 'before_content';
|
||||
|
||||
const AFTER_CONTENT_SCHEMA_KEY = 'after_content';
|
||||
|
||||
final public function __construct(string $name)
|
||||
{
|
||||
$this->name($name);
|
||||
$this->statePath($name);
|
||||
}
|
||||
|
||||
public static function make(?string $name = null): static
|
||||
{
|
||||
$entryClass = static::class;
|
||||
|
||||
$name ??= static::getDefaultName();
|
||||
|
||||
if (blank($name)) {
|
||||
throw new LogicException("Entry of class [$entryClass] must have a unique name, passed to the [make()] method.");
|
||||
}
|
||||
|
||||
$static = app($entryClass, ['name' => $name]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpHint();
|
||||
}
|
||||
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getState(): mixed
|
||||
{
|
||||
return $this->getConstantState();
|
||||
}
|
||||
|
||||
public function getLabel(): string | Htmlable | null
|
||||
{
|
||||
if (filled($label = $this->getBaseLabel())) {
|
||||
return $label;
|
||||
}
|
||||
|
||||
$label = (string) str($this->getName())
|
||||
->afterLast('.')
|
||||
->kebab()
|
||||
->replace(['-', '_'], ' ')
|
||||
->ucfirst();
|
||||
|
||||
return $this->shouldTranslateLabel ? __($label) : $label;
|
||||
}
|
||||
|
||||
public function state(mixed $state): static
|
||||
{
|
||||
$this->constantState($state);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStateUsing(mixed $callback): static
|
||||
{
|
||||
$this->state($callback);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function aboveLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::ABOVE_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function belowLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BELOW_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function beforeLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BEFORE_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function afterLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::AFTER_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function aboveContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::ABOVE_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function belowContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BELOW_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function beforeContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BEFORE_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function afterContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::AFTER_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function makeChildSchema(string $key): Schema
|
||||
{
|
||||
$schema = parent::makeChildSchema($key);
|
||||
|
||||
if (in_array($key, [static::AFTER_LABEL_SCHEMA_KEY, static::AFTER_CONTENT_SCHEMA_KEY])) {
|
||||
$schema->alignEnd();
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
protected function configureChildSchema(Schema $schema, string $key): Schema
|
||||
{
|
||||
$schema = parent::configureChildSchema($schema, $key);
|
||||
|
||||
if (in_array($key, [
|
||||
static::ABOVE_LABEL_SCHEMA_KEY,
|
||||
static::BELOW_LABEL_SCHEMA_KEY,
|
||||
static::BEFORE_LABEL_SCHEMA_KEY,
|
||||
static::AFTER_LABEL_SCHEMA_KEY,
|
||||
static::ABOVE_CONTENT_SCHEMA_KEY,
|
||||
static::BELOW_CONTENT_SCHEMA_KEY,
|
||||
static::BEFORE_CONTENT_SCHEMA_KEY,
|
||||
static::AFTER_CONTENT_SCHEMA_KEY,
|
||||
])) {
|
||||
$schema
|
||||
->inline()
|
||||
->embeddedInParentComponent()
|
||||
->modifyActionsUsing(fn (Action $action) => $action
|
||||
->defaultSize(Size::Small)
|
||||
->defaultView(Action::LINK_VIEW))
|
||||
->modifyActionGroupsUsing(fn (ActionGroup $actionGroup) => $actionGroup->defaultSize(Size::Small));
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*/
|
||||
public function wrapEmbeddedHtml(string $html): string
|
||||
{
|
||||
$view = $this->getEntryWrapperAbsoluteView();
|
||||
|
||||
if ($view !== 'filament-infolists::components.entry-wrapper') {
|
||||
if (view()->exists($view)) {
|
||||
return view($view, [
|
||||
'entry' => $this,
|
||||
'slot' => new ComponentSlot($html),
|
||||
])->toHtml();
|
||||
}
|
||||
|
||||
return $this->renderWrapperBladeComponent(
|
||||
$this->getEntryWrapperView(),
|
||||
new ComponentSlot($html),
|
||||
new FilamentComponentAttributeBag([
|
||||
'entry' => $this,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
$hasInlineLabel = $this->hasInlineLabel();
|
||||
$alignment = $this->getAlignment();
|
||||
$label = $this->getLabel();
|
||||
$labelSrOnly = $this->isLabelHidden();
|
||||
$action = $this->getAction();
|
||||
$url = $this->getUrl();
|
||||
|
||||
$wrapperTag = match (true) {
|
||||
filled($url) => 'a',
|
||||
filled($action) => 'button',
|
||||
default => 'div',
|
||||
};
|
||||
|
||||
if (! $alignment instanceof Alignment) {
|
||||
$alignment = filled($alignment) ? (Alignment::tryFrom($alignment) ?? $alignment) : null;
|
||||
}
|
||||
|
||||
$aboveLabelSchema = $this->getChildSchema($this::ABOVE_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$belowLabelSchema = $this->getChildSchema($this::BELOW_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$beforeLabelSchema = $this->getChildSchema($this::BEFORE_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$afterLabelSchema = $this->getChildSchema($this::AFTER_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$beforeContentSchema = $this->getChildSchema($this::BEFORE_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
$afterContentSchema = $this->getChildSchema($this::AFTER_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
|
||||
$attributes = $this->getExtraEntryWrapperAttributesBag()
|
||||
->class([
|
||||
'fi-in-entry',
|
||||
'fi-in-entry-has-inline-label' => $hasInlineLabel,
|
||||
]);
|
||||
|
||||
$contentAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'type' => ($wrapperTag === 'button') ? 'button' : null,
|
||||
'wire:click' => $wireClickAction = $action?->getLivewireClickHandler(),
|
||||
'wire:loading.attr' => ($wrapperTag === 'button') ? 'disabled' : null,
|
||||
'wire:target' => $wireClickAction,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-in-entry-content',
|
||||
(($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : '')),
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($label) && $labelSrOnly) { ?>
|
||||
<div class="fi-in-entry-label fi-sr-only" role="term">
|
||||
<?= e($label) ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ((filled($label) && (! $labelSrOnly)) || $hasInlineLabel || $aboveLabelSchema || $belowLabelSchema || $beforeLabelSchema || $afterLabelSchema) { ?>
|
||||
<div class="fi-in-entry-label-col">
|
||||
<?= $aboveLabelSchema?->toHtml() ?>
|
||||
|
||||
<?php if ((filled($label) && (! $labelSrOnly)) || $beforeLabelSchema || $afterLabelSchema) { ?>
|
||||
<div class="fi-in-entry-label-ctn">
|
||||
<?= $beforeLabelSchema?->toHtml() ?>
|
||||
|
||||
<?php if (filled($label) && (! $labelSrOnly)) { ?>
|
||||
<div class="fi-in-entry-label" role="term">
|
||||
<?= e($label) ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?= $afterLabelSchema?->toHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?= $belowLabelSchema?->toHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="fi-in-entry-content-col">
|
||||
<?= $this->getChildSchema($this::ABOVE_CONTENT_SCHEMA_KEY)?->toHtml() ?>
|
||||
|
||||
<div class="fi-in-entry-content-ctn" role="definition">
|
||||
<?= $beforeContentSchema?->toHtml() ?>
|
||||
|
||||
<<?= $wrapperTag ?> <?php if ($wrapperTag === 'a') {
|
||||
echo generate_href_html($url, $this->shouldOpenUrlInNewTab())->toHtml();
|
||||
} ?> <?= $contentAttributes->toHtml() ?>>
|
||||
<?= $html ?>
|
||||
</<?= $wrapperTag ?>>
|
||||
|
||||
<?= $afterContentSchema?->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<?= $this->getChildSchema($this::BELOW_CONTENT_SCHEMA_KEY)?->toHtml() ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
public function isDehydrated(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
356
vendor/filament/infolists/src/Components/IconEntry.php
vendored
Normal file
356
vendor/filament/infolists/src/Components/IconEntry.php
vendored
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Infolists\View\Components\IconEntryComponent\IconComponent;
|
||||
use Filament\Infolists\View\InfolistsIconAlias;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanWrap;
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Js;
|
||||
use Stringable;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
use function Filament\Support\generate_icon_html;
|
||||
|
||||
class IconEntry extends Entry implements HasEmbeddedView
|
||||
{
|
||||
use CanWrap;
|
||||
use Concerns\HasColor {
|
||||
getColor as getBaseColor;
|
||||
}
|
||||
use Concerns\HasIcon {
|
||||
getIcon as getBaseIcon;
|
||||
}
|
||||
|
||||
protected bool | Closure | null $isBoolean = null;
|
||||
|
||||
/**
|
||||
* @var string | array<string> | Closure | null
|
||||
*/
|
||||
protected string | array | Closure | null $falseColor = null;
|
||||
|
||||
protected string | BackedEnum | Htmlable | Closure | false | null $falseIcon = null;
|
||||
|
||||
/**
|
||||
* @var string | array<string> | Closure | null
|
||||
*/
|
||||
protected string | array | Closure | null $trueColor = null;
|
||||
|
||||
protected string | BackedEnum | Htmlable | Closure | false | null $trueIcon = null;
|
||||
|
||||
protected IconSize | string | Closure | null $size = null;
|
||||
|
||||
protected bool | Closure $isListWithLineBreaks = false;
|
||||
|
||||
public function boolean(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isBoolean = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<int | string, string | int> | Closure | null $color
|
||||
*/
|
||||
public function false(string | BackedEnum | Htmlable | Closure | false | null $icon = null, string | array | Closure | null $color = null): static
|
||||
{
|
||||
$this->falseIcon($icon);
|
||||
$this->falseColor($color);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | Closure | null $color
|
||||
*/
|
||||
public function falseColor(string | array | Closure | null $color): static
|
||||
{
|
||||
$this->boolean();
|
||||
$this->falseColor = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function falseIcon(string | BackedEnum | Htmlable | Closure | false | null $icon): static
|
||||
{
|
||||
$this->boolean();
|
||||
$this->falseIcon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<int | string, string | int> | Closure | null $color
|
||||
*/
|
||||
public function true(string | BackedEnum | Htmlable | Closure | false | null $icon = null, string | array | Closure | null $color = null): static
|
||||
{
|
||||
$this->trueIcon($icon);
|
||||
$this->trueColor($color);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | Closure | null $color
|
||||
*/
|
||||
public function trueColor(string | array | Closure | null $color): static
|
||||
{
|
||||
$this->boolean();
|
||||
$this->trueColor = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function trueIcon(string | BackedEnum | Htmlable | Closure | false | null $icon): static
|
||||
{
|
||||
$this->boolean();
|
||||
$this->trueIcon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function size(IconSize | string | Closure | null $size): static
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize(mixed $state): IconSize | string | null
|
||||
{
|
||||
return $this->evaluate($this->size, [
|
||||
'state' => $state,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getIcon(mixed $state): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
if (filled($icon = $this->getBaseIcon($state))) {
|
||||
return $icon;
|
||||
}
|
||||
|
||||
if (! $this->isBoolean()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($state === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $state ? $this->getTrueIcon() : $this->getFalseIcon();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<int | string, string | int> | null
|
||||
*/
|
||||
public function getColor(mixed $state): string | array | null
|
||||
{
|
||||
if (filled($color = $this->getBaseColor($state))) {
|
||||
return $color;
|
||||
}
|
||||
|
||||
if (! $this->isBoolean()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($state === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $state ? $this->getTrueColor() : $this->getFalseColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string>
|
||||
*/
|
||||
public function getFalseColor(): string | array
|
||||
{
|
||||
return $this->evaluate($this->falseColor) ?? 'danger';
|
||||
}
|
||||
|
||||
public function getFalseIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
$icon = $this->evaluate($this->falseIcon);
|
||||
|
||||
if ($icon === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $icon
|
||||
?? FilamentIcon::resolve(InfolistsIconAlias::COMPONENTS_ICON_ENTRY_FALSE)
|
||||
?? Heroicon::OutlinedXCircle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string>
|
||||
*/
|
||||
public function getTrueColor(): string | array
|
||||
{
|
||||
return $this->evaluate($this->trueColor) ?? 'success';
|
||||
}
|
||||
|
||||
public function getTrueIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
$icon = $this->evaluate($this->trueIcon);
|
||||
|
||||
if ($icon === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $icon
|
||||
?? FilamentIcon::resolve(InfolistsIconAlias::COMPONENTS_ICON_ENTRY_TRUE)
|
||||
?? Heroicon::OutlinedCheckCircle;
|
||||
}
|
||||
|
||||
public function listWithLineBreaks(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isListWithLineBreaks = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isListWithLineBreaks(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isListWithLineBreaks);
|
||||
}
|
||||
|
||||
public function isBoolean(): bool
|
||||
{
|
||||
if (blank($this->isBoolean)) {
|
||||
$this->isBoolean = $this->getRecord()?->hasCast($this->getName(), ['bool', 'boolean']);
|
||||
}
|
||||
|
||||
return (bool) $this->evaluate($this->isBoolean);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$state = $this->getState();
|
||||
|
||||
if ($state instanceof Collection) {
|
||||
$state = $state->all();
|
||||
}
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-in-icon',
|
||||
]);
|
||||
|
||||
if (blank($state)) {
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-tooltip' => filled($tooltip = $this->getEmptyTooltip())
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false);
|
||||
|
||||
$placeholder = $this->getPlaceholder();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($placeholder)) { ?>
|
||||
<p class="fi-in-placeholder">
|
||||
<?= e($placeholder) ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
$state = Arr::wrap($state);
|
||||
|
||||
$alignment = $this->getAlignment();
|
||||
|
||||
$attributes = $attributes
|
||||
->class([
|
||||
'fi-in-icon-has-line-breaks' => $this->isListWithLineBreaks(),
|
||||
'fi-wrapped' => $this->canWrap(),
|
||||
($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : ''),
|
||||
]);
|
||||
|
||||
$shouldOpenUrlInNewTab = $this->shouldOpenUrlInNewTab();
|
||||
|
||||
$formatState = function (mixed $stateItem) use ($shouldOpenUrlInNewTab): string {
|
||||
$icon = $this->getIcon($stateItem);
|
||||
|
||||
if (blank($icon)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$color = $this->getColor($stateItem);
|
||||
$size = $this->getSize($stateItem);
|
||||
$tooltip = $this->getTooltip($stateItem);
|
||||
|
||||
$item = generate_icon_html($icon, attributes: (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'x-tooltip' => filled($tooltip)
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false)
|
||||
->color(IconComponent::class, $color), size: $size ?? IconSize::Large)
|
||||
->toHtml();
|
||||
|
||||
// The icon and its color are the only value carriers, but `generate_icon_html()` renders a
|
||||
// decorative icon with no accessible name and `x-tooltip` is hover-only, so screen readers get
|
||||
// nothing. Emit a visually-hidden text alternative (WCAG 1.1.1, 1.4.1) alongside each icon.
|
||||
$accessibleText = match (true) {
|
||||
filled($tooltip) => $tooltip instanceof Htmlable ? strip_tags($tooltip->toHtml()) : $tooltip,
|
||||
$this->isBoolean() => $stateItem
|
||||
? __('filament-infolists::components.entries.icon.true')
|
||||
: __('filament-infolists::components.entries.icon.false'),
|
||||
$stateItem instanceof HasLabel => $stateItem->getLabel() ?? (($stateItem instanceof BackedEnum) ? $stateItem->value : ''),
|
||||
$stateItem instanceof BackedEnum => $stateItem->value,
|
||||
$stateItem instanceof Htmlable => strip_tags($stateItem->toHtml()),
|
||||
is_scalar($stateItem) => (string) $stateItem,
|
||||
$stateItem instanceof Stringable => (string) $stateItem,
|
||||
default => '',
|
||||
};
|
||||
|
||||
if (filled($accessibleText)) {
|
||||
$item .= '<span class="fi-sr-only">' . e($accessibleText) . '</span>';
|
||||
}
|
||||
|
||||
if (filled($url = $this->getUrl($stateItem))) {
|
||||
$item = '<a ' . generate_href_html($url, $shouldOpenUrlInNewTab)->toHtml() . '>' . $item . '</a>';
|
||||
}
|
||||
|
||||
return $item;
|
||||
};
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php foreach ($state as $stateItem) { ?>
|
||||
<?= $formatState($stateItem) ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
public function canWrapByDefault(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
573
vendor/filament/infolists/src/Components/ImageEntry.php
vendored
Normal file
573
vendor/filament/infolists/src/Components/ImageEntry.php
vendored
Normal file
|
|
@ -0,0 +1,573 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanWrap;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\TextSize;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
use League\Flysystem\UnableToCheckFileExistence;
|
||||
use Throwable;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
|
||||
class ImageEntry extends Entry implements HasEmbeddedView
|
||||
{
|
||||
use CanWrap;
|
||||
|
||||
protected string | Closure | null $diskName = null;
|
||||
|
||||
protected int | string | Closure | null $imageHeight = null;
|
||||
|
||||
protected int | string | Closure | null $imageWidth = null;
|
||||
|
||||
protected bool | Closure $isCircular = false;
|
||||
|
||||
protected bool | Closure $isSquare = false;
|
||||
|
||||
protected string | Closure | null $visibility = null;
|
||||
|
||||
protected int | string | Closure | null $width = null;
|
||||
|
||||
/**
|
||||
* @var array<mixed> | Closure
|
||||
*/
|
||||
protected array | Closure $extraImgAttributes = [];
|
||||
|
||||
protected string | Closure | null $alt = null;
|
||||
|
||||
protected string | Closure | null $defaultImageUrl = null;
|
||||
|
||||
protected bool | Closure $isStacked = false;
|
||||
|
||||
protected int | Closure | null $overlap = null;
|
||||
|
||||
protected int | Closure | null $ring = null;
|
||||
|
||||
protected int | Closure | null $limit = null;
|
||||
|
||||
protected bool | Closure $hasLimitedRemainingText = false;
|
||||
|
||||
protected bool | Closure $isLimitedRemainingTextSeparate = false;
|
||||
|
||||
protected TextSize | string | Closure | null $limitedRemainingTextSize = null;
|
||||
|
||||
protected bool | Closure $shouldCheckFileExistence = true;
|
||||
|
||||
public function disk(string | Closure | null $disk): static
|
||||
{
|
||||
$this->diskName = $disk;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function imageHeight(int | string | Closure | null $height): static
|
||||
{
|
||||
$this->imageHeight = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `imageHeight()` instead.
|
||||
*/
|
||||
public function height(int | string | Closure | null $height): static
|
||||
{
|
||||
$this->imageHeight($height);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function imageSize(int | string | Closure $size): static
|
||||
{
|
||||
$this->imageWidth($size);
|
||||
$this->imageHeight($size);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `imageSize()` instead.
|
||||
*/
|
||||
public function size(int | string | Closure $size): static
|
||||
{
|
||||
$this->imageSize($size);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function circular(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isCircular = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function square(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isSquare = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function visibility(string | Closure | null $visibility): static
|
||||
{
|
||||
$this->visibility = $visibility;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function imageWidth(int | string | Closure | null $width): static
|
||||
{
|
||||
$this->imageWidth = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `imageWidth()` instead.
|
||||
*/
|
||||
public function width(int | string | Closure | null $width): static
|
||||
{
|
||||
$this->imageWidth($width);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDisk(): Filesystem
|
||||
{
|
||||
return Storage::disk($this->getDiskName());
|
||||
}
|
||||
|
||||
public function getDiskName(): string
|
||||
{
|
||||
$name = $this->evaluate($this->diskName);
|
||||
|
||||
if (filled($name)) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
$defaultName = config('filament.default_filesystem_disk');
|
||||
|
||||
if (
|
||||
($defaultName === 'public')
|
||||
&& ($this->getCustomVisibility() === 'private')
|
||||
) {
|
||||
return 'local';
|
||||
}
|
||||
|
||||
return $defaultName;
|
||||
}
|
||||
|
||||
public function getImageHeight(): ?string
|
||||
{
|
||||
$height = $this->evaluate($this->imageHeight);
|
||||
|
||||
if ($height === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_int($height)) {
|
||||
return "{$height}px";
|
||||
}
|
||||
|
||||
return $height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getImageHeight()` instead.
|
||||
*/
|
||||
public function getHeight(): ?string
|
||||
{
|
||||
return $this->getImageHeight();
|
||||
}
|
||||
|
||||
public function defaultImageUrl(string | Closure | null $url): static
|
||||
{
|
||||
$this->defaultImageUrl = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function alt(string | Closure | null $alt): static
|
||||
{
|
||||
$this->alt = $alt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAlt(mixed $state = null): ?string
|
||||
{
|
||||
return $this->evaluate($this->alt, ['state' => $state]);
|
||||
}
|
||||
|
||||
public function getImageUrl(?string $state = null): ?string
|
||||
{
|
||||
if ((filter_var($state, FILTER_VALIDATE_URL) !== false) || str($state)->startsWith('data:')) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
/** @var FilesystemAdapter $storage */
|
||||
$storage = $this->getDisk();
|
||||
|
||||
if ($this->shouldCheckFileExistence()) {
|
||||
try {
|
||||
if (! $storage->exists($state)) {
|
||||
return null;
|
||||
}
|
||||
} catch (UnableToCheckFileExistence $exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getVisibility() === 'private') {
|
||||
try {
|
||||
return $storage->temporaryUrl(
|
||||
$state,
|
||||
now()->addMinutes(config('filament.temporary_file_url_expiry_minutes', 30))->endOfHour(),
|
||||
);
|
||||
} catch (Throwable $exception) {
|
||||
// This driver does not support creating temporary URLs.
|
||||
}
|
||||
}
|
||||
|
||||
return $storage->url($state);
|
||||
}
|
||||
|
||||
public function getDefaultImageUrl(): ?string
|
||||
{
|
||||
return $this->evaluate($this->defaultImageUrl);
|
||||
}
|
||||
|
||||
public function getVisibility(): string
|
||||
{
|
||||
$visibility = $this->getCustomVisibility();
|
||||
|
||||
if (filled($visibility)) {
|
||||
return $visibility;
|
||||
}
|
||||
|
||||
return ($this->getDiskName() === 'public') ? 'public' : 'private';
|
||||
}
|
||||
|
||||
public function getCustomVisibility(): ?string
|
||||
{
|
||||
return $this->evaluate($this->visibility);
|
||||
}
|
||||
|
||||
public function getImageWidth(): ?string
|
||||
{
|
||||
$width = $this->evaluate($this->imageWidth);
|
||||
|
||||
if ($width === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_int($width)) {
|
||||
return "{$width}px";
|
||||
}
|
||||
|
||||
return $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getImageWidth()` instead.
|
||||
*/
|
||||
public function getWidth(): ?string
|
||||
{
|
||||
return $this->getImageWidth();
|
||||
}
|
||||
|
||||
public function isCircular(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isCircular);
|
||||
}
|
||||
|
||||
public function isSquare(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isSquare);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> | Closure $attributes
|
||||
*/
|
||||
public function extraImgAttributes(array | Closure $attributes): static
|
||||
{
|
||||
// Security: Attribute values are not escaped when rendered. Never
|
||||
// pass unsanitized user input as attribute names or values.
|
||||
|
||||
$this->extraImgAttributes = $attributes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function getExtraImgAttributes(): array
|
||||
{
|
||||
return $this->evaluate($this->extraImgAttributes);
|
||||
}
|
||||
|
||||
public function getExtraImgAttributeBag(): ComponentAttributeBag
|
||||
{
|
||||
return new FilamentComponentAttributeBag($this->getExtraImgAttributes());
|
||||
}
|
||||
|
||||
public function stacked(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isStacked = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isStacked(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isStacked);
|
||||
}
|
||||
|
||||
public function overlap(int | Closure | null $overlap): static
|
||||
{
|
||||
$this->overlap = $overlap;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOverlap(): ?int
|
||||
{
|
||||
return $this->evaluate($this->overlap);
|
||||
}
|
||||
|
||||
public function ring(string | Closure | null $ring): static
|
||||
{
|
||||
$this->ring = $ring;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRing(): ?int
|
||||
{
|
||||
return $this->evaluate($this->ring);
|
||||
}
|
||||
|
||||
public function limit(int | Closure | null $limit = 3): static
|
||||
{
|
||||
$this->limit = $limit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLimit(): ?int
|
||||
{
|
||||
return $this->evaluate($this->limit);
|
||||
}
|
||||
|
||||
public function limitedRemainingText(bool | Closure $condition = true, bool | Closure $isSeparate = false, TextSize | string | Closure | null $size = null): static
|
||||
{
|
||||
$this->hasLimitedRemainingText = $condition;
|
||||
$this->limitedRemainingTextSeparate($isSeparate);
|
||||
$this->limitedRemainingTextSize($size);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limitedRemainingTextSeparate(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isLimitedRemainingTextSeparate = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasLimitedRemainingText(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasLimitedRemainingText);
|
||||
}
|
||||
|
||||
public function isLimitedRemainingTextSeparate(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isLimitedRemainingTextSeparate);
|
||||
}
|
||||
|
||||
public function limitedRemainingTextSize(TextSize | string | Closure | null $size): static
|
||||
{
|
||||
$this->limitedRemainingTextSize = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLimitedRemainingTextSize(): TextSize | string | null
|
||||
{
|
||||
$size = $this->evaluate($this->limitedRemainingTextSize);
|
||||
|
||||
if (blank($size)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($size)) {
|
||||
$size = TextSize::tryFrom($size) ?? $size;
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public function checkFileExistence(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldCheckFileExistence = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shouldCheckFileExistence(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldCheckFileExistence);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$state = $this->getState();
|
||||
|
||||
if ($state instanceof Collection) {
|
||||
$state = $state->all();
|
||||
}
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-in-image',
|
||||
]);
|
||||
|
||||
$defaultImageUrl = $this->getDefaultImageUrl();
|
||||
|
||||
if (blank($state) && filled($defaultImageUrl)) {
|
||||
$state = [null];
|
||||
}
|
||||
|
||||
if (blank($state)) {
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-tooltip' => filled($tooltip = $this->getEmptyTooltip())
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
|
||||
}'
|
||||
: null,
|
||||
], escape: false);
|
||||
|
||||
$placeholder = $this->getPlaceholder();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($placeholder)) { ?>
|
||||
<p class="fi-in-placeholder">
|
||||
<?= e($placeholder) ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
$state = Arr::wrap($state);
|
||||
$stateCount = count($state);
|
||||
|
||||
$limit = $this->getLimit() ?? $stateCount;
|
||||
|
||||
$stateOverLimitCount = ($limit && ($stateCount > $limit))
|
||||
? ($stateCount - $limit)
|
||||
: 0;
|
||||
|
||||
if ($stateOverLimitCount) {
|
||||
$state = array_slice($state, 0, $limit);
|
||||
}
|
||||
|
||||
$alignment = $this->getAlignment();
|
||||
$isCircular = $this->isCircular();
|
||||
$isSquare = $this->isSquare();
|
||||
$isStacked = $this->isStacked();
|
||||
$hasLimitedRemainingText = $stateOverLimitCount && $this->hasLimitedRemainingText();
|
||||
$limitedRemainingTextSize = $this->getLimitedRemainingTextSize();
|
||||
$height = $this->getImageHeight() ?? ($isStacked ? '2.5rem' : '8rem');
|
||||
$width = $this->getImageWidth() ?? (($isCircular || $isSquare) ? $height : null);
|
||||
|
||||
$attributes = $attributes
|
||||
->class([
|
||||
'fi-circular' => $isCircular,
|
||||
'fi-wrapped' => $this->canWrap(),
|
||||
'fi-stacked' => $isStacked,
|
||||
($isStacked && is_int($ring = $this->getRing())) ? "fi-in-image-ring fi-in-image-ring-{$ring}" : '',
|
||||
($isStacked && ($overlap = ($this->getOverlap() ?? 2))) ? "fi-in-image-overlap-{$overlap}" : '',
|
||||
($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : ''),
|
||||
]);
|
||||
|
||||
$shouldOpenUrlInNewTab = $this->shouldOpenUrlInNewTab();
|
||||
|
||||
$formatState = function (mixed $stateItem) use ($defaultImageUrl, $width, $height, $shouldOpenUrlInNewTab): string {
|
||||
$item = '<img ' . $this->getExtraImgAttributeBag()
|
||||
->merge([
|
||||
'alt' => e($this->getAlt($stateItem) ?? ''),
|
||||
'src' => e(filled($stateItem) ? ($this->getImageUrl($stateItem) ?? $defaultImageUrl) : $defaultImageUrl),
|
||||
'x-tooltip' => filled($tooltip = $this->getTooltip($stateItem))
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false)
|
||||
->style([
|
||||
('height: ' . e($height)) => $height,
|
||||
('width: ' . e($width)) => $width,
|
||||
])
|
||||
->toHtml()
|
||||
. ' />';
|
||||
|
||||
if (filled($url = $this->getUrl($stateItem))) {
|
||||
$item = '<a ' . generate_href_html($url, $shouldOpenUrlInNewTab)->toHtml() . '>' . $item . '</a>';
|
||||
}
|
||||
|
||||
return $item;
|
||||
};
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php foreach ($state as $stateItem) { ?>
|
||||
<?= $formatState($stateItem) ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasLimitedRemainingText) { ?>
|
||||
<div <?= (new FilamentComponentAttributeBag)
|
||||
->class([
|
||||
'fi-in-image-limited-remaining-text',
|
||||
(($limitedRemainingTextSize instanceof TextSize) ? "fi-size-{$limitedRemainingTextSize->value}" : $limitedRemainingTextSize) => $limitedRemainingTextSize,
|
||||
])
|
||||
->style([
|
||||
('height: ' . e($height)) => $height,
|
||||
('width: ' . e($width)) => $width,
|
||||
])
|
||||
->toHtml() ?>>
|
||||
+<?= $stateOverLimitCount ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
public function canWrapByDefault(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
111
vendor/filament/infolists/src/Components/KeyValueEntry.php
vendored
Normal file
111
vendor/filament/infolists/src/Components/KeyValueEntry.php
vendored
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Stringable;
|
||||
|
||||
class KeyValueEntry extends Entry implements HasEmbeddedView
|
||||
{
|
||||
protected string | Closure | null $keyLabel = null;
|
||||
|
||||
protected string | Closure | null $valueLabel = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->placeholder(__('filament-infolists::components.entries.key_value.placeholder'));
|
||||
}
|
||||
|
||||
public function keyLabel(string | Closure | null $label): static
|
||||
{
|
||||
$this->keyLabel = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function valueLabel(string | Closure | null $label): static
|
||||
{
|
||||
$this->valueLabel = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `placeholder()` instead.
|
||||
*/
|
||||
public function emptyMessage(string | Closure | null $message): static
|
||||
{
|
||||
$this->placeholder($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getKeyLabel(): string
|
||||
{
|
||||
return $this->evaluate($this->keyLabel) ?? __('filament-infolists::components.entries.key_value.columns.key.label');
|
||||
}
|
||||
|
||||
public function getValueLabel(): string
|
||||
{
|
||||
return $this->evaluate($this->valueLabel) ?? __('filament-infolists::components.entries.key_value.columns.value.label');
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$state = $this->getState();
|
||||
|
||||
if ($state instanceof Collection) {
|
||||
$state = $state->all();
|
||||
}
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-in-key-value',
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<table <?= $attributes->toHtml() ?>>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<?= e($this->getKeyLabel()) ?>
|
||||
</th>
|
||||
|
||||
<th scope="col">
|
||||
<?= e($this->getValueLabel()) ?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<?php foreach (($state ?? []) as $key => $value) { ?>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<?= e($key) ?>
|
||||
</th>
|
||||
|
||||
<td>
|
||||
<?= e($value === null || is_scalar($value) || ($value instanceof Stringable) || ($value instanceof Htmlable) ? $value : json_encode($value)) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (empty($state)) { ?>
|
||||
<tr>
|
||||
<td colspan="2" class="fi-in-placeholder">
|
||||
<?= e($this->getPlaceholder()) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
}
|
||||
347
vendor/filament/infolists/src/Components/RepeatableEntry.php
vendored
Normal file
347
vendor/filament/infolists/src/Components/RepeatableEntry.php
vendored
Normal file
|
|
@ -0,0 +1,347 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
use ArrayAccess;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Concerns\HasContainerGridLayout;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanBeContained;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Generator;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Js;
|
||||
use Traversable;
|
||||
|
||||
class RepeatableEntry extends Entry implements HasEmbeddedView
|
||||
{
|
||||
use CanBeContained;
|
||||
use HasContainerGridLayout;
|
||||
|
||||
/**
|
||||
* @var array<TableColumn> | Closure | null
|
||||
*/
|
||||
protected array | Closure | null $tableColumns = null;
|
||||
|
||||
protected mixed $cachedItemsState = null;
|
||||
|
||||
protected ?Generator $cachedItemsStateGenerator = null;
|
||||
|
||||
/**
|
||||
* @var array<array-key, mixed> | null
|
||||
*/
|
||||
protected ?array $cachedItemsStateGeneratorSnapshot = null;
|
||||
|
||||
/**
|
||||
* Configure table columns for display
|
||||
*
|
||||
* @param array<TableColumn> | Closure | null $columns
|
||||
*/
|
||||
public function table(array | Closure | null $columns): static
|
||||
{
|
||||
$this->tableColumns = $columns;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configured table columns
|
||||
*
|
||||
* @return ?array<TableColumn>
|
||||
*/
|
||||
public function getTableColumns(): ?array
|
||||
{
|
||||
return $this->evaluate($this->tableColumns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if component should render as table
|
||||
*/
|
||||
public function isTable(): bool
|
||||
{
|
||||
return filled($this->getTableColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Schema>
|
||||
*/
|
||||
public function getItems(): array
|
||||
{
|
||||
return $this->getCachedDefaultChildSchemas();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Schema>
|
||||
*/
|
||||
public function getDefaultChildSchemas(): array
|
||||
{
|
||||
$state = $this->normalizeItemsState($this->getState() ?? []);
|
||||
|
||||
$this->cachedItemsState = $state;
|
||||
|
||||
$containers = [];
|
||||
|
||||
foreach ($state as $itemKey => $itemData) {
|
||||
$container = $this
|
||||
->getChildSchema()
|
||||
->getClone()
|
||||
->statePath($itemKey)
|
||||
->inlineLabel(false);
|
||||
|
||||
if ($itemData instanceof Model) {
|
||||
$container->record($itemData);
|
||||
} elseif (is_array($itemData) || is_object($itemData)) {
|
||||
$container->constantState($itemData);
|
||||
}
|
||||
|
||||
$containers[$itemKey] = $container;
|
||||
}
|
||||
|
||||
return $containers;
|
||||
}
|
||||
|
||||
protected function areCachedDefaultChildSchemasFresh(): bool
|
||||
{
|
||||
return $this->cachedItemsState === $this->normalizeItemsState($this->getState() ?? []);
|
||||
}
|
||||
|
||||
protected function isCachedDefaultChildSchemaFresh(string | int $key): bool
|
||||
{
|
||||
[$hasItem, $itemState] = $this->getItemState($this->getState() ?? [], $key);
|
||||
|
||||
return $hasItem
|
||||
&& is_array($this->cachedItemsState)
|
||||
&& array_key_exists($key, $this->cachedItemsState)
|
||||
&& ($this->cachedItemsState[$key] === $itemState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{bool, mixed}
|
||||
*/
|
||||
protected function getItemState(mixed $state, string | int $key): array
|
||||
{
|
||||
if ($state instanceof Generator) {
|
||||
$state = $this->normalizeItemsState($state);
|
||||
}
|
||||
|
||||
if ($state instanceof Collection) {
|
||||
$state = $state->all();
|
||||
}
|
||||
|
||||
if (is_array($state)) {
|
||||
return array_key_exists($key, $state)
|
||||
? [true, $state[$key]]
|
||||
: [false, null];
|
||||
}
|
||||
|
||||
if ($state instanceof ArrayAccess) {
|
||||
return $state->offsetExists($key)
|
||||
? [true, $state->offsetGet($key)]
|
||||
: [false, null];
|
||||
}
|
||||
|
||||
if (is_object($state) && property_exists($state, (string) $key)) {
|
||||
return [true, $state->{$key}];
|
||||
}
|
||||
|
||||
if ($state instanceof Traversable) {
|
||||
foreach ($state as $itemKey => $itemState) {
|
||||
if ($itemKey === $key) {
|
||||
return [true, $itemState];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [false, null];
|
||||
}
|
||||
|
||||
protected function normalizeItemsState(mixed $state): mixed
|
||||
{
|
||||
if ($state instanceof Generator) {
|
||||
if ($state === $this->cachedItemsStateGenerator) {
|
||||
return $this->cachedItemsStateGeneratorSnapshot;
|
||||
}
|
||||
|
||||
$snapshot = iterator_to_array($state);
|
||||
$this->cachedItemsStateGenerator = $state;
|
||||
$this->cachedItemsStateGeneratorSnapshot = $snapshot;
|
||||
|
||||
return $snapshot;
|
||||
}
|
||||
|
||||
if ($state instanceof Collection) {
|
||||
return $state->all();
|
||||
}
|
||||
|
||||
if ($state instanceof Traversable) {
|
||||
return iterator_to_array($state);
|
||||
}
|
||||
|
||||
if (is_object($state)) {
|
||||
return get_object_vars($state);
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
if ($this->isTable()) {
|
||||
return $this->toEmbeddedTableHtml();
|
||||
}
|
||||
|
||||
$items = $this->getItems();
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-in-repeatable',
|
||||
'fi-contained' => $this->isContained(),
|
||||
]);
|
||||
|
||||
if (empty($items)) {
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-tooltip' => filled($tooltip = $this->getEmptyTooltip())
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false);
|
||||
|
||||
$placeholder = $this->getPlaceholder();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($placeholder)) { ?>
|
||||
<p class="fi-in-placeholder">
|
||||
<?= e($placeholder) ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
$attributes = $attributes->grid($this->getGridColumns());
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<ul <?= $attributes->toHtml() ?>>
|
||||
<?php foreach ($items as $item) { ?>
|
||||
<li class="fi-in-repeatable-item">
|
||||
<?= $item->toHtml() ?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
protected function toEmbeddedTableHtml(): string
|
||||
{
|
||||
$items = $this->getItems();
|
||||
$tableColumns = $this->getTableColumns();
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-in-table-repeatable',
|
||||
]);
|
||||
|
||||
if (empty($items)) {
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-tooltip' => filled($tooltip = $this->getEmptyTooltip())
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false);
|
||||
|
||||
$placeholder = $this->getPlaceholder();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($placeholder)) { ?>
|
||||
<p class="fi-in-placeholder">
|
||||
<?= e($placeholder) ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<?php foreach ($tableColumns as $column) { ?>
|
||||
<th
|
||||
scope="col"
|
||||
class="<?= Arr::toCssClasses([
|
||||
'fi-wrapped' => $column->canHeaderWrap(),
|
||||
(($columnAlignment = $column->getAlignment()) instanceof Alignment) ? ('fi-align-' . $columnAlignment->value) : e($columnAlignment),
|
||||
]) ?>"
|
||||
<?php if (filled($columnWidth = $column->getWidth())) { ?>
|
||||
style="width: <?= e($columnWidth) ?>"
|
||||
<?php } ?>
|
||||
>
|
||||
<?php if (! $column->isHeaderLabelHidden()) { ?>
|
||||
<?= e($column->getLabel()) ?>
|
||||
<?php } else { ?>
|
||||
<span class="fi-sr-only">
|
||||
<?= e($column->getLabel()) ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</th>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<?php foreach ($items as $item) { ?>
|
||||
<tr>
|
||||
<?php $counter = 0 ?>
|
||||
|
||||
<?php foreach ($item->getComponents(withHidden: true) as $component) { ?>
|
||||
<?php throw_unless(
|
||||
$component instanceof Component,
|
||||
new Exception('Table repeatable entries must only contain schema components, but [' . $component::class . '] was used.'),
|
||||
) ?>
|
||||
|
||||
<?php if (count($tableColumns) > $counter) { ?>
|
||||
<?php $counter++ ?>
|
||||
|
||||
<?php if ($component->isVisible()) { ?>
|
||||
<td>
|
||||
<?= $component->toHtml() ?>
|
||||
</td>
|
||||
<?php } else { ?>
|
||||
<td class="fi-hidden"></td>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
}
|
||||
49
vendor/filament/infolists/src/Components/RepeatableEntry/TableColumn.php
vendored
Normal file
49
vendor/filament/infolists/src/Components/RepeatableEntry/TableColumn.php
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components\RepeatableEntry;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Component;
|
||||
use Filament\Support\Concerns\CanWrapHeader;
|
||||
use Filament\Support\Concerns\HasAlignment;
|
||||
use Filament\Support\Concerns\HasWidth;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class TableColumn extends Component
|
||||
{
|
||||
use CanWrapHeader;
|
||||
use HasAlignment;
|
||||
use HasWidth;
|
||||
|
||||
protected string $evaluationIdentifier = 'column';
|
||||
|
||||
protected bool | Closure $isHeaderLabelHidden = false;
|
||||
|
||||
public function __construct(protected string | Htmlable | Closure $label) {}
|
||||
|
||||
public static function make(string | Htmlable | Closure $label): static
|
||||
{
|
||||
$static = app(static::class, ['label' => $label]);
|
||||
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function hiddenHeaderLabel(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isHeaderLabelHidden = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLabel(): string | Htmlable
|
||||
{
|
||||
return $this->evaluate($this->label);
|
||||
}
|
||||
|
||||
public function isHeaderLabelHidden(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isHeaderLabelHidden);
|
||||
}
|
||||
}
|
||||
680
vendor/filament/infolists/src/Components/TextEntry.php
vendored
Normal file
680
vendor/filament/infolists/src/Components/TextEntry.php
vendored
Normal file
|
|
@ -0,0 +1,680 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\RichEditor\Models\Contracts\HasRichContent;
|
||||
use Filament\Infolists\View\Components\TextEntryComponent\ItemComponent;
|
||||
use Filament\Infolists\View\Components\TextEntryComponent\ItemComponent\IconComponent;
|
||||
use Filament\Schemas\Components\Contracts\HasAffixActions;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanBeCopied;
|
||||
use Filament\Support\Concerns\CanWrap;
|
||||
use Filament\Support\Concerns\HasFontFamily;
|
||||
use Filament\Support\Concerns\HasLineClamp;
|
||||
use Filament\Support\Concerns\HasWeight;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\FontFamily;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Enums\TextSize;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\BadgeComponent;
|
||||
use Illuminate\Contracts\Database\Query\Expression;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
use function Filament\Support\generate_icon_html;
|
||||
|
||||
class TextEntry extends Entry implements HasAffixActions, HasEmbeddedView
|
||||
{
|
||||
use CanBeCopied;
|
||||
use CanWrap;
|
||||
use Concerns\CanFormatState;
|
||||
use Concerns\HasAffixes;
|
||||
use Concerns\HasColor;
|
||||
use Concerns\HasIcon;
|
||||
use Concerns\HasIconColor;
|
||||
use HasFontFamily;
|
||||
use HasLineClamp;
|
||||
use HasWeight;
|
||||
|
||||
protected bool | Closure $isBadge = false;
|
||||
|
||||
protected bool | Closure $isBulleted = false;
|
||||
|
||||
protected bool | Closure $isProse = false;
|
||||
|
||||
protected bool | Closure $isListWithLineBreaks = false;
|
||||
|
||||
protected int | Closure | null $listLimit = null;
|
||||
|
||||
protected TextSize | string | Closure | null $size = null;
|
||||
|
||||
protected bool | Closure $isLimitedListExpandable = false;
|
||||
|
||||
public function badge(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isBadge = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function bulleted(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isBulleted = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function listWithLineBreaks(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isListWithLineBreaks = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limitList(int | Closure | null $limit = 3): static
|
||||
{
|
||||
$this->listLimit = $limit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function prose(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isProse = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function size(TextSize | string | Closure | null $size): static
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize(mixed $state): TextSize | string
|
||||
{
|
||||
$size = $this->evaluate($this->size, [
|
||||
'state' => $state,
|
||||
]);
|
||||
|
||||
if (blank($size)) {
|
||||
return TextSize::Small;
|
||||
}
|
||||
|
||||
if (is_string($size)) {
|
||||
$size = TextSize::tryFrom($size) ?? $size;
|
||||
}
|
||||
|
||||
if ($size === 'base') {
|
||||
return TextSize::Medium;
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public function isBadge(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isBadge);
|
||||
}
|
||||
|
||||
public function isBulleted(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isBulleted);
|
||||
}
|
||||
|
||||
public function isProse(): bool
|
||||
{
|
||||
if ($this->evaluate($this->isProse)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$record = $this->getRecord();
|
||||
|
||||
if (! ($record instanceof HasRichContent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $record->hasRichContentAttribute($this->getName());
|
||||
}
|
||||
|
||||
public function isListWithLineBreaks(): bool
|
||||
{
|
||||
return $this->evaluate($this->isListWithLineBreaks) || $this->isBulleted();
|
||||
}
|
||||
|
||||
public function getListLimit(): ?int
|
||||
{
|
||||
return $this->evaluate($this->listLimit);
|
||||
}
|
||||
|
||||
public function expandableLimitedList(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isLimitedListExpandable = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isLimitedListExpandable(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isLimitedListExpandable);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$isBadge = $this->isBadge();
|
||||
$isListWithLineBreaks = $this->isListWithLineBreaks();
|
||||
$isLimitedListExpandable = $this->isLimitedListExpandable();
|
||||
|
||||
$state = $this->getState();
|
||||
|
||||
if ($state instanceof Collection) {
|
||||
$state = $state->all();
|
||||
}
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-in-text',
|
||||
'fi-numeric' => $this->isNumeric() || $this->isMoney(),
|
||||
]);
|
||||
|
||||
if (blank($state instanceof Htmlable ? $state->toHtml() : $state)) {
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-tooltip' => filled($tooltip = $this->getEmptyTooltip())
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false);
|
||||
|
||||
$placeholder = $this->getPlaceholder();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($placeholder)) { ?>
|
||||
<p class="fi-in-placeholder">
|
||||
<?= e($placeholder) ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
$shouldOpenUrlInNewTab = $this->shouldOpenUrlInNewTab();
|
||||
|
||||
$formatState = function (mixed $stateItem, mixed $formattedState = null) use ($shouldOpenUrlInNewTab): string {
|
||||
$url = $this->getUrl($stateItem);
|
||||
|
||||
$item = '';
|
||||
|
||||
if (filled($url)) {
|
||||
$item .= '<a ' . generate_href_html($url, $shouldOpenUrlInNewTab)->toHtml() . '>';
|
||||
}
|
||||
|
||||
$item .= e($formattedState ?? $this->formatState($stateItem));
|
||||
|
||||
if (filled($url)) {
|
||||
$item .= '</a>';
|
||||
}
|
||||
|
||||
return $item;
|
||||
};
|
||||
|
||||
/** @var array<mixed> $state */
|
||||
$state = Arr::wrap($state);
|
||||
|
||||
$stateCount = count($state);
|
||||
|
||||
$listLimit = $this->getListLimit() ?? $stateCount;
|
||||
$stateOverListLimitCount = 0;
|
||||
|
||||
if ($listLimit && ($stateCount > $listLimit)) {
|
||||
$stateOverListLimitCount = $stateCount - $listLimit;
|
||||
|
||||
if (
|
||||
(! $isListWithLineBreaks) ||
|
||||
(! $isLimitedListExpandable)
|
||||
) {
|
||||
$state = array_slice($state, 0, $listLimit);
|
||||
}
|
||||
}
|
||||
|
||||
$isCollapsedList = false;
|
||||
|
||||
if (($stateCount > 1) && (! $isListWithLineBreaks) && (! $isBadge)) {
|
||||
$state = [
|
||||
implode(
|
||||
', ',
|
||||
array_map(
|
||||
fn (mixed $stateItem): string => $formatState($stateItem),
|
||||
$state,
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
$stateCount = 1;
|
||||
$formatState = fn (mixed $stateItem, mixed $formattedState = null): string => $stateItem;
|
||||
$isCollapsedList = true;
|
||||
}
|
||||
|
||||
$alignment = $this->getAlignment();
|
||||
|
||||
$attributes = $attributes
|
||||
->class([
|
||||
'fi-in-text-has-badges' => $isBadge,
|
||||
'fi-wrapped' => $this->canWrap(),
|
||||
($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : ''),
|
||||
]);
|
||||
|
||||
$lineClamp = $this->getLineClamp();
|
||||
$iconPosition = $this->getIconPosition();
|
||||
$isBulleted = $this->isBulleted();
|
||||
$isProse = $this->isProse();
|
||||
$isMarkdown = $this->isMarkdown();
|
||||
|
||||
$getStateItem = function (mixed $stateItem, mixed $formattedState = null) use ($iconPosition, $isBadge, $isMarkdown, $isProse, $lineClamp): array {
|
||||
$color = $this->getColor($stateItem) ?? ($isBadge ? 'primary' : null);
|
||||
$iconColor = $this->getIconColor($stateItem);
|
||||
|
||||
$size = $this->getSize($stateItem);
|
||||
|
||||
$iconHtml = generate_icon_html($this->getIcon($stateItem), attributes: (new FilamentComponentAttributeBag)
|
||||
->color(IconComponent::class, $iconColor), size: match ($size) {
|
||||
TextSize::Medium => IconSize::Medium,
|
||||
TextSize::Large => IconSize::Large,
|
||||
default => IconSize::Small,
|
||||
})?->toHtml();
|
||||
|
||||
$isCopyable = $this->isCopyable($stateItem);
|
||||
|
||||
if ($isCopyable) {
|
||||
$copyableStateJs = Js::from($this->getCopyableState($stateItem) ?? $formattedState ?? $this->formatState($stateItem));
|
||||
$copyMessageJs = Js::from($this->getCopyMessage($stateItem));
|
||||
$copyMessageDurationJs = Js::from($this->getCopyMessageDuration($stateItem));
|
||||
}
|
||||
|
||||
$tooltip = $this->getTooltip($stateItem);
|
||||
|
||||
return [
|
||||
'attributes' => (new FilamentComponentAttributeBag)
|
||||
->class([
|
||||
'fi-in-text-item',
|
||||
'fi-prose' => $isProse || $isMarkdown,
|
||||
(($fontFamily = $this->getFontFamily($stateItem)) instanceof FontFamily) ? "fi-font-{$fontFamily->value}" : (is_string($fontFamily) ? $fontFamily : ''),
|
||||
])
|
||||
->when(
|
||||
! $isBadge,
|
||||
fn (ComponentAttributeBag $attributes) => $attributes
|
||||
->class([
|
||||
($size instanceof TextSize) ? "fi-size-{$size->value}" : $size,
|
||||
(($weight = $this->getWeight($stateItem)) instanceof FontWeight) ? "fi-font-{$weight->value}" : (is_string($weight) ? $weight : ''),
|
||||
])
|
||||
->when($lineClamp, fn (ComponentAttributeBag $attributes) => $attributes->style([
|
||||
"--line-clamp: {$lineClamp}",
|
||||
]))
|
||||
->color(ItemComponent::class, $color)
|
||||
),
|
||||
'contentAttributes' => ($isBadge || $isCopyable || filled($tooltip))
|
||||
? (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'x-on:click' => $isCopyable
|
||||
? <<<JS
|
||||
window.navigator.clipboard.writeText({$copyableStateJs})
|
||||
\$tooltip({$copyMessageJs}, {
|
||||
theme: \$store.theme,
|
||||
timeout: {$copyMessageDurationJs},
|
||||
})
|
||||
JS
|
||||
: null,
|
||||
'x-tooltip' => filled($tooltip)
|
||||
? '{
|
||||
content: ' . Js::from($tooltip) . ',
|
||||
theme: $store.theme,
|
||||
allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ',
|
||||
}'
|
||||
: null,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-copyable' => $isCopyable,
|
||||
])
|
||||
->when(
|
||||
$isBadge,
|
||||
fn (ComponentAttributeBag $attributes) => $attributes
|
||||
->class([
|
||||
'fi-badge',
|
||||
($size instanceof TextSize) ? "fi-size-{$size->value}" : $size,
|
||||
])
|
||||
->color(BadgeComponent::class, $color ?? 'primary')
|
||||
)
|
||||
: null,
|
||||
'iconAfterHtml' => ($iconPosition === IconPosition::After) ? $iconHtml : '',
|
||||
'iconBeforeHtml' => ($iconPosition === IconPosition::Before) ? $iconHtml : '',
|
||||
];
|
||||
};
|
||||
|
||||
$prefixActions = array_filter(
|
||||
$this->getPrefixActions(),
|
||||
fn (Action $prefixAction): bool => $prefixAction->isVisible(),
|
||||
);
|
||||
|
||||
$suffixActions = array_filter(
|
||||
$this->getSuffixActions(),
|
||||
fn (Action $suffixAction): bool => $suffixAction->isVisible(),
|
||||
);
|
||||
|
||||
$hasAffixActions = ((bool) $prefixActions) || ((bool) $suffixActions);
|
||||
|
||||
if (
|
||||
($stateCount === 1) &&
|
||||
(! $isBulleted) &&
|
||||
empty($prefixActions) &&
|
||||
empty($suffixActions)
|
||||
) {
|
||||
$stateItem = Arr::first($state);
|
||||
$stateItemFormattedState = $isCollapsedList ? null : $this->formatState($stateItem);
|
||||
[
|
||||
'attributes' => $stateItemAttributes,
|
||||
'contentAttributes' => $stateItemContentAttributes,
|
||||
'iconAfterHtml' => $stateItemIconAfterHtml,
|
||||
'iconBeforeHtml' => $stateItemIconBeforeHtml,
|
||||
] = $getStateItem($stateItem, $stateItemFormattedState);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes
|
||||
->merge($stateItemAttributes->getAttributes(), escape: false)
|
||||
->toHtml() ?>>
|
||||
<?php if ($stateItemContentAttributes) { ?>
|
||||
<span <?= $stateItemContentAttributes->toHtml() ?>>
|
||||
<?php } ?>
|
||||
|
||||
<?= $stateItemIconBeforeHtml ?>
|
||||
<?= $formatState($stateItem, $stateItemFormattedState) ?>
|
||||
<?= $stateItemIconAfterHtml ?>
|
||||
|
||||
<?php if ($stateItemContentAttributes) { ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
$attributes = $attributes
|
||||
->class([
|
||||
'fi-bulleted' => $isBulleted,
|
||||
'fi-in-text-has-line-breaks' => $isListWithLineBreaks,
|
||||
]);
|
||||
|
||||
if ($stateOverListLimitCount || $hasAffixActions) {
|
||||
$attributes = $attributes
|
||||
->merge([
|
||||
'x-data' => $isLimitedListExpandable
|
||||
? '{ isLimited: true }'
|
||||
: null,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-in-text-affixed' => $hasAffixActions,
|
||||
'fi-in-text-list-limited' => $stateOverListLimitCount,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if ($prefixActions) { ?>
|
||||
<div class="fi-in-text-affix">
|
||||
<?php foreach ($prefixActions as $prefixAction) { ?>
|
||||
<?= $prefixAction->toHtml() ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasAffixActions) { ?>
|
||||
<div class="fi-in-text-affixed-content">
|
||||
<?php } ?>
|
||||
|
||||
<ul>
|
||||
<?php $stateIteration = 1; ?>
|
||||
|
||||
<?php foreach ($state as $stateItem) { ?>
|
||||
<?php $stateItemFormattedState = $isCollapsedList ? null : $this->formatState($stateItem); ?>
|
||||
<?php [
|
||||
'attributes' => $stateItemAttributes,
|
||||
'contentAttributes' => $stateItemContentAttributes,
|
||||
'iconAfterHtml' => $stateItemIconAfterHtml,
|
||||
'iconBeforeHtml' => $stateItemIconBeforeHtml,
|
||||
] = $getStateItem($stateItem, $stateItemFormattedState); ?>
|
||||
|
||||
<li
|
||||
<?php if ($stateIteration > $listLimit) { ?>
|
||||
x-show="! isLimited"
|
||||
x-cloak
|
||||
x-transition
|
||||
<?php } ?>
|
||||
<?= $stateItemAttributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($stateItemContentAttributes) { ?>
|
||||
<span <?= $stateItemContentAttributes->toHtml() ?>>
|
||||
<?php } ?>
|
||||
|
||||
<?= $stateItemIconBeforeHtml ?>
|
||||
<?= $formatState($stateItem, $stateItemFormattedState) ?>
|
||||
<?= $stateItemIconAfterHtml ?>
|
||||
|
||||
<?php if ($stateItemContentAttributes) { ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</li>
|
||||
|
||||
<?php $stateIteration++ ?>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
||||
<?php if ($stateOverListLimitCount) { ?>
|
||||
<div class="fi-in-text-list-limited-message">
|
||||
<?php
|
||||
// These stay `<div role="button">` — not a real `<button>`, and deliberately without
|
||||
// `tabindex`. When the entry has a URL or action, `entry-wrapper.blade.php` wraps the whole
|
||||
// entry content in an `<a>` / `<button>`, and a `<button>` — or any element with `tabindex`
|
||||
// — is interactive content that is invalid nested inside a link/button. `role="button"` +
|
||||
// `aria-expanded` expose the control's purpose and state to assistive tech without
|
||||
// introducing that invalid nesting.
|
||||
?>
|
||||
<?php if ($isLimitedListExpandable) { ?>
|
||||
<div
|
||||
role="button"
|
||||
x-bind:aria-expanded="(! isLimited).toString()"
|
||||
x-on:click.prevent.stop="isLimited = false"
|
||||
x-show="isLimited"
|
||||
class="fi-link fi-size-xs"
|
||||
>
|
||||
<?= trans_choice('filament-infolists::components.entries.text.actions.expand_list', $stateOverListLimitCount) ?>
|
||||
</div>
|
||||
|
||||
<div
|
||||
role="button"
|
||||
x-bind:aria-expanded="(! isLimited).toString()"
|
||||
x-on:click.prevent.stop="isLimited = true"
|
||||
x-cloak
|
||||
x-show="! isLimited"
|
||||
class="fi-link fi-size-xs"
|
||||
>
|
||||
<?= trans_choice('filament-infolists::components.entries.text.actions.collapse_list', $stateOverListLimitCount) ?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<?= trans_choice('filament-infolists::components.entries.text.more_list_items', $stateOverListLimitCount) ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasAffixActions) { ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($suffixActions) { ?>
|
||||
<div class="fi-in-text-affix">
|
||||
<?php foreach ($suffixActions as $suffixAction) { ?>
|
||||
<?= $suffixAction->toHtml() ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<ul <?= $attributes->toHtml() ?>>
|
||||
<?php foreach ($state as $stateItem) { ?>
|
||||
<?php $stateItemFormattedState = $isCollapsedList ? null : $this->formatState($stateItem); ?>
|
||||
<?php [
|
||||
'attributes' => $stateItemAttributes,
|
||||
'contentAttributes' => $stateItemContentAttributes,
|
||||
'iconAfterHtml' => $stateItemIconAfterHtml,
|
||||
'iconBeforeHtml' => $stateItemIconBeforeHtml,
|
||||
] = $getStateItem($stateItem, $stateItemFormattedState); ?>
|
||||
|
||||
<li <?= $stateItemAttributes->toHtml() ?>>
|
||||
<?php if ($stateItemContentAttributes) { ?>
|
||||
<span <?= $stateItemContentAttributes->toHtml() ?>>
|
||||
<?php } ?>
|
||||
|
||||
<?= $stateItemIconBeforeHtml ?>
|
||||
<?= $formatState($stateItem, $stateItemFormattedState) ?>
|
||||
<?= $stateItemIconAfterHtml ?>
|
||||
|
||||
<?php if ($stateItemContentAttributes) { ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
||||
<?php return $this->wrapEmbeddedHtml(ob_get_clean());
|
||||
}
|
||||
|
||||
public function canWrapByDefault(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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->state(function (TextEntry $entry, ?Model $record) use ($relationship, $column): int | float | null {
|
||||
if (blank($record)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$record->loadAvg(
|
||||
$entry->evaluate($relationship),
|
||||
$entry->evaluate($column),
|
||||
);
|
||||
|
||||
return $record->getAttributeValue($entry->getName());
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<int | string, string | Closure> | Closure | null $relationships
|
||||
*/
|
||||
public function counts(string | array | Closure | null $relationships): static
|
||||
{
|
||||
$this->state(function (TextEntry $entry, ?Model $record) use ($relationships): int | float | null {
|
||||
if (blank($record)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$record->loadCount(
|
||||
$entry->evaluate($relationships),
|
||||
);
|
||||
|
||||
return $record->getAttributeValue($entry->getName());
|
||||
});
|
||||
|
||||
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->state(function (TextEntry $entry, ?Model $record) use ($relationship, $column): int | float | null {
|
||||
if (blank($record)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$record->loadMax(
|
||||
$entry->evaluate($relationship),
|
||||
$entry->evaluate($column),
|
||||
);
|
||||
|
||||
return $record->getAttributeValue($entry->getName());
|
||||
});
|
||||
|
||||
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->state(function (TextEntry $entry, ?Model $record) use ($relationship, $column): int | float | null {
|
||||
if (blank($record)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$record->loadMin(
|
||||
$entry->evaluate($relationship),
|
||||
$entry->evaluate($column),
|
||||
);
|
||||
|
||||
return $record->getAttributeValue($entry->getName());
|
||||
});
|
||||
|
||||
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->state(function (TextEntry $entry, ?Model $record) use ($relationship, $column): int | float | null {
|
||||
if (blank($record)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$record->loadSum(
|
||||
$entry->evaluate($relationship),
|
||||
$entry->evaluate($column),
|
||||
);
|
||||
|
||||
return $record->getAttributeValue($entry->getName());
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
5
vendor/filament/infolists/src/Components/ViewEntry.php
vendored
Normal file
5
vendor/filament/infolists/src/Components/ViewEntry.php
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Infolists\Components;
|
||||
|
||||
class ViewEntry extends Entry {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue