Skip to content

Commit 4f66b78

Browse files
authored
SVG logo currentColor support (librenms#17903)
If title_image is set and it is on the same server (browser won't include it otherwise), inline the SVG so the SVG can use currentColor and react to theme changes.
1 parent e060c30 commit 4f66b78

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lang/en/settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@
20592059
],
20602060
'title_image' => [
20612061
'description' => 'Title Image',
2062-
'help' => 'Overrides the default Title Image.',
2062+
'help' => 'Overrides the default Title Image. SVG from the same server will be include and can use currentColor to match the current theme dynamically.',
20632063
],
20642064
'traceroute' => [
20652065
'description' => 'Path to traceroute',

resources/views/components/logo.blade.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
@props([
22
'responsive' => false, // crop text at given breakpoint sm,md,lg,xl, etc
3+
'image' => LibrenmsConfig::get('title_image'),
4+
'alt' => LibrenmsConfig::get('project_name')
35
])
46

5-
@if(LibrenmsConfig::get('title_image'))
6-
<img {{ $attributes }} src="{{ asset(LibrenmsConfig::get('title_image')) }}" alt="{{ LibrenmsConfig::get('project_name') }}">
7+
@if($image)
8+
{{-- Include svgs inline so they can use currentColor for light/dark mode, but only if they are hosted on the same server (browser will reject it otherwise) --}}
9+
@if(str_ends_with($image, '.svg') && ! str_contains($image, '//'))
10+
<svg {{ $attributes->class(['tw:dark:text-white', 'tw:text-gray-600']) }}>
11+
<use href="{{ asset($image) }}"></use>
12+
</svg>
13+
@else
14+
<img {{ $attributes }} src="{{ asset($image) }}" alt="{{ $alt }}">
15+
@endif
716
@else
817
<svg {{ $attributes->class(['tw:dark:text-white', 'tw:text-gray-600'])->class($responsive ? ['tw:hidden', "tw:$responsive:inline-block"] : []) }}
918
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 170 32.275086">

0 commit comments

Comments
 (0)