@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
package/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # @shellui/core
2
2
 
3
- Shellui Core - Core React application runtime
4
-
5
- ## Installation
3
+ React runtime for the Shellui host. `@shellui/cli` depends on this package. Install it yourself when you import config types or `useAuth` from host code.
6
4
 
7
5
  ```bash
8
6
  npm install @shellui/core
9
7
  ```
10
8
 
11
- ## Usage
9
+ ```typescript
10
+ import type { ShellUIConfig } from '@shellui/core';
11
+ ```
12
12
 
13
- This package contains the core React application for Shellui. It's typically used by `@shellui/cli` and `@shellui/sdk`.
13
+ Docs: [Core](https://docs.shellui.com/core), [CLI](https://docs.shellui.com/cli).
14
14
 
15
15
  ## License
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shellui/core",
3
- "version": "0.5.0-beta.3",
3
+ "version": "0.5.0",
4
4
  "description": "Shellui Core - Core React application runtime",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -50,6 +50,7 @@
50
50
  "@radix-ui/react-dropdown-menu": "^2.1.16",
51
51
  "@radix-ui/react-separator": "^1.1.8",
52
52
  "@radix-ui/react-slot": "^1.2.4",
53
+ "@radix-ui/react-tabs": "^1.1.21",
53
54
  "@radix-ui/react-tooltip": "^1.2.8",
54
55
  "@sentry/react": "^10.39.0",
55
56
  "@supabase/supabase-js": "^2.99.3",
@@ -71,7 +72,7 @@
71
72
  "workbox-routing": "^7.4.0",
72
73
  "workbox-strategies": "^7.4.0",
73
74
  "workbox-window": "^7.4.0",
74
- "@shellui/sdk": "0.5.0-beta.3"
75
+ "@shellui/sdk": "0.5.0"
75
76
  },
76
77
  "peerDependencies": {
77
78
  "react": "^18.0.0 || ^19.0.0",
package/src/app.tsx CHANGED
@@ -12,6 +12,7 @@ import { CookieConsentModal } from './features/cookieConsent/CookieConsentModal'
12
12
  import { AuthProvider } from './features/auth/AuthProvider';
13
13
  import { StorageBridge } from './features/storage/StorageBridge';
14
14
  import { SonnerProvider } from './features/sonner/SonnerContext';
15
+ import { ChromeActionsHost, ChromeActionsProvider } from './features/chromeActions';
15
16
  import { Toaster } from './components/ui/sonner';
16
17
  import { UploadToaster } from './features/storage/uploads/UploadToaster';
17
18
  import './features/sentry/initSentry';
@@ -136,10 +137,13 @@ const App = () => {
136
137
  <I18nProvider>
137
138
  <DialogProvider>
138
139
  <SonnerProvider>
139
- {/* Toaster + upload progress live at Shellui root so they survive navigation. */}
140
- <Toaster />
141
- <UploadToaster />
142
- <AppContent />
140
+ <ChromeActionsProvider>
141
+ {/* Toaster + upload progress live at Shellui root so they survive navigation. */}
142
+ <Toaster />
143
+ <UploadToaster />
144
+ <ChromeActionsHost />
145
+ <AppContent />
146
+ </ChromeActionsProvider>
143
147
  </SonnerProvider>
144
148
  </DialogProvider>
145
149
  </I18nProvider>
@@ -74,7 +74,11 @@ const DialogContent = forwardRef<ElementRef<typeof DialogPrimitive.Content>, Dia
74
74
  >[0],
75
75
  ) => {
76
76
  const target = event?.target as Element | null;
77
- if (target?.closest?.('[data-sonner-toaster], [data-upload-toast]')) {
77
+ if (
78
+ target?.closest?.(
79
+ '[data-sonner-toaster], [data-upload-toast], [data-shellui-chrome-actions]',
80
+ )
81
+ ) {
78
82
  event.preventDefault();
79
83
  }
80
84
  onPointerDownOutside?.(event);
@@ -1,9 +1,29 @@
1
- import { forwardRef, type ComponentPropsWithoutRef, type ElementRef } from 'react';
1
+ import {
2
+ forwardRef,
3
+ type ComponentPropsWithoutRef,
4
+ type ElementRef,
5
+ type PointerEvent as ReactPointerEvent,
6
+ } from 'react';
2
7
  import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
3
8
  import { cn } from '../../lib/utils';
4
9
  import { Z_INDEX } from '../../lib/z-index';
5
10
 
6
- const DropdownMenu = DropdownMenuPrimitive.Root;
11
+ /**
12
+ * Default `modal={false}`: Radix modal menus set `pointer-events: none` on `body`,
13
+ * which breaks Apple Pencil (and sometimes fine touch) on iPad — items never get
14
+ * a `click` / `onSelect`. Non-modal matches LoginButton and Radix #1027.
15
+ */
16
+ function DropdownMenu({
17
+ modal = false,
18
+ ...props
19
+ }: ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Root>) {
20
+ return (
21
+ <DropdownMenuPrimitive.Root
22
+ modal={modal}
23
+ {...props}
24
+ />
25
+ );
26
+ }
7
27
 
8
28
  const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
9
29
 
@@ -39,17 +59,32 @@ const DropdownMenuContent = forwardRef<
39
59
  ));
40
60
  DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
41
61
 
62
+ /**
63
+ * Pencil taps often never synthesize a `click` under Radix layers (same class of
64
+ * bug as dialog close / toast actions). Fire click on pointerdown for pen only.
65
+ */
66
+ function handlePenPointerDown(
67
+ e: ReactPointerEvent<HTMLDivElement>,
68
+ onPointerDown?: (event: ReactPointerEvent<HTMLDivElement>) => void,
69
+ ) {
70
+ onPointerDown?.(e);
71
+ if (e.defaultPrevented) return;
72
+ if (e.pointerType !== 'pen') return;
73
+ e.currentTarget.click();
74
+ }
75
+
42
76
  const DropdownMenuItem = forwardRef<
43
77
  ElementRef<typeof DropdownMenuPrimitive.Item>,
44
78
  ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item>
45
- >(({ className, ...props }, ref) => (
79
+ >(({ className, onPointerDown, ...props }, ref) => (
46
80
  <DropdownMenuPrimitive.Item
47
81
  ref={ref}
48
82
  className={cn(
49
- 'relative flex items-center gap-2 cursor-pointer select-none rounded-sm px-2 py-1.5 text-sm outline-none transition-colors',
83
+ 'relative flex items-center gap-2 cursor-pointer select-none rounded-sm px-2 py-1.5 text-sm outline-none transition-colors [touch-action:manipulation]',
50
84
  'focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
51
85
  className,
52
86
  )}
87
+ onPointerDown={(e) => handlePenPointerDown(e, onPointerDown)}
53
88
  {...props}
54
89
  />
55
90
  ));
@@ -12,7 +12,7 @@ import { cn } from '../../lib/utils';
12
12
  import { Z_INDEX } from '../../lib/z-index';
13
13
 
14
14
  const PORTALED_OVERLAY_SELECTOR =
15
- '[data-dropdown-menu-content], [data-auth-menu-content], [data-sonner-toaster], [data-upload-toast]';
15
+ '[data-dropdown-menu-content], [data-auth-menu-content], [data-sonner-toaster], [data-upload-toast], [data-shellui-chrome-actions]';
16
16
 
17
17
  function isPortaledOverlayTarget(target: EventTarget | null): boolean {
18
18
  const element = target instanceof Element ? target : (target as Node | null)?.parentElement;
@@ -534,8 +534,9 @@ function SidebarInset({ className, ...props }: React.ComponentProps<'main'>) {
534
534
  data-slot="sidebar-inset"
535
535
  className={cn(
536
536
  'relative flex w-full flex-1 flex-col bg-background',
537
- // Inset layout: float the main frame on a darkened chrome tray.
538
- // Expanded: ml-0 — sidebar's own right pad is the gap. Collapsed: ml-3 matches right/top/bottom.
537
+ // Inset layout: float the main frame on a darkened chrome tray (desktop).
538
+ // Mobile inset rounding lives on the content card in SidebarLayout so the
539
+ // header can sit on the chrome tray above a radiused iframe frame.
539
540
  'md:peer-data-[variant=inset]:m-3 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-2xl md:peer-data-[variant=inset]:border md:peer-data-[variant=inset]:border-border md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-3',
540
541
  className,
541
542
  )}
@@ -0,0 +1,52 @@
1
+ import { forwardRef, type ComponentPropsWithoutRef, type ElementRef } from 'react';
2
+ import * as TabsPrimitive from '@radix-ui/react-tabs';
3
+ import { cn } from '../../lib/utils';
4
+
5
+ const Tabs = TabsPrimitive.Root;
6
+
7
+ const TabsList = forwardRef<
8
+ ElementRef<typeof TabsPrimitive.List>,
9
+ ComponentPropsWithoutRef<typeof TabsPrimitive.List>
10
+ >(({ className, ...props }, ref) => (
11
+ <TabsPrimitive.List
12
+ ref={ref}
13
+ className={cn(
14
+ 'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground',
15
+ className,
16
+ )}
17
+ {...props}
18
+ />
19
+ ));
20
+ TabsList.displayName = TabsPrimitive.List.displayName;
21
+
22
+ const TabsTrigger = forwardRef<
23
+ ElementRef<typeof TabsPrimitive.Trigger>,
24
+ ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
25
+ >(({ className, ...props }, ref) => (
26
+ <TabsPrimitive.Trigger
27
+ ref={ref}
28
+ className={cn(
29
+ 'inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 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 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm',
30
+ className,
31
+ )}
32
+ {...props}
33
+ />
34
+ ));
35
+ TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
36
+
37
+ const TabsContent = forwardRef<
38
+ ElementRef<typeof TabsPrimitive.Content>,
39
+ ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
40
+ >(({ className, ...props }, ref) => (
41
+ <TabsPrimitive.Content
42
+ ref={ref}
43
+ className={cn(
44
+ 'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
45
+ className,
46
+ )}
47
+ {...props}
48
+ />
49
+ ));
50
+ TabsContent.displayName = TabsPrimitive.Content.displayName;
51
+
52
+ export { Tabs, TabsList, TabsTrigger, TabsContent };
@@ -2,6 +2,7 @@ export default {
2
2
  settings: '/__settings',
3
3
  cookiePreferences: '/__cookie-preferences',
4
4
  overlayDemo: '/__overlay-demo',
5
+ chromeActionsDemo: '/__chrome-actions-demo',
5
6
  login: '/login',
6
7
  loginCallback: '/login/callback',
7
8
  admin: '/admin',
@@ -49,6 +49,8 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
49
49
  const sessionRef = useRef<AuthSession | null>(null);
50
50
  sessionRef.current = session;
51
51
  const refreshInFlightRef = useRef(false);
52
+ /** Bumps on every preferences sync so a slower older PUT can’t overwrite a newer theme. */
53
+ const preferencesSyncGenRef = useRef(0);
52
54
 
53
55
  useEffect(() => {
54
56
  let cancelled = false;
@@ -356,24 +358,33 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
356
358
 
357
359
  const syncUserPreferences = useCallback(
358
360
  async (preferences: UserPreferences) => {
361
+ const gen = ++preferencesSyncGenRef.current;
362
+ const sessionAtStart = sessionRef.current;
359
363
  try {
360
- await backend.syncUserPreferences(session, preferences);
364
+ await backend.syncUserPreferences(sessionAtStart, preferences);
365
+ // A newer appearance change started another sync — drop this result.
366
+ if (gen !== preferencesSyncGenRef.current) return;
367
+
361
368
  const now = Math.floor(Date.now() / 1000);
362
369
  let nextSession: AuthSession | null = null;
363
370
  try {
364
- if (session && isTokenAutoRefreshDisabled()) {
371
+ if (sessionAtStart && isTokenAutoRefreshDisabled()) {
365
372
  logger.info(
366
373
  'Skipped token refresh after preferences sync because Develop → Disable token auto-refresh is on',
367
374
  );
368
375
  nextSession = null;
369
376
  } else {
370
- nextSession = session ? await backend.refreshAuthSession(session, now) : null;
377
+ nextSession = sessionAtStart
378
+ ? await backend.refreshAuthSession(sessionAtStart, now)
379
+ : null;
371
380
  }
372
381
  } catch (refreshErr) {
373
382
  logger.error('Failed to refresh auth session after syncing preferences', { refreshErr });
374
383
  }
375
- if (!nextSession && session) {
376
- nextSession = { ...session, userPreferences: preferences };
384
+ if (gen !== preferencesSyncGenRef.current) return;
385
+
386
+ if (!nextSession && sessionAtStart) {
387
+ nextSession = { ...sessionAtStart, userPreferences: preferences };
377
388
  }
378
389
  if (nextSession) {
379
390
  // Keep stored snapshot aligned with what we synced (JWT claims can lag the PUT).
@@ -387,7 +398,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
387
398
  logger.error('Failed to sync user preferences to auth provider metadata', { err });
388
399
  }
389
400
  },
390
- [backend, session],
401
+ [backend],
391
402
  );
392
403
 
393
404
  const loadUserPreferences = useCallback(async () => {
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Built-in glyphs for chrome actions (`icon` name).
3
+ * Image / SVG URLs (http(s), data:, absolute or relative paths) render as <img>.
4
+ */
5
+
6
+ import type { ReactElement } from 'react';
7
+
8
+ type IconProps = {
9
+ className?: string;
10
+ 'data-shellui-chrome-action-animate'?: string;
11
+ };
12
+
13
+ function strokeIcon(
14
+ paths: ReactElement | ReactElement[],
15
+ { className, ...rest }: IconProps,
16
+ size = 20,
17
+ ): ReactElement {
18
+ return (
19
+ <svg
20
+ xmlns="http://www.w3.org/2000/svg"
21
+ width={size}
22
+ height={size}
23
+ viewBox="0 0 24 24"
24
+ fill="none"
25
+ stroke="currentColor"
26
+ strokeWidth="2"
27
+ strokeLinecap="round"
28
+ strokeLinejoin="round"
29
+ className={className}
30
+ aria-hidden
31
+ {...rest}
32
+ >
33
+ {paths}
34
+ </svg>
35
+ );
36
+ }
37
+
38
+ export function ChevronLeftIcon(props: IconProps) {
39
+ return strokeIcon(<path d="m15 18-6-6 6-6" />, props);
40
+ }
41
+
42
+ export function PlusIcon(props: IconProps) {
43
+ return strokeIcon(
44
+ <>
45
+ <path d="M5 12h14" />
46
+ <path d="M12 5v14" />
47
+ </>,
48
+ props,
49
+ 24,
50
+ );
51
+ }
52
+
53
+ export function MoreHorizontalIcon(props: IconProps) {
54
+ return strokeIcon(
55
+ <>
56
+ <circle
57
+ cx="12"
58
+ cy="12"
59
+ r="1"
60
+ />
61
+ <circle
62
+ cx="19"
63
+ cy="12"
64
+ r="1"
65
+ />
66
+ <circle
67
+ cx="5"
68
+ cy="12"
69
+ r="1"
70
+ />
71
+ </>,
72
+ props,
73
+ );
74
+ }
75
+
76
+ export function EditIcon(props: IconProps) {
77
+ return strokeIcon(
78
+ <>
79
+ <path d="M12 20h9" />
80
+ <path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z" />
81
+ </>,
82
+ props,
83
+ );
84
+ }
85
+
86
+ export function ShareIcon(props: IconProps) {
87
+ return strokeIcon(
88
+ <>
89
+ <circle
90
+ cx="18"
91
+ cy="5"
92
+ r="3"
93
+ />
94
+ <circle
95
+ cx="6"
96
+ cy="12"
97
+ r="3"
98
+ />
99
+ <circle
100
+ cx="18"
101
+ cy="19"
102
+ r="3"
103
+ />
104
+ <path d="m8.59 13.51 6.83 3.98" />
105
+ <path d="m15.41 6.51-6.82 3.98" />
106
+ </>,
107
+ props,
108
+ );
109
+ }
110
+
111
+ export function FilterIcon(props: IconProps) {
112
+ return strokeIcon(<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />, props);
113
+ }
114
+
115
+ export function ArchiveIcon(props: IconProps) {
116
+ return strokeIcon(
117
+ <>
118
+ <rect
119
+ width="20"
120
+ height="5"
121
+ x="2"
122
+ y="3"
123
+ rx="1"
124
+ />
125
+ <path d="M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8" />
126
+ <path d="M10 12h4" />
127
+ </>,
128
+ props,
129
+ );
130
+ }
131
+
132
+ export function SettingsIcon(props: IconProps) {
133
+ return strokeIcon(
134
+ <>
135
+ <path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" />
136
+ <circle
137
+ cx="12"
138
+ cy="12"
139
+ r="3"
140
+ />
141
+ </>,
142
+ props,
143
+ );
144
+ }
145
+
146
+ export function DeleteIcon(props: IconProps) {
147
+ return strokeIcon(
148
+ <>
149
+ <path d="M3 6h18" />
150
+ <path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" />
151
+ <path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" />
152
+ <line
153
+ x1="10"
154
+ x2="10"
155
+ y1="11"
156
+ y2="17"
157
+ />
158
+ <line
159
+ x1="14"
160
+ x2="14"
161
+ y1="11"
162
+ y2="17"
163
+ />
164
+ </>,
165
+ props,
166
+ );
167
+ }
168
+
169
+ export function StarIcon(props: IconProps) {
170
+ return strokeIcon(
171
+ <polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />,
172
+ props,
173
+ );
174
+ }
175
+
176
+ export function RefreshIcon(props: IconProps) {
177
+ return strokeIcon(
178
+ <>
179
+ <path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8" />
180
+ <path d="M21 3v5h-5" />
181
+ <path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16" />
182
+ <path d="M8 16H3v5" />
183
+ </>,
184
+ props,
185
+ );
186
+ }
187
+
188
+ const BUILTIN: Record<string, (props: IconProps) => ReactElement> = {
189
+ back: ChevronLeftIcon,
190
+ plus: PlusIcon,
191
+ more: MoreHorizontalIcon,
192
+ edit: EditIcon,
193
+ share: ShareIcon,
194
+ filter: FilterIcon,
195
+ archive: ArchiveIcon,
196
+ settings: SettingsIcon,
197
+ delete: DeleteIcon,
198
+ star: StarIcon,
199
+ refresh: RefreshIcon,
200
+ };
201
+
202
+ export function ChromeActionGlyph({
203
+ icon,
204
+ label,
205
+ className,
206
+ animate,
207
+ }: {
208
+ icon?: string;
209
+ label?: string;
210
+ className?: string;
211
+ /** When `icon-rotate`, continuously spins the glyph. */
212
+ animate?: string;
213
+ }) {
214
+ const spinning = animate === 'icon-rotate';
215
+ const glyphClass = [className ?? 'size-4 shrink-0', spinning ? 'animate-spin' : '']
216
+ .filter(Boolean)
217
+ .join(' ');
218
+ const animateAttr = spinning ? { 'data-shellui-chrome-action-animate': 'icon-rotate' } : {};
219
+
220
+ if (!icon) {
221
+ if (!label) return null;
222
+ return (
223
+ <span
224
+ className={`flex items-center justify-center text-xs font-semibold ${glyphClass}`}
225
+ {...animateAttr}
226
+ >
227
+ {label.charAt(0).toUpperCase()}
228
+ </span>
229
+ );
230
+ }
231
+
232
+ if (/^(https?:|data:|\/|\.)/.test(icon) || icon.includes('/')) {
233
+ return (
234
+ <img
235
+ src={icon}
236
+ alt=""
237
+ className={`${glyphClass} object-contain`}
238
+ {...animateAttr}
239
+ />
240
+ );
241
+ }
242
+
243
+ const Builtin = BUILTIN[icon];
244
+ if (Builtin) {
245
+ return (
246
+ <Builtin
247
+ className={glyphClass}
248
+ {...animateAttr}
249
+ />
250
+ );
251
+ }
252
+
253
+ return (
254
+ <span
255
+ className={`flex items-center justify-center text-xs font-semibold ${glyphClass}`}
256
+ {...animateAttr}
257
+ >
258
+ {(label ?? icon).charAt(0).toUpperCase()}
259
+ </span>
260
+ );
261
+ }