@shellui/core 0.7.0-alpha.10 → 0.7.0-alpha.11
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/package.json +2 -2
- package/src/components/ui/drawer.tsx +47 -30
- package/src/components/ui/sheet.tsx +18 -12
- package/src/components/ui/sidebar.tsx +14 -6
- package/src/components/ui/tooltip.tsx +4 -2
- package/src/features/auth/components/LoginButton.spec.tsx +155 -0
- package/src/features/auth/components/LoginButton.tsx +52 -27
- package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
- package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
- 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 +53 -81
- 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 +1 -1
- package/src/features/layouts/chrome/constants.ts +3 -0
- package/src/features/layouts/chrome/viewport.ts +11 -4
- package/src/features/layouts/floating/FloatingBottomDock.tsx +66 -25
- package/src/features/layouts/floating/FloatingLayout.tsx +1 -0
- package/src/features/layouts/floating/FloatingSidebar.tsx +26 -8
- package/src/features/layouts/floating/moreSections.spec.ts +28 -0
- package/src/features/layouts/floating/moreSections.ts +31 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +10 -1
- package/src/features/layouts/sidebar/NavigationContent.tsx +4 -4
- package/src/features/layouts/sidebar/SidebarIcons.tsx +67 -0
- package/src/features/layouts/sidebar/SidebarInner.spec.tsx +109 -0
- package/src/features/layouts/sidebar/SidebarInner.tsx +49 -9
- package/src/features/layouts/sidebar/SidebarLayout.tsx +23 -13
- package/src/features/layouts/windows/WindowsLayout.tsx +75 -44
- package/src/features/layouts/windows/deskDots.spec.ts +6 -4
- package/src/features/layouts/windows/deskDots.ts +8 -8
- 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/i18n/translations/en/common.json +1 -0
- package/src/i18n/translations/fr/common.json +1 -0
- package/src/index.css +211 -32
- 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
|
@@ -3,7 +3,8 @@ import { Drawer as VaulDrawer } from 'vaul';
|
|
|
3
3
|
import { useLocation, useNavigate } from 'react-router';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { shellui } from '@shellui/sdk';
|
|
6
|
-
import type { NavigationItem } from '../../config/types';
|
|
6
|
+
import type { NavigationGroup, NavigationItem } from '../../config/types';
|
|
7
|
+
import { groupMoreItems, type MoreSection } from './moreSections';
|
|
7
8
|
import {
|
|
8
9
|
flattenNavigationItems,
|
|
9
10
|
getActivePathPrefix,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
DropdownMenu,
|
|
20
21
|
DropdownMenuContent,
|
|
21
22
|
DropdownMenuItem,
|
|
23
|
+
DropdownMenuLabel,
|
|
22
24
|
DropdownMenuSeparator,
|
|
23
25
|
DropdownMenuTrigger,
|
|
24
26
|
} from '../../../components/ui/dropdown-menu';
|
|
@@ -125,12 +127,15 @@ function tabChangeHaptic() {
|
|
|
125
127
|
*/
|
|
126
128
|
export function FloatingBottomDock({
|
|
127
129
|
items,
|
|
130
|
+
navigation = [],
|
|
128
131
|
endItems = [],
|
|
129
132
|
showAuthButton = false,
|
|
130
133
|
chromeVisible,
|
|
131
134
|
viewport,
|
|
132
135
|
}: {
|
|
133
136
|
items: NavigationItem[];
|
|
137
|
+
/** Start navigation tree, so More can label items by their group. */
|
|
138
|
+
navigation?: (NavigationItem | NavigationGroup)[];
|
|
134
139
|
endItems?: NavigationItem[];
|
|
135
140
|
showAuthButton?: boolean;
|
|
136
141
|
chromeVisible: boolean;
|
|
@@ -188,6 +193,10 @@ export function FloatingBottomDock({
|
|
|
188
193
|
const primaryCap = showMoreFinal ? Math.max(1, maxSlots - 1) : maxSlots;
|
|
189
194
|
const primary = useMemo(() => flat.slice(0, primaryCap), [flat, primaryCap]);
|
|
190
195
|
const moreOverflowItems = useMemo(() => flat.slice(primaryCap), [flat, primaryCap]);
|
|
196
|
+
const moreSections = useMemo(
|
|
197
|
+
() => groupMoreItems(moreOverflowItems, navigation),
|
|
198
|
+
[moreOverflowItems, navigation],
|
|
199
|
+
);
|
|
191
200
|
const moreEndItems = endItems;
|
|
192
201
|
const moreItems = useMemo(
|
|
193
202
|
() => [...moreOverflowItems, ...moreEndItems],
|
|
@@ -387,29 +396,39 @@ export function FloatingBottomDock({
|
|
|
387
396
|
sideOffset={10}
|
|
388
397
|
className="min-w-[12rem]"
|
|
389
398
|
>
|
|
390
|
-
{
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
399
|
+
{moreSections.map((section, sectionIndex) => (
|
|
400
|
+
<div key={`more-section-${sectionIndex}`}>
|
|
401
|
+
{sectionIndex > 0 ? <DropdownMenuSeparator /> : null}
|
|
402
|
+
{section.group ? (
|
|
403
|
+
<DropdownMenuLabel className="text-xs font-semibold text-muted-foreground">
|
|
404
|
+
{resolveLocalizedString(section.group.title, lang)}
|
|
405
|
+
</DropdownMenuLabel>
|
|
406
|
+
) : null}
|
|
407
|
+
{section.items.map((item) => {
|
|
408
|
+
const label = resolveLocalizedString(item.label, lang);
|
|
409
|
+
const pathPrefix = getNavPathPrefix(item);
|
|
410
|
+
const isActive =
|
|
411
|
+
item.openIn !== 'modal' &&
|
|
412
|
+
item.openIn !== 'drawer' &&
|
|
413
|
+
item.openIn !== 'external' &&
|
|
414
|
+
pathPrefix === activePathPrefix;
|
|
415
|
+
return (
|
|
416
|
+
<DropdownMenuItem
|
|
417
|
+
key={itemKey(item)}
|
|
418
|
+
className={cn(isActive && 'bg-accent font-medium')}
|
|
419
|
+
aria-current={isActive ? 'page' : undefined}
|
|
420
|
+
onSelect={() => activateItem(item)}
|
|
421
|
+
>
|
|
422
|
+
<TabGlyph
|
|
423
|
+
item={item}
|
|
424
|
+
label={label}
|
|
425
|
+
/>
|
|
426
|
+
<span className="min-w-0 flex-1 truncate">{label}</span>
|
|
427
|
+
</DropdownMenuItem>
|
|
428
|
+
);
|
|
429
|
+
})}
|
|
430
|
+
</div>
|
|
431
|
+
))}
|
|
413
432
|
{moreOverflowItems.length > 0 && (moreEndItems.length > 0 || showAuthButton) ? (
|
|
414
433
|
<DropdownMenuSeparator />
|
|
415
434
|
) : null}
|
|
@@ -473,6 +492,7 @@ export function FloatingBottomDock({
|
|
|
473
492
|
externalLabel={tc('shellChrome.externalLink')}
|
|
474
493
|
lang={lang}
|
|
475
494
|
overflowItems={moreOverflowItems}
|
|
495
|
+
sections={moreSections}
|
|
476
496
|
endItems={moreEndItems}
|
|
477
497
|
showAuthButton={showAuthButton}
|
|
478
498
|
activePathPrefix={activePathPrefix}
|
|
@@ -496,6 +516,7 @@ function FloatingMoreSheet({
|
|
|
496
516
|
externalLabel,
|
|
497
517
|
lang,
|
|
498
518
|
overflowItems,
|
|
519
|
+
sections,
|
|
499
520
|
endItems,
|
|
500
521
|
showAuthButton,
|
|
501
522
|
activePathPrefix,
|
|
@@ -508,6 +529,7 @@ function FloatingMoreSheet({
|
|
|
508
529
|
externalLabel: string;
|
|
509
530
|
lang: string;
|
|
510
531
|
overflowItems: NavigationItem[];
|
|
532
|
+
sections: MoreSection[];
|
|
511
533
|
endItems: NavigationItem[];
|
|
512
534
|
showAuthButton: boolean;
|
|
513
535
|
activePathPrefix: string | null;
|
|
@@ -567,7 +589,26 @@ function FloatingMoreSheet({
|
|
|
567
589
|
aria-label={title}
|
|
568
590
|
className="min-h-0 flex-1 overflow-y-auto px-2 pb-2"
|
|
569
591
|
>
|
|
570
|
-
{
|
|
592
|
+
{sections.map((section, sectionIndex) => (
|
|
593
|
+
<div
|
|
594
|
+
key={`more-sheet-section-${sectionIndex}`}
|
|
595
|
+
role={section.group ? 'group' : undefined}
|
|
596
|
+
aria-label={
|
|
597
|
+
section.group ? resolveLocalizedString(section.group.title, lang) : undefined
|
|
598
|
+
}
|
|
599
|
+
>
|
|
600
|
+
{section.group ? (
|
|
601
|
+
<div
|
|
602
|
+
aria-hidden
|
|
603
|
+
data-shellui-more-sheet-label=""
|
|
604
|
+
className="shellui-more-sheet-label"
|
|
605
|
+
>
|
|
606
|
+
{resolveLocalizedString(section.group.title, lang)}
|
|
607
|
+
</div>
|
|
608
|
+
) : null}
|
|
609
|
+
{section.items.map(renderRow)}
|
|
610
|
+
</div>
|
|
611
|
+
))}
|
|
571
612
|
{overflowItems.length > 0 && (endItems.length > 0 || showAuthButton) ? (
|
|
572
613
|
<div
|
|
573
614
|
aria-hidden
|
|
@@ -142,6 +142,7 @@ export function FloatingLayout({ title, appIcon, navigation = [] }: FloatingLayo
|
|
|
142
142
|
{showTabBar ? (
|
|
143
143
|
<FloatingBottomDock
|
|
144
144
|
items={tabItems}
|
|
145
|
+
navigation={startNav}
|
|
145
146
|
endItems={endItems}
|
|
146
147
|
showAuthButton={showAuthButton}
|
|
147
148
|
chromeVisible={chromeVisible}
|
|
@@ -83,6 +83,9 @@ function SidebarPanelIcon({ className }: { className?: string }) {
|
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** Web brand row height (spec: 52px). */
|
|
87
|
+
const FLOATING_BRAND_ROW_PX = 52;
|
|
88
|
+
|
|
86
89
|
/** Floating glass sidebar for desktop floating layout (collapsible). */
|
|
87
90
|
export function FloatingSidebar({
|
|
88
91
|
title,
|
|
@@ -104,7 +107,7 @@ export function FloatingSidebar({
|
|
|
104
107
|
onToggleCollapsed: () => void;
|
|
105
108
|
}) {
|
|
106
109
|
const location = useLocation();
|
|
107
|
-
const { i18n
|
|
110
|
+
const { i18n } = useTranslation('settings');
|
|
108
111
|
const { t: tc } = useTranslation('common');
|
|
109
112
|
const lang = i18n.language || 'en';
|
|
110
113
|
const isTauriEnv = useIsTauriClient();
|
|
@@ -144,8 +147,8 @@ export function FloatingSidebar({
|
|
|
144
147
|
};
|
|
145
148
|
|
|
146
149
|
const toggleLabel = collapsed
|
|
147
|
-
?
|
|
148
|
-
:
|
|
150
|
+
? tc('shellChrome.expandSidebar')
|
|
151
|
+
: tc('shellChrome.collapseSidebar');
|
|
149
152
|
|
|
150
153
|
const renderItem = (navItem: NavigationItem) => {
|
|
151
154
|
const pathPrefix = getNavPathPrefix(navItem);
|
|
@@ -367,7 +370,7 @@ export function FloatingSidebar({
|
|
|
367
370
|
<div
|
|
368
371
|
className={cn(
|
|
369
372
|
'flex shrink-0 items-center border-b border-sidebar-border/80',
|
|
370
|
-
tauriRuntime ? 'pr-2.5' : '
|
|
373
|
+
tauriRuntime ? 'pr-2.5' : 'pr-2 pl-3.5',
|
|
371
374
|
)}
|
|
372
375
|
style={
|
|
373
376
|
tauriRuntime
|
|
@@ -375,11 +378,16 @@ export function FloatingSidebar({
|
|
|
375
378
|
height: SHELL_HEADER_HEIGHT_PX,
|
|
376
379
|
paddingTop: SHELL_HEADER_PAD_TOP_PX,
|
|
377
380
|
}
|
|
378
|
-
:
|
|
381
|
+
: { height: FLOATING_BRAND_ROW_PX }
|
|
379
382
|
}
|
|
380
383
|
{...(tauriRuntime ? MAC_DRAG_REGION_PROPS : {})}
|
|
381
384
|
>
|
|
382
|
-
<div
|
|
385
|
+
<div
|
|
386
|
+
className={cn(
|
|
387
|
+
'flex h-full min-w-0 flex-1 items-center',
|
|
388
|
+
tauriRuntime ? 'gap-1' : 'gap-1.5',
|
|
389
|
+
)}
|
|
390
|
+
>
|
|
383
391
|
{isTauriEnv && !collapsed ? (
|
|
384
392
|
<DesktopHistoryButtons className="self-center" />
|
|
385
393
|
) : null}
|
|
@@ -387,9 +395,19 @@ export function FloatingSidebar({
|
|
|
387
395
|
<AppBrandIcon
|
|
388
396
|
appIcon={appIcon}
|
|
389
397
|
title={title}
|
|
390
|
-
className=
|
|
398
|
+
className={cn('shrink-0', tauriRuntime ? 'size-7' : 'size-5')}
|
|
391
399
|
/>
|
|
392
400
|
) : null}
|
|
401
|
+
{/* Web brand row: logo + name (the Tauri bar hides the name, like the mock). */}
|
|
402
|
+
{!tauriRuntime && title ? (
|
|
403
|
+
<span
|
|
404
|
+
aria-hidden={appIcon ? true : undefined}
|
|
405
|
+
data-shellui-floating-brand-name=""
|
|
406
|
+
className="ml-0.5 min-w-0 truncate text-sm font-semibold text-sidebar-foreground"
|
|
407
|
+
>
|
|
408
|
+
{title}
|
|
409
|
+
</span>
|
|
410
|
+
) : null}
|
|
393
411
|
<span
|
|
394
412
|
className="min-h-full min-w-0 flex-1 self-stretch"
|
|
395
413
|
{...(tauriRuntime ? MAC_DRAG_REGION_PROPS : {})}
|
|
@@ -398,7 +416,7 @@ export function FloatingSidebar({
|
|
|
398
416
|
type="button"
|
|
399
417
|
tabIndex={collapsed ? -1 : 0}
|
|
400
418
|
data-shellui-no-drag=""
|
|
401
|
-
className="shellui-floating-nav-control flex size-
|
|
419
|
+
className="shellui-floating-nav-control flex size-9 shrink-0 items-center justify-center text-sidebar-foreground transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
|
402
420
|
aria-label={toggleLabel}
|
|
403
421
|
aria-expanded={!collapsed}
|
|
404
422
|
onClick={onToggleCollapsed}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { NavigationGroup, NavigationItem } from '../../config/types';
|
|
3
|
+
import { groupMoreItems } from './moreSections';
|
|
4
|
+
|
|
5
|
+
const item = (path: string): NavigationItem => ({ path, url: `/${path}`, label: path });
|
|
6
|
+
|
|
7
|
+
describe('groupMoreItems', () => {
|
|
8
|
+
const files = item('files');
|
|
9
|
+
const members = item('members');
|
|
10
|
+
const roles = item('roles');
|
|
11
|
+
const help = item('help');
|
|
12
|
+
const team: NavigationGroup = { title: 'Team', items: [members, roles] };
|
|
13
|
+
const tree = [item('home'), files, team, help];
|
|
14
|
+
|
|
15
|
+
it('labels the runs that belong to a group and keeps the order', () => {
|
|
16
|
+
const sections = groupMoreItems([files, members, roles, help], tree);
|
|
17
|
+
expect(sections.map((s) => s.group?.title ?? null)).toEqual([null, 'Team', null]);
|
|
18
|
+
expect(sections[1].items).toEqual([members, roles]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('returns one unlabelled section when nothing is grouped', () => {
|
|
22
|
+
expect(groupMoreItems([files, help], tree)).toEqual([{ group: null, items: [files, help] }]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('returns nothing for an empty overflow', () => {
|
|
26
|
+
expect(groupMoreItems([], tree)).toEqual([]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NavigationGroup, NavigationItem } from '../../config/types';
|
|
2
|
+
|
|
3
|
+
export interface MoreSection {
|
|
4
|
+
/** Group the items came from, or null for top-level links. */
|
|
5
|
+
group: NavigationGroup | null;
|
|
6
|
+
items: NavigationItem[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Split the More overflow into runs that share a navigation group, so the
|
|
11
|
+
* sheet and the tablet menu can show each group's label (order is kept).
|
|
12
|
+
*/
|
|
13
|
+
export function groupMoreItems(
|
|
14
|
+
overflow: NavigationItem[],
|
|
15
|
+
tree: (NavigationItem | NavigationGroup)[],
|
|
16
|
+
): MoreSection[] {
|
|
17
|
+
const owner = new Map<NavigationItem, NavigationGroup>();
|
|
18
|
+
for (const entry of tree) {
|
|
19
|
+
if ('title' in entry && 'items' in entry) {
|
|
20
|
+
for (const item of entry.items) owner.set(item, entry);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const sections: MoreSection[] = [];
|
|
24
|
+
for (const item of overflow) {
|
|
25
|
+
const group = owner.get(item) ?? null;
|
|
26
|
+
const last = sections[sections.length - 1];
|
|
27
|
+
if (last && last.group === group) last.items.push(item);
|
|
28
|
+
else sections.push({ group, items: [item] });
|
|
29
|
+
}
|
|
30
|
+
return sections;
|
|
31
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { FullscreenLayout } from './FullscreenLayout';
|
|
7
|
+
|
|
8
|
+
const env = { mac: false, root: true };
|
|
9
|
+
|
|
10
|
+
vi.mock('react-i18next', () => ({ useTranslation: () => ({ i18n: { language: 'en' } }) }));
|
|
11
|
+
vi.mock('../chrome/runtime', () => ({
|
|
12
|
+
useIsTauriClient: () => env.mac,
|
|
13
|
+
useMacOverlayChrome: () => env.mac,
|
|
14
|
+
useMacTrafficLights: () => env.mac,
|
|
15
|
+
}));
|
|
16
|
+
vi.mock('../chrome/DesktopHistoryButtons', () => ({ DesktopHistoryButtons: () => null }));
|
|
17
|
+
vi.mock('../chrome/SafeAreaTopbar', () => ({ isShellUiRootWindow: () => env.root }));
|
|
18
|
+
|
|
19
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
20
|
+
|
|
21
|
+
let container: HTMLDivElement;
|
|
22
|
+
let root: Root;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
env.mac = false;
|
|
26
|
+
env.root = true;
|
|
27
|
+
container = document.createElement('div');
|
|
28
|
+
document.body.appendChild(container);
|
|
29
|
+
root = createRoot(container);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
act(() => root.unmount());
|
|
34
|
+
container.remove();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function main(): HTMLElement {
|
|
38
|
+
act(() =>
|
|
39
|
+
root.render(
|
|
40
|
+
<MemoryRouter>
|
|
41
|
+
<FullscreenLayout navigation={[]}>
|
|
42
|
+
<p>content</p>
|
|
43
|
+
</FullscreenLayout>
|
|
44
|
+
</MemoryRouter>,
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
const el = container.querySelector<HTMLElement>('[data-shellui-fullscreen]');
|
|
48
|
+
if (!el) throw new Error('missing main');
|
|
49
|
+
return el;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe('FullscreenLayout safe areas', () => {
|
|
53
|
+
it('pads the root window for the notch and home indicator', () => {
|
|
54
|
+
expect(main().className).toContain('shellui-fullscreen-safe');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('does not pad again inside a nested shell iframe', () => {
|
|
58
|
+
env.root = false;
|
|
59
|
+
expect(main().className).not.toContain('shellui-fullscreen-safe');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('keeps the macOS strip padding instead', () => {
|
|
63
|
+
env.mac = true;
|
|
64
|
+
const el = main();
|
|
65
|
+
expect(el.className).not.toContain('shellui-fullscreen-safe');
|
|
66
|
+
expect(el.style.paddingTop).toBe('48px');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
SHELL_HEADER_PAD_TOP_PX,
|
|
14
14
|
} from '../chrome/constants';
|
|
15
15
|
import { MAC_DRAG_REGION_PROPS, MacLightsSafeArea, MacStripSpacer } from '../chrome/MacStrip';
|
|
16
|
+
import { isShellUiRootWindow } from '../chrome/SafeAreaTopbar';
|
|
17
|
+
import { cn } from '../../../lib/utils';
|
|
16
18
|
|
|
17
19
|
/** macOS: content starts under the 32px strip plus 16px. */
|
|
18
20
|
const MAC_CONTENT_PAD_TOP_PX = 48;
|
|
@@ -39,6 +41,8 @@ export function FullscreenLayout({ title, navigation, children }: FullscreenLayo
|
|
|
39
41
|
const trafficLights = useMacTrafficLights();
|
|
40
42
|
const macStrip = useMacOverlayChrome();
|
|
41
43
|
const currentLanguage = i18n.language || 'en';
|
|
44
|
+
// Nested shell-in-iframe: the root window already cleared the safe areas.
|
|
45
|
+
const safeAreaPad = isShellUiRootWindow();
|
|
42
46
|
const navigationItems = useMemo(() => flattenNavigationItems(navigation), [navigation]);
|
|
43
47
|
|
|
44
48
|
useEffect(() => {
|
|
@@ -60,7 +64,12 @@ export function FullscreenLayout({ title, navigation, children }: FullscreenLayo
|
|
|
60
64
|
|
|
61
65
|
return (
|
|
62
66
|
<main
|
|
63
|
-
|
|
67
|
+
data-shellui-fullscreen=""
|
|
68
|
+
className={cn(
|
|
69
|
+
'relative flex h-full max-h-full w-full flex-col overflow-hidden bg-background',
|
|
70
|
+
// Phones: clear the notch and home indicator (nothing higher up pads them).
|
|
71
|
+
!macStrip && safeAreaPad && 'shellui-fullscreen-safe',
|
|
72
|
+
)}
|
|
64
73
|
style={macStrip ? { paddingTop: MAC_CONTENT_PAD_TOP_PX } : undefined}
|
|
65
74
|
>
|
|
66
75
|
{macStrip ? (
|
|
@@ -148,7 +148,7 @@ export function NavigationContent({
|
|
|
148
148
|
|
|
149
149
|
if (sections.length === 0 && trailingItem) {
|
|
150
150
|
return (
|
|
151
|
-
<SidebarGroup className="mt-0">
|
|
151
|
+
<SidebarGroup className="mt-0 px-2 py-0">
|
|
152
152
|
<SidebarGroupContent>
|
|
153
153
|
<SidebarMenu className="gap-0.5">{trailingItem}</SidebarMenu>
|
|
154
154
|
</SidebarGroupContent>
|
|
@@ -167,9 +167,9 @@ export function NavigationContent({
|
|
|
167
167
|
return (
|
|
168
168
|
<SidebarGroup
|
|
169
169
|
key={`group-${groupTitle}-${sectionIndex}`}
|
|
170
|
-
className="mt-0"
|
|
170
|
+
className="mt-0 px-2 py-0"
|
|
171
171
|
>
|
|
172
|
-
<SidebarGroupLabel className="shellui-nav-label
|
|
172
|
+
<SidebarGroupLabel className="shellui-nav-label">{groupTitle}</SidebarGroupLabel>
|
|
173
173
|
<SidebarGroupContent>
|
|
174
174
|
<SidebarMenu className="gap-0.5">
|
|
175
175
|
{section.group.items.map((navItem) => (
|
|
@@ -185,7 +185,7 @@ export function NavigationContent({
|
|
|
185
185
|
return (
|
|
186
186
|
<SidebarGroup
|
|
187
187
|
key={`items-${section.items.map((i) => i.path).join('-')}-${sectionIndex}`}
|
|
188
|
-
className="mt-0"
|
|
188
|
+
className="mt-0 px-2 py-0"
|
|
189
189
|
>
|
|
190
190
|
<SidebarGroupContent>
|
|
191
191
|
<SidebarMenu className="gap-0.5">
|
|
@@ -23,6 +23,73 @@ export function ExternalLinkIcon({ className }: { className?: string }) {
|
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function LucideSvg({ className, children }: { className?: string; children: React.ReactNode }) {
|
|
27
|
+
return (
|
|
28
|
+
<svg
|
|
29
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
30
|
+
width="24"
|
|
31
|
+
height="24"
|
|
32
|
+
viewBox="0 0 24 24"
|
|
33
|
+
fill="none"
|
|
34
|
+
stroke="currentColor"
|
|
35
|
+
strokeWidth="2"
|
|
36
|
+
strokeLinecap="round"
|
|
37
|
+
strokeLinejoin="round"
|
|
38
|
+
className={cn('shrink-0', className)}
|
|
39
|
+
aria-hidden
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
</svg>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** lucide x */
|
|
47
|
+
export function CloseIcon({ className }: { className?: string }) {
|
|
48
|
+
return (
|
|
49
|
+
<LucideSvg className={className}>
|
|
50
|
+
<path d="M18 6 6 18" />
|
|
51
|
+
<path d="m6 6 12 12" />
|
|
52
|
+
</LucideSvg>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** lucide ellipsis */
|
|
57
|
+
export function EllipsisIcon({ className }: { className?: string }) {
|
|
58
|
+
return (
|
|
59
|
+
<LucideSvg className={className}>
|
|
60
|
+
<circle
|
|
61
|
+
cx="12"
|
|
62
|
+
cy="12"
|
|
63
|
+
r="1"
|
|
64
|
+
/>
|
|
65
|
+
<circle
|
|
66
|
+
cx="19"
|
|
67
|
+
cy="12"
|
|
68
|
+
r="1"
|
|
69
|
+
/>
|
|
70
|
+
<circle
|
|
71
|
+
cx="5"
|
|
72
|
+
cy="12"
|
|
73
|
+
r="1"
|
|
74
|
+
/>
|
|
75
|
+
</LucideSvg>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Settings gear (same glyph as the account menu). */
|
|
80
|
+
export function SettingsIcon({ className }: { className?: string }) {
|
|
81
|
+
return (
|
|
82
|
+
<LucideSvg className={className}>
|
|
83
|
+
<circle
|
|
84
|
+
cx="12"
|
|
85
|
+
cy="12"
|
|
86
|
+
r="3"
|
|
87
|
+
/>
|
|
88
|
+
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z" />
|
|
89
|
+
</LucideSvg>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
26
93
|
/** Default nav icon when a navigation item has no custom icon. */
|
|
27
94
|
export function DefaultNavIcon({ className }: { className?: string }) {
|
|
28
95
|
return (
|
|
@@ -0,0 +1,109 @@
|
|
|
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 { SIDEBAR_PANEL_ID, SidebarProvider, SidebarTrigger } from '../../../components/ui/sidebar';
|
|
9
|
+
import { SidebarInner } from './SidebarInner';
|
|
10
|
+
|
|
11
|
+
const mobile = { value: false };
|
|
12
|
+
|
|
13
|
+
vi.mock('../../../hooks/use-mobile', () => ({ useIsMobile: () => mobile.value }));
|
|
14
|
+
vi.mock('../chrome/runtime', () => ({
|
|
15
|
+
useIsTauriClient: () => false,
|
|
16
|
+
useMacOverlayChrome: () => false,
|
|
17
|
+
useMacTrafficLights: () => false,
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('./NavigationContent', () => ({ NavigationContent: () => null }));
|
|
20
|
+
vi.mock('../../config/useConfig', () => ({ useConfig: () => ({ config: {} }) }));
|
|
21
|
+
vi.mock('../../auth/components/LoginButton', () => ({ LoginButton: () => null }));
|
|
22
|
+
vi.mock('react-i18next', () => ({
|
|
23
|
+
useTranslation: () => ({
|
|
24
|
+
t: (key: string) => {
|
|
25
|
+
const [group, leaf] = key.split('.') as [keyof typeof en, string];
|
|
26
|
+
return (en[group] as Record<string, string>)[leaf] ?? key;
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
32
|
+
|
|
33
|
+
let container: HTMLDivElement;
|
|
34
|
+
let root: Root;
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
mobile.value = false;
|
|
38
|
+
container = document.createElement('div');
|
|
39
|
+
document.body.appendChild(container);
|
|
40
|
+
root = createRoot(container);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
act(() => root.unmount());
|
|
45
|
+
container.remove();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function render(node: React.ReactNode, open = true) {
|
|
49
|
+
act(() => {
|
|
50
|
+
root.render(
|
|
51
|
+
<MemoryRouter>
|
|
52
|
+
<SidebarProvider defaultOpen={open}>{node}</SidebarProvider>
|
|
53
|
+
</MemoryRouter>,
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function q<T extends Element = HTMLElement>(scope: ParentNode, sel: string): T {
|
|
59
|
+
const el = scope.querySelector<T>(sel);
|
|
60
|
+
if (!el) throw new Error(`missing ${sel}`);
|
|
61
|
+
return el;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const inner = (
|
|
65
|
+
<SidebarInner
|
|
66
|
+
startNav={[]}
|
|
67
|
+
endItems={[]}
|
|
68
|
+
showAuthButton={false}
|
|
69
|
+
title="Acme"
|
|
70
|
+
appIcon="/icon.svg"
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
describe('SidebarTrigger', () => {
|
|
75
|
+
it('reports aria-expanded and aria-controls', () => {
|
|
76
|
+
render(<SidebarTrigger />);
|
|
77
|
+
const btn = q<HTMLButtonElement>(container, 'button');
|
|
78
|
+
expect(btn.getAttribute('aria-controls')).toBe(SIDEBAR_PANEL_ID);
|
|
79
|
+
expect(btn.getAttribute('aria-expanded')).toBe('true');
|
|
80
|
+
act(() => btn.click());
|
|
81
|
+
expect(btn.getAttribute('aria-expanded')).toBe('false');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('SidebarInner header', () => {
|
|
86
|
+
it('shows the app name next to the logo, with no border under the header', () => {
|
|
87
|
+
render(inner);
|
|
88
|
+
const header = q(container, '[data-sidebar="header"]');
|
|
89
|
+
expect(header.textContent).toContain('Acme');
|
|
90
|
+
expect(header.className).not.toContain('border-b');
|
|
91
|
+
expect(q(header, 'span.truncate').className).toContain(
|
|
92
|
+
'group-data-[collapsible=icon]:opacity-0',
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('mobile sheet header is 52px with a labelled close button', () => {
|
|
97
|
+
mobile.value = true;
|
|
98
|
+
render(inner);
|
|
99
|
+
const header = q(container, '[data-sidebar="header"]');
|
|
100
|
+
expect(header.style.height).toBe('52px');
|
|
101
|
+
const close = q(header, 'button');
|
|
102
|
+
expect(close.getAttribute('aria-label')).toBe('Close menu');
|
|
103
|
+
expect(header.textContent).toContain('Acme');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('has the close label in French', () => {
|
|
107
|
+
expect(fr.shellChrome.closeMenu).toBe('Fermer le menu');
|
|
108
|
+
});
|
|
109
|
+
});
|