@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
@@ -0,0 +1,292 @@
1
+ /*!
2
+ * Local addition: a notch app's timer, from picking a length to "Time's up".
3
+ * Rebuilt from Just Notch's timer plugin (`Picker`, `Running`, `Ring`,
4
+ * `TimeUp`) as presentational parts: the run is a value the host may own.
5
+ */
6
+
7
+ 'use client'
8
+
9
+ import Button from '@justanarthur/modo-ui/components/actions/button'
10
+ import Meter from '@justanarthur/modo-ui/components/feedback/meter'
11
+ import NumberInput from '@justanarthur/modo-ui/components/inputs/number-input'
12
+ import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
13
+ import { cn } from '@justanarthur/modo-ui/lib/utils'
14
+ import { Pause, Play, Plus, Timer as TimerIcon, X } from 'lucide-react'
15
+ import { type FormEvent, useState } from 'react'
16
+ import Countdown from '../../../components/indicators/countdown'
17
+ import IslandFlash from '../../../components/island/island-flash'
18
+ import { formatClock, MINUTE, SECOND, useEdgeClock } from '../../../lib/clock'
19
+
20
+ type TimerKind = 'focus' | 'break' | 'custom'
21
+
22
+ /** A run: running while it has `endsAt`, paused while it has `remaining`. */
23
+ interface TimerRun {
24
+ kind: TimerKind
25
+ /** Its whole length, in ms. */
26
+ total: number
27
+ /** When it ends, in epoch ms, while it runs. */
28
+ endsAt?: number
29
+ /** The time left, in ms, while it is paused. */
30
+ remaining?: number
31
+ }
32
+
33
+ interface TimerProps {
34
+ /** The run (controlled); `null` shows the picker. */
35
+ value?: TimerRun | null
36
+ /** The run at first (uncontrolled). Defaults to `null`. */
37
+ defaultValue?: TimerRun | null
38
+ /** Called with the run a start, pause, resume, +1 min or cancel leaves, and `null` when it ends. */
39
+ onValueChange?: (run: TimerRun | null) => void
40
+ /** Called when a run reaches zero, with the kind that starts next in a Pomodoro cycle. */
41
+ onEnd?: (run: TimerRun, next?: TimerKind) => void
42
+ /** The picker's quick lengths, in minutes, before the Pomodoro preset. Defaults to `[1, 5, 10]`. */
43
+ presets?: number[]
44
+ /** Pomodoro cycles: when a focus run ends a break starts on its own, then focus again. Defaults to `false`. */
45
+ pomodoro?: boolean
46
+ /** A focus run's length, in minutes. Defaults to `25`. */
47
+ focusMinutes?: number
48
+ /** A break's length, in minutes. Defaults to `5`. */
49
+ breakMinutes?: number
50
+ /** Classes for the root, which fills its container. */
51
+ className?: string
52
+ }
53
+
54
+ const LABEL: Record<TimerKind, string> = { focus: 'Focus', break: 'Break', custom: 'Timer' }
55
+
56
+ const start = (minutes: number, kind: TimerKind): TimerRun => ({
57
+ kind,
58
+ total: minutes * MINUTE,
59
+ endsAt: Date.now() + minutes * MINUTE,
60
+ })
61
+ const pause = (run: TimerRun): TimerRun => ({ kind: run.kind, total: run.total, remaining: timeLeft(run, Date.now()) })
62
+ const resume = (run: TimerRun): TimerRun => ({
63
+ kind: run.kind,
64
+ total: run.total,
65
+ endsAt: Date.now() + (run.remaining ?? 0),
66
+ })
67
+ const addMinute = (run: TimerRun): TimerRun =>
68
+ run.endsAt === undefined
69
+ ? { ...run, total: run.total + MINUTE, remaining: (run.remaining ?? 0) + MINUTE }
70
+ : { ...run, total: run.total + MINUTE, endsAt: run.endsAt + MINUTE }
71
+
72
+ /** The time a run has left at `now`, in ms. */
73
+ function timeLeft(run: TimerRun, now: number) {
74
+ return run.endsAt === undefined ? (run.remaining ?? 0) : Math.max(0, run.endsAt - now)
75
+ }
76
+
77
+ /** The time left, re-read on each second's edge while the run runs, never in between. */
78
+ function useTimeLeft(run: TimerRun) {
79
+ const end = run.endsAt ?? 0
80
+ const now = useEdgeClock(end, run.endsAt !== undefined && Date.now() < end + SECOND)
81
+ return timeLeft(run, now)
82
+ }
83
+
84
+ function Ring({ run, className }: { run: TimerRun; className: string }) {
85
+ const left = useTimeLeft(run)
86
+ return (
87
+ <Meter
88
+ variant="ring"
89
+ label={`${LABEL[run.kind]}, ${formatClock(Math.ceil(left / SECOND))} left`}
90
+ value={run.total ? left / run.total : 0}
91
+ tone="default"
92
+ animate={false}
93
+ className={className}
94
+ />
95
+ )
96
+ }
97
+
98
+ function Clock({ run, className, onEnd }: { run: TimerRun; className: string; onEnd?: () => void }) {
99
+ const paused = run.endsAt === undefined
100
+ return (
101
+ <Countdown
102
+ endsAt={run.endsAt}
103
+ paused={paused}
104
+ remaining={run.remaining}
105
+ onEnd={onEnd}
106
+ className={cn(className, paused ? 'text-muted-foreground' : 'text-status-warning')}
107
+ />
108
+ )
109
+ }
110
+
111
+ /** The compact island's left wing: the timer's glyph. */
112
+ function TimerLeading() {
113
+ return <TimerIcon size={16} strokeWidth={1.5} className="text-status-warning" />
114
+ }
115
+
116
+ /** The compact island's right wing: the time left, muted while paused. */
117
+ function TimerTrailing({ run }: { run: TimerRun }) {
118
+ return <Clock run={run} className="text-caption weight-medium" />
119
+ }
120
+
121
+ /** The split island's bubble: a ring of the time left. */
122
+ function TimerMinimal({ run }: { run: TimerRun }) {
123
+ return <Ring run={run} className="size-5.5" />
124
+ }
125
+
126
+ interface TimerDoneProps {
127
+ /** The run that ended. Defaults to `'custom'`. */
128
+ kind?: TimerKind
129
+ /** The kind a Pomodoro cycle starts next. */
130
+ next?: TimerKind
131
+ /** The next run's length, in minutes. */
132
+ minutes?: number
133
+ }
134
+
135
+ /** The island's flash when a run reaches zero: "Time's up", and what starts next in a Pomodoro cycle. */
136
+ function TimerDone({ kind = 'custom', next, minutes }: TimerDoneProps) {
137
+ const detail = next ? `${LABEL[next]} starts now${minutes ? ` · ${minutes} min` : ''}` : `${LABEL[kind]} finished`
138
+ return (
139
+ <IslandFlash icon={<TimerIcon size={20} strokeWidth={1.5} />} tone="warning" title="Time's up" caption={detail} />
140
+ )
141
+ }
142
+
143
+ interface PickerProps {
144
+ presets: number[]
145
+ focusMinutes: number
146
+ onStart: (run: TimerRun) => void
147
+ }
148
+
149
+ function Picker({ presets, focusMinutes, onStart }: PickerProps) {
150
+ const [minutes, setMinutes] = useState<number | null>(null)
151
+ const valid = minutes !== null && Number.isInteger(minutes) && minutes >= 1 && minutes <= 99
152
+ const submit = (event: FormEvent) => {
153
+ event.preventDefault()
154
+ if (valid) onStart(start(minutes, 'custom'))
155
+ }
156
+ return (
157
+ <div className="flex size-full flex-col justify-center gap-3">
158
+ <div className="grid grid-cols-4 gap-2">
159
+ {presets.map(m => (
160
+ <Button key={m} variant="tertiary" onClick={() => onStart(start(m, 'custom'))}>
161
+ {m} min
162
+ </Button>
163
+ ))}
164
+ <Button variant="tertiary" onClick={() => onStart(start(focusMinutes, 'focus'))}>
165
+ Pomodoro
166
+ </Button>
167
+ </div>
168
+ <form className="flex items-center gap-2" onSubmit={submit}>
169
+ <div className="min-w-0 flex-1">
170
+ <NumberInput
171
+ className="w-full"
172
+ variant="bordered"
173
+ min={1}
174
+ max={99}
175
+ placeholder="Custom minutes"
176
+ aria-label="Custom minutes"
177
+ endAdornment="min"
178
+ value={minutes}
179
+ onValueChange={setMinutes}
180
+ />
181
+ </div>
182
+ <Button type="submit" variant="primary" leadingIcon={Play} disabled={!valid}>
183
+ Start
184
+ </Button>
185
+ </form>
186
+ </div>
187
+ )
188
+ }
189
+
190
+ interface RunningProps {
191
+ run: TimerRun
192
+ onChange: (run: TimerRun | null) => void
193
+ onEnd: () => void
194
+ }
195
+
196
+ function Running({ run, onChange, onEnd }: RunningProps) {
197
+ const paused = run.endsAt === undefined
198
+ return (
199
+ <div className="flex size-full items-center gap-5">
200
+ <Ring run={run} className="size-16" />
201
+ <div className="flex min-w-0 flex-1 flex-col">
202
+ <span className="truncate text-caption text-muted-foreground">
203
+ {LABEL[run.kind]} · {Math.round(run.total / MINUTE)} min{paused ? ' · Paused' : ''}
204
+ </span>
205
+ <Clock run={run} className="text-display" onEnd={onEnd} />
206
+ </div>
207
+ <div className="flex shrink-0 items-center gap-2">
208
+ <Button variant="tertiary" leadingIcon={Plus} onClick={() => onChange(addMinute(run))}>
209
+ 1 min
210
+ </Button>
211
+ <Button
212
+ variant="tertiary"
213
+ size="icon"
214
+ className="text-status-warning"
215
+ aria-label={paused ? 'Resume' : 'Pause'}
216
+ onClick={() => onChange(paused ? resume(run) : pause(run))}
217
+ >
218
+ {paused ? (
219
+ <Play size={16} strokeWidth={1.5} fill="currentColor" />
220
+ ) : (
221
+ <Pause size={16} strokeWidth={1.5} fill="currentColor" />
222
+ )}
223
+ </Button>
224
+ <Button variant="tertiary" size="icon" aria-label="Cancel" onClick={() => onChange(null)}>
225
+ <X size={16} strokeWidth={1.5} />
226
+ </Button>
227
+ </div>
228
+ </div>
229
+ )
230
+ }
231
+
232
+ /**
233
+ * A notch app's timer: pick a length, watch it run down, hear when it's up.
234
+ *
235
+ * Without a run it shows the picker: quick lengths (`presets`), a Pomodoro
236
+ * focus run and a custom length in minutes on a NumberInput. A run shows a
237
+ * Meter ring of the time left beside the time itself in display type, with
238
+ * +1 min, pause / resume and cancel. The run is a value (`value` /
239
+ * `onValueChange`, or kept here from `defaultValue`): a running one carries
240
+ * when it ends, a paused one the time it had left, so a host can persist it
241
+ * and resume after a reload. The time re-renders once a second, on the
242
+ * second's edge, and nothing runs while it is paused.
243
+ *
244
+ * At zero it calls `onEnd` and clears the run, unless `pomodoro` cycles:
245
+ * then a focus run hands over to a break and a break back to focus.
246
+ *
247
+ * The other forms are parts: `Timer.Leading` and `Timer.Trailing` for the
248
+ * compact island's wings (the glyph and the time left), `Timer.Minimal` for
249
+ * the split island's bubble (the ring) and `Timer.Done`, the "Time's up"
250
+ * flash.
251
+ *
252
+ * @example {@include ./examples.mdx}
253
+ */
254
+ function Timer({
255
+ value,
256
+ defaultValue = null,
257
+ onValueChange,
258
+ onEnd,
259
+ presets = [1, 5, 10],
260
+ pomodoro = false,
261
+ focusMinutes = 25,
262
+ breakMinutes = 5,
263
+ className,
264
+ }: TimerProps) {
265
+ const [run, setRun] = useControllableState(value, defaultValue, onValueChange)
266
+
267
+ const complete = (ended: TimerRun) => {
268
+ const next = pomodoro && ended.kind !== 'custom' ? (ended.kind === 'focus' ? 'break' : 'focus') : undefined
269
+ onEnd?.(ended, next)
270
+ setRun(next ? start(next === 'break' ? breakMinutes : focusMinutes, next) : null)
271
+ }
272
+
273
+ return (
274
+ <div className={cn('size-full', className)}>
275
+ {run ? (
276
+ <Running run={run} onChange={setRun} onEnd={() => complete(run)} />
277
+ ) : (
278
+ <Picker presets={presets} focusMinutes={focusMinutes} onStart={setRun} />
279
+ )}
280
+ </div>
281
+ )
282
+ }
283
+
284
+ Timer.Leading = TimerLeading
285
+ Timer.Trailing = TimerTrailing
286
+ Timer.Minimal = TimerMinimal
287
+ Timer.Done = TimerDone
288
+
289
+ export default Timer
290
+
291
+ export type { TimerDoneProps, TimerKind, TimerProps, TimerRun }
292
+ export { Timer, TimerDone, TimerLeading, TimerMinimal, TimerTrailing }
@@ -0,0 +1,45 @@
1
+ import ExpandedIsland from './index'
2
+ import Island from '../../../components/island/island'
3
+ import NowPlaying from '../../activities/now-playing'
4
+ import Timer from '../../activities/timer'
5
+ import Agenda from '../../activities/agenda'
6
+ import { ExpandedPanel, PLAYING, ScreenEdge } from '../../../mock/island-content'
7
+ import { AGENDA_NOW, EVENTS } from '../../../mock/data'
8
+ import { CalendarDays, Music, Timer as TimerIcon } from 'lucide-react'
9
+
10
+ # Every widget
11
+
12
+ Tabs in the wings around the notch, settings at the far right; hover a tab to preview its title.
13
+
14
+ <ScreenEdge height={340}>
15
+ <Island defaultState="expanded" collapsedState="idle" expanded={<ExpandedPanel />} />
16
+ </ScreenEdge>
17
+
18
+ # Three tabs
19
+
20
+ `tabs` takes each tab's icon, label and view.
21
+
22
+ <ScreenEdge height={340}>
23
+ <Island
24
+ defaultState="expanded"
25
+ collapsedState="idle"
26
+ expanded={
27
+ <ExpandedIsland
28
+ defaultValue="calendar"
29
+ tabs={[
30
+ { value: 'music', label: 'Now Playing', icon: Music, content: <NowPlaying track={PLAYING} /> },
31
+ { value: 'timer', label: 'Timer', icon: TimerIcon, content: <Timer /> },
32
+ { value: 'calendar', label: 'Calendar', icon: CalendarDays, content: <Agenda events={EVENTS} now={AGENDA_NOW} /> },
33
+ ]}
34
+ />
35
+ }
36
+ />
37
+ </ScreenEdge>
38
+
39
+ # A shorter panel
40
+
41
+ The content area keeps its height and scrolls a taller view, its edges fading.
42
+
43
+ <ScreenEdge height={260}>
44
+ <Island defaultState="expanded" collapsedState="idle" panelHeight={240} expanded={<ExpandedPanel defaultTab="calendar" />} />
45
+ </ScreenEdge>
@@ -0,0 +1,127 @@
1
+ /*!
2
+ * Local addition: the open island's layout, tabs in the wings, the tab's
3
+ * title and its view. Rebuilt from Just Notch's runtime
4
+ * (`island/expanded.tsx`) as a presentational block: tabs and their views
5
+ * come in as props.
6
+ */
7
+
8
+ 'use client'
9
+
10
+ import Button from '@justanarthur/modo-ui/components/actions/button'
11
+ import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
12
+ import { cn } from '@justanarthur/modo-ui/lib/utils'
13
+ import ScrollArea from '@justanarthur/modo-ui/primitives/layout/scroll-area'
14
+ import { SizeProvider } from '@justanarthur/modo-ui/primitives/systems/sizes'
15
+ import { Settings } from 'lucide-react'
16
+ import { type ReactNode, useState } from 'react'
17
+ import IslandTabs, { type IslandTab } from '../../../components/island/island-tabs'
18
+ import { DEFAULT_NOTCH, INSET } from '../../../lib/geometry'
19
+ import { useIsland } from '../../../lib/island-context'
20
+
21
+ interface ExpandedIslandTab extends IslandTab {
22
+ /** The tab's view, in the content area. */
23
+ content: ReactNode
24
+ }
25
+
26
+ interface ExpandedIslandProps {
27
+ /** The tabs, in order, each with its view. */
28
+ tabs: ExpandedIslandTab[]
29
+ /** The selected tab's value (controlled). */
30
+ value?: string
31
+ /** The tab selected at first (uncontrolled). Defaults to the first tab. */
32
+ defaultValue?: string
33
+ /** Called with the value of the tab a press or an arrow key selects. */
34
+ onValueChange?: (value: string) => void
35
+ /** Called by the settings button at the right wing's far end; without it the button hides. */
36
+ onSettings?: () => void
37
+ /** The settings button's accessible name. Defaults to `'Settings'`. */
38
+ settingsLabel?: string
39
+ /** What the content area says without tabs. Defaults to `'Nothing here yet'`. */
40
+ empty?: ReactNode
41
+ /** Classes for the root, which fills the open island. */
42
+ className?: string
43
+ }
44
+
45
+ /**
46
+ * The open island's layout: icon tabs in the wings around the notch, the
47
+ * tab's title under them, and its view in a content area of fixed height.
48
+ *
49
+ * The header is the notch's height, so the tabs sit in the wings beside the
50
+ * hardware notch: the kit's IslandTabs at the compact step, with a settings
51
+ * button at the right wing's far end when `onSettings` is given. Under it
52
+ * the selected tab's title, or the hovered tab's as a preview. The view
53
+ * fills the rest: the area keeps its height whatever the view holds, and a
54
+ * taller view scrolls inside it, its edges fading with `scroll-fade` (a
55
+ * modo-ui ScrollArea), back at the top on each new tab. Every part starts at
56
+ * the island's one inset, clear of its rounded bottom corners.
57
+ *
58
+ * Pass it as the Island's `expanded`; it reads the notch from the Island.
59
+ * Selection runs through `value` / `onValueChange`, or is kept here from
60
+ * `defaultValue`.
61
+ *
62
+ * @example {@include ./examples.mdx}
63
+ */
64
+ export default function ExpandedIsland({
65
+ tabs,
66
+ value: valueProp,
67
+ defaultValue,
68
+ onValueChange,
69
+ onSettings,
70
+ settingsLabel = 'Settings',
71
+ empty = 'Nothing here yet',
72
+ className,
73
+ }: ExpandedIslandProps) {
74
+ const island = useIsland()
75
+ const [value, setValue] = useControllableState(valueProp, defaultValue ?? tabs[0]?.value, onValueChange)
76
+ const [hovered, setHovered] = useState<string | null>(null)
77
+ const tab = tabs.find(t => t.value === value) ?? tabs[0]
78
+ const title = tabs.find(t => t.value === hovered)?.label ?? tab?.label
79
+ const notch = island?.geometry.notch.height ?? DEFAULT_NOTCH.height
80
+
81
+ return (
82
+ <div className={cn('flex size-full flex-col', className)}>
83
+ <SizeProvider size="compact">
84
+ <div className="flex shrink-0 items-center" style={{ height: notch, paddingInline: INSET }}>
85
+ {tabs.length > 0 ? (
86
+ <IslandTabs
87
+ tabs={tabs}
88
+ value={tab?.value}
89
+ onValueChange={setValue}
90
+ onHoverChange={setHovered}
91
+ trailing={
92
+ onSettings && (
93
+ <Button variant="ghost" size="icon-compact" aria-label={settingsLabel} onClick={onSettings}>
94
+ <Settings size={14} strokeWidth={1.5} />
95
+ </Button>
96
+ )
97
+ }
98
+ />
99
+ ) : (
100
+ <div className="flex-1" />
101
+ )}
102
+ </div>
103
+ </SizeProvider>
104
+ <div className="flex min-h-0 flex-1 flex-col pb-3">
105
+ <div className="flex h-6 shrink-0 items-end" style={{ paddingInline: INSET }}>
106
+ <span className="truncate text-caption weight-medium text-muted-foreground">{title}</span>
107
+ </div>
108
+ <ScrollArea
109
+ key={tab?.value}
110
+ className="min-h-0 flex-1"
111
+ viewportClassName="scroll-fade [&>div]:flex [&>div]:min-h-full [&>div]:flex-col"
112
+ >
113
+ <div className="flex flex-1 flex-col py-1 [&>*]:flex-1" style={{ paddingInline: INSET }}>
114
+ {tab ? (
115
+ tab.content
116
+ ) : (
117
+ <div className="flex items-center justify-center text-caption text-muted-foreground">{empty}</div>
118
+ )}
119
+ </div>
120
+ </ScrollArea>
121
+ </div>
122
+ </div>
123
+ )
124
+ }
125
+
126
+ export type { ExpandedIslandProps, ExpandedIslandTab }
127
+ export { ExpandedIsland }
@@ -0,0 +1,30 @@
1
+ import SettingsWindow from './index'
2
+ import { ABOUT, MockWindow, PERMISSIONS, PLUGINS } from '../../../mock/settings'
3
+
4
+ # Settings
5
+
6
+ General, Plugins, Permissions and About, then a page per plugin's settings.
7
+
8
+ <MockWindow title="Settings">
9
+ <SettingsWindow name="Just Notch" plugins={PLUGINS} permissions={PERMISSIONS} about={ABOUT} />
10
+ </MockWindow>
11
+
12
+ # Plugins
13
+
14
+ <MockWindow title="Settings">
15
+ <SettingsWindow name="Just Notch" defaultValue="plugins" plugins={PLUGINS} defaultEnabled={{ stats: false, devices: false }} permissions={PERMISSIONS} about={ABOUT} />
16
+ </MockWindow>
17
+
18
+ # Permissions
19
+
20
+ A spinner while one is read; Open Settings beside one that isn't granted.
21
+
22
+ <MockWindow title="Settings">
23
+ <SettingsWindow name="Just Notch" defaultValue="permissions" plugins={PLUGINS} permissions={PERMISSIONS} about={ABOUT} />
24
+ </MockWindow>
25
+
26
+ # A plugin's settings
27
+
28
+ <MockWindow title="Settings">
29
+ <SettingsWindow name="Just Notch" defaultValue="plugin:calendar" plugins={PLUGINS} permissions={PERMISSIONS} about={ABOUT} />
30
+ </MockWindow>