Redesign v2025.1

This commit is contained in:
Jonny Barnes 2025-12-11 17:17:01 +00:00
commit a8cb30456c
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
37 changed files with 1576 additions and 1174 deletions

View file

@ -1,7 +1,7 @@
import { Auth } from './auth.js';
import { ThemeSelector } from './theme-selector.js';
let auth = new Auth();
document.querySelectorAll('.add-passkey').forEach((el) => {
el.addEventListener('click', () => {
auth.register();
@ -13,3 +13,6 @@ document.querySelectorAll('.login-passkey').forEach((el) => {
auth.login();
});
});
let themeSelector = new ThemeSelector();
themeSelector.setupEventListeners();

View file

@ -0,0 +1,70 @@
class ThemeSelector {
constructor() {
this.widget = document.querySelector('#theme-selector');
}
setupEventListeners() {
this.widget.querySelectorAll('#theme-selector-dropdown input').forEach((radioInput) => radioInput.addEventListener('input', (e) => {
let theme = e.target.value;
// Update current icon
this.widget.querySelectorAll('.toggle svg').forEach((svg) => {
if (svg.classList.contains(theme)) {
svg.style.display = '';
} else {
svg.style.display = 'none';
}
});
// Set the theme
let selectedTheme;
switch (theme) {
case 'dark':
case 'light':
selectedTheme = theme;
break;
default:
selectedTheme = 'light dark';
}
const systemTheme = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light';
const html = document.querySelector('html');
let currentTheme = html.style.getPropertyValue('color-scheme');
if (currentTheme === '') {
currentTheme = 'light dark';
}
/* do we need to transition */
let doTransition = false;
if (selectedTheme !== currentTheme) {
if (selectedTheme === 'light dark') {
doTransition = currentTheme !== systemTheme;
} else if (currentTheme === 'light dark') {
doTransition = selectedTheme !== systemTheme;
} else {
doTransition = true;
}
}
html.style.viewTransitionName = 'changing-theme';
if (doTransition && document.startViewTransition) {
document.startViewTransition(() => {
// Close the popover
document.querySelector('#theme-selector-dropdown').togglePopover();
// Set the colour theme
html.style.setProperty('color-scheme', selectedTheme);
});
} else {
// Close the popover
document.querySelector('#theme-selector-dropdown').togglePopover();
// Set the colour theme
html.style.setProperty('color-scheme', selectedTheme);
}
}));
}
}
export { ThemeSelector };