All checks were successful
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m35s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m37s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m52s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m56s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 4m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 4m21s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 4m5s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
- Vollständiger Satz (1.854 Symbole + Aliase älterer Namen) in resources/icons/svg.php (Admin) und resources/js/lib/icon-set.js (Portal, wird nur bei Bedarf geladen) - Kuratierte 66 mit deutscher Bezeichnung bleiben im Hauptpaket und stehen in Auswahlfeldern vorne; die Suche findet alle - AppIcon-Komponente für Menü, Schnellzugriffe und Pagebuilder; Symbolfeld im Pagebuilder mit Suche Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
138 lines
4.3 KiB
PHP
138 lines
4.3 KiB
PHP
<?php
|
||
|
||
namespace App\Support;
|
||
|
||
/**
|
||
* Symbole (Lucide, alle lokal) für Menü, Schnellzugriffe und Pagebuilder.
|
||
*
|
||
* - Alle Symbole: resources/icons/svg.php (englische Namen, dazu Aliase älterer Namen)
|
||
* - Kuratierte Auswahl mit deutschen Bezeichnungen: resources/icons/icons.json –
|
||
* erscheint zuerst in Auswahlfeldern und ist im Portal ohne Nachladen verfügbar.
|
||
*
|
||
* Nach Änderungen an der Liste oder einem Lucide-Update: npm run icons.
|
||
*/
|
||
final class Icons
|
||
{
|
||
/** @var array<string, string>|null */
|
||
private static ?array $choices = null;
|
||
|
||
/** @var array{icons: array<string, string>, aliases: array<string, string>}|null */
|
||
private static ?array $set = null;
|
||
|
||
/**
|
||
* Kuratierte Auswahl.
|
||
*
|
||
* @return array<string, string> Name => deutsche Bezeichnung
|
||
*/
|
||
public static function choices(): array
|
||
{
|
||
return self::$choices ??= json_decode((string) file_get_contents(resource_path('icons/icons.json')), true);
|
||
}
|
||
|
||
/**
|
||
* @return list<string> alle Namen
|
||
*/
|
||
public static function names(): array
|
||
{
|
||
return array_keys(self::set()['icons']);
|
||
}
|
||
|
||
public static function has(mixed $name): bool
|
||
{
|
||
return is_string($name) && self::resolve($name) !== null;
|
||
}
|
||
|
||
/**
|
||
* Name, wie er in der Symbolliste steht (Aliase älterer Lucide-Versionen aufgelöst).
|
||
*/
|
||
public static function resolve(string $name): ?string
|
||
{
|
||
$set = self::set();
|
||
|
||
return isset($set['icons'][$name]) ? $name : ($set['aliases'][$name] ?? null);
|
||
}
|
||
|
||
public static function label(string $name): string
|
||
{
|
||
return self::choices()[$name] ?? $name;
|
||
}
|
||
|
||
/**
|
||
* Vollständiges SVG, z. B. für Vorschauen im Admin-Bereich.
|
||
*/
|
||
public static function svg(string $name, int $size = 18): string
|
||
{
|
||
$inner = self::set()['icons'][self::resolve($name) ?? ''] ?? '';
|
||
|
||
return '<svg xmlns="http://www.w3.org/2000/svg" width="'.$size.'" height="'.$size.'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="flex-shrink:0">'.$inner.'</svg>';
|
||
}
|
||
|
||
/**
|
||
* Auswahl für Filament-Select mit ->allowHtml(): die kuratierten Symbole.
|
||
* Alle weiteren findet die Suche (search()).
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
public static function options(): array
|
||
{
|
||
return array_combine(array_keys(self::choices()), array_map(fn (string $name) => self::option($name), array_keys(self::choices())));
|
||
}
|
||
|
||
/**
|
||
* Ein Eintrag für Filament-Select (Symbol + Bezeichnung) – auch für gespeicherte
|
||
* Werte außerhalb der kuratierten Auswahl.
|
||
*/
|
||
public static function option(string $name): string
|
||
{
|
||
$label = self::label($name);
|
||
|
||
return '<span style="display:inline-flex;align-items:center;gap:8px">'.self::svg($name).e($label).'</span>';
|
||
}
|
||
|
||
/**
|
||
* Suche über alle Symbole: kuratierte (deutsche Bezeichnung oder Name) zuerst, dann
|
||
* alle übrigen nach englischem Namen. Nie im SVG-Markup.
|
||
*
|
||
* @return array<string, string> Name => HTML für Filament-Select
|
||
*/
|
||
public static function search(string $query, int $limit = 60): array
|
||
{
|
||
$query = mb_strtolower(trim($query));
|
||
|
||
if ($query === '') {
|
||
return self::options();
|
||
}
|
||
|
||
$matches = [];
|
||
|
||
foreach (self::choices() as $name => $label) {
|
||
if (str_contains(mb_strtolower($label), $query) || str_contains($name, $query)) {
|
||
$matches[] = $name;
|
||
}
|
||
}
|
||
|
||
foreach ([...self::names(), ...array_keys(self::set()['aliases'])] as $name) {
|
||
if (count($matches) >= $limit) {
|
||
break;
|
||
}
|
||
|
||
$real = self::resolve($name);
|
||
|
||
if (str_contains($name, $query) && ! in_array($real, $matches, true) && ! in_array($name, $matches, true)) {
|
||
$matches[] = $real;
|
||
}
|
||
}
|
||
|
||
$matches = array_slice(array_values(array_unique($matches)), 0, $limit);
|
||
|
||
return array_combine($matches, array_map(fn (string $name) => self::option($name), $matches));
|
||
}
|
||
|
||
/**
|
||
* @return array{icons: array<string, string>, aliases: array<string, string>}
|
||
*/
|
||
private static function set(): array
|
||
{
|
||
return self::$set ??= require resource_path('icons/svg.php');
|
||
}
|
||
}
|