@justanarthur/modo-ui-notch 0.2.0 → 0.3.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.
- package/README.md +11 -11
- package/blocks/activities/agenda/examples.mdx +21 -5
- package/blocks/activities/agenda/index.tsx +291 -182
- package/blocks/activities/clock/examples.mdx +73 -0
- package/blocks/activities/clock/index.tsx +619 -0
- package/blocks/activities/now-playing/examples.mdx +32 -13
- package/blocks/activities/now-playing/index.tsx +319 -126
- package/blocks/activities/weather/examples.mdx +115 -0
- package/blocks/activities/weather/index.tsx +634 -0
- package/blocks/app/expanded-island/examples.mdx +8 -7
- package/blocks/app/expanded-island/index.tsx +19 -3
- package/blocks/app/settings-window/examples.mdx +6 -2
- package/blocks/app/settings-window/index.tsx +25 -7
- package/blocks/system/clipboard/examples.mdx +83 -0
- package/blocks/system/clipboard/index.tsx +563 -0
- package/blocks/system/recent-files/examples.mdx +66 -0
- package/blocks/system/recent-files/index.tsx +542 -0
- package/blocks/system/system-stats/examples.mdx +38 -9
- package/blocks/system/system-stats/index.tsx +241 -107
- package/components/indicators/media-scrubber/examples.mdx +8 -0
- package/components/indicators/media-scrubber/index.tsx +37 -13
- package/components/island/island/examples.mdx +4 -4
- package/components/island/island/index.tsx +2 -2
- package/components/island/island-flash/examples.mdx +15 -18
- package/components/island/island-flash/index.tsx +4 -4
- package/components/island/island-tabs/examples.mdx +5 -5
- package/components/island/widget/examples.mdx +76 -0
- package/components/island/widget/index.tsx +431 -0
- package/dist/blocks/activities/agenda/index.d.ts +1 -1
- package/dist/blocks/activities/agenda/index.js +3 -3
- package/dist/blocks/activities/clock/index.d.ts +2 -0
- package/dist/blocks/activities/clock/index.js +25 -0
- package/dist/blocks/activities/now-playing/index.d.ts +3 -2
- package/dist/blocks/activities/now-playing/index.js +5 -3
- package/dist/blocks/activities/weather/index.d.ts +2 -0
- package/dist/blocks/activities/weather/index.js +21 -0
- package/dist/blocks/app/expanded-island/index.d.ts +1 -1
- package/dist/blocks/app/expanded-island/index.js +4 -3
- package/dist/blocks/app/settings-window/index.d.ts +1 -1
- package/dist/blocks/app/settings-window/index.js +1 -1
- package/dist/blocks/system/clipboard/index.d.ts +2 -0
- package/dist/blocks/system/clipboard/index.js +17 -0
- package/dist/blocks/system/recent-files/index.d.ts +2 -0
- package/dist/blocks/system/recent-files/index.js +19 -0
- package/dist/blocks/system/system-stats/index.d.ts +2 -2
- package/dist/blocks/system/system-stats/index.js +4 -1
- package/dist/components/indicators/media-scrubber/index.d.ts +1 -1
- package/dist/components/indicators/media-scrubber/index.js +1 -1
- package/dist/components/island/island/index.d.ts +1 -1
- package/dist/components/island/island/index.js +2 -2
- package/dist/components/island/island-flash/index.d.ts +1 -1
- package/dist/components/island/island-flash/index.js +1 -1
- package/dist/components/island/island-tabs/index.js +2 -2
- package/dist/components/island/widget/index.d.ts +2 -0
- package/dist/components/island/widget/index.js +30 -0
- package/dist/index.d.ts +15 -15
- package/dist/index.js +102 -58
- package/dist/lib/artwork.d.ts +2 -0
- package/dist/lib/artwork.js +8 -0
- package/dist/lib/geometry.js +1 -1
- package/dist/shared/chunk-2818esrq.d.ts +140 -0
- package/dist/shared/{chunk-yngkkxz2.d.ts → chunk-2m5dz8nf.d.ts} +4 -4
- package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
- package/dist/shared/chunk-416tsgbc.d.ts +175 -0
- package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
- package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
- package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
- package/dist/shared/chunk-9c7ewvkk.js +381 -0
- package/dist/shared/{chunk-mp1nx0ez.js → chunk-9m0xbg5v.js} +14 -3
- package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
- package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
- package/dist/shared/{chunk-s33y1pcq.js → chunk-cc9nwbtf.js} +20 -10
- package/dist/shared/chunk-da177e8r.d.ts +114 -0
- package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
- package/dist/shared/chunk-j77cx8dp.js +498 -0
- package/dist/shared/chunk-mt0k6v8x.js +474 -0
- package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
- package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-pfhy5e4q.d.ts} +7 -1
- package/dist/shared/chunk-qdzemt2v.js +477 -0
- package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
- package/dist/shared/chunk-s2jeqqan.js +243 -0
- package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
- package/dist/shared/chunk-w5h6ay93.js +72 -0
- package/dist/shared/chunk-wkg17nxs.d.ts +101 -0
- package/dist/shared/chunk-x7f3g82r.js +285 -0
- package/dist/shared/chunk-xq5hc5gv.js +333 -0
- package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
- package/dist/shared/chunk-ym0xbses.js +518 -0
- package/dist/styles.css +97 -55
- package/index.ts +7 -6
- package/lib/artwork.ts +112 -0
- package/lib/geometry.ts +1 -1
- package/mock/activities.tsx +9 -32
- package/mock/artwork.tsx +13 -1
- package/mock/clipboard.tsx +79 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +30 -44
- package/mock/files.tsx +70 -0
- package/mock/island-content.tsx +43 -118
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +370 -91
- package/mock/system.ts +46 -0
- package/mock/weather.tsx +105 -0
- package/package.json +7 -2
- package/blocks/activities/shelf/examples.mdx +0 -33
- package/blocks/activities/shelf/index.tsx +0 -289
- package/blocks/activities/timer/examples.mdx +0 -52
- package/blocks/activities/timer/index.tsx +0 -292
- package/blocks/system/controls/examples.mdx +0 -34
- package/blocks/system/controls/index.tsx +0 -167
- package/blocks/system/devices/examples.mdx +0 -25
- package/blocks/system/devices/index.tsx +0 -172
- package/blocks/system/power-alert/examples.mdx +0 -32
- package/blocks/system/power-alert/index.tsx +0 -89
- package/components/indicators/battery-glyph/examples.mdx +0 -22
- package/components/indicators/battery-glyph/index.tsx +0 -91
- package/dist/blocks/activities/shelf/index.d.ts +0 -2
- package/dist/blocks/activities/shelf/index.js +0 -14
- package/dist/blocks/activities/timer/index.d.ts +0 -2
- package/dist/blocks/activities/timer/index.js +0 -19
- package/dist/blocks/system/controls/index.d.ts +0 -2
- package/dist/blocks/system/controls/index.js +0 -10
- package/dist/blocks/system/devices/index.d.ts +0 -2
- package/dist/blocks/system/devices/index.js +0 -12
- package/dist/blocks/system/power-alert/index.d.ts +0 -2
- package/dist/blocks/system/power-alert/index.js +0 -9
- package/dist/components/indicators/battery-glyph/index.d.ts +0 -2
- package/dist/components/indicators/battery-glyph/index.js +0 -9
- package/dist/shared/chunk-2qpcsv5h.d.ts +0 -45
- package/dist/shared/chunk-45gytfr1.d.ts +0 -84
- package/dist/shared/chunk-50ffk4r7.d.ts +0 -69
- package/dist/shared/chunk-5w0yck07.d.ts +0 -32
- package/dist/shared/chunk-7hr53mby.js +0 -116
- package/dist/shared/chunk-b8jb1w72.js +0 -145
- package/dist/shared/chunk-cpewy6yg.js +0 -178
- package/dist/shared/chunk-e3e4s4ds.d.ts +0 -77
- package/dist/shared/chunk-enm6td0p.js +0 -280
- package/dist/shared/chunk-fvedaas2.d.ts +0 -33
- package/dist/shared/chunk-gex38j8x.d.ts +0 -82
- package/dist/shared/chunk-hwtxpzg0.js +0 -69
- package/dist/shared/chunk-phb53x1f.js +0 -252
- package/dist/shared/chunk-r8esmjfs.d.ts +0 -42
- package/dist/shared/chunk-rcp1g9ca.js +0 -70
- package/dist/shared/chunk-rx9sphz2.js +0 -266
- package/dist/shared/chunk-xdeek16r.d.ts +0 -58
- package/dist/shared/chunk-xkzjk1tq.js +0 -206
|
@@ -0,0 +1,542 @@
|
|
|
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 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
|
+
/** Step on the size ladder. Omitted, it follows the surrounding SizeProvider. */
|
|
103
|
+
size?: SizeVariant
|
|
104
|
+
/** Classes for the root, which fills its container. */
|
|
105
|
+
className?: string
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const SOURCE_LABEL: Record<RecentFilesSource, string> = { downloads: 'Downloads', screenshots: 'Screenshots' }
|
|
109
|
+
const SOURCE_ICON: Record<RecentFilesSource, IconComponent> = { downloads: ArrowDownToLine, screenshots: Camera }
|
|
110
|
+
|
|
111
|
+
/** Rows the downloads list shows, and tiles the screenshots grid, before saying how many more. */
|
|
112
|
+
const ROWS = 3
|
|
113
|
+
const TILES = 6
|
|
114
|
+
|
|
115
|
+
const TYPES: [RegExp, IconComponent][] = [
|
|
116
|
+
[/\.(png|jpe?g|gif|webp|heic|svg|tiff?)$/i, FileImage],
|
|
117
|
+
[/\.(mov|mp4|m4v|avi|mkv|webm)$/i, FileVideo],
|
|
118
|
+
[/\.(mp3|m4a|wav|aiff?|flac|ogg)$/i, FileAudio],
|
|
119
|
+
[/\.(zip|tar|gz|tgz|rar|7z|dmg|xip)$/i, FileArchive],
|
|
120
|
+
[/\.(m?[jt]sx?|json|css|html|swift|rs|go|py|rb|sh|ya?ml|toml)$/i, FileCode],
|
|
121
|
+
[/\.(pdf|md|txt|rtf|docx?|pages|key|numbers|csv)$/i, FileText],
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
/** The glyph for a file's type, from its name's extension. */
|
|
125
|
+
const iconFor = (name: string) => TYPES.find(([pattern]) => pattern.test(name))?.[1] ?? File
|
|
126
|
+
|
|
127
|
+
/** Bytes as `2.4 MB`, `840 KB` or `1.2 GB`. */
|
|
128
|
+
function bytes(n: number) {
|
|
129
|
+
if (n >= 1e9) return `${(n / 1e9).toFixed(1)} GB`
|
|
130
|
+
if (n >= 1e6) return `${n >= 100e6 ? Math.round(n / 1e6) : (n / 1e6).toFixed(1)} MB`
|
|
131
|
+
return `${Math.max(1, Math.round(n / 1e3))} KB`
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Bytes in of a total, in the total's unit: `48 of 120 MB`. */
|
|
135
|
+
function part(n: number, total: number) {
|
|
136
|
+
const [unit, scale] = total >= 1e9 ? ['GB', 1e9] : total >= 1e6 ? ['MB', 1e6] : ['KB', 1e3]
|
|
137
|
+
const digits = total / scale < 10 ? 1 : 0
|
|
138
|
+
return `${(n / scale).toFixed(digits)} of ${(total / scale).toFixed(digits)} ${unit}`
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** How long ago, as a phrase: `just now`, `12 min ago`, `2 h ago`, `3 d ago`. */
|
|
142
|
+
function ago(ms: number) {
|
|
143
|
+
const minutes = Math.floor(ms / MINUTE)
|
|
144
|
+
if (minutes < 1) return 'just now'
|
|
145
|
+
if (minutes < 60) return `${minutes} min ago`
|
|
146
|
+
if (minutes < 24 * 60) return `${Math.floor(minutes / 60)} h ago`
|
|
147
|
+
return `${Math.floor(minutes / (24 * 60))} d ago`
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** How long ago, as a row's figure: `now`, `12 min`, `2 h`, `3 d`. */
|
|
151
|
+
function short(ms: number) {
|
|
152
|
+
const minutes = Math.floor(ms / MINUTE)
|
|
153
|
+
if (minutes < 1) return 'now'
|
|
154
|
+
if (minutes < 60) return `${minutes} min`
|
|
155
|
+
if (minutes < 24 * 60) return `${Math.floor(minutes / 60)} h`
|
|
156
|
+
return `${Math.floor(minutes / (24 * 60))} d`
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Seconds as `11 s left`, `4 min left`. */
|
|
160
|
+
function left(seconds: number) {
|
|
161
|
+
if (seconds < 60) return `${Math.max(1, Math.ceil(seconds))} s left`
|
|
162
|
+
if (seconds < 3600) return `${Math.ceil(seconds / 60)} min left`
|
|
163
|
+
return `${Math.floor(seconds / 3600)} h ${Math.ceil((seconds % 3600) / 60)} min left`
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Drag props for a file, when the host takes drags. */
|
|
167
|
+
const dragOf = (file: RecentFile, onDragStart?: RecentFilesProps['onDragStart']) =>
|
|
168
|
+
onDragStart ? { draggable: true, onDragStart: (event: DragEvent) => onDragStart(file, event) } : {}
|
|
169
|
+
|
|
170
|
+
// Literal tables: UnoCSS only generates the classes it can read whole.
|
|
171
|
+
const TILE = { default: 'size-24 rounded-xl', compact: 'size-20 rounded-xl' }
|
|
172
|
+
|
|
173
|
+
function Thumbnail({
|
|
174
|
+
file,
|
|
175
|
+
className,
|
|
176
|
+
glyph = 28,
|
|
177
|
+
}: {
|
|
178
|
+
file: { name: string; thumbnail?: string | ReactNode }
|
|
179
|
+
className: string
|
|
180
|
+
glyph?: number
|
|
181
|
+
}) {
|
|
182
|
+
const level = useLift(1)
|
|
183
|
+
const Icon = iconFor(file.name)
|
|
184
|
+
return (
|
|
185
|
+
<span
|
|
186
|
+
className={cn(
|
|
187
|
+
'relative flex shrink-0 items-center justify-center overflow-hidden text-muted-foreground',
|
|
188
|
+
file.thumbnail == null && SURFACE_BG[level],
|
|
189
|
+
className,
|
|
190
|
+
)}
|
|
191
|
+
>
|
|
192
|
+
{typeof file.thumbnail === 'string' ? (
|
|
193
|
+
<img alt="" src={file.thumbnail} draggable={false} className="size-full object-cover" />
|
|
194
|
+
) : (
|
|
195
|
+
(file.thumbnail ?? <Icon size={glyph} strokeWidth={1.25} />)
|
|
196
|
+
)}
|
|
197
|
+
<span
|
|
198
|
+
aria-hidden
|
|
199
|
+
className="pointer-events-none absolute inset-0 rounded-[inherit] ring-1 ring-border ring-inset"
|
|
200
|
+
/>
|
|
201
|
+
</span>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface HeroProps {
|
|
206
|
+
file: RecentFile
|
|
207
|
+
now: number
|
|
208
|
+
props: RecentFilesProps
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** The newest file: its name, size, age and where it came from, Show in Finder, Copy, Move to Trash and Open. */
|
|
212
|
+
function Hero({ file, now, props }: HeroProps) {
|
|
213
|
+
const { onOpen, onReveal, onCopy, onDelete } = props
|
|
214
|
+
return (
|
|
215
|
+
<div className="flex min-w-0 flex-col gap-2">
|
|
216
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
217
|
+
<Widget.Title>{file.name}</Widget.Title>
|
|
218
|
+
<Widget.Subtitle>
|
|
219
|
+
{[bytes(file.size), ago(now - file.addedAt), file.from && `from ${file.from}`].filter(Boolean).join(' · ')}
|
|
220
|
+
</Widget.Subtitle>
|
|
221
|
+
</div>
|
|
222
|
+
<div className="-mr-1 flex min-w-0 items-center justify-end gap-0.5">
|
|
223
|
+
{onReveal && <Widget.Action icon={FolderSearch} label="Show in Finder" onClick={() => onReveal(file)} />}
|
|
224
|
+
{onCopy && <Widget.Action icon={Copy} label="Copy" onClick={() => onCopy(file)} />}
|
|
225
|
+
{onDelete && <Widget.Action icon={Trash2} label="Move to Trash" onClick={() => onDelete(file)} />}
|
|
226
|
+
<Button
|
|
227
|
+
variant="primary"
|
|
228
|
+
size="compact"
|
|
229
|
+
leadingIcon={ArrowUpRight}
|
|
230
|
+
className="ml-1.5"
|
|
231
|
+
onClick={() => onOpen?.(file)}
|
|
232
|
+
>
|
|
233
|
+
Open
|
|
234
|
+
</Button>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** The download under way: its name, the progress as a line, how much, how fast and how long, and Cancel. */
|
|
241
|
+
function Downloading({
|
|
242
|
+
download,
|
|
243
|
+
onCancel,
|
|
244
|
+
}: {
|
|
245
|
+
download: RecentDownload
|
|
246
|
+
onCancel?: (download: RecentDownload) => void
|
|
247
|
+
}) {
|
|
248
|
+
const share = download.received / download.total
|
|
249
|
+
return (
|
|
250
|
+
<div className="flex min-w-0 flex-col gap-1.5">
|
|
251
|
+
<div className="flex min-w-0 items-center gap-3">
|
|
252
|
+
<Widget.Title className="flex-1">{download.name}</Widget.Title>
|
|
253
|
+
<span className="shrink-0 text-caption tabular-nums text-muted-foreground">{Math.round(share * 100)}%</span>
|
|
254
|
+
{onCancel && (
|
|
255
|
+
<span className="-my-1 -mr-1 flex shrink-0">
|
|
256
|
+
<Widget.Action icon={X} label="Cancel download" onClick={() => onCancel(download)} />
|
|
257
|
+
</span>
|
|
258
|
+
)}
|
|
259
|
+
</div>
|
|
260
|
+
<Meter variant="line" value={share} tone="default" label={`${download.name}, ${Math.round(share * 100)}%`} />
|
|
261
|
+
<Widget.Meta>
|
|
262
|
+
<Widget.MetaItem>{part(download.received, download.total)}</Widget.MetaItem>
|
|
263
|
+
<Widget.MetaItem>{bytes(download.rate)}/s</Widget.MetaItem>
|
|
264
|
+
<Widget.MetaItem>{left((download.total - download.received) / Math.max(1, download.rate))}</Widget.MetaItem>
|
|
265
|
+
</Widget.Meta>
|
|
266
|
+
</div>
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** An empty folder's tile: its glyph one surface up. */
|
|
271
|
+
function Empty({ source, className }: { source: RecentFilesSource; className: string }) {
|
|
272
|
+
const level = useLift(1)
|
|
273
|
+
const Icon = SOURCE_ICON[source]
|
|
274
|
+
return (
|
|
275
|
+
<span
|
|
276
|
+
className={cn('flex shrink-0 items-center justify-center text-muted-foreground', SURFACE_BG[level], className)}
|
|
277
|
+
>
|
|
278
|
+
<Icon size={28} strokeWidth={1.25} />
|
|
279
|
+
</span>
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface ListProps {
|
|
284
|
+
files: RecentFile[]
|
|
285
|
+
now: number
|
|
286
|
+
onOpen?: (file: RecentFile) => void
|
|
287
|
+
onDragStart?: RecentFilesProps['onDragStart']
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Earlier downloads as rows: how long ago, the file's glyph and name, its size. */
|
|
291
|
+
function Rows({ files, now, onOpen, onDragStart }: ListProps) {
|
|
292
|
+
return (
|
|
293
|
+
<FluidHover className="-mx-2 flex flex-col gap-0">
|
|
294
|
+
{files.slice(0, ROWS).map((file, index) => {
|
|
295
|
+
const Icon = iconFor(file.name)
|
|
296
|
+
return (
|
|
297
|
+
<FluidHover.Item
|
|
298
|
+
key={file.id}
|
|
299
|
+
index={index}
|
|
300
|
+
title={file.name}
|
|
301
|
+
className="h-7 px-2"
|
|
302
|
+
onClick={() => onOpen?.(file)}
|
|
303
|
+
{...dragOf(file, onDragStart)}
|
|
304
|
+
>
|
|
305
|
+
<Widget.Row className="w-full" leading={short(now - file.addedAt)} trailing={bytes(file.size)}>
|
|
306
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
307
|
+
<Icon size={14} strokeWidth={1.5} className="shrink-0 text-muted-foreground" />
|
|
308
|
+
<span className="min-w-0 truncate">{file.name}</span>
|
|
309
|
+
</span>
|
|
310
|
+
</Widget.Row>
|
|
311
|
+
</FluidHover.Item>
|
|
312
|
+
)
|
|
313
|
+
})}
|
|
314
|
+
</FluidHover>
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Earlier screenshots as a grid of image tiles. */
|
|
319
|
+
function Tiles({ files, onOpen, onDragStart }: Omit<ListProps, 'now'>) {
|
|
320
|
+
return (
|
|
321
|
+
<FluidHover columns={3} className="-m-1 grid-cols-3 gap-0" highlightClassName="rounded-lg">
|
|
322
|
+
{files.slice(0, TILES).map((file, index) => (
|
|
323
|
+
<FluidHover.Item
|
|
324
|
+
key={file.id}
|
|
325
|
+
index={index}
|
|
326
|
+
title={file.name}
|
|
327
|
+
aria-label={file.name}
|
|
328
|
+
className="min-h-0 p-1"
|
|
329
|
+
onClick={() => onOpen?.(file)}
|
|
330
|
+
{...dragOf(file, onDragStart)}
|
|
331
|
+
>
|
|
332
|
+
<Thumbnail file={file} glyph={16} className="aspect-[16/10] w-full rounded-md" />
|
|
333
|
+
</FluidHover.Item>
|
|
334
|
+
))}
|
|
335
|
+
</FluidHover>
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** The compact island's left wing: the download glyph, or the camera for a screenshot. */
|
|
340
|
+
function RecentFilesLeading({ source = 'downloads' }: { source?: RecentFilesSource }) {
|
|
341
|
+
const Icon = SOURCE_ICON[source]
|
|
342
|
+
return <Icon size={16} strokeWidth={1.5} className="text-foreground" />
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
interface TrailingProps {
|
|
346
|
+
/** A download under way: its progress shows. */
|
|
347
|
+
download?: RecentDownload | null
|
|
348
|
+
/** Otherwise, how many files came in since the island was open. */
|
|
349
|
+
count?: number
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** The compact island's right wing: a download's progress, else the count of new files. */
|
|
353
|
+
function RecentFilesTrailing({ download, count = 0 }: TrailingProps) {
|
|
354
|
+
return (
|
|
355
|
+
<span className="text-caption weight-semibold tabular-nums text-foreground">
|
|
356
|
+
{download ? `${Math.round((download.received / download.total) * 100)}%` : count}
|
|
357
|
+
</span>
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** The split island's bubble: a download's progress as a ring. */
|
|
362
|
+
function RecentFilesMinimal({ download }: { download: RecentDownload }) {
|
|
363
|
+
const share = download.received / download.total
|
|
364
|
+
return (
|
|
365
|
+
<Meter
|
|
366
|
+
variant="ring"
|
|
367
|
+
className="size-5.5"
|
|
368
|
+
size="compact"
|
|
369
|
+
tone="default"
|
|
370
|
+
value={share}
|
|
371
|
+
label={`${download.name}, ${Math.round(share * 100)}%`}
|
|
372
|
+
/>
|
|
373
|
+
)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
interface SavedProps {
|
|
377
|
+
/** The file that landed. */
|
|
378
|
+
file: RecentFile
|
|
379
|
+
/** Called by Open; without it the button hides. */
|
|
380
|
+
onOpen?: (file: RecentFile) => void
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** The island's flash when a file lands: its thumbnail or glyph, `Downloaded` or `Screenshot saved`, and Open. */
|
|
384
|
+
function RecentFilesSaved({ file, onOpen }: SavedProps) {
|
|
385
|
+
return (
|
|
386
|
+
<IslandFlash
|
|
387
|
+
icon={<Thumbnail file={file} glyph={16} className="size-9 rounded-lg" />}
|
|
388
|
+
title={file.source === 'screenshots' ? 'Screenshot saved' : 'Downloaded'}
|
|
389
|
+
caption={`${file.name} · ${bytes(file.size)}`}
|
|
390
|
+
action={
|
|
391
|
+
onOpen && (
|
|
392
|
+
<Button variant="secondary" size="compact" onClick={() => onOpen(file)}>
|
|
393
|
+
Open
|
|
394
|
+
</Button>
|
|
395
|
+
)
|
|
396
|
+
}
|
|
397
|
+
/>
|
|
398
|
+
)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* A notch app's recent files: the newest download or screenshot as the
|
|
403
|
+
* hero, the ones before it beside it, ready to open or drag out.
|
|
404
|
+
*
|
|
405
|
+
* The hero is the folder's newest file: its thumbnail, or its type's
|
|
406
|
+
* glyph on a tile, then its name, its size, how long ago it landed and
|
|
407
|
+
* where it came from, with Show in Finder, Copy, Move to Trash and Open.
|
|
408
|
+
* Beside it, past a hairline, a switch picks the folder, Downloads or
|
|
409
|
+
* Screenshots (`value` / `defaultValue` / `onValueChange`), over the ones
|
|
410
|
+
* before the newest: downloads as rows of age, glyph, name and size, and
|
|
411
|
+
* screenshots as a grid of image tiles, since a screenshot is found by
|
|
412
|
+
* its look. A press opens a file, and with `onDragStart` every picture and
|
|
413
|
+
* row drags out (the host starts the native drag); Clear empties the list.
|
|
414
|
+
*
|
|
415
|
+
* While a download is under way (`download`) it takes the hero on
|
|
416
|
+
* Downloads: its name, the progress as a modo-ui Meter line, how much is
|
|
417
|
+
* in, the speed and the time left, and Cancel. An empty folder says what
|
|
418
|
+
* will land in it, the switch still beside it.
|
|
419
|
+
*
|
|
420
|
+
* `RecentFiles.Leading` and `RecentFiles.Trailing` show the glyph and the
|
|
421
|
+
* download's progress (or the count of new files) in the compact island's
|
|
422
|
+
* wings, `RecentFiles.Minimal` the progress as a ring in the split
|
|
423
|
+
* island's bubble, and `RecentFiles.Saved` is the flash when a file lands.
|
|
424
|
+
*
|
|
425
|
+
* @example {@include ./examples.mdx}
|
|
426
|
+
*/
|
|
427
|
+
const RecentFiles = Object.assign(
|
|
428
|
+
function RecentFiles(props: RecentFilesProps) {
|
|
429
|
+
const {
|
|
430
|
+
files,
|
|
431
|
+
download,
|
|
432
|
+
value: valueProp,
|
|
433
|
+
defaultValue = 'downloads',
|
|
434
|
+
onValueChange,
|
|
435
|
+
onOpen,
|
|
436
|
+
onDragStart,
|
|
437
|
+
onClear,
|
|
438
|
+
onCancelDownload,
|
|
439
|
+
now: nowProp,
|
|
440
|
+
size,
|
|
441
|
+
className,
|
|
442
|
+
} = props
|
|
443
|
+
const ticking = useEdgeClock(0, nowProp === undefined, MINUTE)
|
|
444
|
+
const now = nowProp ?? ticking
|
|
445
|
+
const [source, setSource] = useControllableState(valueProp, defaultValue, onValueChange)
|
|
446
|
+
const step = size ?? 'default'
|
|
447
|
+
|
|
448
|
+
const shown = files.filter(file => file.source === source).sort((a, b) => b.addedAt - a.addedAt)
|
|
449
|
+
const active = source === 'downloads' ? download : undefined
|
|
450
|
+
const [newest, ...rest] = shown
|
|
451
|
+
const earlier = active ? shown : rest
|
|
452
|
+
const limit = source === 'screenshots' ? TILES : ROWS
|
|
453
|
+
|
|
454
|
+
const empty = !newest && !active
|
|
455
|
+
const header = (
|
|
456
|
+
<Widget.Header icon={SOURCE_ICON[source]}>
|
|
457
|
+
{active
|
|
458
|
+
? ['Downloading', active.from].filter(Boolean).join(' · ')
|
|
459
|
+
: [SOURCE_LABEL[source], shown.length && `${shown.length} ${shown.length === 1 ? 'file' : 'files'}`]
|
|
460
|
+
.filter(Boolean)
|
|
461
|
+
.join(' · ')}
|
|
462
|
+
</Widget.Header>
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
const media = active ? (
|
|
466
|
+
<Thumbnail file={active} className={TILE[step]} />
|
|
467
|
+
) : newest ? (
|
|
468
|
+
<span {...dragOf(newest, onDragStart)} className={cn(onDragStart && 'cursor-grab')}>
|
|
469
|
+
<Thumbnail file={newest} className={TILE[step]} />
|
|
470
|
+
</span>
|
|
471
|
+
) : (
|
|
472
|
+
<Empty source={source} className={TILE[step]} />
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
return (
|
|
476
|
+
<Widget
|
|
477
|
+
size={size}
|
|
478
|
+
className={cn('h-full', className)}
|
|
479
|
+
media={media}
|
|
480
|
+
aside={
|
|
481
|
+
<div className="flex min-w-0 flex-col gap-1.5">
|
|
482
|
+
<div className="flex min-w-0 items-center justify-between gap-2">
|
|
483
|
+
<Tabs
|
|
484
|
+
variant="subtle"
|
|
485
|
+
size="compact"
|
|
486
|
+
value={source}
|
|
487
|
+
onValueChange={v => setSource(v as RecentFilesSource)}
|
|
488
|
+
>
|
|
489
|
+
<Tabs.List className="-ml-2">
|
|
490
|
+
<Tabs.Item value="downloads" label="Downloads" />
|
|
491
|
+
<Tabs.Item value="screenshots" label="Screenshots" />
|
|
492
|
+
</Tabs.List>
|
|
493
|
+
</Tabs>
|
|
494
|
+
<span className="flex shrink-0 items-center gap-1.5 text-caption tabular-nums text-muted-foreground">
|
|
495
|
+
{earlier.length > limit && <span>{earlier.length - limit} more</span>}
|
|
496
|
+
{onClear && !empty && (
|
|
497
|
+
<Button variant="ghost" size="compact" className="-mr-2 h-6 px-2" onClick={() => onClear(source)}>
|
|
498
|
+
Clear
|
|
499
|
+
</Button>
|
|
500
|
+
)}
|
|
501
|
+
</span>
|
|
502
|
+
</div>
|
|
503
|
+
{empty ? null : earlier.length === 0 ? (
|
|
504
|
+
<span className="flex h-7 items-center text-body text-muted-foreground">Nothing earlier</span>
|
|
505
|
+
) : source === 'screenshots' ? (
|
|
506
|
+
<Tiles files={earlier} onOpen={onOpen} onDragStart={onDragStart} />
|
|
507
|
+
) : (
|
|
508
|
+
<Rows files={earlier} now={now} onOpen={onOpen} onDragStart={onDragStart} />
|
|
509
|
+
)}
|
|
510
|
+
</div>
|
|
511
|
+
}
|
|
512
|
+
>
|
|
513
|
+
{header}
|
|
514
|
+
{active ? (
|
|
515
|
+
<Downloading download={active} onCancel={onCancelDownload} />
|
|
516
|
+
) : newest ? (
|
|
517
|
+
<Hero file={newest} now={now} props={props} />
|
|
518
|
+
) : (
|
|
519
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
520
|
+
<Widget.Title>{source === 'downloads' ? 'No downloads yet' : 'No screenshots yet'}</Widget.Title>
|
|
521
|
+
<span className="text-pretty text-caption text-muted-foreground">
|
|
522
|
+
{source === 'downloads'
|
|
523
|
+
? 'Files you download land here, ready to open or drag out.'
|
|
524
|
+
: 'Take one with ⇧⌘4 and it shows up here, ready to drag into a message.'}
|
|
525
|
+
</span>
|
|
526
|
+
</div>
|
|
527
|
+
)}
|
|
528
|
+
</Widget>
|
|
529
|
+
)
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
Leading: RecentFilesLeading,
|
|
533
|
+
Trailing: RecentFilesTrailing,
|
|
534
|
+
Minimal: RecentFilesMinimal,
|
|
535
|
+
Saved: RecentFilesSaved,
|
|
536
|
+
},
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
export default RecentFiles
|
|
540
|
+
|
|
541
|
+
export type { RecentDownload, RecentFile, RecentFilesProps, RecentFilesSource }
|
|
542
|
+
export { RecentFiles, RecentFilesLeading, RecentFilesMinimal, RecentFilesSaved, RecentFilesTrailing }
|
|
@@ -1,23 +1,52 @@
|
|
|
1
1
|
import SystemStats from './index'
|
|
2
|
-
import { WidgetIsland, WingsIsland } from '../../../mock/island-content'
|
|
3
|
-
import {
|
|
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
|
|
8
|
+
The CPU load as the hero with its trend, the facts under it, the busiest processes beside it.
|
|
8
9
|
|
|
9
|
-
<WidgetIsland tab="
|
|
10
|
-
<SystemStats 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="
|
|
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
|
-
|
|
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
|
+
/>
|