@shellui/core 0.7.0-alpha.8 → 0.7.0-beta.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 +1 -1
- package/package.json +23 -6
- package/src/components/ui/drawer.tsx +47 -30
- package/src/components/ui/sheet.tsx +18 -12
- package/src/components/ui/shell-divider.spec.tsx +63 -0
- package/src/components/ui/shell-divider.tsx +20 -0
- package/src/components/ui/sidebar.tsx +26 -12
- package/src/components/ui/tooltip.tsx +4 -2
- package/src/features/admin/AdminView.tsx +9 -6
- package/src/features/auth/AuthProvider.tsx +10 -1
- package/src/features/auth/components/LoginButton.spec.tsx +203 -0
- package/src/features/auth/components/LoginButton.tsx +77 -28
- package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
- package/src/features/auth/utils/index.ts +1 -0
- package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
- package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
- package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
- package/src/features/chromeActions/computeActionInsets.ts +7 -4
- package/src/features/layouts/OverlayShell.tsx +58 -40
- package/src/features/layouts/appbar/AppBarItemIcon.spec.tsx +45 -0
- package/src/features/layouts/appbar/AppBarItemIcon.tsx +19 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +115 -110
- package/src/features/layouts/appbar/appBarOverflow.spec.ts +27 -0
- package/src/features/layouts/appbar/appBarOverflow.ts +42 -0
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +13 -24
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
- package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
- package/src/features/layouts/chrome/MacStrip.tsx +33 -0
- package/src/features/layouts/chrome/constants.ts +36 -8
- package/src/features/layouts/chrome/index.ts +8 -0
- package/src/features/layouts/chrome/stripDragMap.ts +35 -0
- package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
- package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
- package/src/features/layouts/chrome/viewport.ts +11 -4
- package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
- package/src/features/layouts/floating/FloatingBottomDock.tsx +263 -43
- package/src/features/layouts/floating/FloatingLayout.tsx +14 -8
- package/src/features/layouts/floating/FloatingSidebar.tsx +178 -81
- package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
- package/src/features/layouts/floating/moreSections.spec.ts +28 -0
- package/src/features/layouts/floating/moreSections.ts +31 -0
- package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
- package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
- package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +47 -10
- package/src/features/layouts/sidebar/NavigationContent.tsx +17 -9
- package/src/features/layouts/sidebar/SidebarIcons.tsx +70 -9
- package/src/features/layouts/sidebar/SidebarInner.spec.tsx +149 -0
- package/src/features/layouts/sidebar/SidebarInner.tsx +103 -43
- package/src/features/layouts/sidebar/SidebarLayout.tsx +24 -17
- package/src/features/layouts/utils.ts +4 -3
- package/src/features/layouts/windows/DesktopDots.tsx +76 -0
- package/src/features/layouts/windows/WindowsLayout.tsx +265 -160
- package/src/features/layouts/windows/deskDots.spec.ts +54 -0
- package/src/features/layouts/windows/deskDots.ts +314 -0
- package/src/features/overlays/ResponsiveModal.tsx +5 -3
- package/src/features/overlays/overlaySize.spec.ts +56 -16
- package/src/features/overlays/overlaySize.ts +114 -31
- package/src/features/overlays/phoneDrawerAnchoring.spec.ts +187 -0
- package/src/features/overlays/useOverlayReportedSize.ts +8 -3
- package/src/features/theme/applyTheme.ts +8 -0
- package/src/features/theme/navContrast.spec.ts +49 -0
- package/src/features/theme/navContrast.ts +108 -0
- package/src/i18n/translations/en/common.json +26 -0
- package/src/i18n/translations/fr/common.json +26 -0
- package/src/index.css +1156 -77
- package/src/service-worker/devCaches.spec.ts +32 -0
- package/src/service-worker/devCaches.ts +27 -0
- package/src/service-worker/sw-dev.ts +23 -23
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act } from 'react';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
+
import { MemoryRouter } from 'react-router';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import en from '../../../i18n/translations/en/common.json';
|
|
7
|
+
import fr from '../../../i18n/translations/fr/common.json';
|
|
8
|
+
import { SidebarProvider } from '../../../components/ui/sidebar';
|
|
9
|
+
import { getAccountInitials, LoginButton } from './LoginButton';
|
|
10
|
+
|
|
11
|
+
type User = { name?: string; email?: string; profilePicture?: string };
|
|
12
|
+
const auth: { isAuthenticated: boolean; isLoading: boolean; user: User | null } = {
|
|
13
|
+
isAuthenticated: true,
|
|
14
|
+
isLoading: false,
|
|
15
|
+
user: null,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
vi.mock('../hooks/useAuth', () => ({
|
|
19
|
+
useAuth: () => ({ ...auth, logout: vi.fn() }),
|
|
20
|
+
}));
|
|
21
|
+
vi.mock('../../config/useConfig', () => ({
|
|
22
|
+
useConfig: () => ({ config: { backend: { type: 'shellui' } } }),
|
|
23
|
+
}));
|
|
24
|
+
vi.mock('../../../hooks/use-mobile', () => ({ useIsMobile: () => false }));
|
|
25
|
+
vi.mock('react-i18next', () => ({
|
|
26
|
+
useTranslation: () => ({
|
|
27
|
+
t: (key: string, opts?: Record<string, string>) => {
|
|
28
|
+
const [group, leaf] = key.split('.') as [keyof typeof en, string];
|
|
29
|
+
const raw = (en[group] as Record<string, string>)[leaf] ?? opts?.defaultValue ?? key;
|
|
30
|
+
return raw.replace(/\{\{(\w+)\}\}/g, (_, k: string) => opts?.[k] ?? '');
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
36
|
+
|
|
37
|
+
let container: HTMLDivElement;
|
|
38
|
+
let root: Root;
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
container = document.createElement('div');
|
|
42
|
+
document.body.appendChild(container);
|
|
43
|
+
root = createRoot(container);
|
|
44
|
+
auth.isAuthenticated = true;
|
|
45
|
+
auth.isLoading = false;
|
|
46
|
+
auth.user = null;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
act(() => root.unmount());
|
|
51
|
+
container.remove();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
function render(open = true, dividerAbove = false) {
|
|
55
|
+
act(() => {
|
|
56
|
+
root.render(
|
|
57
|
+
<MemoryRouter>
|
|
58
|
+
<SidebarProvider defaultOpen={open}>
|
|
59
|
+
<LoginButton
|
|
60
|
+
variant="sidebar"
|
|
61
|
+
dividerAbove={dividerAbove}
|
|
62
|
+
/>
|
|
63
|
+
</SidebarProvider>
|
|
64
|
+
</MemoryRouter>,
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
return container.querySelector<HTMLButtonElement>('[data-shellui-account-trigger]');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe('getAccountInitials', () => {
|
|
71
|
+
it('uses the first and last word of the name', () => {
|
|
72
|
+
expect(getAccountInitials('Alex Martin', 'alex@acme.dev')).toBe('AM');
|
|
73
|
+
expect(getAccountInitials(' jean claude van damme ', null)).toBe('JD');
|
|
74
|
+
expect(getAccountInitials('Émile', null)).toBe('É');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('falls back to the email', () => {
|
|
78
|
+
expect(getAccountInitials('', 'zoe@acme.dev')).toBe('Z');
|
|
79
|
+
expect(getAccountInitials(null, null)).toBe('');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('sidebar account block', () => {
|
|
84
|
+
it('shows initials, name, email and the chevrons-up-down icon', () => {
|
|
85
|
+
auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
|
|
86
|
+
const btn = render();
|
|
87
|
+
expect(btn).not.toBeNull();
|
|
88
|
+
expect(btn?.querySelector('[data-shellui-account-initials]')?.textContent).toBe('AM');
|
|
89
|
+
expect(btn?.textContent).toContain('Alex Martin');
|
|
90
|
+
expect(btn?.querySelector('[data-shellui-account-email]')?.textContent).toBe('alex@acme.dev');
|
|
91
|
+
expect(btn?.querySelectorAll('svg path')).toHaveLength(2);
|
|
92
|
+
expect(btn?.getAttribute('aria-label')).toBe(
|
|
93
|
+
'Open account menu for Alex Martin, alex@acme.dev',
|
|
94
|
+
);
|
|
95
|
+
expect(btn?.hasAttribute('data-shellui-no-drag')).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('truncates long names and emails', () => {
|
|
99
|
+
auth.user = {
|
|
100
|
+
name: 'Maximilian Alexander von Hohenberg-Wittelsbach',
|
|
101
|
+
email: 'maximilian.alexander.von.hohenberg@very-long-company-domain.example',
|
|
102
|
+
};
|
|
103
|
+
const btn = render();
|
|
104
|
+
const email = btn?.querySelector('[data-shellui-account-email]');
|
|
105
|
+
expect(email?.className).toContain('truncate');
|
|
106
|
+
expect(email?.previousElementSibling?.className).toContain('truncate');
|
|
107
|
+
expect(email?.parentElement?.className).toContain('min-w-0');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('shows the email as the name, once, when there is no name', () => {
|
|
111
|
+
auth.user = { email: 'zoe@acme.dev' };
|
|
112
|
+
const btn = render();
|
|
113
|
+
expect(btn?.querySelector('[data-shellui-account-email]')).toBeNull();
|
|
114
|
+
expect(btn?.querySelector('[data-shellui-account-initials]')?.textContent).toBe('Z');
|
|
115
|
+
expect(btn?.getAttribute('aria-label')).toBe('Open account menu for zoe@acme.dev');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('shows the profile picture instead of initials', () => {
|
|
119
|
+
auth.user = {
|
|
120
|
+
name: 'Alex Martin',
|
|
121
|
+
email: 'alex@acme.dev',
|
|
122
|
+
profilePicture: 'https://x.test/a.png',
|
|
123
|
+
};
|
|
124
|
+
const btn = render();
|
|
125
|
+
expect(btn?.querySelector('img')?.getAttribute('src')).toBe('https://x.test/a.png');
|
|
126
|
+
expect(btn?.querySelector('[data-shellui-account-initials]')).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('collapsed icon mode hides the text and keeps the avatar', () => {
|
|
130
|
+
auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
|
|
131
|
+
const btn = render(false);
|
|
132
|
+
expect(btn?.querySelector('[data-shellui-account-initials]')).not.toBeNull();
|
|
133
|
+
expect(btn?.querySelector('[data-shellui-account-email]')?.parentElement?.className).toContain(
|
|
134
|
+
'group-data-[collapsible=icon]:hidden',
|
|
135
|
+
);
|
|
136
|
+
expect(btn?.querySelector('svg')?.getAttribute('class')).toContain(
|
|
137
|
+
'group-data-[collapsible=icon]:hidden',
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('renders a two line skeleton while loading', () => {
|
|
142
|
+
auth.isLoading = true;
|
|
143
|
+
render();
|
|
144
|
+
const status = container.querySelector('[data-shellui-auth-loading]');
|
|
145
|
+
expect(status?.getAttribute('aria-label')).toBe(en.authMenu.loadingAccount);
|
|
146
|
+
expect(status?.querySelectorAll('[data-slot="skeleton"], .animate-pulse').length).toBe(3);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('account aria strings', () => {
|
|
151
|
+
it('exist in en and fr', () => {
|
|
152
|
+
for (const key of ['openAccountMenuAriaLabel', 'openAccountMenuWithEmailAriaLabel'] as const) {
|
|
153
|
+
expect(en.authMenu[key]).toContain('{{name}}');
|
|
154
|
+
expect(fr.authMenu[key]).toContain('{{name}}');
|
|
155
|
+
}
|
|
156
|
+
expect(fr.authMenu.openAccountMenuWithEmailAriaLabel).toContain('{{email}}');
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('account divider', () => {
|
|
161
|
+
const divider = () => container.querySelector<HTMLElement>('[data-shellui-account-divider]');
|
|
162
|
+
|
|
163
|
+
it('draws the shared divider above the signed-in account block', () => {
|
|
164
|
+
auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
|
|
165
|
+
const btn = render(true, true);
|
|
166
|
+
const line = divider();
|
|
167
|
+
expect(line).not.toBeNull();
|
|
168
|
+
expect(line?.getAttribute('role')).toBe('separator');
|
|
169
|
+
expect(line?.className).toContain('shellui-divider');
|
|
170
|
+
// Full width: cancels the 8px row inset of the footer group.
|
|
171
|
+
expect(line?.className).toContain('-mx-2');
|
|
172
|
+
// 4px of breathing room between the divider and the account row.
|
|
173
|
+
const pad = line?.nextElementSibling;
|
|
174
|
+
expect(pad?.className).toBe('pt-1');
|
|
175
|
+
expect(pad?.firstElementChild).toBe(btn);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('stays in collapsed icon mode', () => {
|
|
179
|
+
auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
|
|
180
|
+
render(false, true);
|
|
181
|
+
expect(divider()).not.toBeNull();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('is off unless asked for', () => {
|
|
185
|
+
auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
|
|
186
|
+
const btn = render(true, false);
|
|
187
|
+
expect(divider()).toBeNull();
|
|
188
|
+
expect(btn?.parentElement?.className).not.toBe('pt-1');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('never shows for the signed-out login button', () => {
|
|
192
|
+
auth.isAuthenticated = false;
|
|
193
|
+
render(true, true);
|
|
194
|
+
expect(container.querySelector('a')?.textContent).toContain(en.authMenu.login);
|
|
195
|
+
expect(divider()).toBeNull();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('never shows while loading', () => {
|
|
199
|
+
auth.isLoading = true;
|
|
200
|
+
render(true, true);
|
|
201
|
+
expect(divider()).toBeNull();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -5,13 +5,14 @@ import { Link, useLocation, useNavigate } from 'react-router';
|
|
|
5
5
|
import urls from '../../../constants/urls';
|
|
6
6
|
import { cn } from '../../../lib/utils';
|
|
7
7
|
import { useIsMobile } from '../../../hooks/use-mobile';
|
|
8
|
+
import { ShellDivider } from '../../../components/ui/shell-divider';
|
|
8
9
|
import { useAuth } from '../hooks/useAuth';
|
|
9
10
|
import { UserIcon } from '../../settings/components/UserIcon';
|
|
10
11
|
import { useConfig } from '../../config/useConfig';
|
|
11
12
|
import { getAdminPath } from '../../admin/config';
|
|
12
13
|
import { isAdminPath } from '../../admin/utils';
|
|
13
14
|
import { flattenNavigationItems, getNavPathPrefix } from '../../layouts/utils';
|
|
14
|
-
import {
|
|
15
|
+
import { ChevronsUpDownIcon, LogoutIcon } from './LoginButtonIcons';
|
|
15
16
|
import {
|
|
16
17
|
DropdownMenu,
|
|
17
18
|
DropdownMenuContent,
|
|
@@ -24,6 +25,17 @@ import { Skeleton } from '../../../components/ui/skeleton';
|
|
|
24
25
|
|
|
25
26
|
type LoginButtonVariant = 'sidebar' | 'appbar' | 'windows';
|
|
26
27
|
|
|
28
|
+
/** Up to two initials from the name, else the first letter of the email. */
|
|
29
|
+
export function getAccountInitials(name?: string | null, email?: string | null): string {
|
|
30
|
+
const words = (name ?? '').trim().split(/\s+/).filter(Boolean);
|
|
31
|
+
if (words.length > 0) {
|
|
32
|
+
const first = Array.from(words[0])[0] ?? '';
|
|
33
|
+
const last = words.length > 1 ? (Array.from(words[words.length - 1])[0] ?? '') : '';
|
|
34
|
+
return (first + last).toUpperCase();
|
|
35
|
+
}
|
|
36
|
+
return (Array.from((email ?? '').trim())[0] ?? '').toUpperCase();
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
const AdministrationIcon = ({ className }: { className?: string }) => (
|
|
28
40
|
<svg
|
|
29
41
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -79,13 +91,13 @@ const variantConfig: Record<
|
|
|
79
91
|
sidebar: {
|
|
80
92
|
button: {
|
|
81
93
|
authenticated:
|
|
82
|
-
'w-full h-
|
|
94
|
+
'shellui-account-row w-full h-10 gap-2.5 rounded-[var(--shellui-r-row)] px-2 text-[13.5px] text-left text-sidebar-foreground hover:bg-[var(--shellui-nav-hover)] hover:text-sidebar-foreground data-[state=open]:bg-[var(--shellui-nav-hover)] group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-0!',
|
|
83
95
|
loggedOut:
|
|
84
96
|
'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!',
|
|
85
97
|
loading:
|
|
86
|
-
'w-full h-
|
|
98
|
+
'shellui-account-row w-full h-10 gap-2.5 px-2 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-0!',
|
|
87
99
|
},
|
|
88
|
-
avatar: 'size-
|
|
100
|
+
avatar: 'size-6 text-[10.5px]',
|
|
89
101
|
menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'right', align: 'start' },
|
|
90
102
|
showDisplayName: true,
|
|
91
103
|
showCaret: true,
|
|
@@ -98,7 +110,7 @@ const variantConfig: Record<
|
|
|
98
110
|
'h-7 max-w-[220px] rounded-md px-2.5 text-xs text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
99
111
|
loading: 'size-7 justify-center',
|
|
100
112
|
},
|
|
101
|
-
avatar: 'size-4',
|
|
113
|
+
avatar: 'size-4 text-[10px]',
|
|
102
114
|
menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'bottom', align: 'end' },
|
|
103
115
|
showDisplayName: false,
|
|
104
116
|
showCaret: false,
|
|
@@ -111,7 +123,7 @@ const variantConfig: Record<
|
|
|
111
123
|
'h-8 max-w-[180px] rounded-md px-2 text-xs text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
112
124
|
loading: 'h-8 w-8 justify-center',
|
|
113
125
|
},
|
|
114
|
-
avatar: 'h-4 w-4',
|
|
126
|
+
avatar: 'h-4 w-4 text-[10px]',
|
|
115
127
|
menu: { width: 'w-[min(15rem,calc(100vw-1.5rem))]', side: 'top', align: 'end' },
|
|
116
128
|
showDisplayName: false,
|
|
117
129
|
showCaret: false,
|
|
@@ -122,10 +134,19 @@ export const LoginButton = ({
|
|
|
122
134
|
variant,
|
|
123
135
|
hideWhenLoggedOut = false,
|
|
124
136
|
logoutOnly = false,
|
|
137
|
+
dividerAbove = false,
|
|
125
138
|
}: {
|
|
126
139
|
variant: LoginButtonVariant;
|
|
127
140
|
hideWhenLoggedOut?: boolean;
|
|
128
141
|
logoutOnly?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Full-width hairline above the signed-in account block, separating it from
|
|
144
|
+
* the footer items above, plus 4px of top padding above the account row.
|
|
145
|
+
* Signed out and loading states never render it. Pass false when the account
|
|
146
|
+
* block is the first footer item (the footer divider already separates it).
|
|
147
|
+
* The parent must inset the block by 8px (sidebar group, floating footer).
|
|
148
|
+
*/
|
|
149
|
+
dividerAbove?: boolean;
|
|
129
150
|
}) => {
|
|
130
151
|
const currentVariantConfig = variantConfig[variant];
|
|
131
152
|
const isMobile = useIsMobile();
|
|
@@ -144,14 +165,22 @@ export const LoginButton = ({
|
|
|
144
165
|
return name || email || t('authMenu.userFallback');
|
|
145
166
|
}, [t, user?.email, user?.name]);
|
|
146
167
|
|
|
147
|
-
const
|
|
168
|
+
const name = user?.name?.trim() || '';
|
|
169
|
+
const email = user?.email?.trim() || '';
|
|
170
|
+
const initials = getAccountInitials(name, email) || displayName.charAt(0).toUpperCase();
|
|
171
|
+
// Small avatars (app bar, taskbar) only fit one letter.
|
|
172
|
+
const avatarText = variant === 'sidebar' ? initials : initials.charAt(0);
|
|
173
|
+
const accountAriaLabel =
|
|
174
|
+
name && email
|
|
175
|
+
? t('authMenu.openAccountMenuWithEmailAriaLabel', { name, email })
|
|
176
|
+
: t('authMenu.openAccountMenuAriaLabel', { name: displayName });
|
|
148
177
|
const { showDisplayName, showCaret } = currentVariantConfig;
|
|
149
178
|
const menuSide = variant === 'sidebar' && isMobile ? 'top' : currentVariantConfig.menu.side;
|
|
150
179
|
const menuAlign = variant === 'sidebar' && isMobile ? 'start' : currentVariantConfig.menu.align;
|
|
151
180
|
const menuCollisionPadding = isMobile ? 12 : 8;
|
|
152
181
|
|
|
153
182
|
const baseButtonClasses = cn(
|
|
154
|
-
'inline-flex items-center gap-2 min-w-0 shrink-0 transition-colors cursor-pointer',
|
|
183
|
+
'inline-flex items-center gap-2 min-w-0 shrink-0 transition-colors motion-reduce:transition-none cursor-pointer',
|
|
155
184
|
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
|
|
156
185
|
'disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed',
|
|
157
186
|
isAuthenticated
|
|
@@ -250,7 +279,10 @@ export const LoginButton = ({
|
|
|
250
279
|
>
|
|
251
280
|
<Skeleton className={cn('shrink-0 rounded-full', currentVariantConfig.avatar)} />
|
|
252
281
|
{showDisplayName && (
|
|
253
|
-
<
|
|
282
|
+
<span className="flex min-w-0 flex-1 flex-col gap-1.5 group-data-[collapsible=icon]:hidden">
|
|
283
|
+
<Skeleton className="h-3 w-24 max-w-full" />
|
|
284
|
+
<Skeleton className="h-2.5 w-32 max-w-full" />
|
|
285
|
+
</span>
|
|
254
286
|
)}
|
|
255
287
|
</div>
|
|
256
288
|
);
|
|
@@ -278,7 +310,7 @@ export const LoginButton = ({
|
|
|
278
310
|
return null;
|
|
279
311
|
}
|
|
280
312
|
|
|
281
|
-
|
|
313
|
+
const accountMenu = (
|
|
282
314
|
<DropdownMenu
|
|
283
315
|
open={isMenuOpen}
|
|
284
316
|
onOpenChange={setIsMenuOpen}
|
|
@@ -289,13 +321,16 @@ export const LoginButton = ({
|
|
|
289
321
|
ref={triggerRef}
|
|
290
322
|
type="button"
|
|
291
323
|
className={baseButtonClasses}
|
|
292
|
-
title={displayName}
|
|
293
|
-
aria-label={
|
|
324
|
+
title={name && email ? `${name}\n${email}` : displayName}
|
|
325
|
+
aria-label={accountAriaLabel}
|
|
326
|
+
data-shellui-account-trigger=""
|
|
327
|
+
data-shellui-no-drag=""
|
|
294
328
|
>
|
|
295
329
|
{user.profilePicture ? (
|
|
296
330
|
<img
|
|
297
331
|
src={user.profilePicture}
|
|
298
|
-
alt=
|
|
332
|
+
alt=""
|
|
333
|
+
aria-hidden
|
|
299
334
|
className={cn(
|
|
300
335
|
'shrink-0 overflow-hidden rounded-full border border-sidebar-border object-cover aspect-square',
|
|
301
336
|
currentVariantConfig.avatar,
|
|
@@ -305,30 +340,30 @@ export const LoginButton = ({
|
|
|
305
340
|
) : (
|
|
306
341
|
<span
|
|
307
342
|
className={cn(
|
|
308
|
-
'flex shrink-0 aspect-square items-center justify-center overflow-hidden rounded-full border border-sidebar-border bg-
|
|
343
|
+
'flex shrink-0 aspect-square items-center justify-center overflow-hidden rounded-full border border-sidebar-border bg-sidebar-accent text-sidebar-foreground font-semibold leading-none',
|
|
309
344
|
currentVariantConfig.avatar,
|
|
310
345
|
)}
|
|
311
346
|
aria-hidden
|
|
347
|
+
data-shellui-account-initials=""
|
|
312
348
|
>
|
|
313
|
-
{
|
|
349
|
+
{avatarText}
|
|
314
350
|
</span>
|
|
315
351
|
)}
|
|
316
352
|
{showDisplayName && (
|
|
317
|
-
<span className="
|
|
353
|
+
<span className="flex min-w-0 flex-1 flex-col group-data-[collapsible=icon]:hidden">
|
|
354
|
+
<span className="truncate leading-tight">{displayName}</span>
|
|
355
|
+
{name && email ? (
|
|
356
|
+
<span
|
|
357
|
+
className="truncate text-[11.5px] leading-tight text-[var(--shellui-nav-label)]"
|
|
358
|
+
data-shellui-account-email=""
|
|
359
|
+
>
|
|
360
|
+
{email}
|
|
361
|
+
</span>
|
|
362
|
+
) : null}
|
|
363
|
+
</span>
|
|
318
364
|
)}
|
|
319
365
|
{showCaret && (
|
|
320
|
-
<
|
|
321
|
-
aria-hidden
|
|
322
|
-
className={cn(
|
|
323
|
-
'ml-auto shrink-0 text-[10px] group-data-[collapsible=icon]:hidden',
|
|
324
|
-
isMenuOpen ? 'text-foreground' : 'text-muted-foreground',
|
|
325
|
-
)}
|
|
326
|
-
>
|
|
327
|
-
<SidebarCaretIcon
|
|
328
|
-
isOpen={isMenuOpen}
|
|
329
|
-
className="h-3 w-3"
|
|
330
|
-
/>
|
|
331
|
-
</span>
|
|
366
|
+
<ChevronsUpDownIcon className="ml-auto size-4 shrink-0 text-[var(--shellui-nav-icon)] group-data-[collapsible=icon]:hidden" />
|
|
332
367
|
)}
|
|
333
368
|
</button>
|
|
334
369
|
</DropdownMenuTrigger>
|
|
@@ -383,4 +418,18 @@ export const LoginButton = ({
|
|
|
383
418
|
</DropdownMenuContent>
|
|
384
419
|
</DropdownMenu>
|
|
385
420
|
);
|
|
421
|
+
|
|
422
|
+
if (!dividerAbove) return accountMenu;
|
|
423
|
+
|
|
424
|
+
// Full-width hairline (cancels the 8px row inset), then 4px so the account
|
|
425
|
+
// row breathes below it.
|
|
426
|
+
return (
|
|
427
|
+
<>
|
|
428
|
+
<ShellDivider
|
|
429
|
+
data-shellui-account-divider=""
|
|
430
|
+
className="-mx-2 mt-1"
|
|
431
|
+
/>
|
|
432
|
+
<div className="pt-1">{accountMenu}</div>
|
|
433
|
+
</>
|
|
434
|
+
);
|
|
386
435
|
};
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
isOpen,
|
|
4
|
-
}: {
|
|
5
|
-
className?: string;
|
|
6
|
-
isOpen: boolean;
|
|
7
|
-
}) => (
|
|
1
|
+
/** lucide chevrons-up-down */
|
|
2
|
+
export const ChevronsUpDownIcon = ({ className }: { className?: string }) => (
|
|
8
3
|
<svg
|
|
9
4
|
xmlns="http://www.w3.org/2000/svg"
|
|
10
5
|
width="24"
|
|
@@ -18,7 +13,8 @@ export const SidebarCaretIcon = ({
|
|
|
18
13
|
className={className}
|
|
19
14
|
aria-hidden
|
|
20
15
|
>
|
|
21
|
-
|
|
16
|
+
<path d="m7 15 5 5 5-5" />
|
|
17
|
+
<path d="m7 9 5-5 5 5" />
|
|
22
18
|
</svg>
|
|
23
19
|
);
|
|
24
20
|
|
|
@@ -4,6 +4,7 @@ export {
|
|
|
4
4
|
getShellUILoginDeviceId,
|
|
5
5
|
} from './clientLoginContext';
|
|
6
6
|
export { buildAuthUrlWithNext } from './buildAuthUrlWithNext';
|
|
7
|
+
export { resolveSdkLoginRedirectPath } from './resolveSdkLoginRedirectPath';
|
|
7
8
|
export { getLoginCancelTarget, isPublicNavigationPage } from './loginCancelTarget';
|
|
8
9
|
export {
|
|
9
10
|
buildOAuthSessionRedirectTo,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import urls from '../../../constants/urls';
|
|
3
|
+
import { resolveSdkLoginRedirectPath } from './resolveSdkLoginRedirectPath';
|
|
4
|
+
|
|
5
|
+
describe('resolveSdkLoginRedirectPath', () => {
|
|
6
|
+
it('returns to the callback with the current page as next', () => {
|
|
7
|
+
expect(resolveSdkLoginRedirectPath(undefined, '/account')).toBe(
|
|
8
|
+
`${urls.loginCallback}?next=%2Faccount`,
|
|
9
|
+
);
|
|
10
|
+
expect(resolveSdkLoginRedirectPath('', '/files?tab=shared')).toBe(
|
|
11
|
+
`${urls.loginCallback}?next=%2Ffiles%3Ftab%3Dshared`,
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('uses redirectPath as the page after sign-in', () => {
|
|
16
|
+
expect(resolveSdkLoginRedirectPath('/dashboard', '/account')).toBe(
|
|
17
|
+
`${urls.loginCallback}?next=%2Fdashboard`,
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('keeps an explicit callback path', () => {
|
|
22
|
+
const callback = `${urls.loginCallback}?next=%2Fapps`;
|
|
23
|
+
expect(resolveSdkLoginRedirectPath(callback, '/account')).toBe(callback);
|
|
24
|
+
expect(resolveSdkLoginRedirectPath(urls.loginCallback, '/account')).toBe(urls.loginCallback);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('falls back to the current page when redirectPath is the login page', () => {
|
|
28
|
+
expect(resolveSdkLoginRedirectPath(urls.login, '/account')).toBe(
|
|
29
|
+
`${urls.loginCallback}?next=%2Faccount`,
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('never sends people back to login or to another origin', () => {
|
|
34
|
+
expect(resolveSdkLoginRedirectPath(undefined, urls.login)).toBe(urls.loginCallback);
|
|
35
|
+
expect(resolveSdkLoginRedirectPath(undefined, '/')).toBe(urls.loginCallback);
|
|
36
|
+
expect(resolveSdkLoginRedirectPath('//evil.example.com', '/account')).toBe(
|
|
37
|
+
`${urls.loginCallback}?next=%2Faccount`,
|
|
38
|
+
);
|
|
39
|
+
expect(resolveSdkLoginRedirectPath('https://evil.example.com', '/')).toBe(urls.loginCallback);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import urls from '../../../constants/urls';
|
|
2
|
+
import { buildAuthUrlWithNext } from './buildAuthUrlWithNext';
|
|
3
|
+
import { normalizeNextPath } from './normalizeNextPath';
|
|
4
|
+
|
|
5
|
+
const isCallbackPath = (value: string) =>
|
|
6
|
+
value === urls.loginCallback || value.startsWith(`${urls.loginCallback}?`);
|
|
7
|
+
|
|
8
|
+
const pageAfterSignIn = (value: string | null | undefined): string | null => {
|
|
9
|
+
const next = normalizeNextPath(value?.trim() || null);
|
|
10
|
+
return next && !isCallbackPath(next) ? next : null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Pick the `redirect_to` path for a `SHELLUI_LOGIN` request from an app.
|
|
15
|
+
*
|
|
16
|
+
* Only the callback route exchanges the OAuth code, so the request always
|
|
17
|
+
* returns there. `redirectPath` names the page to open after sign-in. With no
|
|
18
|
+
* usable `redirectPath`, people come back to the page they started from.
|
|
19
|
+
* An explicit callback path is kept as is.
|
|
20
|
+
*/
|
|
21
|
+
export const resolveSdkLoginRedirectPath = (
|
|
22
|
+
redirectPath: string | null | undefined,
|
|
23
|
+
currentPath: string,
|
|
24
|
+
): string => {
|
|
25
|
+
const requested = redirectPath?.trim();
|
|
26
|
+
if (requested && isCallbackPath(requested)) {
|
|
27
|
+
return requested;
|
|
28
|
+
}
|
|
29
|
+
const next = pageAfterSignIn(requested) ?? pageAfterSignIn(currentPath);
|
|
30
|
+
return buildAuthUrlWithNext(urls.loginCallback, next);
|
|
31
|
+
};
|
|
@@ -1464,9 +1464,12 @@ export function ChromeActionsHost() {
|
|
|
1464
1464
|
export function WindowTitleBarActions({
|
|
1465
1465
|
frameUuid,
|
|
1466
1466
|
fallbackTitle,
|
|
1467
|
+
centerTitle = false,
|
|
1467
1468
|
}: {
|
|
1468
1469
|
frameUuid: string | null;
|
|
1469
1470
|
fallbackTitle?: string;
|
|
1471
|
+
/** Phone header: centred 15px / 600 page title. */
|
|
1472
|
+
centerTitle?: boolean;
|
|
1470
1473
|
}) {
|
|
1471
1474
|
const all = useChromeActionsSnapshot();
|
|
1472
1475
|
const actions = useMemo(
|
|
@@ -1502,7 +1505,8 @@ export function WindowTitleBarActions({
|
|
|
1502
1505
|
return (
|
|
1503
1506
|
<span
|
|
1504
1507
|
className={cn(
|
|
1505
|
-
'min-w-0 flex-1 truncate
|
|
1508
|
+
'min-w-0 flex-1 truncate',
|
|
1509
|
+
centerTitle ? 'text-center text-[15px] font-semibold' : 'text-sm font-medium',
|
|
1506
1510
|
chromeActionsFadeClass,
|
|
1507
1511
|
'opacity-100',
|
|
1508
1512
|
)}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LayoutChromeInsets, LayoutChromeViewport } from '@shellui/sdk';
|
|
2
|
-
import { DESKTOP_TITLEBAR_HEIGHT_PX } from '../layouts/chrome/constants';
|
|
3
|
-
import { isTauriRuntime } from '../layouts/chrome/runtime';
|
|
2
|
+
import { DESKTOP_TITLEBAR_HEIGHT_PX, SHELL_HEADER_HEIGHT_PX } from '../layouts/chrome/constants';
|
|
3
|
+
import { isMacOSDesktop, isTauriRuntime } from '../layouts/chrome/runtime';
|
|
4
4
|
import {
|
|
5
5
|
FLOATING_CHROME_MARGIN,
|
|
6
6
|
FLOATING_CONTENT_CLEARANCE,
|
|
@@ -96,8 +96,11 @@ export function chromeActionsTopMargin(
|
|
|
96
96
|
const { layout, viewport } = context;
|
|
97
97
|
if (layout === 'floating') {
|
|
98
98
|
if (isTauriRuntime() && viewport === 'desktop') {
|
|
99
|
-
// Center the row in the
|
|
100
|
-
|
|
99
|
+
// Center the row in the title bar band, then nudge it off the window edge.
|
|
100
|
+
// macOS: 32px strip, (32 - 32) / 2 + 4 = 4. The row starts right of the panel or,
|
|
101
|
+
// collapsed, right of the strip glass group, so it never enters the lights safe area.
|
|
102
|
+
const band = isMacOSDesktop() ? DESKTOP_TITLEBAR_HEIGHT_PX : SHELL_HEADER_HEIGHT_PX;
|
|
103
|
+
return Math.round((band - chromeActionsTopBarHeight(viewport)) / 2) + 4;
|
|
101
104
|
}
|
|
102
105
|
return viewport === 'desktop' ? CHROME_ACTIONS_TOP_MARGIN_DESKTOP : CHROME_ACTIONS_TOP_MARGIN;
|
|
103
106
|
}
|