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
280
vendor/filament/support/src/View/ComponentAttributeBag.php
vendored
Normal file
280
vendor/filament/support/src/View/ComponentAttributeBag.php
vendored
Normal file
|
|
@ -0,0 +1,280 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Enums\GridDirection;
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\View\AppendableAttributeValue;
|
||||
use Illuminate\View\ComponentAttributeBag as BaseComponentAttributeBag;
|
||||
|
||||
/**
|
||||
* Optimized attribute bag that avoids the Collection overhead in
|
||||
* Laravel's `merge()`, `class()` and `style()` implementations.
|
||||
*
|
||||
* Laravel's `merge()` creates a Collection, partitions it with a
|
||||
* closure, maps with another closure, then merges — all to handle
|
||||
* class/style concatenation.
|
||||
*
|
||||
* @phpstan-consistent-constructor
|
||||
*/
|
||||
class ComponentAttributeBag extends BaseComponentAttributeBag
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public static function hasMacro($name): bool
|
||||
{
|
||||
return parent::hasMacro($name) || BaseComponentAttributeBag::hasMacro($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param array<mixed> $parameters
|
||||
*/
|
||||
public function __call($method, $parameters): mixed
|
||||
{
|
||||
if (parent::hasMacro($method) || (! BaseComponentAttributeBag::hasMacro($method))) {
|
||||
return parent::__call($method, $parameters);
|
||||
}
|
||||
|
||||
$macro = (fn () => static::$macros[$method])->bindTo(null, BaseComponentAttributeBag::class)();
|
||||
|
||||
if ($macro instanceof Closure) {
|
||||
$macro = $macro->bindTo($this, static::class);
|
||||
}
|
||||
|
||||
return $macro(...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* When updating this method, also update the corresponding macro in `Filament\Support\SupportServiceProvider`.
|
||||
*
|
||||
* @param string | array<string> | null $color
|
||||
*/
|
||||
public function color(string | HasColor $component, string | array | null $color): static
|
||||
{
|
||||
if (is_array($color)) {
|
||||
return $this
|
||||
->class(['fi-color'])
|
||||
->style(FilamentColor::getComponentCustomStyles($component, $color));
|
||||
}
|
||||
|
||||
return $this->class(FilamentColor::getComponentClasses($component, $color));
|
||||
}
|
||||
|
||||
/**
|
||||
* When updating this method, also update the corresponding macro in `Filament\Support\SupportServiceProvider`.
|
||||
*
|
||||
* @param array<string, ?int> | int | null $columns
|
||||
*/
|
||||
public function grid(array | int | null $columns = [], GridDirection $direction = GridDirection::Row): static
|
||||
{
|
||||
if (! is_array($columns)) {
|
||||
$columns = ['lg' => $columns];
|
||||
}
|
||||
|
||||
$columns = array_filter($columns);
|
||||
|
||||
$columns['default'] ??= 1;
|
||||
|
||||
return $this
|
||||
->class([
|
||||
'fi-grid',
|
||||
'fi-grid-direction-col' => $direction === GridDirection::Column,
|
||||
...array_map(
|
||||
fn (string $breakpoint): string => match ($breakpoint) {
|
||||
'default' => ($columns[$breakpoint] > 1) ? 'fi-grid-cols' : '',
|
||||
default => "{$breakpoint}:fi-grid-cols",
|
||||
},
|
||||
array_keys($columns),
|
||||
),
|
||||
])
|
||||
->style(array_map(
|
||||
fn (string $breakpoint, int $columns): string => match ($direction) {
|
||||
GridDirection::Row => '--cols-' . str_replace('!', 'n', str_replace('@', 'c', $breakpoint)) . ": repeat({$columns}, minmax(0, 1fr))",
|
||||
GridDirection::Column => '--cols-' . str_replace('!', 'n', str_replace('@', 'c', $breakpoint)) . ": {$columns}",
|
||||
},
|
||||
array_keys($columns),
|
||||
array_values($columns),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* When updating this method, also update the corresponding macro in `Filament\Support\SupportServiceProvider`.
|
||||
*
|
||||
* @param array<string, int | string | null> | int | string | null $span
|
||||
* @param array<string, int | string | null> | int | string | null $start
|
||||
* @param array<string, ?int> | int | string | null $order
|
||||
*/
|
||||
public function gridColumn(array | int | string | null $span = [], array | int | string | null $start = [], array | int | string | null $order = [], bool $isHidden = false): static
|
||||
{
|
||||
if (! is_array($span)) {
|
||||
$span = ['lg' => $span];
|
||||
}
|
||||
|
||||
if (! is_array($start)) {
|
||||
$start = ['lg' => $start];
|
||||
}
|
||||
|
||||
if (! is_array($order)) {
|
||||
$order = ['lg' => $order];
|
||||
}
|
||||
|
||||
$span = array_filter($span);
|
||||
|
||||
$start = array_filter($start);
|
||||
|
||||
$order = Arr::whereNotNull($order);
|
||||
|
||||
return $this
|
||||
->class([
|
||||
'fi-grid-col',
|
||||
'fi-hidden' => $isHidden || (($span['default'] ?? null) === 'hidden'),
|
||||
...array_map(
|
||||
fn (string $breakpoint): string => match ($breakpoint) {
|
||||
'default' => '',
|
||||
default => "{$breakpoint}:fi-grid-col-span",
|
||||
},
|
||||
array_keys($span),
|
||||
),
|
||||
...array_map(
|
||||
fn (string $breakpoint): string => match ($breakpoint) {
|
||||
'default' => 'fi-grid-col-start',
|
||||
default => "{$breakpoint}:fi-grid-col-start",
|
||||
},
|
||||
array_keys($start),
|
||||
),
|
||||
...array_map(
|
||||
fn (string $breakpoint): string => match ($breakpoint) {
|
||||
'default' => 'fi-grid-col-order',
|
||||
default => "{$breakpoint}:fi-grid-col-order",
|
||||
},
|
||||
array_keys($order),
|
||||
),
|
||||
])
|
||||
->style([
|
||||
...array_map(
|
||||
fn (string $breakpoint, int | string $span): string => '--col-span-' . str_replace('!', 'n', str_replace('@', 'c', $breakpoint)) . ': ' . match ($span) {
|
||||
'full' => '1 / -1',
|
||||
default => "span {$span} / span {$span}",
|
||||
},
|
||||
array_keys($span),
|
||||
array_values($span),
|
||||
),
|
||||
...array_map(
|
||||
fn (string $breakpoint, int $start): string => '--col-start-' . str_replace('!', 'n', str_replace('@', 'c', $breakpoint)) . ': ' . $start,
|
||||
array_keys($start),
|
||||
array_values($start),
|
||||
),
|
||||
...array_map(
|
||||
fn (string $breakpoint, int $order): string => '--col-order-' . str_replace('!', 'n', str_replace('@', 'c', $breakpoint)) . ': ' . $order,
|
||||
array_keys($order),
|
||||
array_values($order),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $classList
|
||||
*/
|
||||
public function class($classList): static
|
||||
{
|
||||
$classList = Arr::wrap($classList);
|
||||
$classes = Arr::toCssClasses($classList);
|
||||
|
||||
if ($classes === '') {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$attributes = $this->attributes;
|
||||
$existing = $attributes['class'] ?? '';
|
||||
$attributes['class'] = $existing !== '' ? ($existing . ' ' . $classes) : $classes;
|
||||
|
||||
return new static($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $styleList
|
||||
*/
|
||||
public function style($styleList): static
|
||||
{
|
||||
$styleList = Arr::wrap($styleList);
|
||||
$styles = Arr::toCssStyles($styleList);
|
||||
|
||||
if ($styles === '') {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$attributes = $this->attributes;
|
||||
$existing = $attributes['style'] ?? '';
|
||||
|
||||
if ($existing !== '') {
|
||||
$existing = rtrim($existing, '; ') . '; ';
|
||||
}
|
||||
|
||||
$attributes['style'] = $existing . $styles;
|
||||
|
||||
return new static($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributeDefaults
|
||||
* @param bool $escape
|
||||
*/
|
||||
public function merge(array $attributeDefaults = [], $escape = true): static
|
||||
{
|
||||
if ($escape) {
|
||||
foreach ($attributeDefaults as $key => $value) {
|
||||
if ($this->shouldEscapeAttributeValue($escape, $value)) {
|
||||
$attributeDefaults[$key] = e($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$hasAppendableAttributeValues = false;
|
||||
|
||||
foreach ($attributeDefaults as $key => $value) {
|
||||
if (! ($value instanceof AppendableAttributeValue)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hasAppendableAttributeValues = true;
|
||||
|
||||
$innerValue = $value->value;
|
||||
|
||||
if ($escape && $this->shouldEscapeAttributeValue($escape, $innerValue)) {
|
||||
$attributeDefaults[$key] = new AppendableAttributeValue(e($innerValue));
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasAppendableAttributeValues) {
|
||||
return parent::merge($attributeDefaults, escape: false);
|
||||
}
|
||||
|
||||
$result = $attributeDefaults;
|
||||
|
||||
foreach ($this->attributes as $key => $value) {
|
||||
if ($key === 'class' || $key === 'style') {
|
||||
$defaultValue = $result[$key] ?? '';
|
||||
|
||||
if ($key === 'style' && $value !== '') {
|
||||
$value = rtrim($value, '; ') . ';';
|
||||
}
|
||||
|
||||
$parts = array_filter([$defaultValue, $value], fn ($part) => ($part !== '') && ($part !== null));
|
||||
|
||||
if ($parts !== []) {
|
||||
$result[$key] = implode(' ', array_unique($parts));
|
||||
}
|
||||
} else {
|
||||
// Existing attributes take precedence over defaults
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return new static($result);
|
||||
}
|
||||
}
|
||||
25
vendor/filament/support/src/View/Components/BadgeComponent.php
vendored
Normal file
25
vendor/filament/support/src/View/Components/BadgeComponent.php
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components;
|
||||
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\ColorMaps\ComponentColorMap;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class BadgeComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
$gray = FilamentColor::getColor('gray');
|
||||
|
||||
return ComponentColorMap::make($color)
|
||||
->slot('text', surface: $color[50], fallback: 900)
|
||||
->slot('dark:text', surface: $gray[600], maxShade: 500, shouldStartFromDarkest: true, fallback: 200)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
50
vendor/filament/support/src/View/Components/ButtonComponent.php
vendored
Normal file
50
vendor/filament/support/src/View/Components/ButtonComponent.php
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components;
|
||||
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\ColorMaps\ButtonComponentColorMap;
|
||||
use Filament\Support\View\Components\ColorMaps\ComponentColorMap;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class ButtonComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @var array<int, static>
|
||||
*/
|
||||
protected static array $cachedInstances = [];
|
||||
|
||||
public function __construct(
|
||||
public readonly bool $isOutlined = false,
|
||||
) {}
|
||||
|
||||
public static function make(bool $isOutlined = false): static
|
||||
{
|
||||
return static::$cachedInstances[$isOutlined] ??= app(static::class, ['isOutlined' => $isOutlined]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
$gray = FilamentColor::getColor('gray');
|
||||
|
||||
if ($this->isOutlined) {
|
||||
return ComponentColorMap::make($color)
|
||||
->slot('text', surface: $gray[50], minRatio: Color::WCAG_AA_TEXT, fallback: 900)
|
||||
->slot('dark:text', surface: $gray[700], minRatio: Color::WCAG_AA_TEXT, maxShade: 500, shouldStartFromDarkest: true, fallback: 200)
|
||||
->get();
|
||||
}
|
||||
|
||||
return ButtonComponentColorMap::make($color)
|
||||
->minContrastRatio(Color::WCAG_AA_TEXT)
|
||||
->lightBackground(bg: 600, hover: 500)
|
||||
->lightBackground(bg: 400, hover: 300, alternateHover: 500)
|
||||
->darkBackground(bg: 600, hover: 500, alternateHover: 700)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
18
vendor/filament/support/src/View/Components/CalloutComponent.php
vendored
Normal file
18
vendor/filament/support/src/View/Components/CalloutComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class CalloutComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
18
vendor/filament/support/src/View/Components/CalloutComponent/IconComponent.php
vendored
Normal file
18
vendor/filament/support/src/View/Components/CalloutComponent/IconComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\CalloutComponent;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class IconComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
225
vendor/filament/support/src/View/Components/ColorMaps/ButtonComponentColorMap.php
vendored
Normal file
225
vendor/filament/support/src/View/Components/ColorMaps/ButtonComponentColorMap.php
vendored
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\ColorMaps;
|
||||
|
||||
use Filament\Support\Colors\Color;
|
||||
use LogicException;
|
||||
|
||||
class ButtonComponentColorMap
|
||||
{
|
||||
/**
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected array $palette;
|
||||
|
||||
protected float $minContrastRatio = Color::WCAG_AA_TEXT;
|
||||
|
||||
/**
|
||||
* @var list<array{bg: int, hover: int, alternateHover: int|null}>
|
||||
*/
|
||||
protected array $lightBackgrounds = [];
|
||||
|
||||
/**
|
||||
* @var list<array{bg: int, hover: int, alternateHover: int|null}>
|
||||
*/
|
||||
protected array $darkBackgrounds = [];
|
||||
|
||||
/**
|
||||
* @param array<int, string> $palette
|
||||
*/
|
||||
final public function __construct(array $palette)
|
||||
{
|
||||
ksort($palette);
|
||||
|
||||
$this->palette = $palette;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $palette
|
||||
*/
|
||||
public static function make(array $palette): static
|
||||
{
|
||||
return new static($palette);
|
||||
}
|
||||
|
||||
public function minContrastRatio(float $ratio): static
|
||||
{
|
||||
$this->minContrastRatio = $ratio;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a candidate `(bg, hover, alternateHover?)` triplet for light mode. Each call appends
|
||||
* a candidate; the resolver evaluates them in the order added.
|
||||
*
|
||||
* `$alternateHover` is consulted whenever the main `$hover` isn't a good match — either
|
||||
* because it doesn't produce light text alongside a vibrant `$bg`, or because its
|
||||
* lightness disagrees with `$bg`'s in the fallback case.
|
||||
*
|
||||
* The last candidate added serves as the guaranteed fallback for palettes where no
|
||||
* candidate produces light text on its `$bg` — pale colors like yellow.
|
||||
*/
|
||||
public function lightBackground(int $bg, int $hover, ?int $alternateHover = null): static
|
||||
{
|
||||
$this->lightBackgrounds[] = ['bg' => $bg, 'hover' => $hover, 'alternateHover' => $alternateHover];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a candidate `(bg, hover, alternateHover?)` triplet for dark mode. Each call appends
|
||||
* a candidate; the resolver evaluates them in the order added using the same two-pass
|
||||
* algorithm as `lightBackground()`.
|
||||
*/
|
||||
public function darkBackground(int $bg, int $hover, ?int $alternateHover = null): static
|
||||
{
|
||||
$this->darkBackgrounds[] = ['bg' => $bg, 'hover' => $hover, 'alternateHover' => $alternateHover];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
if (empty($this->lightBackgrounds)) {
|
||||
throw new LogicException('At least one `lightBackground()` candidate must be configured before calling `get()`.');
|
||||
}
|
||||
|
||||
if (empty($this->darkBackgrounds)) {
|
||||
throw new LogicException('At least one `darkBackground()` candidate must be configured before calling `get()`.');
|
||||
}
|
||||
|
||||
$textForBg = $this->resolveTextForEachBackground();
|
||||
|
||||
$textLightness = $this->probeTextLightness($textForBg);
|
||||
|
||||
[$bg, $hoverBg] = $this->pickBackgroundShades($textLightness, $this->lightBackgrounds);
|
||||
[$darkBg, $darkHoverBg] = $this->pickBackgroundShades($textLightness, $this->darkBackgrounds);
|
||||
|
||||
return [
|
||||
'bg' => $bg,
|
||||
'hover:bg' => $hoverBg,
|
||||
'dark:bg' => $darkBg,
|
||||
'dark:hover:bg' => $darkHoverBg,
|
||||
'text' => $textForBg[$bg] ?? 0,
|
||||
'hover:text' => $textForBg[$hoverBg] ?? 0,
|
||||
'dark:text' => $textForBg[$darkBg] ?? 0,
|
||||
'dark:hover:text' => $textForBg[$darkHoverBg] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* For each background shade in the palette, find the best text shade. Walks dark→light
|
||||
* looking for a dark text first (>= 800), then tries shade 50 as a light fallback. Returns
|
||||
* 0 (white) when nothing else qualifies.
|
||||
*
|
||||
* @return array<int, int>
|
||||
*/
|
||||
protected function resolveTextForEachBackground(): array
|
||||
{
|
||||
$textForBg = [];
|
||||
|
||||
$possibleDarkTextShades = $this->palette;
|
||||
unset($possibleDarkTextShades[array_key_first($possibleDarkTextShades)]);
|
||||
|
||||
$isFallbackAccessibleOnDarkerShades = true;
|
||||
|
||||
foreach (array_keys($this->palette) as $bgShade) {
|
||||
foreach ($possibleDarkTextShades as $darkTextShade => $darkTextValue) {
|
||||
if (
|
||||
($darkTextShade >= 800) &&
|
||||
(Color::calculateContrastRatio($this->palette[$bgShade], $darkTextValue) >= $this->minContrastRatio)
|
||||
) {
|
||||
$textForBg[$bgShade] = $darkTextShade;
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
||||
unset($possibleDarkTextShades[$darkTextShade]);
|
||||
}
|
||||
|
||||
if (
|
||||
$isFallbackAccessibleOnDarkerShades &&
|
||||
array_key_exists(50, $this->palette)
|
||||
) {
|
||||
if (Color::calculateContrastRatio($this->palette[$bgShade], $this->palette[50]) >= $this->minContrastRatio) {
|
||||
$textForBg[$bgShade] = 50;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$isFallbackAccessibleOnDarkerShades = false;
|
||||
}
|
||||
|
||||
$textForBg[$bgShade] = 0;
|
||||
}
|
||||
|
||||
return $textForBg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, int> $textForBg
|
||||
* @return array<int, bool>
|
||||
*/
|
||||
protected function probeTextLightness(array $textForBg): array
|
||||
{
|
||||
$shades = [];
|
||||
|
||||
foreach ([...$this->lightBackgrounds, ...$this->darkBackgrounds] as $candidate) {
|
||||
$shades[] = $candidate['bg'];
|
||||
$shades[] = $candidate['hover'];
|
||||
|
||||
if ($candidate['alternateHover'] !== null) {
|
||||
$shades[] = $candidate['alternateHover'];
|
||||
}
|
||||
}
|
||||
|
||||
$lightness = [];
|
||||
|
||||
foreach (array_unique($shades) as $shade) {
|
||||
$textShade = $textForBg[$shade] ?? 0;
|
||||
|
||||
$lightness[$shade] = ($textShade === 0) || Color::isLight($this->palette[$textShade] ?? 'oklch(1 0 0)');
|
||||
}
|
||||
|
||||
return $lightness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Two-pass selection over an ordered list of background candidates. Pass 1 prefers
|
||||
* candidates whose `bg` produces light text and tries `hover` then `alternateHover`.
|
||||
* Pass 2 takes the last candidate as guaranteed fallback with smart-hover selection
|
||||
* (consistency-based pick between `hover` and `alternateHover`).
|
||||
*
|
||||
* @param array<int, bool> $textLightness
|
||||
* @param list<array{bg: int, hover: int, alternateHover: int|null}> $candidates
|
||||
* @return array{int, int}
|
||||
*/
|
||||
protected function pickBackgroundShades(array $textLightness, array $candidates): array
|
||||
{
|
||||
foreach ($candidates as $candidate) {
|
||||
if (! ($textLightness[$candidate['bg']] ?? false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($textLightness[$candidate['hover']] ?? false) {
|
||||
return [$candidate['bg'], $candidate['hover']];
|
||||
}
|
||||
|
||||
if (($candidate['alternateHover'] !== null) && ($textLightness[$candidate['alternateHover']] ?? false)) {
|
||||
return [$candidate['bg'], $candidate['alternateHover']];
|
||||
}
|
||||
}
|
||||
|
||||
$fallback = end($candidates);
|
||||
|
||||
$hover = (($textLightness[$fallback['bg']] ?? false) === ($textLightness[$fallback['hover']] ?? false))
|
||||
? $fallback['hover']
|
||||
: ($fallback['alternateHover'] ?? $fallback['hover']);
|
||||
|
||||
return [$fallback['bg'], $hover];
|
||||
}
|
||||
}
|
||||
68
vendor/filament/support/src/View/Components/ColorMaps/ComponentColorMap.php
vendored
Normal file
68
vendor/filament/support/src/View/Components/ColorMaps/ComponentColorMap.php
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\ColorMaps;
|
||||
|
||||
use Filament\Support\Colors\Color;
|
||||
|
||||
class ComponentColorMap
|
||||
{
|
||||
/**
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected array $palette;
|
||||
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
protected array $resolved = [];
|
||||
|
||||
/**
|
||||
* @param array<int, string> $palette
|
||||
*/
|
||||
final public function __construct(array $palette)
|
||||
{
|
||||
$this->palette = $palette;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $palette
|
||||
*/
|
||||
public static function make(array $palette): static
|
||||
{
|
||||
return new static($palette);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the lightest (or darkest, if `$shouldStartFromDarkest`) shade in the palette that contrasts
|
||||
* against `$surface` by at least `$minRatio`, optionally bounded by `$minShade`/`$maxShade`,
|
||||
* and assign it to the named slot. Falls back to `$fallback` if no shade qualifies.
|
||||
*/
|
||||
public function slot(
|
||||
string $name,
|
||||
string $surface,
|
||||
float $minRatio = Color::WCAG_AA_TEXT,
|
||||
?int $maxShade = null,
|
||||
?int $minShade = null,
|
||||
bool $shouldStartFromDarkest = false,
|
||||
int $fallback = 900,
|
||||
): static {
|
||||
$this->resolved[$name] = Color::findShade(
|
||||
palette: $this->palette,
|
||||
surface: $surface,
|
||||
minRatio: $minRatio,
|
||||
maxShade: $maxShade,
|
||||
minShade: $minShade,
|
||||
shouldStartFromDarkest: $shouldStartFromDarkest,
|
||||
) ?? $fallback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
return $this->resolved;
|
||||
}
|
||||
}
|
||||
126
vendor/filament/support/src/View/Components/ColorMaps/IconButtonComponentColorMap.php
vendored
Normal file
126
vendor/filament/support/src/View/Components/ColorMaps/IconButtonComponentColorMap.php
vendored
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\ColorMaps;
|
||||
|
||||
use Filament\Support\Colors\Color;
|
||||
use LogicException;
|
||||
|
||||
class IconButtonComponentColorMap
|
||||
{
|
||||
/**
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected array $palette;
|
||||
|
||||
protected float $minContrastRatio = Color::WCAG_AA_NON_TEXT;
|
||||
|
||||
protected ?string $lightSurface = null;
|
||||
|
||||
protected ?string $darkSurface = null;
|
||||
|
||||
/**
|
||||
* The maximum shade considered when searching for dark-mode text. Higher shades are skipped
|
||||
* because they would be too dark to read against the dark-mode body surface.
|
||||
*/
|
||||
protected int $darkMaxShade = 500;
|
||||
|
||||
/**
|
||||
* @param array<int, string> $palette
|
||||
*/
|
||||
final public function __construct(array $palette)
|
||||
{
|
||||
$this->palette = $palette;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $palette
|
||||
*/
|
||||
public static function make(array $palette): static
|
||||
{
|
||||
return new static($palette);
|
||||
}
|
||||
|
||||
public function minContrastRatio(float $ratio): static
|
||||
{
|
||||
$this->minContrastRatio = $ratio;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function lightSurface(string $color): static
|
||||
{
|
||||
$this->lightSurface = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function darkSurface(string $color): static
|
||||
{
|
||||
$this->darkSurface = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function darkMaxShade(int $shade): static
|
||||
{
|
||||
$this->darkMaxShade = $shade;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
if ($this->lightSurface === null) {
|
||||
throw new LogicException('A `lightSurface()` must be configured before calling `get()`.');
|
||||
}
|
||||
|
||||
if ($this->darkSurface === null) {
|
||||
throw new LogicException('A `darkSurface()` must be configured before calling `get()`.');
|
||||
}
|
||||
|
||||
$lightShade = Color::findShade(
|
||||
palette: $this->palette,
|
||||
surface: $this->lightSurface,
|
||||
minRatio: $this->minContrastRatio,
|
||||
);
|
||||
|
||||
if ($lightShade === null) {
|
||||
$text = 900;
|
||||
$hoverText = 800;
|
||||
} elseif ($lightShade > 500) {
|
||||
// Shades above 500 are likely to be quite dark, so instead of lightening the icon
|
||||
// when it is hovered, we darken it.
|
||||
$text = $lightShade;
|
||||
$hoverText = $lightShade + 100;
|
||||
} else {
|
||||
$text = $lightShade + 100;
|
||||
$hoverText = $lightShade;
|
||||
}
|
||||
|
||||
$darkShade = Color::findShade(
|
||||
palette: $this->palette,
|
||||
surface: $this->darkSurface,
|
||||
minRatio: $this->minContrastRatio,
|
||||
maxShade: $this->darkMaxShade,
|
||||
shouldStartFromDarkest: true,
|
||||
);
|
||||
|
||||
if ($darkShade === null) {
|
||||
$darkText = 200;
|
||||
$darkHoverText = 100;
|
||||
} else {
|
||||
$darkText = $darkShade;
|
||||
$darkHoverText = $darkShade - 100;
|
||||
}
|
||||
|
||||
return [
|
||||
'text' => $text,
|
||||
'hover:text' => $hoverText,
|
||||
'dark:text' => $darkText,
|
||||
'dark:hover:text' => $darkHoverText,
|
||||
];
|
||||
}
|
||||
}
|
||||
12
vendor/filament/support/src/View/Components/Contracts/HasColor.php
vendored
Normal file
12
vendor/filament/support/src/View/Components/Contracts/HasColor.php
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\Contracts;
|
||||
|
||||
interface HasColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array;
|
||||
}
|
||||
5
vendor/filament/support/src/View/Components/Contracts/HasDefaultGrayColor.php
vendored
Normal file
5
vendor/filament/support/src/View/Components/Contracts/HasDefaultGrayColor.php
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\Contracts;
|
||||
|
||||
interface HasDefaultGrayColor {}
|
||||
25
vendor/filament/support/src/View/Components/DropdownComponent/HeaderComponent.php
vendored
Normal file
25
vendor/filament/support/src/View/Components/DropdownComponent/HeaderComponent.php
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\DropdownComponent;
|
||||
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\ColorMaps\ComponentColorMap;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class HeaderComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
$gray = FilamentColor::getColor('gray');
|
||||
|
||||
return ComponentColorMap::make($color)
|
||||
->slot('text', surface: 'oklch(1 0 0)', minShade: 600, fallback: 950)
|
||||
->slot('dark:text', surface: $gray[900], maxShade: 400, shouldStartFromDarkest: true, fallback: 200)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
27
vendor/filament/support/src/View/Components/DropdownComponent/ItemComponent.php
vendored
Normal file
27
vendor/filament/support/src/View/Components/DropdownComponent/ItemComponent.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\DropdownComponent;
|
||||
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\ColorMaps\ComponentColorMap;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class ItemComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
$gray = FilamentColor::getColor('gray');
|
||||
|
||||
return ComponentColorMap::make($color)
|
||||
->slot('text', surface: 'oklch(1 0 0)', minShade: 600, fallback: 950)
|
||||
->slot('hover:text', surface: $color[50], minShade: 600, fallback: 950)
|
||||
->slot('dark:text', surface: $gray[900], maxShade: 400, shouldStartFromDarkest: true, fallback: 200)
|
||||
->slot('dark:hover:text', surface: $color[950], maxShade: 400, shouldStartFromDarkest: true, fallback: 100)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
18
vendor/filament/support/src/View/Components/DropdownComponent/ItemComponent/IconComponent.php
vendored
Normal file
18
vendor/filament/support/src/View/Components/DropdownComponent/ItemComponent/IconComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\DropdownComponent\ItemComponent;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class IconComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
34
vendor/filament/support/src/View/Components/IconButtonComponent.php
vendored
Normal file
34
vendor/filament/support/src/View/Components/IconButtonComponent.php
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components;
|
||||
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\ColorMaps\IconButtonComponentColorMap;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class IconButtonComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* Since the icon button doesn't contain text, the icon is imperative for the user to
|
||||
* understand the button's purpose. Therefore, the icon should have a color that contrasts
|
||||
* at least 3:1 with the surface to remain compliant with WCAG AA standards.
|
||||
*
|
||||
* @ref https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html
|
||||
*
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
$gray = FilamentColor::getColor('gray');
|
||||
|
||||
return IconButtonComponentColorMap::make($color)
|
||||
->minContrastRatio(Color::WCAG_AA_NON_TEXT)
|
||||
->lightSurface($gray[50])
|
||||
->darkSurface($gray[700])
|
||||
->darkMaxShade(500)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
18
vendor/filament/support/src/View/Components/InputComponent/WrapperComponent/IconComponent.php
vendored
Normal file
18
vendor/filament/support/src/View/Components/InputComponent/WrapperComponent/IconComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\InputComponent\WrapperComponent;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class IconComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
25
vendor/filament/support/src/View/Components/LinkComponent.php
vendored
Normal file
25
vendor/filament/support/src/View/Components/LinkComponent.php
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components;
|
||||
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\ColorMaps\ComponentColorMap;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class LinkComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
$gray = FilamentColor::getColor('gray');
|
||||
|
||||
return ComponentColorMap::make($color)
|
||||
->slot('text', surface: $gray[50], fallback: 900)
|
||||
->slot('dark:text', surface: $gray[700], maxShade: 400, shouldStartFromDarkest: true, fallback: 200)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
34
vendor/filament/support/src/View/Components/ModalComponent.php
vendored
Normal file
34
vendor/filament/support/src/View/Components/ModalComponent.php
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components;
|
||||
|
||||
class ModalComponent
|
||||
{
|
||||
public static bool $hasCloseButton = true;
|
||||
|
||||
public static bool $isClosedByClickingAway = true;
|
||||
|
||||
public static bool $isClosedByEscaping = true;
|
||||
|
||||
public static bool $isAutofocused = true;
|
||||
|
||||
public static function autofocus(bool $condition = true): void
|
||||
{
|
||||
static::$isAutofocused = $condition;
|
||||
}
|
||||
|
||||
public static function closeButton(bool $condition = true): void
|
||||
{
|
||||
static::$hasCloseButton = $condition;
|
||||
}
|
||||
|
||||
public static function closedByClickingAway(bool $condition = true): void
|
||||
{
|
||||
static::$isClosedByClickingAway = $condition;
|
||||
}
|
||||
|
||||
public static function closedByEscaping(bool $condition = true): void
|
||||
{
|
||||
static::$isClosedByEscaping = $condition;
|
||||
}
|
||||
}
|
||||
18
vendor/filament/support/src/View/Components/ModalComponent/IconComponent.php
vendored
Normal file
18
vendor/filament/support/src/View/Components/ModalComponent/IconComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\ModalComponent;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class IconComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
18
vendor/filament/support/src/View/Components/SectionComponent/IconComponent.php
vendored
Normal file
18
vendor/filament/support/src/View/Components/SectionComponent/IconComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components\SectionComponent;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class IconComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
33
vendor/filament/support/src/View/Components/ToggleComponent.php
vendored
Normal file
33
vendor/filament/support/src/View/Components/ToggleComponent.php
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Components;
|
||||
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\ColorMaps\ComponentColorMap;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class ToggleComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* Since the toggle doesn't contain text, the icon may be imperative for the user to
|
||||
* understand the button's state. Therefore, the color should contrast at least 3:1 with the
|
||||
* surface to remain compliant with WCAG AA standards.
|
||||
*
|
||||
* @ref https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html
|
||||
*
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
$gray = FilamentColor::getColor('gray');
|
||||
|
||||
return ComponentColorMap::make($color)
|
||||
->slot('bg', surface: $gray[50], minRatio: Color::WCAG_AA_NON_TEXT, fallback: 900)
|
||||
->slot('text', surface: 'oklch(1 0 0)', minRatio: Color::WCAG_AA_NON_TEXT, fallback: 900)
|
||||
->slot('dark:bg', surface: $gray[700], minRatio: Color::WCAG_AA_NON_TEXT, shouldStartFromDarkest: true, fallback: 200)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
160
vendor/filament/support/src/View/Concerns/CanGenerateBadgeHtml.php
vendored
Normal file
160
vendor/filament/support/src/View/Concerns/CanGenerateBadgeHtml.php
vendored
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\BadgeComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
use function Filament\Support\generate_icon_html;
|
||||
use function Filament\Support\generate_loading_indicator_html;
|
||||
|
||||
trait CanGenerateBadgeHtml
|
||||
{
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*
|
||||
* @param string | array<string> | null $color
|
||||
* @param array<string> $keyBindings
|
||||
*/
|
||||
public function generateBadgeHtml(
|
||||
ComponentAttributeBag $attributes,
|
||||
string | array | null $color = null,
|
||||
?string $form = null,
|
||||
?string $formId = null,
|
||||
bool $hasLoadingIndicator = true,
|
||||
?bool $hasSpaMode = null,
|
||||
?string $href = null,
|
||||
string | BackedEnum | Htmlable | null $icon = null,
|
||||
?string $iconAlias = null,
|
||||
?IconPosition $iconPosition = IconPosition::Before,
|
||||
IconSize | string | null $iconSize = null,
|
||||
bool $isDisabled = false,
|
||||
?array $keyBindings = null,
|
||||
string | Htmlable | null $label = null,
|
||||
Size | string | null $size = null,
|
||||
string $tag = 'span',
|
||||
?string $target = null,
|
||||
string | Htmlable | null $tooltip = null,
|
||||
?string $type = 'button',
|
||||
): string {
|
||||
$color ??= 'primary';
|
||||
|
||||
if (! $iconPosition instanceof IconPosition) {
|
||||
$iconPosition = filled($iconPosition) ? (IconPosition::tryFrom($iconPosition) ?? $iconPosition) : null;
|
||||
}
|
||||
|
||||
if (! $size instanceof Size) {
|
||||
$size = filled($size) ? (Size::tryFrom($size) ?? $size) : null;
|
||||
}
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$wireTarget = $hasLoadingIndicator ? $attributes->whereStartsWith(['wire:target', 'wire:click'])->filter(fn ($value): bool => filled($value))->first() : null;
|
||||
|
||||
$hasLoadingIndicator = filled($wireTarget) || ($type === 'submit' && filled($form));
|
||||
|
||||
if ($hasLoadingIndicator) {
|
||||
$loadingIndicatorTarget = html_entity_decode($wireTarget ?: $form, ENT_QUOTES);
|
||||
}
|
||||
|
||||
$hasTooltip = filled($tooltip);
|
||||
|
||||
$formAttributes = $attributes->only(['action', 'method', 'wire:submit']);
|
||||
|
||||
$attributes = $attributes
|
||||
->when(
|
||||
$tag === 'form',
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->except(['action', 'class', 'method', 'wire:submit']),
|
||||
)
|
||||
->merge([
|
||||
'aria-disabled' => $isDisabled ? 'true' : null,
|
||||
'disabled' => $isDisabled && blank($tooltip),
|
||||
'form' => $tag === 'button' ? $formId : null,
|
||||
'type' => match ($tag) {
|
||||
'button' => $type,
|
||||
'form' => 'submit',
|
||||
default => null,
|
||||
},
|
||||
'wire:loading.attr' => $tag === 'button' ? 'disabled' : null,
|
||||
'wire:target' => ($hasLoadingIndicator && $loadingIndicatorTarget) ? $loadingIndicatorTarget : null,
|
||||
], escape: false)
|
||||
->when(
|
||||
$isDisabled && $hasTooltip,
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->filter(
|
||||
fn (mixed $value, string $key): bool => ! str($key)->startsWith(['href', 'x-on:', 'wire:click']),
|
||||
),
|
||||
)
|
||||
->class([
|
||||
'fi-badge',
|
||||
'fi-disabled' => $isDisabled,
|
||||
($size instanceof Size) ? "fi-size-{$size->value}" : $size,
|
||||
])
|
||||
->color(BadgeComponent::class, $color);
|
||||
|
||||
$loadingDelay = ($icon || $iconAlias || $hasLoadingIndicator)
|
||||
? config('filament.livewire_loading_delay', 'default')
|
||||
: null;
|
||||
|
||||
$iconHtml = ($icon || $iconAlias) ? generate_icon_html($icon, $iconAlias, (new FilamentComponentAttributeBag([
|
||||
'wire:loading.remove.delay.' . $loadingDelay => $hasLoadingIndicator,
|
||||
'wire:target' => $hasLoadingIndicator ? $loadingIndicatorTarget : false,
|
||||
])), size: $iconSize ?? IconSize::Small)?->toHtml() ?? '' : '';
|
||||
|
||||
$loadingIndicatorHtml = $hasLoadingIndicator ? generate_loading_indicator_html((new FilamentComponentAttributeBag([
|
||||
'wire:loading.delay.' . $loadingDelay => '',
|
||||
'wire:target' => $loadingIndicatorTarget,
|
||||
])), size: $iconSize ?? IconSize::Small)->toHtml() : '';
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<?= ($tag === 'form') ? ('<form ' . $formAttributes->toHtml() . '>' . csrf_field()) : '' ?>
|
||||
|
||||
<<?= ($tag === 'form') ? 'button' : $tag ?>
|
||||
<?php if (($tag === 'a') && (! ($isDisabled && $hasTooltip))) { ?>
|
||||
<?= generate_href_html($href, $target === '_blank', $hasSpaMode)->toHtml() ?>
|
||||
<?php } ?>
|
||||
<?php if ($keyBindings) { ?>
|
||||
x-bind:id="$id('key-bindings')"
|
||||
x-mousetrap.global.<?= collect($keyBindings)->map(fn (string $keyBinding): string => str_replace('+', '-', $keyBinding))->implode('.') ?>="document.getElementById($el.id)?.click()"
|
||||
<?php } ?>
|
||||
<?php if ($hasTooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= $attributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($iconPosition === IconPosition::Before) { ?>
|
||||
<?= $iconHtml ?>
|
||||
<?= $loadingIndicatorHtml ?>
|
||||
<?php } ?>
|
||||
|
||||
<span class="fi-badge-label-ctn">
|
||||
<span class="fi-badge-label">
|
||||
<?= e($label) ?>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<?php if ($iconPosition === IconPosition::After) { ?>
|
||||
<?= $iconHtml ?>
|
||||
<?= $loadingIndicatorHtml ?>
|
||||
<?php } ?>
|
||||
</<?= ($tag === 'form') ? 'button' : $tag ?>>
|
||||
|
||||
<?= ($tag === 'form') ? '</form>' : '' ?>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
258
vendor/filament/support/src/View/Concerns/CanGenerateButtonHtml.php
vendored
Normal file
258
vendor/filament/support/src/View/Concerns/CanGenerateButtonHtml.php
vendored
Normal file
|
|
@ -0,0 +1,258 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\BadgeComponent;
|
||||
use Filament\Support\View\Components\ButtonComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
use function Filament\Support\generate_icon_html;
|
||||
use function Filament\Support\generate_loading_indicator_html;
|
||||
|
||||
trait CanGenerateButtonHtml
|
||||
{
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*
|
||||
* @param string | array<string> | null $badgeColor,
|
||||
* @param string | array<string> | null $color,
|
||||
* @param array<string> $keyBindings
|
||||
*/
|
||||
public function generateButtonHtml(
|
||||
ComponentAttributeBag $attributes,
|
||||
string | Htmlable | null $badge = null,
|
||||
string | array | null $badgeColor = 'primary',
|
||||
Size | string | null $badgeSize = null,
|
||||
string | array | null $color = null,
|
||||
?string $form = null,
|
||||
?string $formId = null,
|
||||
bool $hasLoadingIndicator = true,
|
||||
?bool $hasSpaMode = null,
|
||||
?string $href = null,
|
||||
string | BackedEnum | Htmlable | null $icon = null,
|
||||
?string $iconAlias = null,
|
||||
?IconPosition $iconPosition = IconPosition::Before,
|
||||
IconSize | string | null $iconSize = null,
|
||||
bool $isDisabled = false,
|
||||
bool $isLabelSrOnly = false,
|
||||
bool $isOutlined = false,
|
||||
?array $keyBindings = null,
|
||||
string | Htmlable | null $label = null,
|
||||
?string $labeledFromBreakpoint = null,
|
||||
Size | string | null $size = null,
|
||||
string $tag = 'button',
|
||||
?string $target = null,
|
||||
string | Htmlable | null $tooltip = null,
|
||||
?string $type = 'button',
|
||||
): string {
|
||||
$badgeColor ??= 'primary';
|
||||
$color ??= 'primary';
|
||||
|
||||
if (! $iconPosition instanceof IconPosition) {
|
||||
$iconPosition = filled($iconPosition) ? (IconPosition::tryFrom($iconPosition) ?? $iconPosition) : null;
|
||||
}
|
||||
|
||||
if (! $size instanceof Size) {
|
||||
$size = filled($size) ? (Size::tryFrom($size) ?? $size) : Size::Medium;
|
||||
}
|
||||
|
||||
if (! $badgeSize instanceof Size) {
|
||||
$badgeSize = filled($badgeSize) ? (Size::tryFrom($badgeSize) ?? $badgeSize) : Size::ExtraSmall;
|
||||
}
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$iconSize ??= match ($size) {
|
||||
Size::ExtraSmall, Size::Small => IconSize::Small,
|
||||
default => null,
|
||||
};
|
||||
|
||||
$wireTarget = $hasLoadingIndicator ? $attributes->whereStartsWith(['wire:target', 'wire:click'])->filter(fn ($value): bool => filled($value))->first() : null;
|
||||
|
||||
$hasFormProcessingLoadingIndicator = $type === 'submit' && filled($form);
|
||||
$hasLoadingIndicator = filled($wireTarget) || $hasFormProcessingLoadingIndicator;
|
||||
|
||||
if ($hasLoadingIndicator) {
|
||||
$loadingIndicatorTarget = html_entity_decode($wireTarget ?: $form, ENT_QUOTES);
|
||||
}
|
||||
|
||||
$hasTooltip = filled($tooltip);
|
||||
|
||||
$formAttributes = $attributes->only(['action', 'method', 'wire:submit']);
|
||||
|
||||
$attributes = $attributes
|
||||
->when(
|
||||
$tag === 'form',
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->except(['action', 'class', 'method', 'wire:submit']),
|
||||
)
|
||||
->merge([
|
||||
'aria-disabled' => $isDisabled ? 'true' : null,
|
||||
// Security: These attributes are rendered without escaping, so the `aria-label` must be escaped here, otherwise an `Htmlable` label could break out of the attribute. `doubleEncode: false` preserves entities that Blade has already escaped in a string label.
|
||||
'aria-label' => $isLabelSrOnly ? e(trim(strip_tags($label instanceof Htmlable ? $label->toHtml() : ($label ?? ''))), doubleEncode: false) : null,
|
||||
'disabled' => $isDisabled && blank($tooltip),
|
||||
'form' => $formId,
|
||||
'tabindex' => (($tag === 'a') && $isDisabled && $hasTooltip) ? '0' : null,
|
||||
'type' => match ($tag) {
|
||||
'button' => $type,
|
||||
'form' => 'submit',
|
||||
default => null,
|
||||
},
|
||||
'wire:loading.attr' => $tag === 'button' ? 'disabled' : null,
|
||||
'wire:target' => ($hasLoadingIndicator && $loadingIndicatorTarget) ? $loadingIndicatorTarget : null,
|
||||
'x-bind:disabled' => $hasFormProcessingLoadingIndicator ? 'isProcessing' : null,
|
||||
'x-bind:aria-label' => ($isLabelSrOnly && $hasFormProcessingLoadingIndicator) ? ('isProcessing ? processingMessage : ' . Js::from(trim(strip_tags($label instanceof Htmlable ? $label->toHtml() : ($label ?? ''))))) : null,
|
||||
], escape: false)
|
||||
->when(
|
||||
$isDisabled && $hasTooltip,
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->filter(
|
||||
fn (mixed $value, string $key): bool => ! str($key)->startsWith(['href', 'x-on:', 'wire:click']),
|
||||
),
|
||||
);
|
||||
|
||||
$buttonComponent = ButtonComponent::make($isOutlined);
|
||||
|
||||
$buttonAttributes = $attributes
|
||||
->class([
|
||||
'fi-btn',
|
||||
'fi-disabled' => $isDisabled,
|
||||
'fi-outlined' => $isOutlined,
|
||||
($size instanceof Size) ? "fi-size-{$size->value}" : $size,
|
||||
is_string($labeledFromBreakpoint) ? "fi-labeled-from-{$labeledFromBreakpoint}" : null,
|
||||
])
|
||||
->color($buttonComponent, $color);
|
||||
|
||||
$iconButtonAttributes = $attributes;
|
||||
|
||||
if ($labeledFromBreakpoint && filled($wireKey = $attributes->get('wire:key'))) {
|
||||
$iconButtonAttributes = $attributes
|
||||
->except(['wire:key'])
|
||||
->merge(['wire:key' => "{$wireKey}.icon-button"], escape: false);
|
||||
}
|
||||
|
||||
$loadingDelay = ($icon || $iconAlias || $hasLoadingIndicator)
|
||||
? config('filament.livewire_loading_delay', 'default')
|
||||
: null;
|
||||
|
||||
$iconHtml = ($icon || $iconAlias) ? generate_icon_html($icon, $iconAlias, (new FilamentComponentAttributeBag([
|
||||
'wire:loading.remove.delay.' . $loadingDelay => $hasLoadingIndicator,
|
||||
'wire:target' => $hasLoadingIndicator ? $loadingIndicatorTarget : false,
|
||||
])), size: $iconSize)?->toHtml() ?? '' : '';
|
||||
|
||||
$loadingIndicatorHtml = $hasLoadingIndicator ? generate_loading_indicator_html((new FilamentComponentAttributeBag([
|
||||
'wire:loading.delay.' . $loadingDelay => '',
|
||||
'wire:target' => $loadingIndicatorTarget,
|
||||
])), size: $iconSize)->toHtml() : '';
|
||||
|
||||
$formProcessingLoadingIndicatorHtml = $hasFormProcessingLoadingIndicator ? generate_loading_indicator_html((new FilamentComponentAttributeBag([
|
||||
'x-cloak' => 'x-cloak',
|
||||
'x-show' => 'isProcessing',
|
||||
])), size: $iconSize)->toHtml() : '';
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<?php if ($labeledFromBreakpoint) { ?>
|
||||
<?= $this->generateIconButtonHtml(
|
||||
attributes: $iconButtonAttributes,
|
||||
badge: $badge,
|
||||
badgeColor: $badgeColor,
|
||||
badgeSize: $badgeSize,
|
||||
color: $color,
|
||||
form: $form,
|
||||
formId: $formId,
|
||||
hasLoadingIndicator: $hasLoadingIndicator,
|
||||
hasSpaMode: $hasSpaMode,
|
||||
href: $href,
|
||||
icon: $icon,
|
||||
iconAlias: $iconAlias,
|
||||
iconSize: $iconSize,
|
||||
isDisabled: $isDisabled,
|
||||
keyBindings: $keyBindings,
|
||||
label: $label,
|
||||
size: $size,
|
||||
tag: $tag,
|
||||
target: $target,
|
||||
tooltip: $tooltip,
|
||||
type: $type,
|
||||
) ?>
|
||||
<?php } ?>
|
||||
|
||||
<?= ($tag === 'form') ? ('<form ' . $formAttributes->toHtml() . '>' . csrf_field()) : '' ?>
|
||||
|
||||
<<?= ($tag === 'form') ? 'button' : $tag ?>
|
||||
<?php if (($tag === 'a') && (! ($isDisabled && $hasTooltip))) { ?>
|
||||
<?= generate_href_html($href, $target === '_blank', $hasSpaMode)->toHtml() ?>
|
||||
<?php } ?>
|
||||
<?php if ($keyBindings) { ?>
|
||||
x-bind:id="$id('key-bindings')"
|
||||
x-mousetrap.global.<?= collect($keyBindings)->map(fn (string $keyBinding): string => str_replace('+', '-', $keyBinding))->implode('.') ?>="document.getElementById($el.id)?.click()"
|
||||
<?php } ?>
|
||||
<?php if ($hasTooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?php if ($hasFormProcessingLoadingIndicator) { ?>
|
||||
x-data="filamentFormButton"
|
||||
x-bind:class="{ 'fi-processing': isProcessing }"
|
||||
<?php } ?>
|
||||
<?= $buttonAttributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($iconPosition === IconPosition::Before) { ?>
|
||||
<?= $iconHtml ?>
|
||||
<?= $loadingIndicatorHtml ?>
|
||||
<?= $formProcessingLoadingIndicatorHtml ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (! $isLabelSrOnly) { ?>
|
||||
<?php if ($hasFormProcessingLoadingIndicator) { ?>
|
||||
<span x-show="! isProcessing">
|
||||
<?= e($label) ?>
|
||||
</span>
|
||||
<?php } else { ?>
|
||||
<?= e($label) ?>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasFormProcessingLoadingIndicator && (! $isLabelSrOnly)) { ?>
|
||||
<span
|
||||
x-cloak
|
||||
x-show="isProcessing"
|
||||
x-text="processingMessage"
|
||||
></span>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($iconPosition === IconPosition::After) { ?>
|
||||
<?= $iconHtml ?>
|
||||
<?= $loadingIndicatorHtml ?>
|
||||
<?= $formProcessingLoadingIndicatorHtml ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (filled($badge)) { ?>
|
||||
<div class="fi-btn-badge-ctn">
|
||||
<span <?= (new FilamentComponentAttributeBag)->color(BadgeComponent::class, $badgeColor)->class([
|
||||
'fi-badge',
|
||||
($badgeSize instanceof Size) ? "fi-size-{$badgeSize->value}" : $badgeSize,
|
||||
])->toHtml() ?>>
|
||||
<?= e($badge) ?>
|
||||
</span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</<?= ($tag === 'form') ? 'button' : $tag ?>>
|
||||
|
||||
<?= ($tag === 'form') ? '</form>' : '' ?>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
156
vendor/filament/support/src/View/Concerns/CanGenerateDropdownItemHtml.php
vendored
Normal file
156
vendor/filament/support/src/View/Concerns/CanGenerateDropdownItemHtml.php
vendored
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\BadgeComponent;
|
||||
use Filament\Support\View\Components\DropdownComponent\ItemComponent;
|
||||
use Filament\Support\View\Components\DropdownComponent\ItemComponent\IconComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
use function Filament\Support\generate_icon_html;
|
||||
use function Filament\Support\generate_loading_indicator_html;
|
||||
|
||||
trait CanGenerateDropdownItemHtml
|
||||
{
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*
|
||||
* @param string | array<string> | null $badgeColor,
|
||||
* @param string | array<string> | null $color,
|
||||
* @param array<string> $keyBindings
|
||||
*/
|
||||
public function generateDropdownItemHtml(
|
||||
ComponentAttributeBag $attributes,
|
||||
string | Htmlable | null $badge = null,
|
||||
string | array | null $badgeColor = null,
|
||||
string | Htmlable | null $badgeTooltip = null,
|
||||
string | array | null $color = 'primary',
|
||||
bool $hasLoadingIndicator = true,
|
||||
?bool $hasSpaMode = null,
|
||||
?string $href = null,
|
||||
string | BackedEnum | Htmlable | null $icon = null,
|
||||
?string $iconAlias = null,
|
||||
?string $iconColor = null,
|
||||
IconSize | string | null $iconSize = null,
|
||||
bool $isDisabled = false,
|
||||
?array $keyBindings = null,
|
||||
string | Htmlable | null $label = null,
|
||||
string $tag = 'button',
|
||||
?string $target = null,
|
||||
string | Htmlable | null $tooltip = null,
|
||||
?string $type = 'button',
|
||||
): string {
|
||||
$badgeColor ??= 'primary';
|
||||
$color ??= 'gray';
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$iconColor ??= $color;
|
||||
|
||||
$wireTarget = $hasLoadingIndicator ? $attributes->whereStartsWith(['wire:target', 'wire:click'])->filter(fn ($value): bool => filled($value))->first() : null;
|
||||
|
||||
$hasLoadingIndicator = filled($wireTarget);
|
||||
|
||||
if ($hasLoadingIndicator) {
|
||||
$loadingIndicatorTarget = html_entity_decode($wireTarget, ENT_QUOTES);
|
||||
}
|
||||
|
||||
$hasTooltip = filled($tooltip);
|
||||
|
||||
$formAttributes = $attributes->only(['action', 'method', 'wire:submit']);
|
||||
|
||||
$attributes = $attributes
|
||||
->when(
|
||||
$tag === 'form',
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->except(['action', 'class', 'method', 'wire:submit']),
|
||||
)
|
||||
->merge([
|
||||
'aria-disabled' => $isDisabled ? 'true' : null,
|
||||
'disabled' => $isDisabled && blank($tooltip),
|
||||
'type' => match ($tag) {
|
||||
'button' => $type,
|
||||
'form' => 'submit',
|
||||
default => null,
|
||||
},
|
||||
'wire:loading.attr' => $tag === 'button' ? 'disabled' : null,
|
||||
'wire:target' => ($hasLoadingIndicator && $loadingIndicatorTarget) ? $loadingIndicatorTarget : null,
|
||||
], escape: false)
|
||||
->when(
|
||||
$isDisabled && $hasTooltip,
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->filter(
|
||||
fn (mixed $value, string $key): bool => ! str($key)->startsWith(['href', 'x-on:', 'wire:click']),
|
||||
),
|
||||
)
|
||||
->class([
|
||||
'fi-dropdown-list-item',
|
||||
'fi-disabled' => $isDisabled,
|
||||
])
|
||||
->color(ItemComponent::class, $color);
|
||||
|
||||
$loadingDelay = ($icon || $iconAlias || $hasLoadingIndicator)
|
||||
? config('filament.livewire_loading_delay', 'default')
|
||||
: null;
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<?= ($tag === 'form') ? ('<form ' . $formAttributes->toHtml() . '>' . csrf_field()) : '' ?>
|
||||
|
||||
<<?= ($tag === 'form') ? 'button' : $tag ?>
|
||||
<?php if (($tag === 'a') && (! ($isDisabled && $hasTooltip))) { ?>
|
||||
<?= generate_href_html($href, $target === '_blank', $hasSpaMode)->toHtml() ?>
|
||||
<?php } ?>
|
||||
<?php if ($keyBindings) { ?>
|
||||
x-bind:id="$id('key-bindings')"
|
||||
x-mousetrap.global.<?= collect($keyBindings)->map(fn (string $keyBinding): string => str_replace('+', '-', $keyBinding))->implode('.') ?>="document.getElementById($el.id)?.click()"
|
||||
<?php } ?>
|
||||
<?php if ($hasTooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= $attributes->toHtml() ?>
|
||||
>
|
||||
<?= ($icon || $iconAlias) ? generate_icon_html($icon, $iconAlias, (new FilamentComponentAttributeBag([
|
||||
'wire:loading.remove.delay.' . $loadingDelay => $hasLoadingIndicator,
|
||||
'wire:target' => $hasLoadingIndicator ? $loadingIndicatorTarget : false,
|
||||
]))->color(IconComponent::class, $iconColor), size: $iconSize)?->toHtml() ?? '' : '' ?>
|
||||
<?= $hasLoadingIndicator ? generate_loading_indicator_html((new FilamentComponentAttributeBag([
|
||||
'wire:loading.delay.' . $loadingDelay => '',
|
||||
'wire:target' => $loadingIndicatorTarget,
|
||||
])), size: $iconSize)->toHtml() : '' ?>
|
||||
|
||||
<span class="fi-dropdown-list-item-label">
|
||||
<?= e($label) ?>
|
||||
</span>
|
||||
|
||||
<?php if (filled($badge)) { ?>
|
||||
<span
|
||||
<?php if (filled($badgeTooltip)) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($badgeTooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($badgeTooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= (new FilamentComponentAttributeBag)->color(BadgeComponent::class, $badgeColor)->class(['fi-badge'])->toHtml() ?>
|
||||
>
|
||||
<?= e($badge) ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</<?= ($tag === 'form') ? 'button' : $tag ?>>
|
||||
|
||||
<?= ($tag === 'form') ? '</form>' : '' ?>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
170
vendor/filament/support/src/View/Concerns/CanGenerateIconButtonHtml.php
vendored
Normal file
170
vendor/filament/support/src/View/Concerns/CanGenerateIconButtonHtml.php
vendored
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\BadgeComponent;
|
||||
use Filament\Support\View\Components\IconButtonComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
use function Filament\Support\generate_icon_html;
|
||||
use function Filament\Support\generate_loading_indicator_html;
|
||||
|
||||
trait CanGenerateIconButtonHtml
|
||||
{
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*
|
||||
* @param string | array<string> | null $badgeColor,
|
||||
* @param string | array<string> | null $color,
|
||||
* @param array<string> $keyBindings
|
||||
*/
|
||||
public function generateIconButtonHtml(
|
||||
ComponentAttributeBag $attributes,
|
||||
string | Htmlable | null $badge = null,
|
||||
string | array | null $badgeColor = null,
|
||||
Size | string | null $badgeSize = null,
|
||||
string | array | null $color = 'primary',
|
||||
?string $form = null,
|
||||
?string $formId = null,
|
||||
bool $hasLoadingIndicator = true,
|
||||
?bool $hasSpaMode = null,
|
||||
?string $href = null,
|
||||
string | BackedEnum | Htmlable | null $icon = null,
|
||||
?string $iconAlias = null,
|
||||
IconSize | string | null $iconSize = null,
|
||||
bool $isDisabled = false,
|
||||
?array $keyBindings = null,
|
||||
string | Htmlable | null $label = null,
|
||||
Size | string | null $size = null,
|
||||
string $tag = 'button',
|
||||
?string $target = null,
|
||||
string | Htmlable | null $tooltip = null,
|
||||
?string $type = 'button',
|
||||
): string {
|
||||
$badgeColor ??= 'primary';
|
||||
$color ??= 'primary';
|
||||
|
||||
if (! $size instanceof Size) {
|
||||
$size = filled($size) ? (Size::tryFrom($size) ?? $size) : Size::Medium;
|
||||
}
|
||||
|
||||
if (! $badgeSize instanceof Size) {
|
||||
$badgeSize = filled($badgeSize) ? (Size::tryFrom($badgeSize) ?? $badgeSize) : Size::ExtraSmall;
|
||||
}
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$iconSize ??= match ($size) {
|
||||
Size::ExtraSmall => IconSize::Small,
|
||||
Size::Large, Size::ExtraLarge => IconSize::Large,
|
||||
default => null,
|
||||
};
|
||||
|
||||
$wireTarget = $hasLoadingIndicator ? $attributes->whereStartsWith(['wire:target', 'wire:click'])->filter(fn ($value): bool => filled($value))->first() : null;
|
||||
|
||||
$hasLoadingIndicator = filled($wireTarget) || ($type === 'submit' && filled($form));
|
||||
|
||||
if ($hasLoadingIndicator) {
|
||||
$loadingIndicatorTarget = html_entity_decode($wireTarget ?: $form, ENT_QUOTES);
|
||||
}
|
||||
|
||||
$hasTooltip = filled($tooltip);
|
||||
|
||||
$formAttributes = $attributes->only(['action', 'method', 'wire:submit']);
|
||||
|
||||
$attributes = $attributes
|
||||
->when(
|
||||
$tag === 'form',
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->except(['action', 'class', 'method', 'wire:submit']),
|
||||
)
|
||||
->merge([
|
||||
'aria-disabled' => $isDisabled ? 'true' : null,
|
||||
// Security: These attributes are rendered without escaping, so the `aria-label` must be escaped here, otherwise an `Htmlable` label could break out of the attribute. `doubleEncode: false` preserves entities that Blade has already escaped in a string label.
|
||||
'aria-label' => filled($label) ? e(trim(strip_tags($label instanceof Htmlable ? $label->toHtml() : $label)), doubleEncode: false) : null,
|
||||
'disabled' => $isDisabled && blank($tooltip),
|
||||
'form' => $formId,
|
||||
'tabindex' => (($tag === 'a') && $isDisabled && $hasTooltip) ? '0' : null,
|
||||
'type' => match ($tag) {
|
||||
'button' => $type,
|
||||
'form' => 'submit',
|
||||
default => null,
|
||||
},
|
||||
'wire:loading.attr' => $tag === 'button' ? 'disabled' : null,
|
||||
'wire:target' => ($hasLoadingIndicator && $loadingIndicatorTarget) ? $loadingIndicatorTarget : null,
|
||||
], escape: false)
|
||||
->merge([
|
||||
'title' => $hasTooltip ? null : $label,
|
||||
], escape: true)
|
||||
->when(
|
||||
$isDisabled && $hasTooltip,
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->filter(
|
||||
fn (mixed $value, string $key): bool => ! str($key)->startsWith(['href', 'x-on:', 'wire:click']),
|
||||
),
|
||||
)
|
||||
->class([
|
||||
'fi-icon-btn',
|
||||
'fi-disabled' => $isDisabled,
|
||||
($size instanceof Size) ? "fi-size-{$size->value}" : $size,
|
||||
])
|
||||
->color(IconButtonComponent::class, $color);
|
||||
|
||||
$loadingDelay = ($icon || $iconAlias || $hasLoadingIndicator)
|
||||
? config('filament.livewire_loading_delay', 'default')
|
||||
: null;
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<?= ($tag === 'form') ? ('<form ' . $formAttributes->toHtml() . '>' . csrf_field()) : '' ?>
|
||||
|
||||
<<?= ($tag === 'form') ? 'button' : $tag ?>
|
||||
<?php if (($tag === 'a') && (! ($isDisabled && $hasTooltip))) { ?>
|
||||
<?= generate_href_html($href, $target === '_blank', $hasSpaMode)->toHtml() ?>
|
||||
<?php } ?>
|
||||
<?php if ($keyBindings) { ?>
|
||||
x-bind:id="$id('key-bindings')"
|
||||
x-mousetrap.global.<?= collect($keyBindings)->map(fn (string $keyBinding): string => str_replace('+', '-', $keyBinding))->implode('.') ?>="document.getElementById($el.id)?.click()"
|
||||
<?php } ?>
|
||||
<?php if ($hasTooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= $attributes->toHtml() ?>
|
||||
>
|
||||
<?= ($icon || $iconAlias) ? generate_icon_html($icon, $iconAlias, (new FilamentComponentAttributeBag([
|
||||
'wire:loading.remove.delay.' . $loadingDelay => $hasLoadingIndicator,
|
||||
'wire:target' => $hasLoadingIndicator ? $loadingIndicatorTarget : false,
|
||||
])), size: $iconSize)?->toHtml() ?? '' : '' ?>
|
||||
<?= $hasLoadingIndicator ? generate_loading_indicator_html((new FilamentComponentAttributeBag([
|
||||
'wire:loading.delay.' . $loadingDelay => '',
|
||||
'wire:target' => $loadingIndicatorTarget,
|
||||
])), size: $iconSize)->toHtml() : '' ?>
|
||||
|
||||
<?php if (filled($badge)) { ?>
|
||||
<div class="fi-icon-btn-badge-ctn">
|
||||
<span <?= (new FilamentComponentAttributeBag)->color(BadgeComponent::class, $badgeColor)->class([
|
||||
'fi-badge',
|
||||
($badgeSize instanceof Size) ? "fi-size-{$badgeSize->value}" : $badgeSize,
|
||||
])->toHtml() ?>>
|
||||
<?= e($badge) ?>
|
||||
</span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</<?= ($tag === 'form') ? 'button' : $tag ?>>
|
||||
|
||||
<?= ($tag === 'form') ? '</form>' : '' ?>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
198
vendor/filament/support/src/View/Concerns/CanGenerateLinkHtml.php
vendored
Normal file
198
vendor/filament/support/src/View/Concerns/CanGenerateLinkHtml.php
vendored
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\BadgeComponent;
|
||||
use Filament\Support\View\Components\LinkComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
use function Filament\Support\generate_icon_html;
|
||||
use function Filament\Support\generate_loading_indicator_html;
|
||||
|
||||
trait CanGenerateLinkHtml
|
||||
{
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*
|
||||
* @param string | array<string> | null $badgeColor,
|
||||
* @param string | array<string> | null $color,
|
||||
* @param array<string> $keyBindings
|
||||
*/
|
||||
public function generateLinkHtml(
|
||||
ComponentAttributeBag $attributes,
|
||||
string | Htmlable | null $badge = null,
|
||||
string | array | null $badgeColor = 'primary',
|
||||
Size | string | null $badgeSize = null,
|
||||
string | array | null $color = null,
|
||||
?string $form = null,
|
||||
?string $formId = null,
|
||||
bool $hasLoadingIndicator = true,
|
||||
?bool $hasSpaMode = null,
|
||||
?string $href = null,
|
||||
string | BackedEnum | Htmlable | null $icon = null,
|
||||
?string $iconAlias = null,
|
||||
?IconPosition $iconPosition = IconPosition::Before,
|
||||
IconSize | string | null $iconSize = null,
|
||||
bool $isDisabled = false,
|
||||
bool $isLabelSrOnly = false,
|
||||
?array $keyBindings = null,
|
||||
string | Htmlable | null $label = null,
|
||||
Size | string | null $size = null,
|
||||
string $tag = 'button',
|
||||
?string $target = null,
|
||||
string | Htmlable | null $tooltip = null,
|
||||
?string $type = 'button',
|
||||
string | FontWeight | null $weight = null,
|
||||
): string {
|
||||
$badgeColor ??= 'primary';
|
||||
$color ??= 'primary';
|
||||
|
||||
if (! $iconPosition instanceof IconPosition) {
|
||||
$iconPosition = filled($iconPosition) ? (IconPosition::tryFrom($iconPosition) ?? $iconPosition) : null;
|
||||
}
|
||||
|
||||
if (! $size instanceof Size) {
|
||||
$size = filled($size) ? (Size::tryFrom($size) ?? $size) : Size::Medium;
|
||||
}
|
||||
|
||||
if (! $badgeSize instanceof Size) {
|
||||
$badgeSize = filled($badgeSize) ? (Size::tryFrom($badgeSize) ?? $badgeSize) : Size::ExtraSmall;
|
||||
}
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$iconSize ??= match ($size) {
|
||||
Size::ExtraSmall, Size::Small => IconSize::Small,
|
||||
default => null,
|
||||
};
|
||||
|
||||
if (! $weight instanceof FontWeight) {
|
||||
$weight = filled($weight) ? (FontWeight::tryFrom($weight) ?? $weight) : null;
|
||||
}
|
||||
|
||||
$wireTarget = $hasLoadingIndicator ? $attributes->whereStartsWith(['wire:target', 'wire:click'])->filter(fn ($value): bool => filled($value))->first() : null;
|
||||
|
||||
$hasLoadingIndicator = filled($wireTarget) || ($type === 'submit' && filled($form));
|
||||
|
||||
if ($hasLoadingIndicator) {
|
||||
$loadingIndicatorTarget = html_entity_decode($wireTarget ?: $form, ENT_QUOTES);
|
||||
}
|
||||
|
||||
$hasTooltip = filled($tooltip);
|
||||
|
||||
$formAttributes = $attributes->only(['action', 'method', 'wire:submit']);
|
||||
|
||||
$attributes = $attributes
|
||||
->when(
|
||||
$tag === 'form',
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->except(['action', 'class', 'method', 'wire:submit']),
|
||||
)
|
||||
->merge([
|
||||
'aria-disabled' => $isDisabled ? 'true' : null,
|
||||
// Security: These attributes are rendered without escaping, so the `aria-label` must be escaped here, otherwise an `Htmlable` label could break out of the attribute. `doubleEncode: false` preserves entities that Blade has already escaped in a string label.
|
||||
'aria-label' => $isLabelSrOnly
|
||||
? e(trim(strip_tags($label instanceof Htmlable ? $label->toHtml() : ($label ?? ''))), doubleEncode: false)
|
||||
: null,
|
||||
'disabled' => $isDisabled && blank($tooltip),
|
||||
'form' => $formId,
|
||||
'type' => match ($tag) {
|
||||
'button' => $type,
|
||||
'form' => 'submit',
|
||||
default => null,
|
||||
},
|
||||
'wire:loading.attr' => $tag === 'button' ? 'disabled' : null,
|
||||
'wire:target' => ($hasLoadingIndicator && $loadingIndicatorTarget) ? $loadingIndicatorTarget : null,
|
||||
], escape: false)
|
||||
->when(
|
||||
$isDisabled && $hasTooltip,
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->filter(
|
||||
fn (mixed $value, string $key): bool => ! str($key)->startsWith(['href', 'x-on:', 'wire:click']),
|
||||
),
|
||||
)
|
||||
->class([
|
||||
'fi-link',
|
||||
'fi-disabled' => $isDisabled,
|
||||
($size instanceof Size) ? "fi-size-{$size->value}" : $size,
|
||||
($weight instanceof FontWeight) ? "fi-font-{$weight->value}" : $weight,
|
||||
])
|
||||
->color(LinkComponent::class, $color);
|
||||
|
||||
$loadingDelay = ($icon || $iconAlias || $hasLoadingIndicator)
|
||||
? config('filament.livewire_loading_delay', 'default')
|
||||
: null;
|
||||
|
||||
$iconHtml = ($icon || $iconAlias) ? generate_icon_html($icon, $iconAlias, (new FilamentComponentAttributeBag([
|
||||
'wire:loading.remove.delay.' . $loadingDelay => $hasLoadingIndicator,
|
||||
'wire:target' => $hasLoadingIndicator ? $loadingIndicatorTarget : false,
|
||||
])), size: $iconSize)?->toHtml() ?? '' : '';
|
||||
|
||||
$loadingIndicatorHtml = $hasLoadingIndicator ? generate_loading_indicator_html((new FilamentComponentAttributeBag([
|
||||
'wire:loading.delay.' . $loadingDelay => '',
|
||||
'wire:target' => $loadingIndicatorTarget,
|
||||
])), size: $iconSize)->toHtml() : '';
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<?= ($tag === 'form') ? ('<form ' . $formAttributes->toHtml() . '>' . csrf_field()) : '' ?>
|
||||
|
||||
<<?= ($tag === 'form') ? 'button' : $tag ?>
|
||||
<?php if (($tag === 'a') && (! ($isDisabled && $hasTooltip))) { ?>
|
||||
<?= generate_href_html($href, $target === '_blank', $hasSpaMode)->toHtml() ?>
|
||||
<?php } ?>
|
||||
<?php if ($keyBindings) { ?>
|
||||
x-bind:id="$id('key-bindings')"
|
||||
x-mousetrap.global.<?= collect($keyBindings)->map(fn (string $keyBinding): string => str_replace('+', '-', $keyBinding))->implode('.') ?>="document.getElementById($el.id)?.click()"
|
||||
<?php } ?>
|
||||
<?php if ($hasTooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= $attributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($iconPosition === IconPosition::Before) { ?>
|
||||
<?= $iconHtml ?>
|
||||
<?= $loadingIndicatorHtml ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (! $isLabelSrOnly) { ?>
|
||||
<span class="fi-link-label">
|
||||
<?= e($label) ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($iconPosition === IconPosition::After) { ?>
|
||||
<?= $iconHtml ?>
|
||||
<?= $loadingIndicatorHtml ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (filled($badge)) { ?>
|
||||
<div class="fi-link-badge-ctn">
|
||||
<span <?= (new FilamentComponentAttributeBag)->color(BadgeComponent::class, $badgeColor)->class([
|
||||
'fi-badge',
|
||||
($badgeSize instanceof Size) ? "fi-size-{$badgeSize->value}" : $badgeSize,
|
||||
])->toHtml() ?>>
|
||||
<?= e($badge) ?>
|
||||
</span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</<?= ($tag === 'form') ? 'button' : $tag ?>>
|
||||
|
||||
<?= ($tag === 'form') ? '</form>' : '' ?>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
38
vendor/filament/support/src/View/DefaultLoadingIndicator.php
vendored
Normal file
38
vendor/filament/support/src/View/DefaultLoadingIndicator.php
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View;
|
||||
|
||||
use Filament\Support\Contracts\LoadingIndicator;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
class DefaultLoadingIndicator implements LoadingIndicator
|
||||
{
|
||||
public function toHtml(ComponentAttributeBag $attributes): string
|
||||
{
|
||||
// The spinner is decorative — the surrounding control (button `aria-label`, loading section
|
||||
// `role="status"`) conveys the loading state — so hide it from assistive tech by default. A
|
||||
// caller can still override by passing its own `aria-hidden`.
|
||||
$attributes = $attributes->merge(['aria-hidden' => 'true'], escape: false);
|
||||
|
||||
return <<<HTML
|
||||
<svg
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
{$attributes->toHtml()}
|
||||
>
|
||||
<path
|
||||
clip-rule="evenodd"
|
||||
d="M12 19C15.866 19 19 15.866 19 12C19 8.13401 15.866 5 12 5C8.13401 5 5 8.13401 5 12C5 15.866 8.13401 19 12 19ZM12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z"
|
||||
fill-rule="evenodd"
|
||||
fill="currentColor"
|
||||
opacity="0.2"
|
||||
></path>
|
||||
<path
|
||||
d="M2 12C2 6.47715 6.47715 2 12 2V5C8.13401 5 5 8.13401 5 12H2Z"
|
||||
fill="currentColor"
|
||||
></path>
|
||||
</svg>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
35
vendor/filament/support/src/View/SupportIconAlias.php
vendored
Normal file
35
vendor/filament/support/src/View/SupportIconAlias.php
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View;
|
||||
|
||||
class SupportIconAlias
|
||||
{
|
||||
/**
|
||||
* @deprecated Customize the `.fi-badge-delete-btn-icon` CSS class instead.
|
||||
*/
|
||||
const BADGE_DELETE_BUTTON = 'badge.delete-button';
|
||||
|
||||
const BREADCRUMBS_SEPARATOR = 'breadcrumbs.separator';
|
||||
|
||||
const BREADCRUMBS_SEPARATOR_RTL = 'breadcrumbs.separator.rtl';
|
||||
|
||||
const MODAL_CLOSE_BUTTON = 'modal.close-button';
|
||||
|
||||
const PAGINATION_FIRST_BUTTON = 'pagination.first-button';
|
||||
|
||||
const PAGINATION_FIRST_BUTTON_RTL = 'pagination.first-button.rtl';
|
||||
|
||||
const PAGINATION_LAST_BUTTON = 'pagination.last-button';
|
||||
|
||||
const PAGINATION_LAST_BUTTON_RTL = 'pagination.last-button.rtl';
|
||||
|
||||
const PAGINATION_NEXT_BUTTON = 'pagination.next-button';
|
||||
|
||||
const PAGINATION_NEXT_BUTTON_RTL = 'pagination.next-button.rtl';
|
||||
|
||||
const PAGINATION_PREVIOUS_BUTTON = 'pagination.previous-button';
|
||||
|
||||
const PAGINATION_PREVIOUS_BUTTON_RTL = 'pagination.previous-button.rtl';
|
||||
|
||||
const SECTION_COLLAPSE_BUTTON = 'section.collapse-button';
|
||||
}
|
||||
150
vendor/filament/support/src/View/ViewManager.php
vendored
Normal file
150
vendor/filament/support/src/View/ViewManager.php
vendored
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\View;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
use function Filament\Support\is_app_url;
|
||||
|
||||
class ViewManager
|
||||
{
|
||||
/**
|
||||
* @var array<string, array<string, array<Closure>>>
|
||||
*/
|
||||
protected array $renderHooks = [];
|
||||
|
||||
protected bool $hasSpaMode = false;
|
||||
|
||||
protected bool $hasSpaPrefetching = false;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $spaModeUrlExceptions = [];
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $scopes
|
||||
*/
|
||||
public function registerRenderHook(string $name, Closure $hook, string | array | null $scopes = null): void
|
||||
{
|
||||
if ($scopes === null) {
|
||||
$scopes = [''];
|
||||
}
|
||||
|
||||
if (! is_array($scopes)) {
|
||||
$scopes = [$scopes];
|
||||
}
|
||||
|
||||
foreach ($scopes as $scopeName) {
|
||||
$this->renderHooks[$name][$scopeName][] = $hook;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $scopes
|
||||
*/
|
||||
public function hasRenderHook(string $name, string | array | null $scopes = null): bool
|
||||
{
|
||||
if (! isset($this->renderHooks[$name])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->renderHooks[$name]['']) && count($this->renderHooks[$name][''])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$scopes = Arr::wrap($scopes);
|
||||
|
||||
foreach ($scopes as $scopeName) {
|
||||
if (isset($this->renderHooks[$name][$scopeName]) && count($this->renderHooks[$name][$scopeName])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $scopes
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function renderHook(string $name, string | array | null $scopes = null, array $data = []): Htmlable
|
||||
{
|
||||
$renderedHooks = [];
|
||||
|
||||
$scopes = Arr::wrap($scopes);
|
||||
|
||||
$renderHook = function (callable $hook) use (&$renderedHooks, $scopes, $data): ?string {
|
||||
$hookId = spl_object_id($hook);
|
||||
|
||||
if (in_array($hookId, $renderedHooks)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$renderedHooks[] = $hookId;
|
||||
|
||||
$result = app()->call($hook, ['data' => $data, 'scopes' => $scopes]);
|
||||
|
||||
return (string) $result;
|
||||
};
|
||||
|
||||
$hooks = array_map(
|
||||
$renderHook,
|
||||
$this->renderHooks[$name][''] ?? [],
|
||||
);
|
||||
|
||||
foreach ($scopes as $scopeName) {
|
||||
$hooks = [
|
||||
...$hooks,
|
||||
...array_map(
|
||||
$renderHook,
|
||||
$this->renderHooks[$name][$scopeName] ?? [],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
return new HtmlString(implode('', $hooks));
|
||||
}
|
||||
|
||||
public function spa(bool $condition = true, bool $hasPrefetching = false): void
|
||||
{
|
||||
$this->hasSpaMode = $condition;
|
||||
$this->hasSpaPrefetching = $hasPrefetching;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $exceptions
|
||||
*/
|
||||
public function spaUrlExceptions(array $exceptions): void
|
||||
{
|
||||
$this->spaModeUrlExceptions = [
|
||||
...$this->spaModeUrlExceptions,
|
||||
...$exceptions,
|
||||
];
|
||||
}
|
||||
|
||||
public function hasSpaMode(?string $url = null): bool
|
||||
{
|
||||
if (! $this->hasSpaMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (blank($url)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (count($this->spaModeUrlExceptions) && str($url)->is($this->spaModeUrlExceptions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return is_app_url($url);
|
||||
}
|
||||
|
||||
public function hasSpaPrefetching(): bool
|
||||
{
|
||||
return $this->hasSpaPrefetching;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue