Loheide-eu-mitarbeiterplatt.../app/Support/Icons.php
Friederich Loheide 23c36d28b5
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m47s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m33s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m41s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m18s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m9s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m0s
Menü: Symbole je Menüpunkt, gemeinsame Symbolauswahl
- Optionales Symbol für jeden Menü- und Unterpunkt (Kopfzeile,
  Aufklappmenüs, „Mehr“, Handy-Menü)
- Gemeinsame Liste resources/icons/icons.json (66 Lucide-Symbole) für
  Menü, Schnellzugriffe und Pagebuilder; `npm run icons` erzeugt
  Frontend-Zuordnung und SVGs für die Vorschau im Admin
- Admin-Auswahl mit Symbolvorschau und Suche

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 14:14:52 +00:00

68 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Support;
/**
* Kuratierte Symbole (Lucide) für Menü, Schnellzugriffe und Pagebuilder.
* Liste: resources/icons/icons.json – nach Änderungen `npm run icons` ausführen.
*/
final class Icons
{
/** @var array<string, string>|null */
private static ?array $choices = null;
/** @var array<string, string>|null */
private static ?array $svg = null;
/**
* @return array<string, string> Name => Bezeichnung
*/
public static function choices(): array
{
return self::$choices ??= json_decode((string) file_get_contents(resource_path('icons/icons.json')), true);
}
public static function has(mixed $name): bool
{
return is_string($name) && array_key_exists($name, self::choices());
}
/**
* Vollständiges SVG, z. B. für Vorschauen im Admin-Bereich.
*/
public static function svg(string $name, int $size = 18): string
{
self::$svg ??= require resource_path('icons/svg.php');
$inner = self::$svg[$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.
*
* @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();
}
/**
* Suche in der Auswahl nach Bezeichnung oder Name (nicht im SVG-Markup).
*
* @return array<string, string>
*/
public static function search(string $query): 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,
));
}
}