@shellui/core 0.5.0-beta.3 → 0.5.0

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.
Files changed (62) hide show
  1. package/README.md +5 -5
  2. package/package.json +3 -2
  3. package/src/app.tsx +8 -4
  4. package/src/components/ui/dialog.tsx +5 -1
  5. package/src/components/ui/dropdown-menu.tsx +39 -4
  6. package/src/components/ui/sheet.tsx +1 -1
  7. package/src/components/ui/sidebar.tsx +3 -2
  8. package/src/components/ui/tabs.tsx +52 -0
  9. package/src/constants/urls.ts +1 -0
  10. package/src/features/auth/AuthProvider.tsx +17 -6
  11. package/src/features/chromeActions/ChromeActionIcons.tsx +261 -0
  12. package/src/features/chromeActions/ChromeActionsDemoView.tsx +149 -0
  13. package/src/features/chromeActions/ChromeActionsHost.tsx +1511 -0
  14. package/src/features/chromeActions/ChromeActionsProvider.tsx +141 -0
  15. package/src/features/chromeActions/chromeActionsStore.spec.ts +61 -0
  16. package/src/features/chromeActions/chromeActionsStore.ts +77 -0
  17. package/src/features/chromeActions/computeActionInsets.spec.ts +360 -0
  18. package/src/features/chromeActions/computeActionInsets.ts +326 -0
  19. package/src/features/chromeActions/index.ts +26 -0
  20. package/src/features/chromeActions/resolveUuidForRemoveIframe.spec.ts +49 -0
  21. package/src/features/layouts/AppLayout.tsx +4 -4
  22. package/src/features/layouts/OverlayShell.tsx +60 -12
  23. package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +1 -1
  24. package/src/features/layouts/appbar/AppBarLayout.tsx +194 -89
  25. package/src/features/layouts/chrome/DesktopChrome.tsx +17 -3
  26. package/src/features/layouts/chrome/InsetMobileRadiusOverlay.tsx +18 -0
  27. package/src/features/layouts/chrome/index.ts +8 -0
  28. package/src/features/layouts/chrome/runtime.ts +73 -0
  29. package/src/features/layouts/chrome/useScrollHideChrome.ts +210 -0
  30. package/src/features/layouts/floating/FloatingBottomDock.tsx +410 -0
  31. package/src/features/layouts/floating/FloatingLayout.tsx +31 -21
  32. package/src/features/layouts/floating/FloatingStatusScrim.tsx +36 -0
  33. package/src/features/layouts/floating/computeFloatingInsets.spec.ts +5 -5
  34. package/src/features/layouts/floating/computeFloatingInsets.ts +64 -12
  35. package/src/features/layouts/floating/isShellOwnedPath.spec.ts +2 -0
  36. package/src/features/layouts/floating/isShellOwnedPath.ts +1 -0
  37. package/src/features/layouts/floating/layoutChromeStore.spec.ts +138 -0
  38. package/src/features/layouts/floating/layoutChromeStore.ts +169 -6
  39. package/src/features/layouts/floating/useFloatingChrome.ts +20 -30
  40. package/src/features/layouts/sidebar/SidebarLayout.tsx +87 -31
  41. package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +1 -1
  42. package/src/features/layouts/windows/WindowsLayout.tsx +240 -110
  43. package/src/features/overlays/ResponsiveModal.tsx +201 -21
  44. package/src/features/overlays/overlaySize.spec.ts +18 -0
  45. package/src/features/overlays/overlaySize.ts +89 -0
  46. package/src/features/settings/SettingsProvider.tsx +29 -9
  47. package/src/features/settings/components/Develop.tsx +2 -0
  48. package/src/features/settings/components/develop/ChromeActionsTestButtons.tsx +63 -0
  49. package/src/features/storage/uploads/uploadQueue.spec.ts +56 -1
  50. package/src/features/storage/uploads/uploadQueue.ts +42 -1
  51. package/src/features/theme/applyTheme.ts +23 -5
  52. package/src/hooks/use-mobile.tsx +21 -7
  53. package/src/i18n/translations/en/settings.json +9 -0
  54. package/src/i18n/translations/fr/settings.json +9 -0
  55. package/src/index.css +264 -124
  56. package/src/index.html +6 -4
  57. package/src/index.ts +8 -0
  58. package/src/routes/components/RouteFallback.tsx +15 -0
  59. package/src/routes/routes.tsx +14 -0
  60. package/src/features/layouts/floating/FloatingFadeMask.tsx +0 -22
  61. package/src/features/layouts/floating/FloatingTabBar.tsx +0 -437
  62. package/src/features/layouts/floating/FloatingTabIndicator.tsx +0 -216
@@ -0,0 +1,210 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { useLocation } from 'react-router';
3
+ import {
4
+ shellui,
5
+ getScrollMetrics,
6
+ reduceScrollChromeVisibility,
7
+ type LayoutChrome,
8
+ type LayoutChromeViewport,
9
+ type ScrollChromeState,
10
+ } from '@shellui/sdk';
11
+ import { resolveViewport } from '../../../hooks/use-viewport';
12
+ import { publishLayoutChrome } from '../floating/layoutChromeStore';
13
+ import { readShellSafeAreaPx } from '../floating/computeFloatingInsets';
14
+ import { DESKTOP_TITLEBAR_HEIGHT_PX } from './constants';
15
+
16
+ export type ScrollHideLayoutId = 'sidebar' | 'sidebar-inset' | 'app-bar' | 'app-bar-inset';
17
+
18
+ /** Host CSS var: stable mobile shell header height (safe-area + bar). */
19
+ export const SHELL_HEADER_HEIGHT_VAR = '--shellui-shell-header-height';
20
+ /**
21
+ * Shared hide-on-scroll motion for mobile shell chrome (header + inset tray +
22
+ * action row). Toggling this attribute on `html` applies the same translate /
23
+ * opacity targets to every consumer so they stay in sync.
24
+ */
25
+ export const CHROME_HIDE_ATTR = 'data-shellui-chrome-hidden';
26
+
27
+ /**
28
+ * Pixel height of the mobile shell top bar (title row + optional safe-area).
29
+ * Keep in sync with sidebar / app-bar header `height` styles.
30
+ */
31
+ export function mobileShellHeaderHeightPx(options?: {
32
+ includeSafeArea?: boolean;
33
+ barHeightPx?: number;
34
+ }): number {
35
+ const bar = options?.barHeightPx ?? DESKTOP_TITLEBAR_HEIGHT_PX;
36
+ if (options?.includeSafeArea === false) return bar;
37
+ const safe = typeof document !== 'undefined' ? readShellSafeAreaPx().top : 0;
38
+ return bar + safe;
39
+ }
40
+
41
+ function syncShellHeaderHeightVar(heightPx: number, enabled: boolean): void {
42
+ if (typeof document === 'undefined') return;
43
+ if (!enabled) {
44
+ document.documentElement.style.removeProperty(SHELL_HEADER_HEIGHT_VAR);
45
+ return;
46
+ }
47
+ document.documentElement.style.setProperty(SHELL_HEADER_HEIGHT_VAR, `${heightPx}px`);
48
+ }
49
+
50
+ /** Toggle the shared chrome hide motion on <html>. */
51
+ function syncChromeHideMotion(visible: boolean, enabled: boolean): void {
52
+ if (typeof document === 'undefined') return;
53
+ const root = document.documentElement;
54
+ if (!enabled) {
55
+ root.removeAttribute(CHROME_HIDE_ATTR);
56
+ return;
57
+ }
58
+ if (visible) root.removeAttribute(CHROME_HIDE_ATTR);
59
+ else root.setAttribute(CHROME_HIDE_ATTR, 'true');
60
+ }
61
+
62
+ /**
63
+ * Hide-on-scroll for shell top chrome (sidebar / app-bar mobile headers).
64
+ * Same hysteresis as floating dock: hide on scroll down, show on scroll up,
65
+ * near top, or near bottom.
66
+ *
67
+ * Publishes a **stable** top inset (header height) so iframe padding does not
68
+ * jump when the overlay header slides away. Inset layouts keep the same stable
69
+ * pad; their radius/tray personality is a pointer-events-none overlay that
70
+ * hides with the bar (see `InsetMobileRadiusOverlay`).
71
+ */
72
+ export function useScrollHideChrome(options: {
73
+ /** When false (desktop), chrome stays visible and no layout chrome is published. */
74
+ enabled: boolean;
75
+ layout: ScrollHideLayoutId;
76
+ /** Title-row height without safe-area (default 42). */
77
+ barHeightPx?: number;
78
+ /** When true (root shell), include safe-area-top in the header band height. */
79
+ includeSafeArea?: boolean;
80
+ }) {
81
+ const {
82
+ enabled,
83
+ layout,
84
+ barHeightPx = DESKTOP_TITLEBAR_HEIGHT_PX,
85
+ includeSafeArea = true,
86
+ } = options;
87
+ const location = useLocation();
88
+ const [chromeVisible, setChromeVisible] = useState(true);
89
+ const scrollStateRef = useRef<ScrollChromeState>({ visible: true, lastY: 0 });
90
+ const enabledRef = useRef(enabled);
91
+ enabledRef.current = enabled;
92
+
93
+ const readHeaderHeight = useCallback(() => {
94
+ return mobileShellHeaderHeightPx({ barHeightPx, includeSafeArea });
95
+ }, [barHeightPx, includeSafeArea]);
96
+
97
+ const pushChrome = useCallback(
98
+ (visible: boolean) => {
99
+ if (!enabledRef.current) return;
100
+ const viewport: LayoutChromeViewport =
101
+ typeof window !== 'undefined' ? resolveViewport(window.innerWidth) : 'mobile';
102
+ const headerHeight = readHeaderHeight();
103
+ syncShellHeaderHeightVar(headerHeight, true);
104
+ syncChromeHideMotion(visible, true);
105
+ const snapshot: LayoutChrome = {
106
+ layout,
107
+ viewport,
108
+ chromeVisible: visible,
109
+ autoPadding: true,
110
+ insets: {
111
+ top: headerHeight,
112
+ right: 0,
113
+ bottom: 0,
114
+ left: 0,
115
+ },
116
+ };
117
+ publishLayoutChrome(snapshot);
118
+ },
119
+ [layout, readHeaderHeight],
120
+ );
121
+
122
+ const applyScrollMetrics = useCallback((scrollY: number, distanceFromBottom?: number) => {
123
+ if (!enabledRef.current) return;
124
+ const prevVisible = scrollStateRef.current.visible;
125
+ const next = reduceScrollChromeVisibility(scrollStateRef.current, scrollY, {
126
+ distanceFromBottom,
127
+ });
128
+ scrollStateRef.current = next;
129
+ // Flip the shared CSS motion immediately (before React paint) so the header
130
+ // stack and action row stay on the same animation clock.
131
+ if (next.visible !== prevVisible) {
132
+ syncChromeHideMotion(next.visible, true);
133
+ }
134
+ setChromeVisible((prev) => (prev === next.visible ? prev : next.visible));
135
+ }, []);
136
+
137
+ // Reset when route changes or hide-on-scroll toggles (e.g. rotate to desktop).
138
+ useEffect(() => {
139
+ setChromeVisible(true);
140
+ scrollStateRef.current = { visible: true, lastY: 0 };
141
+ if (!enabled) {
142
+ syncShellHeaderHeightVar(0, false);
143
+ syncChromeHideMotion(true, false);
144
+ publishLayoutChrome(null);
145
+ return;
146
+ }
147
+ pushChrome(true);
148
+ const metrics = getScrollMetrics(document);
149
+ if (metrics) {
150
+ applyScrollMetrics(metrics.scrollY, metrics.distanceFromBottom);
151
+ }
152
+ }, [enabled, layout, location.pathname, pushChrome, applyScrollMetrics]);
153
+
154
+ useEffect(() => {
155
+ if (!enabled) return;
156
+ pushChrome(chromeVisible);
157
+ }, [chromeVisible, enabled, pushChrome]);
158
+
159
+ useEffect(() => {
160
+ if (!enabled) return;
161
+ const cleanup = shellui.addMessageListener('SHELLUI_CONTENT_SCROLL', (data) => {
162
+ const payload = data.payload as { scrollY?: number; distanceFromBottom?: number } | undefined;
163
+ if (typeof payload?.scrollY !== 'number') return;
164
+ applyScrollMetrics(payload.scrollY, payload.distanceFromBottom);
165
+ });
166
+ return cleanup;
167
+ }, [applyScrollMetrics, enabled]);
168
+
169
+ useEffect(() => {
170
+ if (!enabled) return;
171
+ const onScroll = (event: Event) => {
172
+ const el = event.target;
173
+ if (el instanceof Element) {
174
+ if (
175
+ el.closest('[data-shellui-scroll-hide-header], [data-sidebar], [data-slot="sidebar"]')
176
+ ) {
177
+ return;
178
+ }
179
+ }
180
+ const metrics = getScrollMetrics(el);
181
+ if (!metrics) return;
182
+ applyScrollMetrics(metrics.scrollY, metrics.distanceFromBottom);
183
+ };
184
+ document.addEventListener('scroll', onScroll, { capture: true, passive: true });
185
+ return () => document.removeEventListener('scroll', onScroll, true);
186
+ }, [applyScrollMetrics, enabled]);
187
+
188
+ useEffect(() => {
189
+ if (!enabled) return;
190
+ const onResize = () => {
191
+ pushChrome(scrollStateRef.current.visible);
192
+ };
193
+ window.addEventListener('resize', onResize);
194
+ return () => window.removeEventListener('resize', onResize);
195
+ }, [enabled, pushChrome]);
196
+
197
+ useEffect(() => {
198
+ return () => {
199
+ syncShellHeaderHeightVar(0, false);
200
+ syncChromeHideMotion(true, false);
201
+ publishLayoutChrome(null);
202
+ };
203
+ }, []);
204
+
205
+ return {
206
+ chromeVisible: enabled ? chromeVisible : true,
207
+ /** Stable header band height used for iframe top inset. */
208
+ headerHeightPx: enabled ? readHeaderHeight() : 0,
209
+ };
210
+ }
@@ -0,0 +1,410 @@
1
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
2
+ import { useLocation, useNavigate } from 'react-router';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { shellui } from '@shellui/sdk';
5
+ import type { NavigationItem } from '../../config/types';
6
+ import {
7
+ flattenNavigationItems,
8
+ getActivePathPrefix,
9
+ getNavPathPrefix,
10
+ resolveLocalizedString,
11
+ } from '../utils';
12
+ import { getExternalFaviconUrl } from '../sidebar/sidebarUtils';
13
+ import { NavIcon } from '../sidebar/SidebarIcons';
14
+ import { LoginButton } from '../../auth/components/LoginButton';
15
+ import { cn } from '../../../lib/utils';
16
+ import { Tabs, TabsList, TabsTrigger } from '../../../components/ui/tabs';
17
+ import {
18
+ DropdownMenu,
19
+ DropdownMenuContent,
20
+ DropdownMenuItem,
21
+ DropdownMenuSeparator,
22
+ DropdownMenuTrigger,
23
+ } from '../../../components/ui/dropdown-menu';
24
+ import {
25
+ FLOATING_CHROME_MARGIN,
26
+ FLOATING_DOCK_SIDE_INSET,
27
+ FLOATING_FAB_NAV_GAP,
28
+ FLOATING_MAX_TAB_SLOTS,
29
+ FLOATING_MAX_TAB_SLOTS_WITH_FAB,
30
+ FLOATING_MIN_TAB_SLOT_WIDTH,
31
+ floatingMinTabSlotWidth,
32
+ floatingTabBarBottomPadCss,
33
+ floatingTabBarHeight,
34
+ } from './computeFloatingInsets';
35
+ import type { ShellViewport } from '../../../hooks/use-viewport';
36
+ import { useChromeActionsSnapshot } from '../../chromeActions/ChromeActionsProvider';
37
+ import { SHELL_DEVELOP_CHROME_ACTIONS_FRAME } from '../../chromeActions/chromeActionsStore';
38
+ import { CHROME_ACTIONS_FAB_SIZE_FLOATING } from '../../chromeActions/computeActionInsets';
39
+ import { MoreHorizontalIcon } from '../../chromeActions/ChromeActionIcons';
40
+
41
+ const MORE_TAB_KEY = '__more__';
42
+
43
+ function itemIconSrc(item: NavigationItem): string | null {
44
+ if (item.icon) return item.icon;
45
+ if (item.openIn === 'external') return getExternalFaviconUrl(item.url);
46
+ return null;
47
+ }
48
+
49
+ function TabGlyph({ item, label }: { item: NavigationItem; label: string }) {
50
+ const iconSrc = itemIconSrc(item);
51
+ if (iconSrc) {
52
+ return (
53
+ <NavIcon
54
+ src={iconSrc}
55
+ className="size-5"
56
+ />
57
+ );
58
+ }
59
+ return (
60
+ <span className="flex size-5 items-center justify-center text-xs font-semibold leading-none">
61
+ {label.charAt(0).toUpperCase() || '?'}
62
+ </span>
63
+ );
64
+ }
65
+
66
+ function itemKey(item: NavigationItem): string {
67
+ return `${item.path}-${item.url}`;
68
+ }
69
+
70
+ /** True when the main frame has a primary FAB (corner) — reserve space in the nav. */
71
+ function useMainHasPrimaryFab(): boolean {
72
+ const all = useChromeActionsSnapshot();
73
+ return useMemo(() => {
74
+ for (const actions of all) {
75
+ if (!actions.primary) continue;
76
+ if (actions.frameUuid === SHELL_DEVELOP_CHROME_ACTIONS_FRAME) continue;
77
+ for (const [uuid, iframe] of shellui.frameRegistry.getAllIframes()) {
78
+ if (uuid !== actions.frameUuid || !iframe.isConnected) continue;
79
+ if (iframe.dataset.shelluiFrame === 'overlay') continue;
80
+ if (iframe.closest('[data-shellui-windows-layout]')) continue;
81
+ return true;
82
+ }
83
+ }
84
+ return false;
85
+ }, [all]);
86
+ }
87
+
88
+ const tabTriggerClass =
89
+ 'h-auto min-w-0 flex-1 basis-0 flex-col gap-0.5 px-2 py-1.5 text-[11px] font-medium leading-tight text-muted-foreground data-[state=active]:bg-muted data-[state=active]:text-foreground data-[state=active]:shadow-none';
90
+ const tabTriggerClassTablet =
91
+ 'h-auto min-w-0 flex-1 basis-0 flex-col gap-1 px-3.5 py-2 text-xs font-medium leading-tight text-muted-foreground data-[state=active]:bg-muted data-[state=active]:text-foreground data-[state=active]:shadow-none';
92
+
93
+ /**
94
+ * Floating phone/tablet bottom nav: shadcn Tabs with equal slots.
95
+ * Phone: full-width bar clearing the corner FAB (4 slots when FAB is present).
96
+ * Tablet: larger centered island keeps 5 slots with FAB; FAB stays bottom-right.
97
+ */
98
+ export function FloatingBottomDock({
99
+ items,
100
+ endItems = [],
101
+ showAuthButton = false,
102
+ chromeVisible,
103
+ viewport,
104
+ }: {
105
+ items: NavigationItem[];
106
+ endItems?: NavigationItem[];
107
+ showAuthButton?: boolean;
108
+ chromeVisible: boolean;
109
+ viewport: ShellViewport;
110
+ }) {
111
+ const location = useLocation();
112
+ const navigate = useNavigate();
113
+ const { i18n, t } = useTranslation('settings');
114
+ const lang = i18n.language || 'en';
115
+ const [moreOpen, setMoreOpen] = useState(false);
116
+ const listRef = useRef<HTMLDivElement>(null);
117
+ const hasPrimaryFab = useMainHasPrimaryFab();
118
+ const isPhone = viewport === 'mobile';
119
+ const isTablet = viewport === 'tablet';
120
+ // Phone: drop a slot when the corner FAB is present. Tablet has room for 5 + FAB.
121
+ const slotCap =
122
+ isPhone && hasPrimaryFab ? FLOATING_MAX_TAB_SLOTS_WITH_FAB : FLOATING_MAX_TAB_SLOTS;
123
+ const [maxSlots, setMaxSlots] = useState(slotCap);
124
+ const dockHeight = floatingTabBarHeight(viewport);
125
+ const slotWidth = floatingMinTabSlotWidth(viewport);
126
+ const triggerClass = isTablet ? tabTriggerClassTablet : tabTriggerClass;
127
+
128
+ const flat = useMemo(() => flattenNavigationItems(items), [items]);
129
+
130
+ // Measure how many equal-width slots fit; tablet island uses the slot cap.
131
+ useLayoutEffect(() => {
132
+ if (!isPhone) {
133
+ setMaxSlots(slotCap);
134
+ return;
135
+ }
136
+
137
+ const el = listRef.current;
138
+ if (!el) return;
139
+
140
+ const measure = () => {
141
+ const width = el.clientWidth;
142
+ if (width <= 0) return;
143
+ const fitted = Math.min(
144
+ slotCap,
145
+ Math.max(2, Math.floor(width / FLOATING_MIN_TAB_SLOT_WIDTH)),
146
+ );
147
+ setMaxSlots((prev) => (prev === fitted ? prev : fitted));
148
+ };
149
+
150
+ measure();
151
+ const ro = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : null;
152
+ ro?.observe(el);
153
+ return () => ro?.disconnect();
154
+ }, [hasPrimaryFab, isPhone, slotCap]);
155
+
156
+ const needsMoreChrome = endItems.length > 0 || showAuthButton;
157
+ // Fit as many equal slots as width allows; reserve one for More when needed.
158
+ const showMoreFinal = needsMoreChrome || flat.length > maxSlots;
159
+ const primaryCap = showMoreFinal ? Math.max(1, maxSlots - 1) : maxSlots;
160
+ const primary = useMemo(() => flat.slice(0, primaryCap), [flat, primaryCap]);
161
+ const moreOverflowItems = useMemo(() => flat.slice(primaryCap), [flat, primaryCap]);
162
+ const moreEndItems = endItems;
163
+ const moreItems = useMemo(
164
+ () => [...moreOverflowItems, ...moreEndItems],
165
+ [moreOverflowItems, moreEndItems],
166
+ );
167
+
168
+ const activePathPrefix = useMemo(
169
+ () => getActivePathPrefix(location.pathname, [...flat, ...endItems]),
170
+ [location.pathname, flat, endItems],
171
+ );
172
+
173
+ const moreActive = useMemo(
174
+ () =>
175
+ moreItems.some((item) => {
176
+ if (item.openIn === 'modal' || item.openIn === 'drawer' || item.openIn === 'external') {
177
+ return false;
178
+ }
179
+ return getNavPathPrefix(item) === activePathPrefix;
180
+ }),
181
+ [moreItems, activePathPrefix],
182
+ );
183
+
184
+ const activeTabKey = useMemo(() => {
185
+ if (moreActive || moreOpen) return MORE_TAB_KEY;
186
+ const active = primary.find((item) => {
187
+ if (item.openIn === 'modal' || item.openIn === 'drawer' || item.openIn === 'external') {
188
+ return false;
189
+ }
190
+ return getNavPathPrefix(item) === activePathPrefix;
191
+ });
192
+ return active ? itemKey(active) : primary[0] ? itemKey(primary[0]) : MORE_TAB_KEY;
193
+ }, [moreActive, moreOpen, primary, activePathPrefix]);
194
+
195
+ useEffect(() => {
196
+ setMoreOpen(false);
197
+ }, [location.pathname]);
198
+
199
+ useEffect(() => {
200
+ if (!chromeVisible) setMoreOpen(false);
201
+ }, [chromeVisible]);
202
+
203
+ const activateItem = (navItem: NavigationItem) => {
204
+ setMoreOpen(false);
205
+ if (navItem.openIn === 'modal') {
206
+ shellui.openModal(navItem.url);
207
+ return;
208
+ }
209
+ if (navItem.openIn === 'drawer') {
210
+ shellui.openDrawer({
211
+ url: navItem.url,
212
+ position: navItem.drawerPosition || 'right',
213
+ });
214
+ return;
215
+ }
216
+ if (navItem.openIn === 'external') {
217
+ window.open(navItem.url, '_blank', 'noopener,noreferrer');
218
+ return;
219
+ }
220
+ navigate(getNavPathPrefix(navItem));
221
+ };
222
+
223
+ const onTabChange = (value: string) => {
224
+ setMoreOpen(false);
225
+ const navItem = primary.find((item) => itemKey(item) === value);
226
+ if (navItem) activateItem(navItem);
227
+ };
228
+
229
+ const bottomPad = floatingTabBarBottomPadCss(viewport);
230
+
231
+ // Phone: full-width bar clears the corner FAB. Tablet: centered island;
232
+ // FAB stays bottom-right so they don’t share a row.
233
+ const fabReserve =
234
+ isPhone && hasPrimaryFab ? CHROME_ACTIONS_FAB_SIZE_FLOATING + FLOATING_FAB_NAV_GAP : 0;
235
+ const leftPad = `calc(${FLOATING_CHROME_MARGIN + FLOATING_DOCK_SIDE_INSET}px + var(--shellui-safe-area-left, 0px))`;
236
+ const rightPad = isPhone
237
+ ? hasPrimaryFab
238
+ ? `calc(${FLOATING_CHROME_MARGIN}px + var(--shellui-safe-area-right, 0px))`
239
+ : `calc(${FLOATING_CHROME_MARGIN + FLOATING_DOCK_SIDE_INSET}px + var(--shellui-safe-area-right, 0px))`
240
+ : `calc(${FLOATING_CHROME_MARGIN + FLOATING_DOCK_SIDE_INSET}px + var(--shellui-safe-area-right, 0px))`;
241
+ const tabCount = primary.length + (showMoreFinal ? 1 : 0);
242
+
243
+ return (
244
+ <div
245
+ data-shellui-floating-dock="bottom"
246
+ data-chrome-visible={chromeVisible ? 'true' : 'false'}
247
+ data-has-fab={hasPrimaryFab ? 'true' : 'false'}
248
+ data-dock-align={isPhone ? 'stretch' : 'center'}
249
+ className={cn(
250
+ 'pointer-events-none absolute inset-x-0 bottom-0 z-[45] flex',
251
+ !isPhone && 'justify-center',
252
+ )}
253
+ style={{
254
+ paddingLeft: leftPad,
255
+ paddingRight: rightPad,
256
+ paddingBottom: bottomPad,
257
+ }}
258
+ >
259
+ <div
260
+ data-shellui-floating-dock-row=""
261
+ className={cn('pointer-events-auto min-w-0', isPhone ? 'flex-1' : 'w-auto max-w-xl')}
262
+ style={{
263
+ height: dockHeight,
264
+ marginRight: fabReserve,
265
+ transitionProperty: 'margin-right',
266
+ transitionDuration: '380ms',
267
+ transitionTimingFunction: 'cubic-bezier(0.22, 1, 0.36, 1)',
268
+ }}
269
+ >
270
+ <Tabs
271
+ value={activeTabKey}
272
+ onValueChange={onTabChange}
273
+ className={cn('h-full min-w-0', isPhone ? 'w-full' : 'w-auto')}
274
+ >
275
+ <TabsList
276
+ ref={listRef}
277
+ data-shellui-floating-dock-list=""
278
+ aria-label={t('develop.layout.floating', { defaultValue: 'Floating' })}
279
+ className={cn(
280
+ 'flex h-full min-w-0 gap-1 border border-border/60 bg-background/90 p-1.5 text-muted-foreground shadow-sm backdrop-blur-md',
281
+ // Override TabsList default `h-10` so height matches the FAB.
282
+ isTablet ? 'h-16 gap-1.5 p-2' : 'h-14',
283
+ isPhone ? 'w-full' : 'w-auto',
284
+ )}
285
+ style={{
286
+ height: dockHeight,
287
+ ...(!isPhone
288
+ ? {
289
+ width: `${tabCount * slotWidth}px`,
290
+ }
291
+ : {}),
292
+ }}
293
+ >
294
+ {primary.map((navItem) => {
295
+ const label = resolveLocalizedString(navItem.label, lang);
296
+ const key = itemKey(navItem);
297
+ const isActive = key === activeTabKey;
298
+ return (
299
+ <TabsTrigger
300
+ key={key}
301
+ value={key}
302
+ data-shellui-floating-dock-tab=""
303
+ className={triggerClass}
304
+ aria-current={isActive ? 'page' : undefined}
305
+ >
306
+ <TabGlyph
307
+ item={navItem}
308
+ label={label}
309
+ />
310
+ <span className="w-full truncate text-center">{label}</span>
311
+ </TabsTrigger>
312
+ );
313
+ })}
314
+ {showMoreFinal ? (
315
+ <TabsTrigger
316
+ value={MORE_TAB_KEY}
317
+ className="sr-only"
318
+ tabIndex={-1}
319
+ aria-hidden
320
+ />
321
+ ) : null}
322
+ {showMoreFinal ? (
323
+ <DropdownMenu
324
+ open={moreOpen}
325
+ onOpenChange={setMoreOpen}
326
+ >
327
+ <DropdownMenuTrigger asChild>
328
+ <button
329
+ type="button"
330
+ role="tab"
331
+ aria-selected={activeTabKey === MORE_TAB_KEY}
332
+ aria-current={activeTabKey === MORE_TAB_KEY ? 'page' : undefined}
333
+ data-state={activeTabKey === MORE_TAB_KEY ? 'active' : 'inactive'}
334
+ data-shellui-floating-dock-tab=""
335
+ className={cn(
336
+ 'inline-flex items-center justify-center whitespace-nowrap text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
337
+ triggerClass,
338
+ )}
339
+ >
340
+ <MoreHorizontalIcon className="size-5" />
341
+ <span className="w-full truncate text-center">
342
+ {t('develop.layout.more', { defaultValue: 'More' })}
343
+ </span>
344
+ </button>
345
+ </DropdownMenuTrigger>
346
+ <DropdownMenuContent
347
+ side="top"
348
+ align="end"
349
+ sideOffset={10}
350
+ className="min-w-[12rem]"
351
+ >
352
+ {moreOverflowItems.map((item) => {
353
+ const label = resolveLocalizedString(item.label, lang);
354
+ const pathPrefix = getNavPathPrefix(item);
355
+ const isActive =
356
+ item.openIn !== 'modal' &&
357
+ item.openIn !== 'drawer' &&
358
+ item.openIn !== 'external' &&
359
+ pathPrefix === activePathPrefix;
360
+ return (
361
+ <DropdownMenuItem
362
+ key={itemKey(item)}
363
+ className={cn(isActive && 'bg-accent font-medium')}
364
+ onSelect={() => activateItem(item)}
365
+ >
366
+ <TabGlyph
367
+ item={item}
368
+ label={label}
369
+ />
370
+ <span className="min-w-0 flex-1 truncate">{label}</span>
371
+ </DropdownMenuItem>
372
+ );
373
+ })}
374
+ {moreOverflowItems.length > 0 && (moreEndItems.length > 0 || showAuthButton) ? (
375
+ <DropdownMenuSeparator />
376
+ ) : null}
377
+ {moreEndItems.map((item) => {
378
+ const label = resolveLocalizedString(item.label, lang);
379
+ return (
380
+ <DropdownMenuItem
381
+ key={itemKey(item)}
382
+ onSelect={() => activateItem(item)}
383
+ >
384
+ <TabGlyph
385
+ item={item}
386
+ label={label}
387
+ />
388
+ <span className="min-w-0 flex-1 truncate">{label}</span>
389
+ </DropdownMenuItem>
390
+ );
391
+ })}
392
+ {showAuthButton ? (
393
+ <>
394
+ {moreEndItems.length > 0 || moreOverflowItems.length > 0 ? (
395
+ <DropdownMenuSeparator />
396
+ ) : null}
397
+ <div className="px-1 py-1">
398
+ <LoginButton variant="sidebar" />
399
+ </div>
400
+ </>
401
+ ) : null}
402
+ </DropdownMenuContent>
403
+ </DropdownMenu>
404
+ ) : null}
405
+ </TabsList>
406
+ </Tabs>
407
+ </div>
408
+ </div>
409
+ );
410
+ }