Enables the user to customize navbar links

This commit is contained in:
Alicia Sykes committed 2025-09-22 20:23:46 +01:00
1 parent 6f68601f44
commit ee3e041fbf
10 files changed
+349 -29

No files matched your search

@@ -40,15 +40,31 @@
</header>
<style lang="scss">
.header-content {
display: flex;
align-items: center;
justify-content: space-between;
min-width: 0; // Allow flex children to shrink
}
.logo {
min-width: 15rem;
flex-shrink: 0; // Prevent logo from shrinking
}
.header-actions {
display: flex;
align-items: center;
gap: var(--spacing-md);
min-width: 0;
flex: 1;
justify-content: end;
}
.header-buttons {
display: flex;
align-items: center;
gap: var(--spacing-sm);
flex-shrink: 0; // Always keep buttons visible
}
</style>
@@ -6,6 +6,7 @@
import { tooltip } from '$lib/actions/tooltip';
import { browser } from '$app/environment';
import { theme, themes, type ThemeOption } from '$lib/stores/theme';
import { navbarDisplay, navbarDisplayOptions, type NavbarDisplayMode } from '$lib/stores/navbarDisplay';
import { site } from '$lib/constants/site';
interface Props {
@@ -20,6 +21,7 @@
let triggerRef = $state<HTMLButtonElement>();
let accessibilitySettings = $state(accessibility);
let currentTheme = $state(theme);
let currentNavbarDisplay = $state(navbarDisplay);
// Shortcut key detection
const isMac = browser && navigator.platform.toUpperCase().indexOf('MAC') >= 0;
@@ -44,6 +46,12 @@
accessibility.toggle(optionId);
}
// Handle navbar display mode change
function handleNavbarDisplayChange(event: Event) {
const target = event.currentTarget as HTMLSelectElement;
navbarDisplay.setMode(target.value as NavbarDisplayMode);
}
// Primary accessibility options (always visible)
const primaryA11yOptions = ['reduce-motion'];
// const primaryA11yOptions: string[] = [];
@@ -97,6 +105,7 @@
// Initialize stores
accessibility.init();
theme.init();
navbarDisplay.init();
return () => {
document.removeEventListener('click', handleClickOutside);
@@ -181,6 +190,24 @@
</div>
</div>
<!-- Navbar Display -->
<div class="settings-section">
<h3>Top Navigation</h3>
<div class="navbar-select-wrapper">
<select class="navbar-select" value={$currentNavbarDisplay} onchange={handleNavbarDisplayChange}>
{#each navbarDisplayOptions as option (option.id)}
<option value={option.id}>{option.name}</option>
{/each}
</select>
<div class="dropdown-icon">
<Icon name="chevron-down" size="xs" />
</div>
</div>
<small class="navbar-description">
{navbarDisplayOptions.find((opt) => opt.id === $currentNavbarDisplay)?.description}
</small>
</div>
<!-- Accessibility Options -->
<div class="settings-section">
<h3>Accessibility</h3>
@@ -392,6 +419,82 @@
}
}
.navbar-select-wrapper {
position: relative;
display: block;
.dropdown-icon {
position: absolute;
right: var(--spacing-sm);
top: 50%;
transform: translateY(-50%);
pointer-events: none;
color: var(--text-secondary);
transition: all var(--transition-fast);
width: 0.75rem;
height: 0.75rem;
z-index: 1;
}
}
.navbar-select {
width: 100%;
padding: var(--spacing-sm) 2rem var(--spacing-sm) var(--spacing-sm);
background: var(--bg-tertiary);
border: 1px solid var(--border-primary);
border-radius: var(--radius-sm);
font-size: var(--font-size-sm);
color: var(--text-primary);
cursor: pointer;
transition: all var(--transition-normal);
appearance: none;
position: relative;
&:hover {
background: var(--surface-hover);
border-color: var(--border-secondary);
}
&:focus {
outline: none;
border-color: var(--color-primary);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary), transparent 85%);
}
&:focus ~ .dropdown-icon {
color: var(--color-primary);
transform: translateY(-50%) rotate(180deg);
}
&:hover ~ .dropdown-icon {
color: var(--text-primary);
}
// Try to customize option colors (browser support varies)
option {
background: var(--bg-secondary);
color: var(--text-primary);
padding: var(--spacing-sm);
&:hover {
background: var(--surface-hover);
}
&:checked {
background: color-mix(in srgb, var(--color-primary), transparent 90%);
color: var(--text-primary);
}
}
}
.navbar-description {
color: var(--text-tertiary);
font-size: var(--font-size-xs);
line-height: 1.3;
margin-top: var(--spacing-xs);
display: block;
}
.accessibility-options {
display: flex;
flex-direction: column;
+105 -6
View File
@@ -2,6 +2,10 @@
import { page } from '$app/stores';
import { TOP_NAV, SUB_NAV, isActive, type NavItem, type NavGroup } from '$lib/constants/nav';
import Icon from '$lib/components/global/Icon.svelte';
import { navbarDisplay } from '$lib/stores/navbarDisplay';
import { bookmarks } from '$lib/stores/bookmarks';
import { frequentlyUsedTools, toolUsage } from '$lib/stores/toolUsage';
import { onMount } from 'svelte';
$: currentPath = $page.url.pathname;
@@ -48,7 +52,8 @@
}
function hasSubPages(href: string): boolean {
return href in SUB_NAV;
// Only show dropdowns for default mode
return $navbarDisplay === 'default' && href in SUB_NAV;
}
function getSubPages(href: string): (NavItem | NavGroup)[] {
@@ -66,10 +71,56 @@
function isNavGroup(item: NavItem | NavGroup): item is NavGroup {
return 'title' in item && 'items' in item;
}
// Check if current mode has dropdowns (only default mode has dropdowns)
$: hasDropdowns = $navbarDisplay === 'default';
// Reactive navigation items based on current display mode and store changes
$: navigationItems = (() => {
let items: NavItem[];
switch ($navbarDisplay) {
case 'bookmarked':
items = $bookmarks.map((bookmark) => ({
href: bookmark.href,
label: bookmark.label,
icon: bookmark.icon,
description: bookmark.description,
}));
break;
case 'frequent':
items = $frequentlyUsedTools.slice(0, 8).map(tool => ({
href: tool.href,
label: tool.label || 'Untitled Tool',
icon: tool.icon,
description: tool.description
}));
break;
case 'none':
items = [];
break;
case 'default':
default:
items = TOP_NAV;
break;
}
// Reverse array so items overflow from left but appear in correct visual order
return items.reverse();
})();
onMount(() => {
navbarDisplay.init();
bookmarks.init();
toolUsage.init();
});
</script>
<nav class="top-nav" aria-label="Primary navigation">
{#each TOP_NAV as item (item.href)}
<nav class="top-nav" class:has-dropdowns={hasDropdowns} aria-label="Primary navigation">
{#each navigationItems as item (item.href)}
<div
class="nav-item"
class:has-dropdown={hasSubPages(item.href)}
@@ -84,7 +135,7 @@
aria-expanded={activeDropdown === item.href}
aria-haspopup={hasSubPages(item.href)}
>
{item.label}
<span class="nav-text">{item.label}</span>
{#if hasSubPages(item.href)}
<svg class="dropdown-icon" width="12" height="12" viewBox="0 0 12 12" fill="none">
<path
@@ -195,10 +246,25 @@
display: flex;
align-items: center;
gap: var(--spacing-sm);
flex: 1;
min-width: 0;
justify-content: flex-end;
// Default: Hide horizontal overflow (for bookmarked/frequent modes)
overflow-x: hidden;
overflow-y: visible;
// When has dropdowns (default mode): Allow overflow for dropdowns
&.has-dropdowns {
overflow: visible;
}
}
.nav-item {
position: relative;
max-width: 12rem;
min-width: 0;
flex-shrink: 0;
}
.nav-link {
@@ -211,8 +277,20 @@
text-decoration: none;
border-radius: var(--radius-md);
transition: all 0.2s ease;
width: 100%;
min-width: 0;
.nav-text {
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
flex: 1;
}
.dropdown-icon {
opacity: 0.4;
flex-shrink: 0;
}
&:hover {
@@ -388,7 +466,6 @@
.secondary-dropdown {
position: absolute;
top: 0;
left: calc(100% + 0.5rem);
min-width: 18rem;
max-width: 28rem;
background: var(--bg-secondary);
@@ -397,9 +474,20 @@
box-shadow: var(--shadow-lg);
z-index: 6;
animation: secondary-enter 0.15s ease-out;
transform-origin: left center;
pointer-events: auto;
white-space: normal;
// Smart positioning: try right first, auto-fallback to left
left: calc(100% + 0.5rem);
transform-origin: left center;
// Auto-position to left when overflowing viewport
@media (max-width: 1200px) {
right: calc(100% + 0.5rem);
left: auto;
transform-origin: right center;
animation: secondary-enter-left 0.15s ease-out;
}
}
@keyframes secondary-enter {
@@ -413,6 +501,17 @@
}
}
@keyframes secondary-enter-left {
from {
opacity: 0;
transform: scale(0.95) translateX(0.5rem);
}
to {
opacity: 1;
transform: scale(1) translateX(0);
}
}
.secondary-content {
padding: 0.5rem;
}
@@ -62,10 +62,10 @@
.slice(0, 8);
}
const showSearch = () => {
export function showSearch() {
isOpen = true;
setTimeout(() => searchInput?.focus(), 0);
};
}
function close() {
isOpen = false;
+26 -8
View File
@@ -106,17 +106,39 @@
flex-direction: column;
gap: var(--spacing-sm);
padding: var(--spacing-lg);
background: linear-gradient(225deg, var(--bg-secondary), color-mix(in srgb, var(--bg-secondary), var(--bg-tertiary) 70%));
background: linear-gradient(
225deg,
var(--bg-secondary),
color-mix(in srgb, var(--bg-secondary), var(--bg-tertiary) 70%)
);
border: 1px solid var(--border-primary);
border-radius: var(--radius-lg);
text-decoration: none;
color: inherit;
transition: all var(--transition-fast), background 0.5s ease-in-out;
transition: all var(--transition-fast);
position: relative;
height: 100%;
min-width: 0;
overflow: hidden;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(
180deg,
var(--bg-secondary),
color-mix(in srgb, var(--bg-secondary), var(--bg-tertiary) 85%)
);
opacity: 0;
transition: opacity var(--transition-slow);
border-radius: inherit;
z-index: 0;
}
.card-header {
display: flex;
align-items: flex-start;
@@ -214,17 +236,13 @@
}
&:hover {
// border-color: var(--color-primary);
transform: translateY(-2px);
box-shadow: var(--shadow-lg);
background: linear-gradient(
180deg,
var(--bg-secondary),
color-mix(in srgb, var(--bg-secondary), var(--bg-tertiary) 85%)
);
&::before {
opacity: 1;
}
.tool-arrow {
transform: translateX(4px);
color: var(--color-primary);
@@ -18,7 +18,7 @@
let subnets = $state<SubnetRequirement[]>([]);
let vlsmResult = $state<VLSMResult | null>(null);
let copiedStates = $state<Record<string, boolean>>({});
let expandedSubnets = $state(new SvelteSet<string>());
let expandedSubnets = new SvelteSet<string>();
// Add initial subnet requirement
$effect(() => {
+2 -2
View File
@@ -140,7 +140,7 @@ function createAccessibilityStore() {
set({ options });
// Load dyslexic font if it's enabled
if (options.some(opt => opt.id === 'dyslexia-font' && opt.enabled)) {
if (options.some((opt) => opt.id === 'dyslexia-font' && opt.enabled)) {
loadDyslexicFont();
}
}
@@ -159,7 +159,7 @@ function createAccessibilityStore() {
// Load dyslexic font if dyslexia-font option was just enabled
if (optionId === 'dyslexia-font') {
const isEnabled = newOptions.find(opt => opt.id === 'dyslexia-font')?.enabled;
const isEnabled = newOptions.find((opt) => opt.id === 'dyslexia-font')?.enabled;
if (isEnabled) {
loadDyslexicFont();
}
+84
View File
@@ -0,0 +1,84 @@
import { writable } from 'svelte/store';
import { browser } from '$app/environment';
export type NavbarDisplayMode = 'default' | 'bookmarked' | 'frequent' | 'none';
export interface NavbarDisplayOption {
id: NavbarDisplayMode;
name: string;
description: string;
}
const STORAGE_KEY = 'navbar-display';
// Available navbar display options
export const navbarDisplayOptions: NavbarDisplayOption[] = [
{
id: 'default',
name: 'Default/All',
description: 'Show dropdown links for each page/sub-page',
},
{
id: 'bookmarked',
name: 'Bookmarked',
description: 'Show bookmarked links in the top nav',
},
{
id: 'frequent',
name: 'Frequent',
description: 'Show most frequently used tools',
},
{
id: 'none',
name: 'None',
description: "Don't show any links in the top nav",
},
];
function createNavbarDisplayStore() {
const { subscribe, set } = writable<NavbarDisplayMode>('default');
return {
subscribe,
// Initialize from localStorage or default
init: () => {
if (browser) {
const stored = localStorage.getItem(STORAGE_KEY);
const isValidMode = navbarDisplayOptions.some((option) => option.id === stored);
const initialMode = isValidMode ? (stored as NavbarDisplayMode) : 'default';
set(initialMode);
return initialMode;
}
return 'default';
},
// Set navbar display mode and persist to localStorage
setMode: (mode: NavbarDisplayMode) => {
const option = navbarDisplayOptions.find((opt) => opt.id === mode);
if (!option) {
console.warn(`Navbar display mode "${mode}" is not valid`);
return;
}
set(mode);
if (browser) {
localStorage.setItem(STORAGE_KEY, mode);
}
},
// Get option configuration
getOption: (mode: NavbarDisplayMode): NavbarDisplayOption | undefined => {
return navbarDisplayOptions.find((opt) => opt.id === mode);
},
// Get all available options
getAllOptions: (): NavbarDisplayOption[] => {
return navbarDisplayOptions;
},
};
}
export const navbarDisplay = createNavbarDisplayStore();
+9 -9
View File
@@ -43,7 +43,7 @@ function applyThemeClasses(theme: ThemeOption) {
if (!browser) return;
// Remove all existing theme classes
const allThemeClasses = themes.map(t => `theme-${t.id}`);
const allThemeClasses = themes.map((t) => `theme-${t.id}`);
document.documentElement.classList.remove(...allThemeClasses);
// Add the current theme class (except for default 'dark' theme)
@@ -52,7 +52,7 @@ function applyThemeClasses(theme: ThemeOption) {
}
// Load custom font if the theme has one
const themeConfig = themes.find(t => t.id === theme);
const themeConfig = themes.find((t) => t.id === theme);
if (themeConfig?.font) {
loadCustomFont(themeConfig.font);
}
@@ -63,7 +63,7 @@ export const themes: Theme[] = [
{
id: 'light',
name: 'Light',
available: true,
available: true,
},
{
id: 'dark',
@@ -77,8 +77,8 @@ export const themes: Theme[] = [
font: {
name: 'Inter',
url: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap',
fallback: 'sans-serif'
}
fallback: 'sans-serif',
},
},
{
id: 'purple',
@@ -86,9 +86,9 @@ export const themes: Theme[] = [
available: true,
font: {
name: 'Poppins',
url: 'https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap',
fallback: 'sans'
}
url: 'https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400..700;1,400..700&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap',
fallback: 'sans',
},
},
];
@@ -102,7 +102,7 @@ function createThemeStore() {
init: () => {
if (browser) {
const saved = localStorage.getItem(STORAGE_KEY);
const isValidTheme = themes.some(t => t.id === saved && t.available);
const isValidTheme = themes.some((t) => t.id === saved && t.available);
const initialTheme = isValidTheme ? (saved as ThemeOption) : 'dark';
set(initialTheme);
+1 -1
View File
@@ -100,7 +100,7 @@ html[data-theme='purple'] {
--surface-hover: #2b384b;
--border-primary: #30405b;
--font-body: 'Poppins', sans-serif;
--font-heading: 'Poppins', sans-serif;
--font-heading: 'Lora', 'Poppins', sans-serif;
}
/* Light theme */