@shellui/core 0.4.1 → 0.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +15 -3
- package/schemas/curated-themes.json +4035 -0
- package/schemas/shellui.config.schema.json +961 -0
- package/schemas/shellui.theme.schema.json +187 -0
- package/src/app.tsx +4 -1
- package/src/components/ContentView.tsx +144 -9
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/dialog.tsx +23 -5
- package/src/components/ui/drawer.tsx +282 -42
- package/src/components/ui/dropdown-menu.tsx +7 -2
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +220 -0
- package/src/components/ui/sidebar.tsx +785 -221
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/admin/utils.ts +2 -45
- package/src/features/alertDialog/DialogContext.tsx +1 -1
- package/src/features/auth/components/LoginButton.tsx +25 -18
- package/src/features/auth/components/LoginPreferencesControls.tsx +124 -0
- package/src/features/auth/components/LoginView.tsx +131 -49
- package/src/features/config/types.ts +64 -82
- package/src/features/drawer/DrawerContext.tsx +55 -19
- package/src/features/layouts/AppLayout.tsx +3 -3
- package/src/features/layouts/OverlayShell.tsx +376 -77
- package/src/features/layouts/appbar/AppBarLayout.tsx +501 -88
- package/src/features/layouts/branding/AppBrandIcon.tsx +95 -0
- package/src/features/layouts/branding/resolveThemeAsset.spec.ts +33 -0
- package/src/features/layouts/branding/resolveThemeAsset.ts +33 -0
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +49 -0
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +19 -0
- package/src/features/layouts/chrome/DesktopBackButton.tsx +71 -0
- package/src/features/layouts/chrome/DesktopChrome.tsx +28 -0
- package/src/features/layouts/chrome/DesktopForwardButton.tsx +59 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +16 -0
- package/src/features/layouts/chrome/constants.ts +11 -0
- package/src/features/layouts/chrome/goDesktopBack.spec.ts +218 -0
- package/src/features/layouts/chrome/goDesktopBack.ts +106 -0
- package/src/features/layouts/chrome/index.ts +26 -0
- package/src/features/layouts/chrome/runtime.ts +45 -0
- package/src/features/layouts/findMatchingNavigationItem.spec.ts +55 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +17 -1
- package/src/features/layouts/isFrameForAppUrl.spec.ts +33 -0
- package/src/features/layouts/sidebar/NavigationContent.tsx +70 -34
- package/src/features/layouts/sidebar/SidebarIcons.tsx +41 -42
- package/src/features/layouts/sidebar/SidebarInner.tsx +142 -24
- package/src/features/layouts/sidebar/SidebarLayout.tsx +100 -37
- package/src/features/layouts/sidebar/sidebarUtils.ts +0 -7
- package/src/features/layouts/sidebar/types.ts +3 -3
- package/src/features/layouts/utils.ts +73 -5
- package/src/features/layouts/windows/WindowsLayout.tsx +173 -61
- package/src/features/modal/ModalContext.tsx +21 -8
- package/src/features/overlays/OverlayDrawerPendingBar.tsx +26 -0
- package/src/features/overlays/OverlayDynamicDemoView.tsx +108 -0
- package/src/features/overlays/OverlayPendingSpinner.tsx +18 -0
- package/src/features/overlays/ResponsiveModal.tsx +483 -0
- package/src/features/overlays/overlaySize.spec.ts +71 -0
- package/src/features/overlays/overlaySize.ts +228 -0
- package/src/features/overlays/useOverlayReportedSize.ts +130 -0
- package/src/features/settings/SettingsProvider.tsx +66 -46
- package/src/features/settings/SettingsView.tsx +42 -47
- package/src/features/settings/components/Appearance.tsx +305 -55
- package/src/features/settings/components/develop/DrawerTestButtons.tsx +18 -0
- package/src/features/settings/components/develop/ModalTestButtons.tsx +23 -0
- package/src/features/settings/utils/getResolvedAppearanceForSettings.ts +11 -5
- package/src/features/theme/applyTheme.ts +143 -0
- package/src/features/theme/color.ts +83 -0
- package/src/features/theme/curated/amber-minimal.json +86 -0
- package/src/features/theme/curated/amethyst-haze.json +86 -0
- package/src/features/theme/curated/astro-vista.json +86 -0
- package/src/features/theme/curated/bold-tech.json +86 -0
- package/src/features/theme/curated/bubblegum.json +86 -0
- package/src/features/theme/curated/caffeine.json +83 -0
- package/src/features/theme/curated/candyland.json +86 -0
- package/src/features/theme/curated/catppuccin.json +86 -0
- package/src/features/theme/curated/claude.json +86 -0
- package/src/features/theme/curated/claymorphism.json +86 -0
- package/src/features/theme/curated/clean-slate.json +86 -0
- package/src/features/theme/curated/cosmic-night.json +86 -0
- package/src/features/theme/curated/cyberpunk.json +86 -0
- package/src/features/theme/curated/darkmatter.json +86 -0
- package/src/features/theme/curated/doom-64.json +86 -0
- package/src/features/theme/curated/elegant-luxury.json +86 -0
- package/src/features/theme/curated/graphite.json +86 -0
- package/src/features/theme/curated/index.ts +260 -0
- package/src/features/theme/curated/kodama-grove.json +86 -0
- package/src/features/theme/curated/light-green.json +87 -0
- package/src/features/theme/curated/midnight-bloom.json +86 -0
- package/src/features/theme/curated/mocha-mousse.json +86 -0
- package/src/features/theme/curated/modern-minimal.json +86 -0
- package/src/features/theme/curated/mono.json +84 -0
- package/src/features/theme/curated/nature.json +86 -0
- package/src/features/theme/curated/neo-brutalism.json +86 -0
- package/src/features/theme/curated/northern-lights.json +86 -0
- package/src/features/theme/curated/notebook.json +87 -0
- package/src/features/theme/curated/ocean-breeze.json +86 -0
- package/src/features/theme/curated/pastel-dreams.json +86 -0
- package/src/features/theme/curated/perpetuity.json +86 -0
- package/src/features/theme/curated/quantum-rose.json +86 -0
- package/src/features/theme/curated/retro-arcade.json +86 -0
- package/src/features/theme/curated/sage-garden.json +86 -0
- package/src/features/theme/curated/shadcn.json +83 -0
- package/src/features/theme/curated/shellui.json +82 -0
- package/src/features/theme/curated/soft-pop.json +86 -0
- package/src/features/theme/curated/solar-dusk.json +86 -0
- package/src/features/theme/curated/starry-night.json +86 -0
- package/src/features/theme/curated/sunset-horizon.json +86 -0
- package/src/features/theme/curated/supabase.json +85 -0
- package/src/features/theme/curated/t3-chat.json +83 -0
- package/src/features/theme/curated/tangerine.json +86 -0
- package/src/features/theme/curated/twitter.json +86 -0
- package/src/features/theme/curated/vercel.json +86 -0
- package/src/features/theme/curated/vintage-paper.json +86 -0
- package/src/features/theme/curated/violet-bloom.json +87 -0
- package/src/features/theme/curated/zen-inspired.json +87 -0
- package/src/features/theme/index.ts +76 -0
- package/src/features/theme/normalize.ts +159 -0
- package/src/features/theme/registry.ts +50 -0
- package/src/features/theme/resolveConfig.ts +182 -0
- package/src/features/theme/safeApplyTheme.ts +147 -0
- package/src/features/theme/themes.spec.ts +276 -0
- package/src/features/theme/themes.ts +82 -558
- package/src/features/theme/tokenKeys.ts +60 -0
- package/src/features/theme/types.ts +170 -0
- package/src/features/theme/useTheme.tsx +48 -50
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/i18n/translations/en/common.json +41 -0
- package/src/i18n/translations/en/settings.json +10 -2
- package/src/i18n/translations/fr/common.json +41 -0
- package/src/i18n/translations/fr/settings.json +10 -2
- package/src/index.css +372 -128
- package/src/index.ts +71 -0
- package/src/lib/z-index.ts +4 -1
- package/src/routes/components/IndexRoute.tsx +12 -2
- package/src/routes/components/NavigationItemRoute.tsx +1 -10
- package/src/routes/hooks/useNavigationItems.ts +29 -44
- package/src/routes/routes.tsx +58 -27
- package/tailwind.config.js +27 -27
- package/src/features/layouts/sidebar/BottomNavItem.tsx +0 -88
- package/src/features/layouts/sidebar/MobileBottomNav.tsx +0 -168
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
import { cn } from '../../lib/utils';
|
|
3
|
+
|
|
4
|
+
function Skeleton({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
|
|
5
|
+
return (
|
|
6
|
+
<div
|
|
7
|
+
className={cn('animate-pulse rounded-md bg-muted', className)}
|
|
8
|
+
{...props}
|
|
9
|
+
/>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { Skeleton };
|
package/src/constants/urls.ts
CHANGED
|
@@ -1,53 +1,10 @@
|
|
|
1
1
|
import type { ShellUIConfig } from '../config/types';
|
|
2
|
-
import { getBaseUrlWithoutHash,
|
|
2
|
+
import { getBaseUrlWithoutHash, isFrameForAppUrl } from '../layouts/utils';
|
|
3
3
|
import { getAdminContentUrl, getAdminPath } from './config';
|
|
4
4
|
|
|
5
|
-
const toAbsoluteUrl = (url: string): URL | null => {
|
|
6
|
-
try {
|
|
7
|
-
return new URL(
|
|
8
|
-
url,
|
|
9
|
-
typeof window !== 'undefined' ? window.location.origin : 'http://localhost',
|
|
10
|
-
);
|
|
11
|
-
} catch {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const normalizePath = (value: string): string => {
|
|
17
|
-
const trimmed = value.trim();
|
|
18
|
-
if (!trimmed) return '/';
|
|
19
|
-
const withoutTrailing = trimmed.replace(/\/+$/, '');
|
|
20
|
-
return withoutTrailing || '/';
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const normalizeHashPath = (value: string): string => {
|
|
24
|
-
return value.replace(/^#\/?/, '').replace(/\/+$/, '');
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const isFrameForIframeUrl = (frameSrc: string, itemUrl: string): boolean => {
|
|
28
|
-
const frame = toAbsoluteUrl(frameSrc);
|
|
29
|
-
const item = toAbsoluteUrl(itemUrl);
|
|
30
|
-
if (!frame || !item) return false;
|
|
31
|
-
if (frame.origin !== item.origin) return false;
|
|
32
|
-
|
|
33
|
-
const itemPathname = normalizePath(item.pathname);
|
|
34
|
-
const framePathname = normalizePath(frame.pathname);
|
|
35
|
-
if (framePathname !== itemPathname && !framePathname.startsWith(`${itemPathname}/`)) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const itemHashPath = normalizeHashPath(item.hash || getHashPathFromUrl(itemUrl));
|
|
40
|
-
if (!itemHashPath) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const frameHashPath = normalizeHashPath(frame.hash);
|
|
45
|
-
return frameHashPath === itemHashPath || frameHashPath.startsWith(`${itemHashPath}/`);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
5
|
/** Whether an iframe src belongs to the embedded admin microfrontend. */
|
|
49
6
|
export function isAdminFrame(frameSrc: string, config?: ShellUIConfig): boolean {
|
|
50
|
-
return
|
|
7
|
+
return isFrameForAppUrl(frameSrc, getAdminContentUrl(config));
|
|
51
8
|
}
|
|
52
9
|
|
|
53
10
|
/** Admin microfrontend uses hash routes (e.g. createHashRouter); sync shell `/admin/...` with iframe `#/...`. */
|
|
@@ -396,7 +396,7 @@ export const DialogProvider = ({ children }: DialogProviderProps) => {
|
|
|
396
396
|
bottom: 16,
|
|
397
397
|
left: 16,
|
|
398
398
|
zIndex: Z_INDEX.COOKIE_CONSENT_CONTENT,
|
|
399
|
-
backgroundColor: '
|
|
399
|
+
backgroundColor: 'var(--background)',
|
|
400
400
|
top: 'auto',
|
|
401
401
|
right: 'auto',
|
|
402
402
|
transform: 'none',
|
|
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
4
4
|
import { Link, useLocation, useNavigate } from 'react-router';
|
|
5
5
|
import urls from '../../../constants/urls';
|
|
6
6
|
import { cn } from '../../../lib/utils';
|
|
7
|
+
import { useIsMobile } from '../../../hooks/use-mobile';
|
|
7
8
|
import { useAuth } from '../hooks/useAuth';
|
|
8
9
|
import { UserIcon } from '../../settings/components/UserIcon';
|
|
9
10
|
import { useConfig } from '../../config/useConfig';
|
|
@@ -77,24 +78,24 @@ const variantConfig: Record<
|
|
|
77
78
|
sidebar: {
|
|
78
79
|
button: {
|
|
79
80
|
authenticated:
|
|
80
|
-
'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
81
|
+
'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
|
|
81
82
|
loggedOut:
|
|
82
|
-
'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
83
|
+
'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
|
|
83
84
|
},
|
|
84
|
-
avatar: '
|
|
85
|
-
menu: { width: 'w-
|
|
85
|
+
avatar: 'size-4',
|
|
86
|
+
menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'right', align: 'start' },
|
|
86
87
|
showDisplayName: true,
|
|
87
88
|
showCaret: true,
|
|
88
89
|
},
|
|
89
90
|
appbar: {
|
|
90
91
|
button: {
|
|
91
92
|
authenticated:
|
|
92
|
-
'
|
|
93
|
+
'size-7 rounded-md p-0 justify-center text-sm text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
93
94
|
loggedOut:
|
|
94
|
-
'h-
|
|
95
|
+
'h-7 max-w-[220px] rounded-md px-2 text-xs text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
95
96
|
},
|
|
96
|
-
avatar: '
|
|
97
|
-
menu: { width: 'w-
|
|
97
|
+
avatar: 'size-4',
|
|
98
|
+
menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'bottom', align: 'end' },
|
|
98
99
|
showDisplayName: false,
|
|
99
100
|
showCaret: false,
|
|
100
101
|
},
|
|
@@ -106,7 +107,7 @@ const variantConfig: Record<
|
|
|
106
107
|
'h-8 max-w-[180px] rounded-md px-2 text-xs text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
107
108
|
},
|
|
108
109
|
avatar: 'h-4 w-4',
|
|
109
|
-
menu: { width: 'w-
|
|
110
|
+
menu: { width: 'w-[min(15rem,calc(100vw-1.5rem))]', side: 'top', align: 'end' },
|
|
110
111
|
showDisplayName: false,
|
|
111
112
|
showCaret: false,
|
|
112
113
|
},
|
|
@@ -122,6 +123,7 @@ export const LoginButton = ({
|
|
|
122
123
|
logoutOnly?: boolean;
|
|
123
124
|
}) => {
|
|
124
125
|
const currentVariantConfig = variantConfig[variant];
|
|
126
|
+
const isMobile = useIsMobile();
|
|
125
127
|
const { t } = useTranslation('common');
|
|
126
128
|
const { config } = useConfig();
|
|
127
129
|
const { isAuthenticated, user, logout } = useAuth();
|
|
@@ -139,6 +141,9 @@ export const LoginButton = ({
|
|
|
139
141
|
|
|
140
142
|
const fallbackInitial = displayName.charAt(0).toUpperCase();
|
|
141
143
|
const { showDisplayName, showCaret } = currentVariantConfig;
|
|
144
|
+
const menuSide = variant === 'sidebar' && isMobile ? 'top' : currentVariantConfig.menu.side;
|
|
145
|
+
const menuAlign = variant === 'sidebar' && isMobile ? 'start' : currentVariantConfig.menu.align;
|
|
146
|
+
const menuCollisionPadding = isMobile ? 12 : 8;
|
|
142
147
|
|
|
143
148
|
const baseButtonClasses = cn(
|
|
144
149
|
'inline-flex items-center gap-2 min-w-0 shrink-0 transition-colors cursor-pointer',
|
|
@@ -240,7 +245,7 @@ export const LoginButton = ({
|
|
|
240
245
|
title={t('authMenu.login')}
|
|
241
246
|
>
|
|
242
247
|
<UserIcon />
|
|
243
|
-
<span className="truncate">{t('authMenu.login')}</span>
|
|
248
|
+
<span className="truncate group-data-[collapsible=icon]:hidden">{t('authMenu.login')}</span>
|
|
244
249
|
</Link>
|
|
245
250
|
);
|
|
246
251
|
}
|
|
@@ -268,7 +273,7 @@ export const LoginButton = ({
|
|
|
268
273
|
src={user.profilePicture}
|
|
269
274
|
alt={displayName}
|
|
270
275
|
className={cn(
|
|
271
|
-
'shrink-0 rounded-full border border-sidebar-border object-cover',
|
|
276
|
+
'shrink-0 overflow-hidden rounded-full border border-sidebar-border object-cover aspect-square',
|
|
272
277
|
currentVariantConfig.avatar,
|
|
273
278
|
)}
|
|
274
279
|
referrerPolicy="no-referrer"
|
|
@@ -276,7 +281,7 @@ export const LoginButton = ({
|
|
|
276
281
|
) : (
|
|
277
282
|
<span
|
|
278
283
|
className={cn(
|
|
279
|
-
'shrink-0 rounded-full border border-sidebar-border bg-muted
|
|
284
|
+
'flex shrink-0 aspect-square items-center justify-center overflow-hidden rounded-full border border-sidebar-border bg-muted text-[10px] font-semibold leading-none',
|
|
280
285
|
currentVariantConfig.avatar,
|
|
281
286
|
)}
|
|
282
287
|
aria-hidden
|
|
@@ -284,12 +289,14 @@ export const LoginButton = ({
|
|
|
284
289
|
{fallbackInitial}
|
|
285
290
|
</span>
|
|
286
291
|
)}
|
|
287
|
-
{showDisplayName &&
|
|
292
|
+
{showDisplayName && (
|
|
293
|
+
<span className="truncate group-data-[collapsible=icon]:hidden">{displayName}</span>
|
|
294
|
+
)}
|
|
288
295
|
{showCaret && (
|
|
289
296
|
<span
|
|
290
297
|
aria-hidden
|
|
291
298
|
className={cn(
|
|
292
|
-
'ml-auto shrink-0 text-[10px]',
|
|
299
|
+
'ml-auto shrink-0 text-[10px] group-data-[collapsible=icon]:hidden',
|
|
293
300
|
isMenuOpen ? 'text-foreground' : 'text-muted-foreground',
|
|
294
301
|
)}
|
|
295
302
|
>
|
|
@@ -305,10 +312,10 @@ export const LoginButton = ({
|
|
|
305
312
|
ref={contentRef}
|
|
306
313
|
forceMount
|
|
307
314
|
data-auth-menu-content
|
|
308
|
-
side={
|
|
309
|
-
align={
|
|
310
|
-
collisionPadding={
|
|
311
|
-
className={cn('p-1.5', currentVariantConfig.menu.width)}
|
|
315
|
+
side={menuSide}
|
|
316
|
+
align={menuAlign}
|
|
317
|
+
collisionPadding={menuCollisionPadding}
|
|
318
|
+
className={cn('p-1.5 max-w-[calc(100vw-1.5rem)]', currentVariantConfig.menu.width)}
|
|
312
319
|
onPointerDownOutside={() => setIsMenuOpen(false)}
|
|
313
320
|
onFocusOutside={() => setIsMenuOpen(false)}
|
|
314
321
|
onEscapeKeyDown={() => setIsMenuOpen(false)}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { getSupportedLanguages } from '../../../i18n/config';
|
|
4
|
+
import { cn } from '../../../lib/utils';
|
|
5
|
+
import { useConfig } from '../../config/useConfig';
|
|
6
|
+
import { useSettings } from '../../settings/hooks/useSettings';
|
|
7
|
+
|
|
8
|
+
const SunIcon = ({ className }: { className?: string }) => (
|
|
9
|
+
<svg
|
|
10
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
11
|
+
viewBox="0 0 24 24"
|
|
12
|
+
fill="none"
|
|
13
|
+
stroke="currentColor"
|
|
14
|
+
strokeWidth="2"
|
|
15
|
+
strokeLinecap="round"
|
|
16
|
+
strokeLinejoin="round"
|
|
17
|
+
className={className}
|
|
18
|
+
aria-hidden
|
|
19
|
+
>
|
|
20
|
+
<circle
|
|
21
|
+
cx="12"
|
|
22
|
+
cy="12"
|
|
23
|
+
r="4"
|
|
24
|
+
/>
|
|
25
|
+
<path d="M12 2v2" />
|
|
26
|
+
<path d="M12 20v2" />
|
|
27
|
+
<path d="m4.93 4.93 1.41 1.41" />
|
|
28
|
+
<path d="m17.66 17.66 1.41 1.41" />
|
|
29
|
+
<path d="M2 12h2" />
|
|
30
|
+
<path d="M20 12h2" />
|
|
31
|
+
<path d="m6.34 17.66-1.41 1.41" />
|
|
32
|
+
<path d="m19.07 4.93-1.41 1.41" />
|
|
33
|
+
</svg>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const MoonIcon = ({ className }: { className?: string }) => (
|
|
37
|
+
<svg
|
|
38
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
39
|
+
viewBox="0 0 24 24"
|
|
40
|
+
fill="none"
|
|
41
|
+
stroke="currentColor"
|
|
42
|
+
strokeWidth="2"
|
|
43
|
+
strokeLinecap="round"
|
|
44
|
+
strokeLinejoin="round"
|
|
45
|
+
className={className}
|
|
46
|
+
aria-hidden
|
|
47
|
+
>
|
|
48
|
+
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
|
49
|
+
</svg>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const controlButtonClassName = cn(
|
|
53
|
+
'inline-flex h-8 items-center justify-center rounded-md px-2',
|
|
54
|
+
'text-xs font-medium tracking-wide text-muted-foreground/70',
|
|
55
|
+
'transition-colors hover:bg-muted/60 hover:text-muted-foreground',
|
|
56
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Discreet language + color-scheme controls for the full-screen login page.
|
|
61
|
+
* Hidden when login is embedded in a modal iframe.
|
|
62
|
+
*/
|
|
63
|
+
export const LoginPreferencesControls = () => {
|
|
64
|
+
const { t } = useTranslation('settings');
|
|
65
|
+
const { config } = useConfig();
|
|
66
|
+
const { settings, updateSetting } = useSettings();
|
|
67
|
+
const languages = useMemo(() => getSupportedLanguages(config?.language), [config?.language]);
|
|
68
|
+
const currentLanguage = settings.language?.code || languages[0]?.code || 'en';
|
|
69
|
+
const [isDark, setIsDark] = useState(() =>
|
|
70
|
+
typeof document !== 'undefined' ? document.documentElement.classList.contains('dark') : false,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const root = document.documentElement;
|
|
75
|
+
const sync = () => setIsDark(root.classList.contains('dark'));
|
|
76
|
+
sync();
|
|
77
|
+
const observer = new MutationObserver(sync);
|
|
78
|
+
observer.observe(root, { attributes: true, attributeFilter: ['class'] });
|
|
79
|
+
return () => observer.disconnect();
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
const showLanguage = languages.length > 1;
|
|
83
|
+
|
|
84
|
+
const cycleLanguage = () => {
|
|
85
|
+
if (languages.length < 2) return;
|
|
86
|
+
const index = languages.findIndex((lang) => lang.code === currentLanguage);
|
|
87
|
+
const next = languages[(index + 1) % languages.length];
|
|
88
|
+
if (next) {
|
|
89
|
+
updateSetting('language', { code: next.code });
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const toggleColorScheme = () => {
|
|
94
|
+
updateSetting('appearance', { colorScheme: isDark ? 'light' : 'dark' });
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const currentLang = languages.find((lang) => lang.code === currentLanguage) ?? languages[0];
|
|
98
|
+
const colorSchemeLabel = isDark ? t('appearance.themes.light') : t('appearance.themes.dark');
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div className="flex items-center gap-0.5">
|
|
102
|
+
{showLanguage && currentLang ? (
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
className={controlButtonClassName}
|
|
106
|
+
onClick={cycleLanguage}
|
|
107
|
+
aria-label={currentLang.nativeName}
|
|
108
|
+
title={currentLang.nativeName}
|
|
109
|
+
>
|
|
110
|
+
{currentLang.code.toUpperCase()}
|
|
111
|
+
</button>
|
|
112
|
+
) : null}
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
className={cn(controlButtonClassName, 'w-8 px-0')}
|
|
116
|
+
onClick={toggleColorScheme}
|
|
117
|
+
aria-label={colorSchemeLabel}
|
|
118
|
+
title={colorSchemeLabel}
|
|
119
|
+
>
|
|
120
|
+
{isDark ? <SunIcon className="size-3.5" /> : <MoonIcon className="size-3.5" />}
|
|
121
|
+
</button>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
};
|