@justanarthur/modo-ui-notch 0.0.0-stage → 0.2.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 (136) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -2
  3. package/blocks/activities/agenda/examples.mdx +58 -0
  4. package/blocks/activities/agenda/index.tsx +332 -0
  5. package/blocks/activities/now-playing/examples.mdx +49 -0
  6. package/blocks/activities/now-playing/index.tsx +218 -0
  7. package/blocks/activities/shelf/examples.mdx +33 -0
  8. package/blocks/activities/shelf/index.tsx +289 -0
  9. package/blocks/activities/timer/examples.mdx +52 -0
  10. package/blocks/activities/timer/index.tsx +292 -0
  11. package/blocks/app/expanded-island/examples.mdx +45 -0
  12. package/blocks/app/expanded-island/index.tsx +127 -0
  13. package/blocks/app/settings-window/examples.mdx +30 -0
  14. package/blocks/app/settings-window/index.tsx +357 -0
  15. package/blocks/system/controls/examples.mdx +34 -0
  16. package/blocks/system/controls/index.tsx +167 -0
  17. package/blocks/system/devices/examples.mdx +25 -0
  18. package/blocks/system/devices/index.tsx +172 -0
  19. package/blocks/system/power-alert/examples.mdx +32 -0
  20. package/blocks/system/power-alert/index.tsx +89 -0
  21. package/blocks/system/system-stats/examples.mdx +23 -0
  22. package/blocks/system/system-stats/index.tsx +178 -0
  23. package/components/indicators/battery-glyph/examples.mdx +22 -0
  24. package/components/indicators/battery-glyph/index.tsx +91 -0
  25. package/components/indicators/countdown/examples.mdx +25 -0
  26. package/components/indicators/countdown/index.tsx +83 -0
  27. package/components/indicators/equalizer/examples.mdx +20 -0
  28. package/components/indicators/equalizer/index.tsx +116 -0
  29. package/components/indicators/media-scrubber/examples.mdx +21 -0
  30. package/components/indicators/media-scrubber/index.tsx +98 -0
  31. package/components/island/island/examples.mdx +57 -0
  32. package/components/island/island/index.tsx +415 -0
  33. package/components/island/island-flash/examples.mdx +55 -0
  34. package/components/island/island-flash/index.tsx +79 -0
  35. package/components/island/island-tabs/examples.mdx +53 -0
  36. package/components/island/island-tabs/index.tsx +285 -0
  37. package/dist/blocks/activities/agenda/index.d.ts +2 -0
  38. package/dist/blocks/activities/agenda/index.js +21 -0
  39. package/dist/blocks/activities/now-playing/index.d.ts +2 -0
  40. package/dist/blocks/activities/now-playing/index.js +22 -0
  41. package/dist/blocks/activities/shelf/index.d.ts +2 -0
  42. package/dist/blocks/activities/shelf/index.js +14 -0
  43. package/dist/blocks/activities/timer/index.d.ts +2 -0
  44. package/dist/blocks/activities/timer/index.js +19 -0
  45. package/dist/blocks/app/expanded-island/index.d.ts +3 -0
  46. package/dist/blocks/app/expanded-island/index.js +10 -0
  47. package/dist/blocks/app/settings-window/index.d.ts +2 -0
  48. package/dist/blocks/app/settings-window/index.js +7 -0
  49. package/dist/blocks/system/controls/index.d.ts +2 -0
  50. package/dist/blocks/system/controls/index.js +10 -0
  51. package/dist/blocks/system/devices/index.d.ts +2 -0
  52. package/dist/blocks/system/devices/index.js +12 -0
  53. package/dist/blocks/system/power-alert/index.d.ts +2 -0
  54. package/dist/blocks/system/power-alert/index.js +9 -0
  55. package/dist/blocks/system/system-stats/index.d.ts +2 -0
  56. package/dist/blocks/system/system-stats/index.js +12 -0
  57. package/dist/components/indicators/battery-glyph/index.d.ts +2 -0
  58. package/dist/components/indicators/battery-glyph/index.js +9 -0
  59. package/dist/components/indicators/countdown/index.d.ts +2 -0
  60. package/dist/components/indicators/countdown/index.js +8 -0
  61. package/dist/components/indicators/equalizer/index.d.ts +2 -0
  62. package/dist/components/indicators/equalizer/index.js +7 -0
  63. package/dist/components/indicators/media-scrubber/index.d.ts +2 -0
  64. package/dist/components/indicators/media-scrubber/index.js +8 -0
  65. package/dist/components/island/island/index.d.ts +3 -0
  66. package/dist/components/island/island/index.js +10 -0
  67. package/dist/components/island/island-flash/index.d.ts +2 -0
  68. package/dist/components/island/island-flash/index.js +7 -0
  69. package/dist/components/island/island-tabs/index.d.ts +2 -0
  70. package/dist/components/island/island-tabs/index.js +9 -0
  71. package/dist/index.d.ts +21 -0
  72. package/dist/index.js +151 -0
  73. package/dist/lib/clock.d.ts +2 -0
  74. package/dist/lib/clock.js +14 -0
  75. package/dist/lib/geometry.d.ts +2 -0
  76. package/dist/lib/geometry.js +24 -0
  77. package/dist/lib/island-context.d.ts +3 -0
  78. package/dist/lib/island-context.js +8 -0
  79. package/dist/lib/motion.d.ts +21 -0
  80. package/dist/lib/motion.js +16 -0
  81. package/dist/shared/chunk-152gpyq3.d.ts +13 -0
  82. package/dist/shared/chunk-2f7zxrbk.js +65 -0
  83. package/dist/shared/chunk-2qpcsv5h.d.ts +45 -0
  84. package/dist/shared/chunk-2s4q6mt0.js +27 -0
  85. package/dist/shared/chunk-45gytfr1.d.ts +84 -0
  86. package/dist/shared/chunk-502rmtap.js +54 -0
  87. package/dist/shared/chunk-50ffk4r7.d.ts +69 -0
  88. package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
  89. package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
  90. package/dist/shared/chunk-5w0yck07.d.ts +32 -0
  91. package/dist/shared/chunk-6c1jbefs.d.ts +36 -0
  92. package/dist/shared/chunk-78w7qwp0.js +58 -0
  93. package/dist/shared/chunk-7hr53mby.js +116 -0
  94. package/dist/shared/chunk-9nhpg9t8.d.ts +47 -0
  95. package/dist/shared/chunk-b8jb1w72.js +145 -0
  96. package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
  97. package/dist/shared/chunk-cpewy6yg.js +178 -0
  98. package/dist/shared/chunk-d5qm9cps.js +10 -0
  99. package/dist/shared/chunk-e3e4s4ds.d.ts +77 -0
  100. package/dist/shared/chunk-enm6td0p.js +280 -0
  101. package/dist/shared/chunk-fvedaas2.d.ts +33 -0
  102. package/dist/shared/chunk-gb56m10p.js +39 -0
  103. package/dist/shared/chunk-gex38j8x.d.ts +82 -0
  104. package/dist/shared/chunk-hpsabfsd.d.ts +75 -0
  105. package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
  106. package/dist/shared/chunk-hwtxpzg0.js +69 -0
  107. package/dist/shared/chunk-mp1nx0ez.js +101 -0
  108. package/dist/shared/chunk-phb53x1f.js +252 -0
  109. package/dist/shared/chunk-r8esmjfs.d.ts +42 -0
  110. package/dist/shared/chunk-rcp1g9ca.js +70 -0
  111. package/dist/shared/chunk-rpfwv3pz.js +209 -0
  112. package/dist/shared/chunk-rr5e0g15.d.ts +35 -0
  113. package/dist/shared/chunk-rx9sphz2.js +266 -0
  114. package/dist/shared/chunk-s33y1pcq.js +305 -0
  115. package/dist/shared/chunk-sbnrhy5m.js +331 -0
  116. package/dist/shared/chunk-w48eyvfr.d.ts +56 -0
  117. package/dist/shared/chunk-wwjxs75m.js +74 -0
  118. package/dist/shared/chunk-xdeek16r.d.ts +58 -0
  119. package/dist/shared/chunk-xkzjk1tq.js +206 -0
  120. package/dist/shared/chunk-yngkkxz2.d.ts +88 -0
  121. package/dist/shared/chunk-zvh0d3qb.js +63 -0
  122. package/dist/styles.css +222 -0
  123. package/index.ts +21 -0
  124. package/lib/clock.ts +53 -0
  125. package/lib/geometry.ts +130 -0
  126. package/lib/island-context.tsx +24 -0
  127. package/lib/motion.ts +42 -0
  128. package/mock/activities.tsx +100 -0
  129. package/mock/artwork.tsx +25 -0
  130. package/mock/data.ts +153 -0
  131. package/mock/desktop.tsx +83 -0
  132. package/mock/fit.ts +26 -0
  133. package/mock/island-content.tsx +217 -0
  134. package/mock/scene.tsx +52 -0
  135. package/mock/settings.tsx +210 -0
  136. package/package.json +117 -4
package/mock/data.ts ADDED
@@ -0,0 +1,153 @@
1
+ /*
2
+ * Mock data for the docs: what a notch app's activities would report. Pages
3
+ * and examples read it; nothing here ships in the barrel.
4
+ */
5
+
6
+ import { Activity, CalendarDays, Files, Headphones, Music, SlidersHorizontal, Timer } from 'lucide-react'
7
+ import type { AgendaEvent } from '../blocks/activities/agenda'
8
+ import type { ShelfFile } from '../blocks/activities/shelf'
9
+ import type { DeviceInfo } from '../blocks/system/devices'
10
+ import type { StatsSample } from '../blocks/system/system-stats'
11
+ import type { IslandTab } from '../components/island/island-tabs'
12
+
13
+ export interface Track {
14
+ title: string
15
+ artist: string
16
+ album: string
17
+ source: string
18
+ /** Seconds. */
19
+ duration: number
20
+ /** Seconds. */
21
+ position: number
22
+ }
23
+
24
+ export const TRACK: Track = {
25
+ title: 'Midnight City',
26
+ artist: 'M83',
27
+ album: "Hurry Up, We're Dreaming",
28
+ source: 'Music',
29
+ duration: 243,
30
+ position: 71,
31
+ }
32
+
33
+ export const TRACKS: Track[] = [
34
+ TRACK,
35
+ { title: 'Teardrop', artist: 'Massive Attack', album: 'Mezzanine', source: 'Spotify', duration: 330, position: 12 },
36
+ { title: 'Nightcall', artist: 'Kavinsky', album: 'OutRun', source: 'Safari', duration: 258, position: 190 },
37
+ ]
38
+
39
+ export const POWER = { level: 82, charging: true, untilFull: 38, remaining: 252 }
40
+
41
+ export const TIMER = { label: 'Focus', minutes: 25 }
42
+
43
+ const MINUTE = 60_000
44
+ const at = (day: number, hours: number, minutes: number) => {
45
+ const date = new Date()
46
+ date.setDate(date.getDate() + day)
47
+ date.setHours(hours, minutes, 0, 0)
48
+ return date.getTime()
49
+ }
50
+
51
+ /** The moment the agenda is read at: today, 9:40. */
52
+ export const AGENDA_NOW = at(0, 9, 40)
53
+
54
+ // A calendar's color is data; here it reads modo-ui's badge palette, so it follows the theme.
55
+ export const EVENTS: AgendaEvent[] = [
56
+ {
57
+ id: 'offsite',
58
+ title: 'Team offsite',
59
+ start: at(0, 0, 0),
60
+ end: at(1, 0, 0),
61
+ allDay: true,
62
+ color: 'var(--badge-green)',
63
+ },
64
+ {
65
+ id: 'review',
66
+ title: 'Design review',
67
+ start: at(0, 10, 30),
68
+ end: at(0, 11, 15),
69
+ location: 'Studio 2',
70
+ color: 'var(--badge-blue)',
71
+ },
72
+ { id: 'lunch', title: 'Lunch with Ana', start: at(0, 12, 45), end: at(0, 13, 45), color: 'var(--badge-orange)' },
73
+ {
74
+ id: 'ship',
75
+ title: 'Ship the island kit',
76
+ start: at(0, 16, 0),
77
+ end: at(0, 16, 30),
78
+ meetingUrl: 'https://meet.example.com/ship',
79
+ color: 'var(--badge-violet)',
80
+ },
81
+ {
82
+ id: 'standup',
83
+ title: 'Standup',
84
+ start: at(1, 9, 30),
85
+ end: at(1, 9, 45),
86
+ meetingUrl: 'https://meet.example.com/standup',
87
+ color: 'var(--badge-blue)',
88
+ },
89
+ {
90
+ id: 'dentist',
91
+ title: 'Dentist',
92
+ start: at(1, 14, 0),
93
+ end: at(1, 15, 0),
94
+ location: 'Main St 12',
95
+ color: 'var(--badge-rose)',
96
+ },
97
+ ]
98
+
99
+ /** An event a few minutes out, for the "Up next" activity: it counts down for real. */
100
+ export function soonEvent(minutes = 4): AgendaEvent {
101
+ const start = Date.now() + minutes * MINUTE
102
+ return {
103
+ id: `soon-${minutes}`,
104
+ title: 'Design review',
105
+ start,
106
+ end: start + 45 * MINUTE,
107
+ location: 'Studio 2',
108
+ meetingUrl: 'https://meet.example.com/review',
109
+ color: 'var(--badge-blue)',
110
+ }
111
+ }
112
+
113
+ export const DEVICES: DeviceInfo[] = [
114
+ { id: 'airpods', name: 'AirPods Pro', kind: 'headphones', connected: true, battery: 74 },
115
+ { id: 'keyboard', name: 'Magic Keyboard', kind: 'keyboard', connected: true, battery: 18 },
116
+ { id: 'mouse', name: 'Magic Mouse', kind: 'mouse', connected: false },
117
+ { id: 'controller', name: 'DualSense', kind: 'gamepad', connected: true, battery: 56, charging: true },
118
+ { id: 'speaker', name: 'Living room', kind: 'speaker', connected: false },
119
+ ]
120
+
121
+ export const FILES: ShelfFile[] = [
122
+ { id: 'brief', name: 'Island brief.pdf' },
123
+ { id: 'cover', name: 'Cover.png' },
124
+ { id: 'notes', name: 'Notes.md' },
125
+ { id: 'demo', name: 'Demo.mov' },
126
+ { id: 'archive', name: 'Assets.zip' },
127
+ { id: 'theme', name: 'theme.ts' },
128
+ ]
129
+
130
+ const wave = (i: number, base: number, swing: number) =>
131
+ base + swing * Math.sin(i / 2.4) + swing * 0.4 * Math.sin(i * 1.7)
132
+
133
+ /** Thirty seconds of samples, oldest first. */
134
+ export const SAMPLES: StatsSample[] = Array.from({ length: 30 }, (_, i) => ({
135
+ cpu: Math.min(1, Math.max(0.02, wave(i, 0.32, 0.14))),
136
+ memoryUsed: wave(i, 11.2e9, 0.25e9),
137
+ memoryTotal: 16e9,
138
+ netIn: Math.max(0, wave(i, 2.4e6, 1.6e6)),
139
+ netOut: Math.max(0, wave(i + 5, 0.4e6, 0.3e6)),
140
+ }))
141
+
142
+ /** The open island's tabs: one per widget. */
143
+ export const TABS: IslandTab[] = [
144
+ { value: 'now-playing', label: 'Now Playing', icon: Music },
145
+ { value: 'timer', label: 'Timer', icon: Timer },
146
+ { value: 'calendar', label: 'Calendar', icon: CalendarDays },
147
+ { value: 'shelf', label: 'Shelf', icon: Files },
148
+ { value: 'controls', label: 'Controls', icon: SlidersHorizontal },
149
+ { value: 'devices', label: 'Devices', icon: Headphones },
150
+ { value: 'stats', label: 'System', icon: Activity },
151
+ ]
152
+
153
+ export const MENUS = ['Finder', 'File', 'Edit', 'View', 'Go', 'Window', 'Help']
@@ -0,0 +1,83 @@
1
+ /*!
2
+ * Mock: a Mac's screen for the docs, made only of tokens: a wallpaper, a menu
3
+ * bar as tall as the notch, and the island hanging from the top edge over it.
4
+ * It lays the screen out at a fixed size and scales it down to the width it
5
+ * gets (CSS zoom), so a whole desktop reads inside a docs column.
6
+ */
7
+
8
+ 'use client'
9
+
10
+ import { useShape } from '@justanarthur/modo-ui/lib/shape-context'
11
+ import { cn } from '@justanarthur/modo-ui/lib/utils'
12
+ import type { ReactNode } from 'react'
13
+ import { DEFAULT_NOTCH } from '../lib/geometry'
14
+ import { MENUS } from './data'
15
+ import { useFitScale } from './fit'
16
+
17
+ export interface MockDesktopProps {
18
+ /** The screen's width in px. Defaults to `1024`. */
19
+ width?: number
20
+ /** The screen's height in px. Defaults to `640`. */
21
+ height?: number
22
+ /** The menu bar's height: the notch's. Defaults to `32`. */
23
+ notchHeight?: number
24
+ /** The notch's width, kept free in the menu bar. Defaults to `185`. */
25
+ notchWidth?: number
26
+ /** The app named first in the menu bar. Defaults to `'Finder'`. */
27
+ app?: string
28
+ /** The clock at the right end. Defaults to `'Mon 16 Nov 13:05'`. */
29
+ clock?: string
30
+ /** The island, hung from the top edge across the screen's width. */
31
+ island?: ReactNode
32
+ /** Anything else on the desktop, under the menu bar. */
33
+ children?: ReactNode
34
+ className?: string
35
+ }
36
+
37
+ export function MockDesktop({
38
+ width = 1024,
39
+ height = 640,
40
+ notchHeight = DEFAULT_NOTCH.height,
41
+ notchWidth = DEFAULT_NOTCH.width,
42
+ app = 'Finder',
43
+ clock = 'Mon 16 Nov 13:05',
44
+ island,
45
+ children,
46
+ className,
47
+ }: MockDesktopProps) {
48
+ const shape = useShape()
49
+ const { outer, scale } = useFitScale(width)
50
+
51
+ return (
52
+ <div ref={outer} className="w-full" style={{ height: height * scale }}>
53
+ <div
54
+ className={cn(
55
+ 'relative overflow-hidden border border-border bg-linear-to-br from-brand/30 via-surface-2 to-status-info/25',
56
+ shape.container,
57
+ className,
58
+ )}
59
+ style={{ width, height, zoom: scale }}
60
+ >
61
+ <div
62
+ className="absolute inset-x-0 top-0 flex items-center bg-background/70 text-caption text-foreground"
63
+ style={{ height: notchHeight }}
64
+ >
65
+ <div className="flex flex-1 items-center gap-4 px-4">
66
+ <span className="weight-semibold">{app}</span>
67
+ {MENUS.slice(1).map(menu => (
68
+ <span key={menu}>{menu}</span>
69
+ ))}
70
+ </div>
71
+ <div aria-hidden className="shrink-0" style={{ width: notchWidth }} />
72
+ <div className="flex flex-1 items-center justify-end gap-4 px-4 tabular-nums">
73
+ <span>{clock}</span>
74
+ </div>
75
+ </div>
76
+ <div className="absolute inset-x-0 bottom-0" style={{ top: notchHeight }}>
77
+ {children}
78
+ </div>
79
+ <div className="absolute inset-x-0 top-0">{island}</div>
80
+ </div>
81
+ </div>
82
+ )
83
+ }
package/mock/fit.ts ADDED
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Mock: scale a fixed-size stage down to the width it gets (CSS zoom, as the
3
+ * docs' bento previews do), so a screen keeps its proportions in a narrow
4
+ * column. Never above 1:1.
5
+ */
6
+
7
+ 'use client'
8
+
9
+ import { useLayoutEffect, useRef, useState } from 'react'
10
+
11
+ export function useFitScale(width: number) {
12
+ const outer = useRef<HTMLDivElement | null>(null)
13
+ const [scale, setScale] = useState(1)
14
+
15
+ useLayoutEffect(() => {
16
+ const el = outer.current
17
+ if (!el) return
18
+ const observer = new ResizeObserver(([entry]) => {
19
+ if (entry) setScale(Math.min(1, entry.contentRect.width / width))
20
+ })
21
+ observer.observe(el)
22
+ return () => observer.disconnect()
23
+ }, [width])
24
+
25
+ return { outer, scale }
26
+ }
@@ -0,0 +1,217 @@
1
+ /*!
2
+ * Mock: what the docs put in the island, on the kit's blocks and mock data:
3
+ * the now-playing wings, a timer bubble, a charging flash and the open
4
+ * island with a tab per widget. Pages and examples start from these; nothing
5
+ * here ships in the barrel.
6
+ */
7
+
8
+ 'use client'
9
+
10
+ import Tabs from '@justanarthur/modo-ui/components/navigation/tabs'
11
+ import { useSize } from '@justanarthur/modo-ui/lib/size-context'
12
+ import { type ReactNode, useState } from 'react'
13
+ import Agenda from '../blocks/activities/agenda'
14
+ import NowPlaying, { type NowPlayingTrack } from '../blocks/activities/now-playing'
15
+ import Shelf, { type ShelfFile } from '../blocks/activities/shelf'
16
+ import Timer, { type TimerRun } from '../blocks/activities/timer'
17
+ import ExpandedIsland, { type ExpandedIslandTab } from '../blocks/app/expanded-island'
18
+ import Controls from '../blocks/system/controls'
19
+ import Devices from '../blocks/system/devices'
20
+ import PowerAlert from '../blocks/system/power-alert'
21
+ import SystemStats from '../blocks/system/system-stats'
22
+ import Island from '../components/island/island'
23
+ import { ISLAND_STATES, type IslandState } from '../lib/geometry'
24
+ import { MockArtwork } from './artwork'
25
+ import { AGENDA_NOW, DEVICES, EVENTS, FILES, POWER, SAMPLES, TABS, TIMER, TRACK } from './data'
26
+ import { useFitScale } from './fit'
27
+
28
+ const MINUTE = 60_000
29
+
30
+ /** The mock track, with generated artwork. */
31
+ export const PLAYING: NowPlayingTrack = { ...TRACK, artwork: <MockArtwork /> }
32
+
33
+ /** The mock shelf, two files with previews. */
34
+ export const SHELF: ShelfFile[] = FILES.map(file =>
35
+ file.id === 'cover'
36
+ ? { ...file, thumbnail: <MockArtwork variant="dusk" /> }
37
+ : file.id === 'demo'
38
+ ? { ...file, thumbnail: <MockArtwork variant="night" /> }
39
+ : file,
40
+ )
41
+
42
+ /** A focus run with `left` of its length to go, from now. */
43
+ export function focusRun(left = 0.62, minutes = TIMER.minutes): TimerRun {
44
+ return { kind: 'focus', total: minutes * MINUTE, endsAt: Date.now() + left * minutes * MINUTE }
45
+ }
46
+
47
+ /** A run made once, when the component mounts, so it keeps counting down across renders. */
48
+ export function useRun(left?: number) {
49
+ return useState(() => focusRun(left))[0]
50
+ }
51
+
52
+ /** The now-playing glyph for the compact island's left wing. */
53
+ export function ArtworkTile() {
54
+ return <NowPlaying.Leading track={PLAYING} />
55
+ }
56
+
57
+ /** The timer's ring for the split bubble. */
58
+ export function TimerBubble() {
59
+ return <Timer.Minimal run={useRun()} />
60
+ }
61
+
62
+ /** The charging alert, for the island's `flash`. */
63
+ export function ChargingFlash() {
64
+ return <PowerAlert kind="charging" level={POWER.level} minutes={POWER.untilFull} />
65
+ }
66
+
67
+ /** Every widget of the open island, by tab value. */
68
+ export function widgetFor(tab: string): ReactNode {
69
+ if (tab === 'now-playing') return <NowPlaying track={PLAYING} />
70
+ if (tab === 'timer') return <Timer />
71
+ if (tab === 'calendar') return <Agenda events={EVENTS} now={AGENDA_NOW} />
72
+ if (tab === 'shelf') return <Shelf defaultValue={SHELF} onAirDrop={() => {}} />
73
+ if (tab === 'controls')
74
+ return <Controls defaultValue={{ volume: 0.6, brightness: 0.8, keyboard: 0.35 }} output="MacBook Pro Speakers" />
75
+ if (tab === 'devices') return <Devices devices={DEVICES} />
76
+ if (tab === 'stats') return <SystemStats samples={SAMPLES} />
77
+ return null
78
+ }
79
+
80
+ const WIDGET_TABS: ExpandedIslandTab[] = TABS.map(tab => ({ ...tab, content: widgetFor(tab.value) }))
81
+
82
+ /** The open island's tabs, a view per widget, with `views` in place of the mock ones. */
83
+ export function panelTabs(views: Record<string, ReactNode> = {}): ExpandedIslandTab[] {
84
+ return WIDGET_TABS.map(tab => (tab.value in views ? { ...tab, content: views[tab.value] } : tab))
85
+ }
86
+
87
+ /** The open island: a tab per widget in the wings, settings at the far right. */
88
+ export function ExpandedPanel({ defaultTab = 'now-playing' }: { defaultTab?: string }) {
89
+ return <ExpandedIsland tabs={WIDGET_TABS} defaultValue={defaultTab} onSettings={() => {}} />
90
+ }
91
+
92
+ type DemoIslandProps = Omit<
93
+ React.ComponentProps<typeof Island>,
94
+ 'leading' | 'trailing' | 'minimal' | 'flash' | 'expanded'
95
+ > & { defaultTab?: string }
96
+
97
+ /** Every slot filled, so any state shows something: the docs' island. */
98
+ export function DemoIsland({ defaultTab, ...props }: DemoIslandProps) {
99
+ return (
100
+ <Island
101
+ leading={<ArtworkTile />}
102
+ trailing={<NowPlaying.Trailing />}
103
+ minimal={<TimerBubble />}
104
+ flash={<ChargingFlash />}
105
+ expanded={<ExpandedPanel defaultTab={defaultTab} />}
106
+ activity="now-playing"
107
+ {...props}
108
+ />
109
+ )
110
+ }
111
+
112
+ const STATE_LABEL: Record<IslandState, string> = {
113
+ idle: 'Idle',
114
+ compact: 'Compact',
115
+ split: 'Split',
116
+ expanded: 'Expanded',
117
+ flash: 'Flash',
118
+ }
119
+
120
+ /** A strip of screen edge with the island hanging from it, and the five states to pick from below. */
121
+ export function IslandPlayground({ defaultState = 'compact' }: { defaultState?: IslandState }) {
122
+ const [state, setState] = useState<IslandState>(defaultState)
123
+ const size = useSize()
124
+ return (
125
+ <div className="flex w-full flex-col items-center gap-4">
126
+ <ScreenEdge>
127
+ <DemoIsland state={state} onStateChange={setState} expandOnHover />
128
+ </ScreenEdge>
129
+ <Tabs variant="subtle" value={state} onValueChange={v => setState(v as IslandState)} size={size.variant}>
130
+ <Tabs.List className="max-w-full overflow-x-auto scrollbar-hide">
131
+ {ISLAND_STATES.map(s => (
132
+ <Tabs.Item key={s} value={s} label={STATE_LABEL[s]} />
133
+ ))}
134
+ </Tabs.List>
135
+ </Tabs>
136
+ </div>
137
+ )
138
+ }
139
+
140
+ /**
141
+ * The top of a screen: a band the island hangs from, tall enough for what it
142
+ * shows. Narrower than `width`, it scales down whole, so the island keeps the
143
+ * proportions it has on a Mac.
144
+ */
145
+ export function ScreenEdge({
146
+ children,
147
+ height = 360,
148
+ width = 760,
149
+ }: {
150
+ children: ReactNode
151
+ height?: number
152
+ width?: number
153
+ }) {
154
+ const { outer, scale } = useFitScale(width)
155
+ return (
156
+ <div ref={outer} className="w-full" style={{ height: height * scale }}>
157
+ <div
158
+ className="relative mx-auto overflow-hidden rounded-box bg-sunken"
159
+ style={{ width: scale < 1 ? width : '100%', maxWidth: width, height, zoom: scale }}
160
+ >
161
+ {children}
162
+ </div>
163
+ </div>
164
+ )
165
+ }
166
+
167
+ /** The open island on a strip of screen, on `tab`, its view replaced by `children` when given. */
168
+ export function WidgetIsland({ tab, children, height = 340 }: { tab: string; children?: ReactNode; height?: number }) {
169
+ const tabs = panelTabs(children ? { [tab]: children } : {})
170
+ return (
171
+ <ScreenEdge height={height}>
172
+ <Island
173
+ defaultState="expanded"
174
+ collapsedState="idle"
175
+ expanded={<ExpandedIsland tabs={tabs} defaultValue={tab} onSettings={() => {}} />}
176
+ />
177
+ </ScreenEdge>
178
+ )
179
+ }
180
+
181
+ /** A flash below the notch, on a strip of screen. */
182
+ export function FlashIsland({ children, activity }: { children: ReactNode; activity?: string }) {
183
+ return (
184
+ <ScreenEdge height={112}>
185
+ <Island defaultState="flash" collapsedState="idle" flash={children} activity={activity} />
186
+ </ScreenEdge>
187
+ )
188
+ }
189
+
190
+ /** An activity in the compact island's wings, with a second one's bubble when `minimal` is given. */
191
+ export function WingsIsland({
192
+ leading,
193
+ trailing,
194
+ minimal,
195
+ }: {
196
+ leading: ReactNode
197
+ trailing: ReactNode
198
+ minimal?: ReactNode
199
+ }) {
200
+ return (
201
+ <ScreenEdge height={64}>
202
+ <Island defaultState={minimal ? 'split' : 'compact'} leading={leading} trailing={trailing} minimal={minimal} />
203
+ </ScreenEdge>
204
+ )
205
+ }
206
+
207
+ /** Lays `children` out at `width` and scales them down whole when the column is narrower. */
208
+ export function Fit({ width, children }: { width: number; children: ReactNode }) {
209
+ const { outer, scale } = useFitScale(width)
210
+ return (
211
+ <div ref={outer} className="flex w-full justify-center">
212
+ <div className="shrink-0" style={{ width: scale < 1 ? width : '100%', maxWidth: width, zoom: scale }}>
213
+ {children}
214
+ </div>
215
+ </div>
216
+ )
217
+ }
package/mock/scene.tsx ADDED
@@ -0,0 +1,52 @@
1
+ /*!
2
+ * Mock: a desktop with the island and a strip of scenes to pick under it,
3
+ * the frame of the docs' app-screen pages. Nothing here ships in the barrel.
4
+ */
5
+
6
+ 'use client'
7
+
8
+ import Tabs from '@justanarthur/modo-ui/components/navigation/tabs'
9
+ import type { ReactNode } from 'react'
10
+ import { MockDesktop } from './desktop'
11
+
12
+ export interface Scene {
13
+ value: string
14
+ label: string
15
+ }
16
+
17
+ interface SceneDeskProps {
18
+ /** The scenes to pick from. */
19
+ scenes: Scene[]
20
+ /** The scene shown. */
21
+ value: string
22
+ /** Called with the scene picked. */
23
+ onValueChange: (value: string) => void
24
+ /** The island, hung from the desktop's top edge. */
25
+ island: ReactNode
26
+ /** The desktop's height in px. Defaults to `520`. */
27
+ height?: number
28
+ /** The app named first in the menu bar. */
29
+ app?: string
30
+ /** Show the scenes under the screen. Defaults to `true`. */
31
+ picker?: boolean
32
+ }
33
+
34
+ /** A desktop with the island, and the scenes as subtle tabs under it; the strip scrolls sideways when it runs out of room. */
35
+ export function SceneDesk({ scenes, value, onValueChange, island, height = 520, app, picker = true }: SceneDeskProps) {
36
+ return (
37
+ <div className="flex w-full min-w-0 flex-col items-center gap-4">
38
+ <MockDesktop height={height} app={app} island={island} />
39
+ {picker && (
40
+ <div className="scroll-fade-x w-full overflow-x-auto scrollbar-hide">
41
+ <Tabs variant="subtle" value={value} onValueChange={onValueChange} className="mx-auto w-max">
42
+ <Tabs.List>
43
+ {scenes.map(scene => (
44
+ <Tabs.Item key={scene.value} value={scene.value} label={scene.label} />
45
+ ))}
46
+ </Tabs.List>
47
+ </Tabs>
48
+ </div>
49
+ )}
50
+ </div>
51
+ )
52
+ }