@justanarthur/modo-ui-notch 0.2.0 → 0.4.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 (148) hide show
  1. package/README.md +11 -11
  2. package/blocks/activities/agenda/examples.mdx +29 -5
  3. package/blocks/activities/agenda/index.tsx +438 -181
  4. package/blocks/activities/clock/examples.mdx +89 -0
  5. package/blocks/activities/clock/index.tsx +917 -0
  6. package/blocks/activities/now-playing/examples.mdx +40 -13
  7. package/blocks/activities/now-playing/index.tsx +399 -120
  8. package/blocks/activities/weather/examples.mdx +123 -0
  9. package/blocks/activities/weather/index.tsx +863 -0
  10. package/blocks/app/expanded-island/examples.mdx +8 -7
  11. package/blocks/app/expanded-island/index.tsx +22 -4
  12. package/blocks/app/settings-window/examples.mdx +14 -2
  13. package/blocks/app/settings-window/index.tsx +33 -10
  14. package/blocks/system/clipboard/examples.mdx +91 -0
  15. package/blocks/system/clipboard/index.tsx +773 -0
  16. package/blocks/system/recent-files/examples.mdx +80 -0
  17. package/blocks/system/recent-files/index.tsx +627 -0
  18. package/blocks/system/system-stats/examples.mdx +46 -9
  19. package/blocks/system/system-stats/index.tsx +445 -104
  20. package/components/indicators/media-scrubber/examples.mdx +8 -0
  21. package/components/indicators/media-scrubber/index.tsx +37 -13
  22. package/components/island/island/examples.mdx +4 -4
  23. package/components/island/island/index.tsx +2 -2
  24. package/components/island/island-flash/examples.mdx +15 -18
  25. package/components/island/island-flash/index.tsx +4 -4
  26. package/components/island/island-tabs/examples.mdx +5 -5
  27. package/components/island/widget/examples.mdx +76 -0
  28. package/components/island/widget/index.tsx +465 -0
  29. package/dist/blocks/activities/agenda/index.d.ts +2 -1
  30. package/dist/blocks/activities/agenda/index.js +3 -3
  31. package/dist/blocks/activities/clock/index.d.ts +3 -0
  32. package/dist/blocks/activities/clock/index.js +25 -0
  33. package/dist/blocks/activities/now-playing/index.d.ts +4 -2
  34. package/dist/blocks/activities/now-playing/index.js +5 -3
  35. package/dist/blocks/activities/weather/index.d.ts +3 -0
  36. package/dist/blocks/activities/weather/index.js +21 -0
  37. package/dist/blocks/app/expanded-island/index.d.ts +1 -1
  38. package/dist/blocks/app/expanded-island/index.js +4 -3
  39. package/dist/blocks/app/settings-window/index.d.ts +1 -1
  40. package/dist/blocks/app/settings-window/index.js +1 -1
  41. package/dist/blocks/system/clipboard/index.d.ts +3 -0
  42. package/dist/blocks/system/clipboard/index.js +17 -0
  43. package/dist/blocks/system/recent-files/index.d.ts +3 -0
  44. package/dist/blocks/system/recent-files/index.js +19 -0
  45. package/dist/blocks/system/system-stats/index.d.ts +3 -2
  46. package/dist/blocks/system/system-stats/index.js +4 -1
  47. package/dist/components/indicators/media-scrubber/index.d.ts +1 -1
  48. package/dist/components/indicators/media-scrubber/index.js +1 -1
  49. package/dist/components/island/island/index.d.ts +1 -1
  50. package/dist/components/island/island/index.js +2 -2
  51. package/dist/components/island/island-flash/index.d.ts +1 -1
  52. package/dist/components/island/island-flash/index.js +1 -1
  53. package/dist/components/island/island-tabs/index.js +2 -2
  54. package/dist/components/island/widget/index.d.ts +2 -0
  55. package/dist/components/island/widget/index.js +32 -0
  56. package/dist/index.d.ts +15 -15
  57. package/dist/index.js +104 -58
  58. package/dist/lib/artwork.d.ts +2 -0
  59. package/dist/lib/artwork.js +8 -0
  60. package/dist/lib/geometry.js +1 -1
  61. package/dist/shared/{chunk-yngkkxz2.d.ts → chunk-0ym9mcqc.d.ts} +10 -6
  62. package/dist/shared/chunk-2b6gpn8k.js +444 -0
  63. package/dist/shared/chunk-3hcnf4yx.js +481 -0
  64. package/dist/shared/chunk-42wab62s.d.ts +197 -0
  65. package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
  66. package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-6tnq6p89.d.ts} +9 -1
  67. package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
  68. package/dist/shared/chunk-93dtpjz7.js +789 -0
  69. package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
  70. package/dist/shared/chunk-a6njb8db.d.ts +129 -0
  71. package/dist/shared/chunk-ab8mdg0n.d.ts +149 -0
  72. package/dist/shared/chunk-evqpf92s.d.ts +168 -0
  73. package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
  74. package/dist/shared/chunk-gcyspvgr.js +582 -0
  75. package/dist/shared/chunk-gejenfap.d.ts +25 -0
  76. package/dist/shared/chunk-gkj0hjrn.d.ts +136 -0
  77. package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
  78. package/dist/shared/chunk-n739am8j.d.ts +112 -0
  79. package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
  80. package/dist/shared/chunk-nwzpekvy.js +774 -0
  81. package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
  82. package/dist/shared/chunk-sbrtesdg.d.ts +138 -0
  83. package/dist/shared/chunk-swc7dqpw.d.ts +115 -0
  84. package/dist/shared/chunk-t9wqhgzt.js +765 -0
  85. package/dist/shared/chunk-w5h6ay93.js +72 -0
  86. package/dist/shared/{chunk-mp1nx0ez.js → chunk-wayv5rhr.js} +15 -4
  87. package/dist/shared/chunk-wf0jtzhs.js +295 -0
  88. package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
  89. package/dist/shared/chunk-yq5svpk7.js +524 -0
  90. package/dist/shared/{chunk-s33y1pcq.js → chunk-z3tj1ydg.js} +23 -10
  91. package/dist/styles.css +151 -49
  92. package/index.ts +7 -6
  93. package/lib/artwork.ts +112 -0
  94. package/lib/geometry.ts +1 -1
  95. package/mock/activities.tsx +9 -32
  96. package/mock/artwork.tsx +13 -1
  97. package/mock/clipboard.tsx +113 -0
  98. package/mock/clock.tsx +77 -0
  99. package/mock/data.ts +78 -44
  100. package/mock/files.tsx +83 -0
  101. package/mock/island-content.tsx +79 -122
  102. package/mock/screen.tsx +76 -0
  103. package/mock/settings.tsx +370 -91
  104. package/mock/system.ts +49 -0
  105. package/mock/weather.tsx +135 -0
  106. package/package.json +7 -2
  107. package/blocks/activities/shelf/examples.mdx +0 -33
  108. package/blocks/activities/shelf/index.tsx +0 -289
  109. package/blocks/activities/timer/examples.mdx +0 -52
  110. package/blocks/activities/timer/index.tsx +0 -292
  111. package/blocks/system/controls/examples.mdx +0 -34
  112. package/blocks/system/controls/index.tsx +0 -167
  113. package/blocks/system/devices/examples.mdx +0 -25
  114. package/blocks/system/devices/index.tsx +0 -172
  115. package/blocks/system/power-alert/examples.mdx +0 -32
  116. package/blocks/system/power-alert/index.tsx +0 -89
  117. package/components/indicators/battery-glyph/examples.mdx +0 -22
  118. package/components/indicators/battery-glyph/index.tsx +0 -91
  119. package/dist/blocks/activities/shelf/index.d.ts +0 -2
  120. package/dist/blocks/activities/shelf/index.js +0 -14
  121. package/dist/blocks/activities/timer/index.d.ts +0 -2
  122. package/dist/blocks/activities/timer/index.js +0 -19
  123. package/dist/blocks/system/controls/index.d.ts +0 -2
  124. package/dist/blocks/system/controls/index.js +0 -10
  125. package/dist/blocks/system/devices/index.d.ts +0 -2
  126. package/dist/blocks/system/devices/index.js +0 -12
  127. package/dist/blocks/system/power-alert/index.d.ts +0 -2
  128. package/dist/blocks/system/power-alert/index.js +0 -9
  129. package/dist/components/indicators/battery-glyph/index.d.ts +0 -2
  130. package/dist/components/indicators/battery-glyph/index.js +0 -9
  131. package/dist/shared/chunk-2qpcsv5h.d.ts +0 -45
  132. package/dist/shared/chunk-45gytfr1.d.ts +0 -84
  133. package/dist/shared/chunk-50ffk4r7.d.ts +0 -69
  134. package/dist/shared/chunk-5w0yck07.d.ts +0 -32
  135. package/dist/shared/chunk-7hr53mby.js +0 -116
  136. package/dist/shared/chunk-b8jb1w72.js +0 -145
  137. package/dist/shared/chunk-cpewy6yg.js +0 -178
  138. package/dist/shared/chunk-e3e4s4ds.d.ts +0 -77
  139. package/dist/shared/chunk-enm6td0p.js +0 -280
  140. package/dist/shared/chunk-fvedaas2.d.ts +0 -33
  141. package/dist/shared/chunk-gex38j8x.d.ts +0 -82
  142. package/dist/shared/chunk-hwtxpzg0.js +0 -69
  143. package/dist/shared/chunk-phb53x1f.js +0 -252
  144. package/dist/shared/chunk-r8esmjfs.d.ts +0 -42
  145. package/dist/shared/chunk-rcp1g9ca.js +0 -70
  146. package/dist/shared/chunk-rx9sphz2.js +0 -266
  147. package/dist/shared/chunk-xdeek16r.d.ts +0 -58
  148. package/dist/shared/chunk-xkzjk1tq.js +0 -206
@@ -0,0 +1,627 @@
1
+ /*!
2
+ * Local addition: a notch app's recent files, the newest download or
3
+ * screenshot as the hero and the ones before it beside it, ready to open or
4
+ * drag out. Presentational: the files and what to do with them come in as
5
+ * props.
6
+ */
7
+
8
+ 'use client'
9
+
10
+ import Button from '@justanarthur/modo-ui/components/actions/button'
11
+ import Meter from '@justanarthur/modo-ui/components/feedback/meter'
12
+ import Tabs from '@justanarthur/modo-ui/components/navigation/tabs'
13
+ import type { IconComponent } from '@justanarthur/modo-ui/lib/icon-context'
14
+ import type { SizeVariant } from '@justanarthur/modo-ui/lib/size-context'
15
+ import { SURFACE_BG } from '@justanarthur/modo-ui/lib/surface-classes'
16
+ import { useLift } from '@justanarthur/modo-ui/lib/surface-context'
17
+ import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
18
+ import { cn } from '@justanarthur/modo-ui/lib/utils'
19
+ import FluidHover from '@justanarthur/modo-ui/primitives/systems/fluid-hover'
20
+ import {
21
+ ArrowDownToLine,
22
+ ArrowUpRight,
23
+ Camera,
24
+ Copy,
25
+ File,
26
+ FileArchive,
27
+ FileAudio,
28
+ FileCode,
29
+ FileImage,
30
+ FileText,
31
+ FileVideo,
32
+ FolderSearch,
33
+ Trash2,
34
+ X,
35
+ } from 'lucide-react'
36
+ import type { DragEvent, ReactNode } from 'react'
37
+ import IslandFlash from '../../../components/island/island-flash'
38
+ import Widget, { type WidgetLayout } from '../../../components/island/widget'
39
+ import { MINUTE, useEdgeClock } from '../../../lib/clock'
40
+
41
+ type RecentFilesSource = 'downloads' | 'screenshots'
42
+
43
+ interface RecentFile {
44
+ /** What tells it apart: its path. */
45
+ id: string
46
+ /** Its name, with the extension: it picks the glyph when there is no thumbnail. */
47
+ name: string
48
+ /** Its size, in bytes. */
49
+ size: number
50
+ /** When it landed, in epoch ms. */
51
+ addedAt: number
52
+ /** The folder it is in. */
53
+ source: RecentFilesSource
54
+ /** A preview: an image URL, or any element. */
55
+ thumbnail?: string | ReactNode
56
+ /** Where a download came from: a site's domain. */
57
+ from?: string
58
+ }
59
+
60
+ interface RecentDownload {
61
+ /** What tells it apart. */
62
+ id: string
63
+ /** The file's name. */
64
+ name: string
65
+ /** Bytes in so far. */
66
+ received: number
67
+ /** The file's size, in bytes. */
68
+ total: number
69
+ /** The current speed, in bytes per second. */
70
+ rate: number
71
+ /** Where it comes from: a site's domain. */
72
+ from?: string
73
+ }
74
+
75
+ interface RecentFilesProps {
76
+ /** The files of both folders, in any order: each folder lists newest first. */
77
+ files: RecentFile[]
78
+ /** A download under way: it takes the hero on Downloads, with its progress and speed. */
79
+ download?: RecentDownload | null
80
+ /** The folder shown (controlled). */
81
+ value?: RecentFilesSource
82
+ /** The folder shown at first (uncontrolled). Defaults to `'downloads'`. */
83
+ defaultValue?: RecentFilesSource
84
+ /** Called with the folder when the switch is pressed. */
85
+ onValueChange?: (source: RecentFilesSource) => void
86
+ /** Called by Open, or a press on a file in the list. */
87
+ onOpen?: (file: RecentFile) => void
88
+ /** Called by Show in Finder. */
89
+ onReveal?: (file: RecentFile) => void
90
+ /** Called by Copy, to put the file on the clipboard. */
91
+ onCopy?: (file: RecentFile) => void
92
+ /** Called when a file starts to be dragged out, with the drag event, for the host to start a native drag. Without it nothing drags. */
93
+ onDragStart?: (file: RecentFile, event: DragEvent) => void
94
+ /** Called by Move to Trash. */
95
+ onDelete?: (file: RecentFile) => void
96
+ /** Called by Clear with the folder whose list to clear; without it the button hides. */
97
+ onClear?: (source: RecentFilesSource) => void
98
+ /** Called by the download's Cancel. */
99
+ onCancelDownload?: (download: RecentDownload) => void
100
+ /** The moment the times are read at, in epoch ms. Defaults to now, re-read on each minute. */
101
+ now?: number
102
+ /** `tall` is the open island's tall snap: the switch across the top, the newest file large with its actions, and every earlier file of the folder as a grid of named tiles. Defaults to `'fit'`. */
103
+ layout?: WidgetLayout
104
+ /** Step on the size ladder. Omitted, it follows the surrounding SizeProvider. */
105
+ size?: SizeVariant
106
+ /** Classes for the root, which fills its container. */
107
+ className?: string
108
+ }
109
+
110
+ const SOURCE_LABEL: Record<RecentFilesSource, string> = { downloads: 'Downloads', screenshots: 'Screenshots' }
111
+ const SOURCE_ICON: Record<RecentFilesSource, IconComponent> = { downloads: ArrowDownToLine, screenshots: Camera }
112
+
113
+ /** Rows the downloads list shows, and tiles the screenshots grid, before saying how many more. */
114
+ const ROWS = 3
115
+ const TILES = 6
116
+
117
+ const TYPES: [RegExp, IconComponent][] = [
118
+ [/\.(png|jpe?g|gif|webp|heic|svg|tiff?)$/i, FileImage],
119
+ [/\.(mov|mp4|m4v|avi|mkv|webm)$/i, FileVideo],
120
+ [/\.(mp3|m4a|wav|aiff?|flac|ogg)$/i, FileAudio],
121
+ [/\.(zip|tar|gz|tgz|rar|7z|dmg|xip)$/i, FileArchive],
122
+ [/\.(m?[jt]sx?|json|css|html|swift|rs|go|py|rb|sh|ya?ml|toml)$/i, FileCode],
123
+ [/\.(pdf|md|txt|rtf|docx?|pages|key|numbers|csv)$/i, FileText],
124
+ ]
125
+
126
+ /** The glyph for a file's type, from its name's extension. */
127
+ const iconFor = (name: string) => TYPES.find(([pattern]) => pattern.test(name))?.[1] ?? File
128
+
129
+ /** Bytes as `2.4 MB`, `840 KB` or `1.2 GB`. */
130
+ function bytes(n: number) {
131
+ if (n >= 1e9) return `${(n / 1e9).toFixed(1)} GB`
132
+ if (n >= 1e6) return `${n >= 100e6 ? Math.round(n / 1e6) : (n / 1e6).toFixed(1)} MB`
133
+ return `${Math.max(1, Math.round(n / 1e3))} KB`
134
+ }
135
+
136
+ /** Bytes in of a total, in the total's unit: `48 of 120 MB`. */
137
+ function part(n: number, total: number) {
138
+ const [unit, scale] = total >= 1e9 ? ['GB', 1e9] : total >= 1e6 ? ['MB', 1e6] : ['KB', 1e3]
139
+ const digits = total / scale < 10 ? 1 : 0
140
+ return `${(n / scale).toFixed(digits)} of ${(total / scale).toFixed(digits)} ${unit}`
141
+ }
142
+
143
+ /** How long ago, as a phrase: `just now`, `12 min ago`, `2 h ago`, `3 d ago`. */
144
+ function ago(ms: number) {
145
+ const minutes = Math.floor(ms / MINUTE)
146
+ if (minutes < 1) return 'just now'
147
+ if (minutes < 60) return `${minutes} min ago`
148
+ if (minutes < 24 * 60) return `${Math.floor(minutes / 60)} h ago`
149
+ return `${Math.floor(minutes / (24 * 60))} d ago`
150
+ }
151
+
152
+ /** How long ago, as a row's figure: `now`, `12 min`, `2 h`, `3 d`. */
153
+ function short(ms: number) {
154
+ const minutes = Math.floor(ms / MINUTE)
155
+ if (minutes < 1) return 'now'
156
+ if (minutes < 60) return `${minutes} min`
157
+ if (minutes < 24 * 60) return `${Math.floor(minutes / 60)} h`
158
+ return `${Math.floor(minutes / (24 * 60))} d`
159
+ }
160
+
161
+ /** Seconds as `11 s left`, `4 min left`. */
162
+ function left(seconds: number) {
163
+ if (seconds < 60) return `${Math.max(1, Math.ceil(seconds))} s left`
164
+ if (seconds < 3600) return `${Math.ceil(seconds / 60)} min left`
165
+ return `${Math.floor(seconds / 3600)} h ${Math.ceil((seconds % 3600) / 60)} min left`
166
+ }
167
+
168
+ /** Drag props for a file, when the host takes drags. */
169
+ const dragOf = (file: RecentFile, onDragStart?: RecentFilesProps['onDragStart']) =>
170
+ onDragStart ? { draggable: true, onDragStart: (event: DragEvent) => onDragStart(file, event) } : {}
171
+
172
+ // Literal tables: UnoCSS only generates the classes it can read whole.
173
+ const TILE = { default: 'size-24 rounded-xl', compact: 'size-20 rounded-xl' }
174
+ const SHEET_TILE = { default: 'h-32 w-48 rounded-2xl', compact: 'h-28 w-42 rounded-2xl' }
175
+
176
+ function Thumbnail({
177
+ file,
178
+ className,
179
+ glyph = 28,
180
+ }: {
181
+ file: { name: string; thumbnail?: string | ReactNode }
182
+ className: string
183
+ glyph?: number
184
+ }) {
185
+ const level = useLift(1)
186
+ const Icon = iconFor(file.name)
187
+ return (
188
+ <span
189
+ className={cn(
190
+ 'relative flex shrink-0 items-center justify-center overflow-hidden text-muted-foreground',
191
+ file.thumbnail == null && SURFACE_BG[level],
192
+ className,
193
+ )}
194
+ >
195
+ {typeof file.thumbnail === 'string' ? (
196
+ <img alt="" src={file.thumbnail} draggable={false} className="size-full object-cover" />
197
+ ) : (
198
+ (file.thumbnail ?? <Icon size={glyph} strokeWidth={1.25} />)
199
+ )}
200
+ <span
201
+ aria-hidden
202
+ className="pointer-events-none absolute inset-0 rounded-[inherit] ring-1 ring-border ring-inset"
203
+ />
204
+ </span>
205
+ )
206
+ }
207
+
208
+ interface HeroProps {
209
+ file: RecentFile
210
+ now: number
211
+ props: RecentFilesProps
212
+ }
213
+
214
+ /** The newest file: its name, size, age and where it came from, Show in Finder, Copy, Move to Trash and Open. */
215
+ function Hero({ file, now, props }: HeroProps) {
216
+ const { onOpen, onReveal, onCopy, onDelete } = props
217
+ return (
218
+ <div className="flex min-w-0 flex-col gap-2">
219
+ <div className="flex min-w-0 flex-col gap-0.5">
220
+ <Widget.Title>{file.name}</Widget.Title>
221
+ <Widget.Subtitle>
222
+ {[bytes(file.size), ago(now - file.addedAt), file.from && `from ${file.from}`].filter(Boolean).join(' · ')}
223
+ </Widget.Subtitle>
224
+ </div>
225
+ <div className="-mr-1 flex min-w-0 items-center justify-end gap-0.5">
226
+ {onReveal && <Widget.Action icon={FolderSearch} label="Show in Finder" onClick={() => onReveal(file)} />}
227
+ {onCopy && <Widget.Action icon={Copy} label="Copy" onClick={() => onCopy(file)} />}
228
+ {onDelete && <Widget.Action icon={Trash2} label="Move to Trash" onClick={() => onDelete(file)} />}
229
+ <Button
230
+ variant="primary"
231
+ size="compact"
232
+ leadingIcon={ArrowUpRight}
233
+ className="ml-1.5"
234
+ onClick={() => onOpen?.(file)}
235
+ >
236
+ Open
237
+ </Button>
238
+ </div>
239
+ </div>
240
+ )
241
+ }
242
+
243
+ /** The download under way: its name, the progress as a line, how much, how fast and how long, and Cancel. */
244
+ function Downloading({
245
+ download,
246
+ onCancel,
247
+ }: {
248
+ download: RecentDownload
249
+ onCancel?: (download: RecentDownload) => void
250
+ }) {
251
+ const share = download.received / download.total
252
+ return (
253
+ <div className="flex min-w-0 flex-col gap-1.5">
254
+ <div className="flex min-w-0 items-center gap-3">
255
+ <Widget.Title className="flex-1">{download.name}</Widget.Title>
256
+ <span className="shrink-0 text-caption tabular-nums text-muted-foreground">{Math.round(share * 100)}%</span>
257
+ {onCancel && (
258
+ <span className="-my-1 -mr-1 flex shrink-0">
259
+ <Widget.Action icon={X} label="Cancel download" onClick={() => onCancel(download)} />
260
+ </span>
261
+ )}
262
+ </div>
263
+ <Meter variant="line" value={share} tone="default" label={`${download.name}, ${Math.round(share * 100)}%`} />
264
+ <Widget.Meta>
265
+ <Widget.MetaItem>{part(download.received, download.total)}</Widget.MetaItem>
266
+ <Widget.MetaItem>{bytes(download.rate)}/s</Widget.MetaItem>
267
+ <Widget.MetaItem>{left((download.total - download.received) / Math.max(1, download.rate))}</Widget.MetaItem>
268
+ </Widget.Meta>
269
+ </div>
270
+ )
271
+ }
272
+
273
+ /** An empty folder's tile: its glyph one surface up. */
274
+ function Empty({ source, className }: { source: RecentFilesSource; className: string }) {
275
+ const level = useLift(1)
276
+ const Icon = SOURCE_ICON[source]
277
+ return (
278
+ <span
279
+ className={cn('flex shrink-0 items-center justify-center text-muted-foreground', SURFACE_BG[level], className)}
280
+ >
281
+ <Icon size={28} strokeWidth={1.25} />
282
+ </span>
283
+ )
284
+ }
285
+
286
+ interface ListProps {
287
+ files: RecentFile[]
288
+ now: number
289
+ onOpen?: (file: RecentFile) => void
290
+ onDragStart?: RecentFilesProps['onDragStart']
291
+ }
292
+
293
+ /** Earlier downloads as rows: how long ago, the file's glyph and name, its size. */
294
+ function Rows({ files, now, onOpen, onDragStart }: ListProps) {
295
+ return (
296
+ <FluidHover className="-mx-2 flex flex-col gap-0">
297
+ {files.slice(0, ROWS).map((file, index) => {
298
+ const Icon = iconFor(file.name)
299
+ return (
300
+ <FluidHover.Item
301
+ key={file.id}
302
+ index={index}
303
+ title={file.name}
304
+ className="h-7 px-2"
305
+ onClick={() => onOpen?.(file)}
306
+ {...dragOf(file, onDragStart)}
307
+ >
308
+ <Widget.Row className="w-full" leading={short(now - file.addedAt)} trailing={bytes(file.size)}>
309
+ <span className="flex min-w-0 items-center gap-2">
310
+ <Icon size={14} strokeWidth={1.5} className="shrink-0 text-muted-foreground" />
311
+ <span className="min-w-0 truncate">{file.name}</span>
312
+ </span>
313
+ </Widget.Row>
314
+ </FluidHover.Item>
315
+ )
316
+ })}
317
+ </FluidHover>
318
+ )
319
+ }
320
+
321
+ /** Earlier screenshots as a grid of image tiles. */
322
+ function Tiles({ files, onOpen, onDragStart }: Omit<ListProps, 'now'>) {
323
+ return (
324
+ <FluidHover columns={3} className="-m-1 grid-cols-3 gap-0" highlightClassName="rounded-lg">
325
+ {files.slice(0, TILES).map((file, index) => (
326
+ <FluidHover.Item
327
+ key={file.id}
328
+ index={index}
329
+ title={file.name}
330
+ aria-label={file.name}
331
+ className="min-h-0 p-1"
332
+ onClick={() => onOpen?.(file)}
333
+ {...dragOf(file, onDragStart)}
334
+ >
335
+ <Thumbnail file={file} glyph={16} className="aspect-[16/10] w-full rounded-md" />
336
+ </FluidHover.Item>
337
+ ))}
338
+ </FluidHover>
339
+ )
340
+ }
341
+
342
+ /** Every earlier file as a grid of tiles, five across: its thumbnail or glyph, its name, its size and age. */
343
+ function Grid({ files, now, onOpen, onDragStart }: ListProps) {
344
+ return (
345
+ <FluidHover columns={5} className="-m-1.5 grid-cols-5 gap-0" highlightClassName="rounded-xl">
346
+ {files.map((file, index) => (
347
+ <FluidHover.Item
348
+ key={file.id}
349
+ index={index}
350
+ title={file.name}
351
+ className="min-h-0 flex-col items-stretch gap-1.5 p-1.5 text-left"
352
+ onClick={() => onOpen?.(file)}
353
+ {...dragOf(file, onDragStart)}
354
+ >
355
+ <Thumbnail file={file} glyph={24} className="aspect-[4/3] w-full rounded-lg" />
356
+ <span className="flex min-w-0 flex-col px-0.5">
357
+ <span className="truncate text-caption text-foreground">{file.name}</span>
358
+ <span className="truncate text-micro tabular-nums text-muted-foreground">
359
+ {bytes(file.size)} · {short(now - file.addedAt)}
360
+ </span>
361
+ </span>
362
+ </FluidHover.Item>
363
+ ))}
364
+ </FluidHover>
365
+ )
366
+ }
367
+
368
+ /** The compact island's left wing: the download glyph, or the camera for a screenshot. */
369
+ function RecentFilesLeading({ source = 'downloads' }: { source?: RecentFilesSource }) {
370
+ const Icon = SOURCE_ICON[source]
371
+ return <Icon size={16} strokeWidth={1.5} className="text-foreground" />
372
+ }
373
+
374
+ interface TrailingProps {
375
+ /** A download under way: its progress shows. */
376
+ download?: RecentDownload | null
377
+ /** Otherwise, how many files came in since the island was open. */
378
+ count?: number
379
+ }
380
+
381
+ /** The compact island's right wing: a download's progress, else the count of new files. */
382
+ function RecentFilesTrailing({ download, count = 0 }: TrailingProps) {
383
+ return (
384
+ <span className="text-caption weight-semibold tabular-nums text-foreground">
385
+ {download ? `${Math.round((download.received / download.total) * 100)}%` : count}
386
+ </span>
387
+ )
388
+ }
389
+
390
+ /** The split island's bubble: a download's progress as a ring. */
391
+ function RecentFilesMinimal({ download }: { download: RecentDownload }) {
392
+ const share = download.received / download.total
393
+ return (
394
+ <Meter
395
+ variant="ring"
396
+ className="size-5.5"
397
+ size="compact"
398
+ tone="default"
399
+ value={share}
400
+ label={`${download.name}, ${Math.round(share * 100)}%`}
401
+ />
402
+ )
403
+ }
404
+
405
+ interface SavedProps {
406
+ /** The file that landed. */
407
+ file: RecentFile
408
+ /** Called by Open; without it the button hides. */
409
+ onOpen?: (file: RecentFile) => void
410
+ }
411
+
412
+ /** The island's flash when a file lands: its thumbnail or glyph, `Downloaded` or `Screenshot saved`, and Open. */
413
+ function RecentFilesSaved({ file, onOpen }: SavedProps) {
414
+ return (
415
+ <IslandFlash
416
+ icon={<Thumbnail file={file} glyph={16} className="size-9 rounded-lg" />}
417
+ title={file.source === 'screenshots' ? 'Screenshot saved' : 'Downloaded'}
418
+ caption={`${file.name} · ${bytes(file.size)}`}
419
+ action={
420
+ onOpen && (
421
+ <Button variant="secondary" size="compact" onClick={() => onOpen(file)}>
422
+ Open
423
+ </Button>
424
+ )
425
+ }
426
+ />
427
+ )
428
+ }
429
+
430
+ /**
431
+ * A notch app's recent files: the newest download or screenshot as the
432
+ * hero, the ones before it beside it, ready to open or drag out.
433
+ *
434
+ * The hero is the folder's newest file: its thumbnail, or its type's
435
+ * glyph on a tile, then its name, its size, how long ago it landed and
436
+ * where it came from, with Show in Finder, Copy, Move to Trash and Open.
437
+ * Beside it, past a hairline, a switch picks the folder, Downloads or
438
+ * Screenshots (`value` / `defaultValue` / `onValueChange`), over the ones
439
+ * before the newest: downloads as rows of age, glyph, name and size, and
440
+ * screenshots as a grid of image tiles, since a screenshot is found by
441
+ * its look. A press opens a file, and with `onDragStart` every picture and
442
+ * row drags out (the host starts the native drag); Clear empties the list.
443
+ *
444
+ * While a download is under way (`download`) it takes the hero on
445
+ * Downloads: its name, the progress as a modo-ui Meter line, how much is
446
+ * in, the speed and the time left, and Cancel. An empty folder says what
447
+ * will land in it, the switch still beside it.
448
+ *
449
+ * At the open island's tall snap (`layout="tall"`) it becomes a sheet:
450
+ * the switch and Clear across the top; the newest file (or the download
451
+ * under way) large beside its name, its facts and its actions; then every
452
+ * earlier file of the folder, not three, as a grid five across, each tile
453
+ * its thumbnail or its type's glyph over its name, its size and how long
454
+ * ago it landed. Downloads and screenshots read alike there, since a tile
455
+ * has room for both the look and the name; the grid scrolls with the
456
+ * island, and every tile opens on a press and drags out like the rows.
457
+ *
458
+ * `RecentFiles.Leading` and `RecentFiles.Trailing` show the glyph and the
459
+ * download's progress (or the count of new files) in the compact island's
460
+ * wings, `RecentFiles.Minimal` the progress as a ring in the split
461
+ * island's bubble, and `RecentFiles.Saved` is the flash when a file lands.
462
+ *
463
+ * @example {@include ./examples.mdx}
464
+ */
465
+ const RecentFiles = Object.assign(
466
+ function RecentFiles(props: RecentFilesProps) {
467
+ const {
468
+ files,
469
+ download,
470
+ value: valueProp,
471
+ defaultValue = 'downloads',
472
+ onValueChange,
473
+ onOpen,
474
+ onDragStart,
475
+ onClear,
476
+ onCancelDownload,
477
+ now: nowProp,
478
+ layout = 'fit',
479
+ size,
480
+ className,
481
+ } = props
482
+ const ticking = useEdgeClock(0, nowProp === undefined, MINUTE)
483
+ const now = nowProp ?? ticking
484
+ const [source, setSource] = useControllableState(valueProp, defaultValue, onValueChange)
485
+ const step = size ?? 'default'
486
+
487
+ const shown = files.filter(file => file.source === source).sort((a, b) => b.addedAt - a.addedAt)
488
+ const active = source === 'downloads' ? download : undefined
489
+ const [newest, ...rest] = shown
490
+ const earlier = active ? shown : rest
491
+ const limit = source === 'screenshots' ? TILES : ROWS
492
+
493
+ const empty = !newest && !active
494
+ const header = (
495
+ <Widget.Header icon={SOURCE_ICON[source]}>
496
+ {active
497
+ ? ['Downloading', active.from].filter(Boolean).join(' · ')
498
+ : [SOURCE_LABEL[source], shown.length && `${shown.length} ${shown.length === 1 ? 'file' : 'files'}`]
499
+ .filter(Boolean)
500
+ .join(' · ')}
501
+ </Widget.Header>
502
+ )
503
+
504
+ const media = active ? (
505
+ <Thumbnail file={active} className={TILE[step]} />
506
+ ) : newest ? (
507
+ <span {...dragOf(newest, onDragStart)} className={cn(onDragStart && 'cursor-grab')}>
508
+ <Thumbnail file={newest} className={TILE[step]} />
509
+ </span>
510
+ ) : (
511
+ <Empty source={source} className={TILE[step]} />
512
+ )
513
+
514
+ const tabs = (
515
+ <Tabs variant="subtle" size="compact" value={source} onValueChange={v => setSource(v as RecentFilesSource)}>
516
+ <Tabs.List className="-ml-2">
517
+ <Tabs.Item value="downloads" label="Downloads" />
518
+ <Tabs.Item value="screenshots" label="Screenshots" />
519
+ </Tabs.List>
520
+ </Tabs>
521
+ )
522
+ const clear = onClear && !empty && (
523
+ <Button variant="ghost" size="compact" className="-mr-2 h-6 px-2" onClick={() => onClear(source)}>
524
+ Clear
525
+ </Button>
526
+ )
527
+ const nothing = (
528
+ <div className="flex min-w-0 flex-col gap-0.5">
529
+ <Widget.Title>{source === 'downloads' ? 'No downloads yet' : 'No screenshots yet'}</Widget.Title>
530
+ <span className="text-pretty text-caption text-muted-foreground">
531
+ {source === 'downloads'
532
+ ? 'Files you download land here, ready to open or drag out.'
533
+ : 'Take one with ⇧⌘4 and it shows up here, ready to drag into a message.'}
534
+ </span>
535
+ </div>
536
+ )
537
+
538
+ if (layout === 'tall')
539
+ return (
540
+ <Widget.Sheet size={size} className={className}>
541
+ <div className="flex min-w-0 items-center justify-between gap-2">
542
+ {tabs}
543
+ {clear}
544
+ </div>
545
+
546
+ <div className="flex min-w-0 items-center gap-6">
547
+ {active ? (
548
+ <Thumbnail file={active} glyph={40} className={SHEET_TILE[step]} />
549
+ ) : newest ? (
550
+ <span {...dragOf(newest, onDragStart)} className={cn('shrink-0', onDragStart && 'cursor-grab')}>
551
+ <Thumbnail file={newest} glyph={40} className={SHEET_TILE[step]} />
552
+ </span>
553
+ ) : (
554
+ <Empty source={source} className={SHEET_TILE[step]} />
555
+ )}
556
+ <div className="flex min-w-0 flex-1 flex-col gap-1">
557
+ {header}
558
+ {active ? (
559
+ <Downloading download={active} onCancel={onCancelDownload} />
560
+ ) : newest ? (
561
+ <Hero file={newest} now={now} props={props} />
562
+ ) : (
563
+ nothing
564
+ )}
565
+ </div>
566
+ </div>
567
+
568
+ {earlier.length > 0 && (
569
+ <Widget.Section
570
+ label={active ? 'Latest' : 'Earlier'}
571
+ trailing={<span className="tabular-nums">{earlier.length}</span>}
572
+ >
573
+ <div className="pt-1.5">
574
+ <Grid files={earlier} now={now} onOpen={onOpen} onDragStart={onDragStart} />
575
+ </div>
576
+ </Widget.Section>
577
+ )}
578
+ </Widget.Sheet>
579
+ )
580
+
581
+ return (
582
+ <Widget
583
+ size={size}
584
+ className={cn('h-full', className)}
585
+ media={media}
586
+ aside={
587
+ <div className="flex min-w-0 flex-col gap-1.5">
588
+ <div className="flex min-w-0 items-center justify-between gap-2">
589
+ {tabs}
590
+ <span className="flex shrink-0 items-center gap-1.5 text-caption tabular-nums text-muted-foreground">
591
+ {earlier.length > limit && <span>{earlier.length - limit} more</span>}
592
+ {clear}
593
+ </span>
594
+ </div>
595
+ {empty ? null : earlier.length === 0 ? (
596
+ <span className="flex h-7 items-center text-body text-muted-foreground">Nothing earlier</span>
597
+ ) : source === 'screenshots' ? (
598
+ <Tiles files={earlier} onOpen={onOpen} onDragStart={onDragStart} />
599
+ ) : (
600
+ <Rows files={earlier} now={now} onOpen={onOpen} onDragStart={onDragStart} />
601
+ )}
602
+ </div>
603
+ }
604
+ >
605
+ {header}
606
+ {active ? (
607
+ <Downloading download={active} onCancel={onCancelDownload} />
608
+ ) : newest ? (
609
+ <Hero file={newest} now={now} props={props} />
610
+ ) : (
611
+ nothing
612
+ )}
613
+ </Widget>
614
+ )
615
+ },
616
+ {
617
+ Leading: RecentFilesLeading,
618
+ Trailing: RecentFilesTrailing,
619
+ Minimal: RecentFilesMinimal,
620
+ Saved: RecentFilesSaved,
621
+ },
622
+ )
623
+
624
+ export default RecentFiles
625
+
626
+ export type { RecentDownload, RecentFile, RecentFilesProps, RecentFilesSource }
627
+ export { RecentFiles, RecentFilesLeading, RecentFilesMinimal, RecentFilesSaved, RecentFilesTrailing }
@@ -1,23 +1,60 @@
1
1
  import SystemStats from './index'
2
- import { WidgetIsland, WingsIsland } from '../../../mock/island-content'
3
- import { SAMPLES } from '../../../mock/data'
2
+ import { PLAYING, WidgetIsland, WingsIsland } from '../../../mock/island-content'
3
+ import { BATTERY, CHARGING, DISK, PRESSURE_READINGS, PROCESSES, READINGS, UPTIME } from '../../../mock/system'
4
+ import NowPlaying from '../../activities/now-playing'
4
5
 
5
6
  # System
6
7
 
7
- The latest reading as the figure, every reading so far as the trend.
8
+ The CPU load as the hero with its trend, the facts under it, the busiest processes beside it.
8
9
 
9
- <WidgetIsland tab="stats">
10
- <SystemStats samples={SAMPLES} />
10
+ <WidgetIsland tab="system">
11
+ <SystemStats samples={READINGS} battery={BATTERY} disk={DISK} uptime={UPTIME} processes={PROCESSES} />
12
+ </WidgetIsland>
13
+
14
+ # Memory pressure
15
+
16
+ When memory is what's tight, `hero="memory"` makes its pressure the figure; the line takes the warning hue.
17
+
18
+ <WidgetIsland tab="system">
19
+ <SystemStats samples={PRESSURE_READINGS} hero="memory" battery={CHARGING} disk={DISK} uptime={UPTIME} processes={PROCESSES} />
20
+ </WidgetIsland>
21
+
22
+ # Without processes
23
+
24
+ No `processes`, no aside: the hero takes the width.
25
+
26
+ <WidgetIsland tab="system">
27
+ <SystemStats samples={READINGS} disk={DISK} uptime={UPTIME} />
11
28
  </WidgetIsland>
12
29
 
13
30
  # Measuring
14
31
 
15
- Before the first reading.
32
+ Before the first reading the figures are dashes over the Sparkline's baseline; the battery and the disk need no second reading.
16
33
 
17
- <WidgetIsland tab="stats">
18
- <SystemStats samples={[]} />
34
+ <WidgetIsland tab="system">
35
+ <SystemStats samples={[]} battery={BATTERY} disk={DISK} uptime={UPTIME} />
19
36
  </WidgetIsland>
20
37
 
21
38
  # Compact
22
39
 
23
- <WingsIsland leading={<SystemStats.Leading />} trailing={<SystemStats.Trailing sample={SAMPLES[SAMPLES.length - 1]} />} />
40
+ `SystemStats.Leading` and `SystemStats.Trailing`: the CPU glyph and its load in the wings.
41
+
42
+ <WingsIsland leading={<SystemStats.Leading />} trailing={<SystemStats.Trailing sample={READINGS[READINGS.length - 1]} />} />
43
+
44
+ # Minimal
45
+
46
+ `SystemStats.Minimal`, the load as a ring in the split island's bubble, music in the wings.
47
+
48
+ <WingsIsland
49
+ leading={<NowPlaying.Leading track={PLAYING} />}
50
+ trailing={<NowPlaying.Trailing track={PLAYING} />}
51
+ minimal={<SystemStats.Minimal sample={READINGS[READINGS.length - 1]} />}
52
+ />
53
+
54
+ # Tall
55
+
56
+ `layout="tall"` at the island's tall snap: CPU and memory pressure side by side with their trends, the network's in and out as one graph beside the battery and the disk, and the top eight processes as a table.
57
+
58
+ <WidgetIsland tab="system" tall>
59
+ <SystemStats samples={READINGS} battery={BATTERY} disk={DISK} uptime={UPTIME} processes={PROCESSES} layout="tall" />
60
+ </WidgetIsland>