@re-venue/ui-core-react 0.3.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@re-venue/ui-core-react",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "main": "./dist/ui-core-react.umd.cjs",
6
6
  "module": "./dist/ui-core-react.js",
@@ -1,5 +1,5 @@
1
- import { useMemo, useState, useEffect } from 'react'
2
- import type { ReactNode } from 'react'
1
+ import { useMemo, useRef, useState, useEffect } from 'react'
2
+ import type { FocusEvent, ReactNode } from 'react'
3
3
  import { ConfirmModal } from './ConfirmModal'
4
4
  import { useTheme } from '../hooks/useTheme'
5
5
  import type { AuthUser, SidebarNavItem, Venue } from '../types'
@@ -20,6 +20,13 @@ interface Props {
20
20
  headerActions?: ReactNode
21
21
  sidebarPanel?: ReactNode
22
22
  scrollable?: boolean
23
+ /**
24
+ * When the consumer updates the active venue inline (reactively, from
25
+ * `onSwitchVenue`) the AppShell skips the otherwise-redundant full-page reload
26
+ * that would just refresh the app you're already on. Apps that re-route on a
27
+ * reload (rather than reactively) should leave this off.
28
+ */
29
+ inlineVenueSwitch?: boolean
23
30
  children: ReactNode
24
31
  }
25
32
 
@@ -73,6 +80,7 @@ export function AppShell({
73
80
  headerActions,
74
81
  sidebarPanel,
75
82
  scrollable = true,
83
+ inlineVenueSwitch,
76
84
  children,
77
85
  }: Props) {
78
86
  const { theme, toggleTheme } = useTheme()
@@ -81,6 +89,16 @@ export function AppShell({
81
89
  const [currentHref, setCurrentHref] = useState(() => window.location.href)
82
90
  const [expanded, setExpanded] = useState<Set<string>>(() => new Set())
83
91
 
92
+ // When collapsed, the sidebar is a thin icon rail. Hovering (or focusing into) the
93
+ // nav reveals the full sidebar as an overlay drawer floating over the page content —
94
+ // so navigation stays usable without permanently reflowing the page. `railMode` is
95
+ // the visual "mini rail" state: collapsed AND the drawer is not currently revealed.
96
+ const [flyoutOpen, setFlyoutOpen] = useState(false)
97
+ const railMode = collapsed && !flyoutOpen
98
+ const asideRef = useRef<HTMLElement>(null)
99
+ const openTimer = useRef<ReturnType<typeof setTimeout>>()
100
+ const closeTimer = useRef<ReturnType<typeof setTimeout>>()
101
+
84
102
  useEffect(() => {
85
103
  ensureHistoryPatched()
86
104
  function onLocationChange() { setCurrentHref(window.location.href) }
@@ -92,10 +110,54 @@ export function AppShell({
92
110
  }
93
111
  }, [])
94
112
 
113
+ function clearFlyoutTimers() {
114
+ if (openTimer.current) clearTimeout(openTimer.current)
115
+ if (closeTimer.current) clearTimeout(closeTimer.current)
116
+ openTimer.current = undefined
117
+ closeTimer.current = undefined
118
+ }
119
+
120
+ useEffect(() => clearFlyoutTimers, [])
121
+
122
+ const FLYOUT_DELAY = 150
123
+
124
+ function scheduleOpen() {
125
+ if (!collapsed) return
126
+ clearFlyoutTimers()
127
+ openTimer.current = setTimeout(() => setFlyoutOpen(true), FLYOUT_DELAY)
128
+ }
129
+
130
+ function scheduleClose() {
131
+ clearFlyoutTimers()
132
+ closeTimer.current = setTimeout(() => setFlyoutOpen(false), FLYOUT_DELAY)
133
+ }
134
+
135
+ function closeFlyoutNow() {
136
+ clearFlyoutTimers()
137
+ setFlyoutOpen(false)
138
+ }
139
+
140
+ function openFlyout() {
141
+ if (!collapsed) return
142
+ clearFlyoutTimers()
143
+ setFlyoutOpen(true)
144
+ }
145
+
146
+ function onFocusIn() {
147
+ openFlyout()
148
+ }
149
+
150
+ function onFocusOut(event: FocusEvent<HTMLElement>) {
151
+ const next = event.relatedTarget as Node | null
152
+ if (next && asideRef.current?.contains(next)) return
153
+ closeFlyoutNow()
154
+ }
155
+
95
156
  function toggleCollapse() {
96
157
  const next = !collapsed
97
158
  setCollapsed(next)
98
159
  writeSidebarCookie(next, cookieDomain)
160
+ closeFlyoutNow()
99
161
  }
100
162
 
101
163
  const activeVenue = useMemo(() => venues.find((v) => v.id === activeVenueId), [venues, activeVenueId])
@@ -147,13 +209,15 @@ export function AppShell({
147
209
  return groups
148
210
  }, [venues])
149
211
 
150
- const activeNavUrl = useMemo(() => {
212
+ const activeNavItem = useMemo(() => {
151
213
  const matches = navItems
152
214
  .filter(item => item.url && currentHref.startsWith(item.url))
153
215
  .sort((a, b) => b.url.length - a.url.length)
154
- return matches[0]?.url ?? null
216
+ return matches[0] ?? null
155
217
  }, [navItems, currentHref])
156
218
 
219
+ const activeNavUrl = activeNavItem?.url ?? null
220
+
157
221
  function toggleWorkspace(id: string) {
158
222
  setExpanded((prev) => {
159
223
  const next = new Set(prev)
@@ -173,19 +237,37 @@ export function AppShell({
173
237
  }
174
238
 
175
239
  function onVenueClick(venueId: string) {
176
- if (venueId === activeVenueId) return
177
- onSwitchVenue?.(venueId)
178
- const url = firstHeaderItem?.url
240
+ // Stay within the current venue/workspace-scoped app (heatmap, flow builder,
241
+ // venue/workspace settings) when switching venue, instead of always jumping to
242
+ // the heatmap. From the navigational hubs (Portfolio/Dashboard) we still drill
243
+ // into the venue's heatmap — the first header tool.
244
+ const stayHere = !!activeNavItem && (placementOf(activeNavItem) === 'header' || placementOf(activeNavItem) === 'settings')
245
+ const url = stayHere ? activeNavItem!.url : firstHeaderItem?.url
246
+ const alreadyOnDestination = url ? currentHref.startsWith(url) : false
247
+ if (venueId === activeVenueId && alreadyOnDestination) return
248
+ if (venueId !== activeVenueId) onSwitchVenue?.(venueId)
249
+ // If the consumer applies the venue switch inline and we'd only be reloading the
250
+ // page we're already on, skip the disruptive full-page reload.
251
+ if (inlineVenueSwitch && alreadyOnDestination) return
179
252
  if (url) window.location.assign(url)
180
253
  }
181
254
 
182
- const showHeader = headerNavItems.length > 0 || settingsNavItems.length > 0 || headerActions !== undefined || headerSlot !== undefined
255
+ const showHeader = headerNavItems.length > 0 || settingsNavItems.length > 0 || headerActions !== undefined || headerSlot !== undefined || (collapsed && !!activeVenue)
183
256
 
184
257
  return (
185
258
  <div className="rv-app-shell">
186
- <aside className={`rv-sidebar${collapsed ? ' rv-collapsed' : ''}`}>
259
+ {/* Holds the rail's width in the layout flow while the real sidebar floats over the page. */}
260
+ {collapsed && <div className="rv-sidebar-rail-spacer" />}
261
+ <aside
262
+ ref={asideRef}
263
+ className={`rv-sidebar${railMode ? ' rv-collapsed' : ''}${collapsed ? ' rv-floating' : ''}${collapsed && flyoutOpen ? ' rv-flyout' : ''}`}
264
+ onMouseLeave={scheduleClose}
265
+ onFocus={onFocusIn}
266
+ onBlur={onFocusOut}
267
+ onKeyDown={(e) => { if (e.key === 'Escape') closeFlyoutNow() }}
268
+ >
187
269
  <div className="rv-sidebar-top">
188
- {!collapsed && (
270
+ {!railMode && (
189
271
  <div className="rv-sidebar-brand">
190
272
  <svg
191
273
  className="rv-sidebar-logo"
@@ -231,70 +313,88 @@ export function AppShell({
231
313
  </button>
232
314
  </div>
233
315
 
234
- {sidebarPanel && <div className="rv-sidebar-panel">{sidebarPanel}</div>}
316
+ {sidebarPanel && <div className="rv-sidebar-panel" onMouseEnter={scheduleOpen}>{sidebarPanel}</div>}
235
317
 
236
318
  {sidebarNavItems.length > 0 && (
237
- <nav className="rv-sidebar-top-nav">
319
+ <nav className="rv-sidebar-top-nav" onMouseEnter={scheduleOpen}>
238
320
  {sidebarNavItems.map((item) => (
239
321
  <a
240
322
  key={item.url}
241
323
  href={item.url}
242
324
  className={`rv-nav-item${item.url === activeNavUrl ? ' rv-active' : ''}`}
243
- title={collapsed ? item.label : undefined}
325
+ title={railMode ? item.label : undefined}
244
326
  >
245
327
  <span className="rv-nav-icon" dangerouslySetInnerHTML={{ __html: item.icon }} />
246
- {!collapsed && <span className="rv-nav-label">{item.label}</span>}
328
+ {!railMode && <span className="rv-nav-label">{item.label}</span>}
247
329
  </a>
248
330
  ))}
249
331
  </nav>
250
332
  )}
251
333
 
252
- <div className="rv-sidebar-tree">
253
- {!collapsed && tree.length > 0 && <div className="rv-tree-section-label">Workspaces &amp; venues</div>}
254
- {tree.map((ws) => (
255
- <div key={ws.id} className="rv-tree-group">
256
- <div className="rv-tree-ws" title={collapsed ? ws.name : undefined}>
257
- {!collapsed && (
258
- <button
259
- className={`rv-tree-disclosure${expanded.has(ws.id) ? ' rv-open' : ''}`}
260
- aria-label={expanded.has(ws.id) ? 'Collapse workspace' : 'Expand workspace'}
261
- onClick={(e) => { e.stopPropagation(); toggleWorkspace(ws.id) }}
262
- >
263
- <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
264
- <polyline points="6 9 12 15 18 9" />
265
- </svg>
266
- </button>
267
- )}
268
- <button className="rv-tree-ws-title" onClick={() => onWorkspaceTitleClick(ws.id)}>
334
+ <div className="rv-sidebar-tree" onMouseEnter={scheduleOpen}>
335
+ {railMode ? (
336
+ /* Collapsed rail: a single workspace icon stands in for the whole tree (hover/click reveals it). */
337
+ tree.length > 0 && (
338
+ <div className="rv-tree-ws">
339
+ <button
340
+ className="rv-tree-ws-title"
341
+ title="Workspaces & venues"
342
+ aria-label="Show workspaces and venues"
343
+ onClick={openFlyout}
344
+ >
269
345
  <svg className="rv-tree-ws-icon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
270
346
  <path d="M3 21h18" /><path d="M5 21V7l7-4 7 4v14" /><path d="M9 9h.01M15 9h.01M9 13h.01M15 13h.01M9 17h.01M15 17h.01" />
271
347
  </svg>
272
- {!collapsed && <span className="rv-tree-ws-name">{ws.name}</span>}
273
348
  </button>
274
349
  </div>
275
- {!collapsed && expanded.has(ws.id) && (
276
- <div className="rv-tree-venues">
277
- {ws.venues.map((venue) => (
350
+ )
351
+ ) : (
352
+ <>
353
+ {tree.length > 0 && <div className="rv-tree-section-label">Workspaces &amp; venues</div>}
354
+ {tree.map((ws) => (
355
+ <div key={ws.id} className="rv-tree-group">
356
+ <div className="rv-tree-ws">
278
357
  <button
279
- key={venue.id}
280
- className={`rv-tree-venue${venue.id === activeVenueId ? ' rv-active' : ''}`}
281
- onClick={() => onVenueClick(venue.id)}
358
+ className={`rv-tree-disclosure${expanded.has(ws.id) ? ' rv-open' : ''}`}
359
+ aria-label={expanded.has(ws.id) ? 'Collapse workspace' : 'Expand workspace'}
360
+ onClick={(e) => { e.stopPropagation(); toggleWorkspace(ws.id) }}
282
361
  >
283
362
  <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
284
- <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" /><circle cx="12" cy="10" r="3" />
363
+ <polyline points="6 9 12 15 18 9" />
364
+ </svg>
365
+ </button>
366
+ <button className="rv-tree-ws-title" onClick={() => onWorkspaceTitleClick(ws.id)}>
367
+ <svg className="rv-tree-ws-icon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
368
+ <path d="M3 21h18" /><path d="M5 21V7l7-4 7 4v14" /><path d="M9 9h.01M15 9h.01M9 13h.01M15 13h.01M9 17h.01M15 17h.01" />
285
369
  </svg>
286
- <span className="rv-tree-venue-name">{venue.name}</span>
370
+ <span className="rv-tree-ws-name">{ws.name}</span>
287
371
  </button>
288
- ))}
372
+ </div>
373
+ {expanded.has(ws.id) && (
374
+ <div className="rv-tree-venues">
375
+ {ws.venues.map((venue) => (
376
+ <button
377
+ key={venue.id}
378
+ className={`rv-tree-venue${venue.id === activeVenueId ? ' rv-active' : ''}`}
379
+ onClick={() => onVenueClick(venue.id)}
380
+ >
381
+ <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
382
+ <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" /><circle cx="12" cy="10" r="3" />
383
+ </svg>
384
+ <span className="rv-tree-venue-name">{venue.name}</span>
385
+ </button>
386
+ ))}
387
+ </div>
388
+ )}
289
389
  </div>
290
- )}
291
- </div>
292
- ))}
390
+ ))}
391
+ </>
392
+ )}
293
393
  </div>
294
394
 
295
- <div className="rv-sidebar-user">
395
+ <div className="rv-sidebar-user" onMouseEnter={scheduleOpen}>
296
396
  <div className="rv-user-avatar">{userInitials}</div>
297
- {!collapsed && (
397
+ {!railMode && (
298
398
  <div className="rv-user-info">
299
399
  <span className="rv-user-email" title={user?.email ?? ''}>{user?.email}</span>
300
400
  </div>
@@ -314,7 +414,7 @@ export function AppShell({
314
414
  )}
315
415
  </button>
316
416
  )}
317
- {accountSettingsUrl && (
417
+ {accountSettingsUrl && !railMode && (
318
418
  <a className="rv-account-settings-btn" href={accountSettingsUrl} title="Account settings">
319
419
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
320
420
  <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" />
@@ -322,6 +422,7 @@ export function AppShell({
322
422
  </svg>
323
423
  </a>
324
424
  )}
425
+ {!railMode && (
325
426
  <button className="rv-logout-btn" title="Sign out" onClick={() => setShowLogoutConfirm(true)}>
326
427
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
327
428
  <path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
@@ -329,12 +430,22 @@ export function AppShell({
329
430
  <line x1="21" y1="12" x2="9" y2="12" />
330
431
  </svg>
331
432
  </button>
433
+ )}
332
434
  </div>
333
435
  </aside>
334
436
 
335
437
  <div className="rv-shell-body">
336
438
  {showHeader && (
337
439
  <header className="rv-shell-header">
440
+ {/* When collapsed the active venue isn't named in the rail, so surface it here. */}
441
+ {collapsed && activeVenue && (
442
+ <div className="rv-header-venue" title={activeVenue.name}>
443
+ <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
444
+ <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" /><circle cx="12" cy="10" r="3" />
445
+ </svg>
446
+ <span className="rv-header-venue-name">{activeVenue.name}</span>
447
+ </div>
448
+ )}
338
449
  {headerNavItems.length > 0 && (
339
450
  <nav className="rv-header-nav">
340
451
  {headerNavItems.map((item) => (
@@ -2,9 +2,16 @@
2
2
  display: flex;
3
3
  height: 100dvh;
4
4
  overflow: hidden;
5
+ position: relative;
5
6
  font-family: 'Host Grotesk', system-ui, sans-serif;
6
7
  }
7
8
 
9
+ /* Reserves the collapsed rail's width in the flex flow while the real sidebar floats over the content. */
10
+ .rv-sidebar-rail-spacer {
11
+ width: 56px;
12
+ flex-shrink: 0;
13
+ }
14
+
8
15
  .rv-sidebar {
9
16
  width: 280px;
10
17
  flex-shrink: 0;
@@ -12,7 +19,7 @@
12
19
  flex-direction: column;
13
20
  background: var(--color-bg-panel, #ffffff);
14
21
  border-right: 1px solid var(--color-border-subtle, #d1d5db);
15
- transition: width var(--transition-slow, 0.25s ease);
22
+ transition: width var(--transition-slow, 0.25s ease), box-shadow var(--transition-fast, 0.1s ease);
16
23
  overflow: hidden;
17
24
  }
18
25
 
@@ -20,6 +27,22 @@
20
27
  width: 56px;
21
28
  }
22
29
 
30
+ /* Collapsed: lift out of flow and float over the page (the spacer holds the layout width). */
31
+ .rv-sidebar.rv-floating {
32
+ position: absolute;
33
+ top: 0;
34
+ left: 0;
35
+ bottom: 0;
36
+ z-index: 50;
37
+ width: 56px;
38
+ }
39
+
40
+ /* Hover/focus reveal: expand the floating panel over the content without reflowing it. */
41
+ .rv-sidebar.rv-floating.rv-flyout {
42
+ width: 280px;
43
+ box-shadow: 4px 0 24px rgba(0, 0, 0, 0.16);
44
+ }
45
+
23
46
  .rv-sidebar.rv-collapsed .rv-sidebar-top {
24
47
  justify-content: center;
25
48
  padding: 0;
@@ -314,6 +337,10 @@
314
337
  text-transform: uppercase;
315
338
  color: var(--color-text-muted, #777777);
316
339
  padding: 0.375rem 0.625rem 0.25rem;
340
+ /* Keep on one line so it clips (rather than wraps + reflows) while the width animates. */
341
+ white-space: nowrap;
342
+ overflow: hidden;
343
+ text-overflow: ellipsis;
317
344
  }
318
345
 
319
346
  .rv-tree-group {
@@ -450,6 +477,51 @@
450
477
  white-space: nowrap;
451
478
  }
452
479
 
480
+ /* Active venue label (shown in the header when the sidebar is collapsed) */
481
+ .rv-header-venue {
482
+ display: flex;
483
+ align-items: center;
484
+ gap: 0.4375rem;
485
+ padding-right: 1.75rem;
486
+ margin-right: 0.5rem;
487
+ border-right: 1px solid var(--color-border-subtle, #d1d5db);
488
+ font-size: 0.875rem;
489
+ font-weight: 600;
490
+ color: var(--color-text-primary, #111111);
491
+ white-space: nowrap;
492
+ min-width: 0;
493
+ /* Plays on mount, i.e. when the sidebar collapses and the label appears. */
494
+ animation: rv-header-venue-in var(--transition-slow, 0.25s) ease both;
495
+ }
496
+
497
+ @keyframes rv-header-venue-in {
498
+ from {
499
+ opacity: 0;
500
+ transform: translateX(-10px);
501
+ }
502
+ to {
503
+ opacity: 1;
504
+ transform: translateX(0);
505
+ }
506
+ }
507
+
508
+ @media (prefers-reduced-motion: reduce) {
509
+ .rv-header-venue {
510
+ animation: none;
511
+ }
512
+ }
513
+
514
+ .rv-header-venue svg {
515
+ flex-shrink: 0;
516
+ color: var(--color-text-muted, #777777);
517
+ }
518
+
519
+ .rv-header-venue-name {
520
+ overflow: hidden;
521
+ text-overflow: ellipsis;
522
+ max-width: 220px;
523
+ }
524
+
453
525
  /* Header nav (top-bar tool buttons) */
454
526
  .rv-header-nav {
455
527
  display: flex;