-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(ui): Dark Mode #2493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(ui): Dark Mode #2493
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,89 @@ | ||
| <template> | ||
| <nav class="navbar navbar-expand-lg navbar-light" style="background-color: #ffc400"> | ||
| <div class="container-fluid"> | ||
| <a class="navbar-brand" href="/" title="Sunshine"> | ||
| <img src="/images/logo-sunshine-45.png" height="45" alt="Sunshine"> | ||
| </a> | ||
| <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" | ||
| aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> | ||
| <span class="navbar-toggler-icon"></span> | ||
| </button> | ||
| <div class="collapse navbar-collapse" id="navbarSupportedContent"> | ||
| <ul class="navbar-nav me-auto mb-2 mb-lg-0"> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/"><i class="fas fa-fw fa-home"></i> {{ $t('navbar.home') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/pin"><i class="fas fa-fw fa-unlock"></i> {{ $t('navbar.pin') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/apps"><i class="fas fa-fw fa-stream"></i> {{ $t('navbar.applications') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/config"><i class="fas fa-fw fa-cog"></i> {{ $t('navbar.configuration') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/password"><i class="fas fa-fw fa-user-shield"></i> {{ $t('navbar.password') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/troubleshooting"><i class="fas fa-fw fa-info"></i> {{ $t('navbar.troubleshoot') }}</a> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </nav> | ||
| <nav class="navbar navbar-light navbar-expand-lg navbar-background header"> | ||
| <div class="container-fluid"> | ||
| <a class="navbar-brand" href="/" title="Sunshine"> | ||
| <img src="/images/logo-sunshine-45.png" height="45" alt="Sunshine"> | ||
| </a> | ||
| <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" | ||
| aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> | ||
| <span class="navbar-toggler-icon"></span> | ||
| </button> | ||
| <div class="collapse navbar-collapse" id="navbarSupportedContent"> | ||
| <ul class="navbar-nav me-auto mb-2 mb-lg-0"> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/"><i class="fas fa-fw fa-home"></i> {{ $t('navbar.home') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/pin"><i class="fas fa-fw fa-unlock"></i> {{ $t('navbar.pin') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/apps"><i class="fas fa-fw fa-stream"></i> {{ $t('navbar.applications') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/config"><i class="fas fa-fw fa-cog"></i> {{ $t('navbar.configuration') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/password"><i class="fas fa-fw fa-user-shield"></i> {{ $t('navbar.password') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link" href="/troubleshooting"><i class="fas fa-fw fa-info"></i> {{ $t('navbar.troubleshoot') }}</a> | ||
| </li> | ||
| <li class="nav-item"> | ||
| <ThemeToggle/> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </nav> | ||
| </template> | ||
|
|
||
| <script> | ||
| import ThemeToggle from './ThemeToggle.vue' | ||
|
|
||
| export default { | ||
| created() { | ||
| console.log("Header mounted!") | ||
| }, | ||
| mounted() { | ||
| let el = document.querySelector("a[href='" + document.location.pathname + "']"); | ||
| if (el) el.classList.add("active") | ||
| let discordWidget = document.createElement('script') | ||
| discordWidget.setAttribute('src', 'https://app.lizardbyte.dev/js/discord.js') | ||
| document.head.appendChild(discordWidget) | ||
| } | ||
| components: { ThemeToggle }, | ||
| created() { | ||
| console.log("Header mounted!") | ||
| }, | ||
| mounted() { | ||
| let el = document.querySelector("a[href='" + document.location.pathname + "']"); | ||
| if (el) el.classList.add("active") | ||
| let discordWidget = document.createElement('script') | ||
| discordWidget.setAttribute('src', 'https://app.lizardbyte.dev/js/discord.js') | ||
| document.head.appendChild(discordWidget) | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <style> | ||
| .nav-link.active { | ||
| font-weight: 500; | ||
| .navbar-background { | ||
| background-color: #ffc400 | ||
| } | ||
|
|
||
| .header .nav-link { | ||
| color: rgba(0, 0, 0, .65) !important; | ||
| } | ||
|
|
||
| .header .nav-link.active { | ||
| color: rgb(0, 0, 0) !important; | ||
| font-weight: 500; | ||
| } | ||
|
|
||
| .header .nav-link:hover { | ||
| color: rgb(0, 0, 0) !important; | ||
| font-weight: 500; | ||
| } | ||
|
|
||
| .header .navbar-toggler { | ||
| color: rgba(var(--bs-dark-rgb), .65) !important; | ||
| border: var(--bs-border-width) solid rgba(var(--bs-dark-rgb), 0.15) !important; | ||
| } | ||
|
|
||
| .header .navbar-toggler-icon { | ||
| --bs-navbar-toggler-icon-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2833, 37, 41, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") !important; | ||
| } | ||
|
|
||
| .form-control::placeholder { | ||
| opacity: 0.5; | ||
| opacity: 0.5; | ||
| } | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <script setup> | ||
| import { loadAutoTheme, setupThemeToggleListener } from './theme' | ||
| import { onMounted } from 'vue' | ||
|
|
||
| onMounted(() => { | ||
| loadAutoTheme() | ||
| setupThemeToggleListener() | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <div class="dropdown bd-mode-toggle"> | ||
| <a class="nav-link dropdown-toggle align-items-center" | ||
| id="bd-theme" | ||
| type="button" | ||
| aria-expanded="false" | ||
| data-bs-toggle="dropdown" | ||
| aria-label="{{ $t('navbar.toggle_theme') }} ({{ $t('navbar.theme_auto') }})"> | ||
| <span class="bi my-1 theme-icon-active"><i class="fa-solid fa-circle-half-stroke"></i></span> | ||
| <span id="bd-theme-text">{{ $t('navbar.toggle_theme') }}</span> | ||
| </a> | ||
| <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="bd-theme-text"> | ||
| <li> | ||
| <button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="light" aria-pressed="false"> | ||
| <i class="bi me-2 theme-icon fas fa-fw fa-solid fa-sun"></i> | ||
| {{ $t('navbar.theme_light') }} | ||
| </button> | ||
| </li> | ||
| <li> | ||
| <button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="dark" aria-pressed="false"> | ||
| <i class="bi me-2 theme-icon fas fa-fw fa-solid fa-moon"></i> | ||
| {{ $t('navbar.theme_dark') }} | ||
| </button> | ||
| </li> | ||
| <li> | ||
| <button type="button" class="dropdown-item d-flex align-items-center active" data-bs-theme-value="auto" aria-pressed="true"> | ||
| <i class="bi me-2 theme-icon fas fa-fw fa-solid fa-circle-half-stroke"></i> | ||
| {{ $t('navbar.theme_auto') }} | ||
| </button> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,3 +87,6 @@ const config = ref(props.config) | |
|
|
||
| </div> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <html lang="en" data-bs-theme="auto"> | ||
|
|
||
| <head> | ||
| <%- header %> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <html lang="en" data-bs-theme="auto"> | ||
|
|
||
| <head> | ||
| <%- header %> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <html lang="en" data-bs-theme="auto"> | ||
|
|
||
| <head> | ||
| <%- header %> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| const getStoredTheme = () => localStorage.getItem('theme') | ||
| const setStoredTheme = theme => localStorage.setItem('theme', theme) | ||
|
|
||
| export const getPreferredTheme = () => { | ||
| const storedTheme = getStoredTheme() | ||
| if (storedTheme) { | ||
| return storedTheme | ||
| } | ||
|
|
||
| return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' | ||
| } | ||
|
|
||
| const setTheme = theme => { | ||
| if (theme === 'auto') { | ||
| document.documentElement.setAttribute( | ||
| 'data-bs-theme', | ||
| (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') | ||
| ) | ||
| } else { | ||
| document.documentElement.setAttribute('data-bs-theme', theme) | ||
| } | ||
| } | ||
|
|
||
| export const showActiveTheme = (theme, focus = false) => { | ||
| const themeSwitcher = document.querySelector('#bd-theme') | ||
|
|
||
| if (!themeSwitcher) { | ||
| return | ||
| } | ||
|
|
||
| const themeSwitcherText = document.querySelector('#bd-theme-text') | ||
| const activeThemeIcon = document.querySelector('.theme-icon-active i') | ||
| const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`) | ||
| const classListOfActiveBtn = btnToActive.querySelector('i').classList | ||
|
|
||
| document.querySelectorAll('[data-bs-theme-value]').forEach(element => { | ||
| element.classList.remove('active') | ||
| element.setAttribute('aria-pressed', 'false') | ||
| }) | ||
|
|
||
| btnToActive.classList.add('active') | ||
| btnToActive.setAttribute('aria-pressed', 'true') | ||
| activeThemeIcon.classList.remove(...activeThemeIcon.classList.values()) | ||
| activeThemeIcon.classList.add(...classListOfActiveBtn) | ||
| const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.textContent.trim()})` | ||
| themeSwitcher.setAttribute('aria-label', themeSwitcherLabel) | ||
|
|
||
| if (focus) { | ||
| themeSwitcher.focus() | ||
| } | ||
| } | ||
|
|
||
| export function setupThemeToggleListener() { | ||
| document.querySelectorAll('[data-bs-theme-value]') | ||
| .forEach(toggle => { | ||
| toggle.addEventListener('click', () => { | ||
| const theme = toggle.getAttribute('data-bs-theme-value') | ||
| setStoredTheme(theme) | ||
| setTheme(theme) | ||
| showActiveTheme(theme, true) | ||
| }) | ||
| }) | ||
|
|
||
| showActiveTheme(getPreferredTheme(), false) | ||
| } | ||
|
|
||
| export function loadAutoTheme() { | ||
| (() => { | ||
| 'use strict' | ||
|
|
||
| setTheme(getPreferredTheme()) | ||
|
|
||
| window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { | ||
| const storedTheme = getStoredTheme() | ||
| if (storedTheme !== 'light' && storedTheme !== 'dark') { | ||
| setTheme(getPreferredTheme()) | ||
| } | ||
| }) | ||
|
|
||
| window.addEventListener('DOMContentLoaded', () => { | ||
| showActiveTheme(getPreferredTheme()) | ||
| }) | ||
| })() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <html lang="en" data-bs-theme="auto"> | ||
|
|
||
| <head> | ||
| <%- header %> | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.