Symbole: alle Lucide-Symbole lokal verfügbar
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
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>
This commit is contained in:
parent
23c36d28b5
commit
c71131d054
151 changed files with 4621 additions and 512 deletions
|
|
@ -3,28 +3,58 @@
|
|||
namespace App\Support;
|
||||
|
||||
/**
|
||||
* Kuratierte Symbole (Lucide) für Menü, Schnellzugriffe und Pagebuilder.
|
||||
* Liste: resources/icons/icons.json – nach Änderungen `npm run icons` ausführen.
|
||||
* 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<string, string>|null */
|
||||
private static ?array $svg = null;
|
||||
/** @var array{icons: array<string, string>, aliases: array<string, string>}|null */
|
||||
private static ?array $set = null;
|
||||
|
||||
/**
|
||||
* @return array<string, string> Name => Bezeichnung
|
||||
* 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) && array_key_exists($name, self::choices());
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -32,37 +62,77 @@ final class Icons
|
|||
*/
|
||||
public static function svg(string $name, int $size = 18): string
|
||||
{
|
||||
self::$svg ??= require resource_path('icons/svg.php');
|
||||
$inner = self::$svg[$name] ?? '';
|
||||
$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(): Symbol und Bezeichnung.
|
||||
* 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 collect(self::choices())
|
||||
->map(fn (string $label, string $name) => '<span style="display:inline-flex;align-items:center;gap:8px">'.self::svg($name).e($label).'</span>')
|
||||
->all();
|
||||
return array_combine(array_keys(self::choices()), array_map(fn (string $name) => self::option($name), array_keys(self::choices())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Suche in der Auswahl nach Bezeichnung oder Name (nicht im SVG-Markup).
|
||||
*
|
||||
* @return array<string, string>
|
||||
* Ein Eintrag für Filament-Select (Symbol + Bezeichnung) – auch für gespeicherte
|
||||
* Werte außerhalb der kuratierten Auswahl.
|
||||
*/
|
||||
public static function search(string $query): array
|
||||
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));
|
||||
|
||||
return array_intersect_key(self::options(), array_filter(
|
||||
self::choices(),
|
||||
fn (string $label, string $name) => $query === '' || str_contains(mb_strtolower($label), $query) || str_contains($name, $query),
|
||||
ARRAY_FILTER_USE_BOTH,
|
||||
));
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue