Icon-System: icon()-Helper, lokale Bootstrap-Icons, icons-add.php
Inline-SVG-Ausgabe via icon('name', 'klasse', 'label?') aus
public/assets/icons/. Dekorativ (aria-hidden) oder semantisch (role=img).
.icon-Basisklasse in utilities.css (1em, currentColor). bin/icons-add.php
holt neue Icons einzeln von icons.getbootstrap.com.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KDQZ6FuchNUh2bxSW9PeNv
This commit is contained in:
@@ -55,6 +55,30 @@ function asset(string $path): string
|
||||
return '/assets/' . $path . '?v=' . $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap-Icon als Inline-SVG ausgeben (lokal aus public/assets/icons/<name>.svg).
|
||||
* Standard: dekorativ (aria-hidden). Mit $label wird es als beschriftetes Bild
|
||||
* (role="img") ausgegeben. Größe/Farbe steuert CSS über die Klasse .icon.
|
||||
* Quelle: Bootstrap Icons (MIT) — neue Icons via bin/icons-add.php hinzufügen.
|
||||
*/
|
||||
function icon(string $name, string $class = '', ?string $label = null): string
|
||||
{
|
||||
static $cache = [];
|
||||
if (!array_key_exists($name, $cache)) {
|
||||
$file = PUBLIC_PATH . '/assets/icons/' . basename($name) . '.svg';
|
||||
$cache[$name] = is_file($file) ? trim((string) file_get_contents($file)) : '';
|
||||
}
|
||||
if ($cache[$name] === '') {
|
||||
return '';
|
||||
}
|
||||
$attrs = 'class="icon' . ($class !== '' ? ' ' . e($class) : '') . '"';
|
||||
$attrs .= $label !== null && $label !== ''
|
||||
? ' role="img" aria-label="' . e($label) . '"'
|
||||
: ' aria-hidden="true" focusable="false"';
|
||||
|
||||
return preg_replace('/<svg\b/', '<svg ' . $attrs, $cache[$name], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON-Datendatei laden (data/<name>.json) mit Request-weitem Cache.
|
||||
* Wirft bei kaputtem JSON — Datenfehler sollen laut scheitern, nicht leise.
|
||||
|
||||
Reference in New Issue
Block a user