Enhance web-ui components and styles with new features and dependencies
- Added @lucide/svelte as a dependency for icon support in various components. - Updated AboutDialog, AppShell, AuthPage, Header, SettingsDialog, and styles for improved functionality and UI consistency. - Introduced new props and state management for better user experience. - Refactored CSS for cleaner styling and improved layout.
This commit is contained in:
1 parent
ce6db8a457
commit
e3544617e1
9 files changed
+260
-43
No files matched your search
@@ -7,22 +7,37 @@
|
||||
brand = 'Application',
|
||||
children,
|
||||
description = '',
|
||||
icon,
|
||||
links = [],
|
||||
onClose,
|
||||
open = $bindable(false),
|
||||
version = ''
|
||||
}: {
|
||||
brand?: string;
|
||||
children?: Snippet;
|
||||
description?: string;
|
||||
icon?: Snippet;
|
||||
links?: AboutLink[];
|
||||
onClose?: () => void | Promise<void>;
|
||||
open?: boolean;
|
||||
version?: string;
|
||||
} = $props();
|
||||
|
||||
let wasOpen = false;
|
||||
|
||||
$effect(() => {
|
||||
if (wasOpen && !open) void onClose?.();
|
||||
wasOpen = open;
|
||||
});
|
||||
</script>
|
||||
|
||||
<Dialog bind:open title={`About ${brand}`}>
|
||||
<div class="sc-auth-brand">
|
||||
<span aria-hidden="true" class="sc-brand-mark">{brand.slice(0, 1).toUpperCase()}</span>
|
||||
{#if icon}
|
||||
{@render icon()}
|
||||
{:else}
|
||||
<span aria-hidden="true" class="sc-brand-mark">{brand.slice(0, 1).toUpperCase()}</span>
|
||||
{/if}
|
||||
<strong>{brand}</strong>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import type { Snippet } from 'svelte';
|
||||
import type { NavItem } from '../types';
|
||||
import Header from './Header.svelte';
|
||||
import PageHeader from './PageHeader.svelte';
|
||||
|
||||
let {
|
||||
brand = 'Application',
|
||||
@@ -15,9 +16,10 @@
|
||||
onNavigate,
|
||||
onProfile,
|
||||
onSettings,
|
||||
showPageHeader = true,
|
||||
showSettings = true,
|
||||
theme = 'dark',
|
||||
username = ''
|
||||
username = '',
|
||||
}: {
|
||||
brand?: string;
|
||||
brandHref?: string;
|
||||
@@ -30,10 +32,17 @@
|
||||
onNavigate?: (item: NavItem) => void;
|
||||
onProfile?: () => void;
|
||||
onSettings?: () => void;
|
||||
showPageHeader?: boolean;
|
||||
showSettings?: boolean;
|
||||
theme?: 'dark' | 'light' | 'system';
|
||||
username?: string;
|
||||
} = $props();
|
||||
|
||||
const activeNavItem = $derived(
|
||||
navItems.find((item) =>
|
||||
item.href === '/' ? currentPath === '/' : currentPath === item.href || currentPath.startsWith(`${item.href}/`),
|
||||
),
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class={`sc-root sc-app-shell ${className}`} data-theme={theme === 'system' ? undefined : theme}>
|
||||
@@ -52,6 +61,13 @@
|
||||
/>
|
||||
|
||||
<main class="sc-main">
|
||||
{#if showPageHeader && activeNavItem?.href !== '/about'}
|
||||
<PageHeader
|
||||
title={activeNavItem?.label ?? brand}
|
||||
description={activeNavItem?.description ??
|
||||
`Explore the ${activeNavItem?.label?.toLowerCase() ?? 'application'} section.`}
|
||||
/>
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
</main>
|
||||
</div>
|
||||
@@ -39,6 +39,7 @@
|
||||
let identifier = $state('');
|
||||
let password = $state('');
|
||||
let totpToken = $state('');
|
||||
let totpRequired = $state(false);
|
||||
let confirmPassword = $state('');
|
||||
let submitError = $state('');
|
||||
let submitting = $state(false);
|
||||
@@ -47,6 +48,17 @@
|
||||
let resetOpen = $state(false);
|
||||
let resetting = $state(false);
|
||||
|
||||
function isTotpChallenge(caught: unknown): boolean {
|
||||
if (!(caught instanceof Error)) return false;
|
||||
const message = caught.message.toLowerCase();
|
||||
return (
|
||||
message.includes('two-factor authentication code required') ||
|
||||
message.includes('multi-factor authentication code required') ||
|
||||
(message.includes('totp') && message.includes('required')) ||
|
||||
(message.includes('mfa') && message.includes('required'))
|
||||
);
|
||||
}
|
||||
|
||||
async function submit(event: SubmitEvent): Promise<void> {
|
||||
event.preventDefault();
|
||||
submitError = '';
|
||||
@@ -64,10 +76,23 @@
|
||||
await onSetup({ username, email, password });
|
||||
} else {
|
||||
if (!onLogin) throw new Error('The application has not configured its login handler.');
|
||||
if (totpRequired && !totpToken.trim()) {
|
||||
submitError = 'Enter the six-digit authenticator code to continue.';
|
||||
return;
|
||||
}
|
||||
await onLogin({ identifier, password, totpToken: totpToken.trim() });
|
||||
}
|
||||
} catch (caught) {
|
||||
submitError = caught instanceof Error ? caught.message : 'Authentication failed.';
|
||||
if (!setupRequired && showTotp && isTotpChallenge(caught)) {
|
||||
totpRequired = true;
|
||||
submitError = 'Enter the six-digit authenticator code to continue.';
|
||||
} else {
|
||||
if (!setupRequired) {
|
||||
totpRequired = false;
|
||||
totpToken = '';
|
||||
}
|
||||
submitError = caught instanceof Error ? caught.message : 'Authentication failed.';
|
||||
}
|
||||
} finally {
|
||||
submitting = false;
|
||||
}
|
||||
@@ -170,9 +195,9 @@
|
||||
/>
|
||||
</label>
|
||||
|
||||
{#if showTotp && !setupRequired}
|
||||
{#if showTotp && !setupRequired && totpRequired}
|
||||
<label class="sc-field">
|
||||
<span class="sc-label">Authenticator code <span class="sc-label-optional">(if enabled)</span></span>
|
||||
<span class="sc-label">Authenticator code</span>
|
||||
<input
|
||||
autocomplete="one-time-code"
|
||||
class="sc-input"
|
||||
|
||||
@@ -1,7 +1,95 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
Activity,
|
||||
Archive,
|
||||
BarChart3,
|
||||
Bot,
|
||||
Box,
|
||||
CircleAlert,
|
||||
CircleHelp,
|
||||
CircleUserRound,
|
||||
CloudDownload,
|
||||
Database,
|
||||
FileCog,
|
||||
FolderOpen,
|
||||
Gamepad2,
|
||||
GalleryHorizontalEnd,
|
||||
HardDrive,
|
||||
Image,
|
||||
Info,
|
||||
LayoutDashboard,
|
||||
ListVideo,
|
||||
Logs,
|
||||
Magnet,
|
||||
Map,
|
||||
MapPinned,
|
||||
MessageCircle,
|
||||
MonitorPlay,
|
||||
Play,
|
||||
Plug,
|
||||
RefreshCw,
|
||||
ScanSearch,
|
||||
ScrollText,
|
||||
Send,
|
||||
Server,
|
||||
Settings2,
|
||||
ShieldCheck,
|
||||
SlidersHorizontal,
|
||||
Sparkles,
|
||||
Tags,
|
||||
Upload,
|
||||
Users,
|
||||
WandSparkles,
|
||||
Workflow,
|
||||
Wrench,
|
||||
} from '@lucide/svelte';
|
||||
import type { Snippet } from 'svelte';
|
||||
import type { NavItem } from '../types';
|
||||
|
||||
const icons: Record<string, typeof LayoutDashboard> = {
|
||||
activity: Activity,
|
||||
archive: Archive,
|
||||
'bar-chart-3': BarChart3,
|
||||
bot: Bot,
|
||||
box: Box,
|
||||
'circle-alert': CircleAlert,
|
||||
'circle-help': CircleHelp,
|
||||
'cloud-download': CloudDownload,
|
||||
database: Database,
|
||||
'file-cog': FileCog,
|
||||
'folder-open': FolderOpen,
|
||||
gamepad: Gamepad2,
|
||||
'gallery-horizontal-end': GalleryHorizontalEnd,
|
||||
'hard-drive': HardDrive,
|
||||
image: Image,
|
||||
info: Info,
|
||||
'layout-dashboard': LayoutDashboard,
|
||||
'list-video': ListVideo,
|
||||
logs: Logs,
|
||||
magnet: Magnet,
|
||||
map: Map,
|
||||
'map-pinned': MapPinned,
|
||||
'message-circle': MessageCircle,
|
||||
'monitor-play': MonitorPlay,
|
||||
play: Play,
|
||||
plug: Plug,
|
||||
'refresh-cw': RefreshCw,
|
||||
'scan-search': ScanSearch,
|
||||
'scroll-text': ScrollText,
|
||||
send: Send,
|
||||
server: Server,
|
||||
'settings-2': Settings2,
|
||||
'shield-check': ShieldCheck,
|
||||
'sliders-horizontal': SlidersHorizontal,
|
||||
sparkles: Sparkles,
|
||||
tags: Tags,
|
||||
upload: Upload,
|
||||
users: Users,
|
||||
'wand-sparkles': WandSparkles,
|
||||
workflow: Workflow,
|
||||
wrench: Wrench,
|
||||
};
|
||||
|
||||
let {
|
||||
brand = 'Application',
|
||||
brandHref = '/',
|
||||
@@ -30,6 +118,10 @@
|
||||
|
||||
let navOpen = $state(false);
|
||||
|
||||
function iconFor(item: NavItem) {
|
||||
return icons[item.icon ?? 'layout-dashboard'] ?? LayoutDashboard;
|
||||
}
|
||||
|
||||
function isActive(item: NavItem): boolean {
|
||||
return item.href === '/'
|
||||
? currentPath === '/'
|
||||
@@ -45,6 +137,7 @@
|
||||
|
||||
<nav aria-label="Primary navigation" class="sc-nav" data-open={navOpen}>
|
||||
{#each navItems as item}
|
||||
{@const Icon = iconFor(item)}
|
||||
<a
|
||||
aria-current={isActive(item) ? 'page' : undefined}
|
||||
class="sc-nav-link"
|
||||
@@ -58,6 +151,7 @@
|
||||
navOpen = false;
|
||||
}}
|
||||
>
|
||||
<Icon aria-hidden="true" class="sc-nav-icon" size={16} strokeWidth={2} />
|
||||
{item.label}
|
||||
</a>
|
||||
{/each}
|
||||
@@ -71,7 +165,10 @@
|
||||
{/if}
|
||||
|
||||
{#if username && onProfile}
|
||||
<button class="sc-profile-button" type="button" onclick={onProfile}>{username}</button>
|
||||
<button class="sc-profile-button" type="button" onclick={onProfile}>
|
||||
<CircleUserRound aria-hidden="true" class="sc-profile-icon" size={16} strokeWidth={2} />
|
||||
<span>{username}</span>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if onLogout}
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
description = '',
|
||||
currentRole = 'user',
|
||||
currentUserId,
|
||||
loginRequired = true,
|
||||
onCreateUser,
|
||||
onDeleteUser,
|
||||
onLoginRequiredChange,
|
||||
onListUsers,
|
||||
onUpdateUser,
|
||||
open = $bindable(false),
|
||||
@@ -27,16 +29,54 @@
|
||||
description?: string;
|
||||
currentRole?: UserRole;
|
||||
currentUserId?: UserId;
|
||||
loginRequired?: boolean;
|
||||
onCreateUser?: UserCreateRequest;
|
||||
onDeleteUser?: UserDeleteRequest;
|
||||
onLoginRequiredChange?: (required: boolean) => void | Promise<void>;
|
||||
onListUsers?: UserListRequest;
|
||||
onUpdateUser?: UserUpdateRequest;
|
||||
open?: boolean;
|
||||
title?: string;
|
||||
} = $props();
|
||||
|
||||
let loginRequiredValue = $state<boolean>(true);
|
||||
let loginSettingError = $state('');
|
||||
|
||||
$effect(() => {
|
||||
loginRequiredValue = loginRequired;
|
||||
});
|
||||
|
||||
async function updateLoginRequired(required: boolean) {
|
||||
const previous = loginRequiredValue;
|
||||
loginRequiredValue = required;
|
||||
loginSettingError = '';
|
||||
try {
|
||||
await onLoginRequiredChange?.(required);
|
||||
} catch (error) {
|
||||
loginRequiredValue = previous;
|
||||
loginSettingError = error instanceof Error ? error.message : 'The setting could not be saved.';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog bind:open {description} {title}>
|
||||
{#if currentRole === 'admin' || currentRole === 'superadmin'}
|
||||
<div class="sc-field">
|
||||
<label class="flex items-center gap-3">
|
||||
<input
|
||||
class="size-4 accent-primary"
|
||||
type="checkbox"
|
||||
checked={loginRequiredValue}
|
||||
onchange={(event) => updateLoginRequired((event.currentTarget as HTMLInputElement).checked)}
|
||||
/>
|
||||
<span>
|
||||
<span class="block font-medium">Require login to access app</span>
|
||||
<span class="sc-muted">Admins and superadmins can change this setting.</span>
|
||||
</span>
|
||||
</label>
|
||||
{#if loginSettingError}<p class="sc-error" role="alert">{loginSettingError}</p>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if children}
|
||||
{@render children()}
|
||||
{:else}
|
||||
|
||||
Reference in new issue
Block a user