@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,218 @@
1
+ /*!
2
+ * Local addition: what's playing, in every form a notch app shows it.
3
+ * Rebuilt from Just Notch's now-playing plugin (`Player`, `Artwork`,
4
+ * `TrackFlash`) as presentational parts: the track and the commands come in
5
+ * as props.
6
+ */
7
+
8
+ 'use client'
9
+
10
+ import Button from '@justanarthur/modo-ui/components/actions/button'
11
+ import EmptyState from '@justanarthur/modo-ui/components/feedback/empty-state'
12
+ import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
13
+ import { cn } from '@justanarthur/modo-ui/lib/utils'
14
+ import { Music, Pause, Play, SkipBack, SkipForward } from 'lucide-react'
15
+ import type { ReactNode } from 'react'
16
+ import Equalizer from '../../../components/indicators/equalizer'
17
+ import MediaScrubber from '../../../components/indicators/media-scrubber'
18
+ import IslandFlash from '../../../components/island/island-flash'
19
+
20
+ interface NowPlayingTrack {
21
+ title: string
22
+ artist?: string
23
+ album?: string
24
+ /** The artwork: an image URL, or any element (an `<img>`, a generated tile). */
25
+ artwork?: string | ReactNode
26
+ /** The app it plays in, shown under the controls. */
27
+ source?: string
28
+ /** The track's length, in seconds; `0` for a stream, which hides the scrubber. */
29
+ duration: number
30
+ /** Where playback is, in seconds. */
31
+ position: number
32
+ }
33
+
34
+ interface NowPlayingProps {
35
+ /** What plays; without one the player says nothing is playing. */
36
+ track?: NowPlayingTrack | null
37
+ /** It plays (controlled). */
38
+ playing?: boolean
39
+ /** It plays at first (uncontrolled). Defaults to `true`. */
40
+ defaultPlaying?: boolean
41
+ /** Called with the new state when play / pause is pressed. */
42
+ onPlayingChange?: (playing: boolean) => void
43
+ /** Called when the previous button is pressed. */
44
+ onPrevious?: () => void
45
+ /** Called when the next button is pressed. */
46
+ onNext?: () => void
47
+ /** Called with the position to seek to, once, when a drag on the scrubber ends. */
48
+ onSeek?: (seconds: number) => void
49
+ /** The empty state's line. Defaults to `'Play something in Music, Spotify or a browser.'`. */
50
+ emptyDescription?: ReactNode
51
+ /** Classes for the root, which fills its container. */
52
+ className?: string
53
+ }
54
+
55
+ const GLYPH = { strokeWidth: 1.5, fill: 'currentColor', strokeLinejoin: 'round' } as const
56
+
57
+ interface ArtworkProps {
58
+ /** The track's artwork; without one, a note on a tile one surface up. */
59
+ artwork?: string | ReactNode
60
+ /** The note's size in px when there is no artwork. Defaults to `14`. */
61
+ glyph?: number
62
+ /** Classes for the tile: its size and radius. */
63
+ className?: string
64
+ }
65
+
66
+ /** A track's artwork in a tile, or a note on a raised tile when it has none. */
67
+ function NowPlayingArtwork({ artwork, glyph = 14, className }: ArtworkProps) {
68
+ return (
69
+ <span
70
+ className={cn(
71
+ 'flex shrink-0 items-center justify-center overflow-hidden bg-surface-3 text-muted-foreground',
72
+ className,
73
+ )}
74
+ >
75
+ {typeof artwork === 'string' ? (
76
+ <img alt="" src={artwork} draggable={false} className="size-full object-cover" />
77
+ ) : (
78
+ (artwork ?? <Music size={glyph} strokeWidth={1.5} />)
79
+ )}
80
+ </span>
81
+ )
82
+ }
83
+
84
+ /** The compact island's left wing: the artwork, small. */
85
+ function NowPlayingLeading({ track }: { track?: Pick<NowPlayingTrack, 'artwork'> | null }) {
86
+ return <NowPlayingArtwork artwork={track?.artwork} glyph={12} className="size-5.5 rounded-md" />
87
+ }
88
+
89
+ /** The compact island's right wing: the level bars, low while paused. */
90
+ function NowPlayingTrailing({ playing = true }: { playing?: boolean }) {
91
+ return <Equalizer playing={playing} label={playing ? 'Playing' : 'Paused'} />
92
+ }
93
+
94
+ /** The split island's bubble: the artwork as a disc. */
95
+ function NowPlayingMinimal({ track }: { track?: Pick<NowPlayingTrack, 'artwork'> | null }) {
96
+ return <NowPlayingArtwork artwork={track?.artwork} glyph={12} className="size-6 rounded-full" />
97
+ }
98
+
99
+ /** The island's flash when the track changes: its artwork, title and artist, and the bars. */
100
+ function NowPlayingFlash({ track, playing = true }: { track: NowPlayingTrack; playing?: boolean }) {
101
+ return (
102
+ <IslandFlash
103
+ icon={<NowPlayingArtwork artwork={track.artwork} className="size-8 rounded-lg" />}
104
+ title={track.title || 'Unknown title'}
105
+ caption={track.artist || track.album || track.source}
106
+ trailing={<Equalizer playing={playing} />}
107
+ />
108
+ )
109
+ }
110
+
111
+ interface ControlsProps {
112
+ playing: boolean
113
+ onToggle: () => void
114
+ onPrevious?: () => void
115
+ onNext?: () => void
116
+ }
117
+
118
+ function Controls({ playing, onToggle, onPrevious, onNext }: ControlsProps) {
119
+ return (
120
+ <div className="flex items-center gap-2">
121
+ <Button variant="ghost" size="icon" aria-label="Previous" onClick={onPrevious}>
122
+ <SkipBack {...GLYPH} size={16} />
123
+ </Button>
124
+ <Button
125
+ variant="ghost"
126
+ size="icon"
127
+ className="text-foreground"
128
+ aria-label={playing ? 'Pause' : 'Play'}
129
+ onClick={onToggle}
130
+ >
131
+ {playing ? <Pause {...GLYPH} size={18} /> : <Play {...GLYPH} size={18} />}
132
+ </Button>
133
+ <Button variant="ghost" size="icon" aria-label="Next" onClick={onNext}>
134
+ <SkipForward {...GLYPH} size={16} />
135
+ </Button>
136
+ </div>
137
+ )
138
+ }
139
+
140
+ /**
141
+ * What's playing, as a notch app's open island shows it: the artwork, the
142
+ * title and artist, where the track is, and the transport.
143
+ *
144
+ * The scrubber is the kit's MediaScrubber: it runs on by itself while
145
+ * playing and seeks once when a drag ends (`onSeek`). Play / pause is
146
+ * controlled through `playing` / `onPlayingChange`, or kept here from
147
+ * `defaultPlaying`; previous and next report their press. Without artwork a
148
+ * big square would be an empty box, so a small note tile leads the title row
149
+ * instead. Without a track it says nothing is playing.
150
+ *
151
+ * The other forms are parts: `NowPlaying.Leading` and `NowPlaying.Trailing`
152
+ * for the compact island's wings (the artwork, and an Equalizer that settles
153
+ * when paused), `NowPlaying.Minimal` for the split island's bubble (the
154
+ * artwork as a disc), `NowPlaying.Flash` for the flash on a track change and
155
+ * `NowPlaying.Artwork` for the tile on its own.
156
+ *
157
+ * @example {@include ./examples.mdx}
158
+ */
159
+ function NowPlaying({
160
+ track,
161
+ playing: playingProp,
162
+ defaultPlaying = true,
163
+ onPlayingChange,
164
+ onPrevious,
165
+ onNext,
166
+ onSeek,
167
+ emptyDescription = 'Play something in Music, Spotify or a browser.',
168
+ className,
169
+ }: NowPlayingProps) {
170
+ const [playing, setPlaying] = useControllableState(playingProp, defaultPlaying, onPlayingChange)
171
+
172
+ if (!track)
173
+ return (
174
+ <div className={cn('flex size-full items-center justify-center', className)}>
175
+ <EmptyState size="compact" icon={Music} title="Nothing playing" description={emptyDescription} />
176
+ </div>
177
+ )
178
+
179
+ const art = track.artwork !== undefined
180
+ return (
181
+ <div className={cn('flex size-full items-center gap-5', className)}>
182
+ {art && <NowPlayingArtwork artwork={track.artwork} className="size-30 rounded-2xl" />}
183
+ <div className="flex min-w-0 flex-1 flex-col gap-2">
184
+ <div className="flex items-center gap-3">
185
+ {!art && <NowPlayingArtwork glyph={18} className="size-10 rounded-xl" />}
186
+ <div className="flex min-w-0 flex-1 flex-col">
187
+ <span className="truncate text-subtitle weight-semibold text-foreground">
188
+ {track.title || 'Unknown title'}
189
+ </span>
190
+ {(track.artist || track.album) && (
191
+ <span className="truncate text-caption text-muted-foreground">{track.artist || track.album}</span>
192
+ )}
193
+ </div>
194
+ <Equalizer playing={playing} />
195
+ </div>
196
+ {track.duration > 0 && (
197
+ <MediaScrubber position={track.position} duration={track.duration} playing={playing} onSeek={onSeek} />
198
+ )}
199
+ <div className="grid grid-cols-[1fr_auto_1fr] items-center gap-3">
200
+ <span className="truncate text-caption text-muted-foreground">{track.source}</span>
201
+ <Controls playing={playing} onToggle={() => setPlaying(!playing)} onPrevious={onPrevious} onNext={onNext} />
202
+ <span />
203
+ </div>
204
+ </div>
205
+ </div>
206
+ )
207
+ }
208
+
209
+ NowPlaying.Artwork = NowPlayingArtwork
210
+ NowPlaying.Leading = NowPlayingLeading
211
+ NowPlaying.Trailing = NowPlayingTrailing
212
+ NowPlaying.Minimal = NowPlayingMinimal
213
+ NowPlaying.Flash = NowPlayingFlash
214
+
215
+ export default NowPlaying
216
+
217
+ export type { NowPlayingProps, NowPlayingTrack }
218
+ export { NowPlaying, NowPlayingArtwork, NowPlayingFlash, NowPlayingLeading, NowPlayingMinimal, NowPlayingTrailing }
@@ -0,0 +1,33 @@
1
+ import Shelf from './index'
2
+ import { FlashIsland, SHELF, WidgetIsland, WingsIsland } from '../../../mock/island-content'
3
+
4
+ # Shelf
5
+
6
+ Right-click a tile for Open, Show in Finder and Remove; Clear empties the shelf.
7
+
8
+ <WidgetIsland tab="shelf">
9
+ <Shelf defaultValue={SHELF} onAirDrop={() => {}} />
10
+ </WidgetIsland>
11
+
12
+ # Empty
13
+
14
+ <WidgetIsland tab="shelf">
15
+ <Shelf />
16
+ </WidgetIsland>
17
+
18
+ # Dropping
19
+
20
+ `Shelf.Drop` while files hover over the notch, a dashed target in the brand hue, then once they land.
21
+
22
+ <div className="flex w-full flex-col gap-3">
23
+ <FlashIsland activity="dragging">
24
+ <Shelf.Drop phase="dragging" count={2} />
25
+ </FlashIsland>
26
+ <FlashIsland activity="added">
27
+ <Shelf.Drop phase="added" count={2} total={6} />
28
+ </FlashIsland>
29
+ </div>
30
+
31
+ # Compact
32
+
33
+ <WingsIsland leading={<Shelf.Leading />} trailing={<Shelf.Trailing count={6} />} />
@@ -0,0 +1,289 @@
1
+ /*!
2
+ * Local addition: a notch app's file shelf, the files dragged onto the notch
3
+ * to keep for later. Rebuilt from Just Notch's shelf plugin (`Shelf`, `Tile`,
4
+ * `DropFlash`, `Count`) as presentational parts: the files and what to do
5
+ * with them come in as props.
6
+ */
7
+
8
+ 'use client'
9
+
10
+ import Button from '@justanarthur/modo-ui/components/actions/button'
11
+ import EmptyState from '@justanarthur/modo-ui/components/feedback/empty-state'
12
+ import ContextMenu from '@justanarthur/modo-ui/components/overlays/context-menu'
13
+ import { useReduceMotion } from '@justanarthur/modo-ui/lib/reduced-motion'
14
+ import { spring } from '@justanarthur/modo-ui/lib/springs'
15
+ import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
16
+ import { cn } from '@justanarthur/modo-ui/lib/utils'
17
+ import FluidHover from '@justanarthur/modo-ui/primitives/systems/fluid-hover'
18
+ import {
19
+ ArrowDownToLine,
20
+ Check,
21
+ File,
22
+ FileArchive,
23
+ FileAudio,
24
+ FileCode,
25
+ FileImage,
26
+ Files,
27
+ FileText,
28
+ FileVideo,
29
+ type LucideIcon,
30
+ Send,
31
+ Trash2,
32
+ } from 'lucide-react'
33
+ import { AnimatePresence, motion } from 'motion/react'
34
+ import { type ReactNode, useRef } from 'react'
35
+
36
+ interface ShelfFile {
37
+ /** What tells it apart: its path. */
38
+ id: string
39
+ /** Its name, shown under the tile. */
40
+ name: string
41
+ /** A preview: an image URL, or any element. Without one, an icon for the file's type. */
42
+ thumbnail?: string | ReactNode
43
+ }
44
+
45
+ interface ShelfProps {
46
+ /** The files on the shelf, in order (controlled). */
47
+ value?: ShelfFile[]
48
+ /** The files at first (uncontrolled). Defaults to `[]`. */
49
+ defaultValue?: ShelfFile[]
50
+ /** Called with the files left after Remove or Clear. */
51
+ onValueChange?: (files: ShelfFile[]) => void
52
+ /** Called on a double-click or the menu's Open. */
53
+ onOpen?: (file: ShelfFile) => void
54
+ /** Called on the menu's Show in Finder. */
55
+ onReveal?: (file: ShelfFile) => void
56
+ /** Called with every file on AirDrop; without it the button hides. */
57
+ onAirDrop?: (files: ShelfFile[]) => void
58
+ /** Called when a tile starts to be dragged out, for the host to start a native drag. */
59
+ onDragOut?: (file: ShelfFile) => void
60
+ /** Classes for the root, which fills its container. */
61
+ className?: string
62
+ }
63
+
64
+ const DRAG_SLOP_PX = 4
65
+
66
+ const TYPES: [RegExp, LucideIcon][] = [
67
+ [/\.(png|jpe?g|gif|webp|heic|svg|tiff?)$/i, FileImage],
68
+ [/\.(mov|mp4|m4v|avi|mkv|webm)$/i, FileVideo],
69
+ [/\.(mp3|m4a|wav|aiff?|flac|ogg)$/i, FileAudio],
70
+ [/\.(zip|tar|gz|tgz|rar|7z|dmg)$/i, FileArchive],
71
+ [/\.(m?[jt]sx?|json|css|html|swift|rs|go|py|rb|sh|ya?ml|toml)$/i, FileCode],
72
+ [/\.(pdf|md|txt|rtf|docx?|pages|key|numbers|csv)$/i, FileText],
73
+ ]
74
+
75
+ /** The icon for a file's type, from its name's extension. */
76
+ const iconFor = (name: string) => TYPES.find(([pattern]) => pattern.test(name))?.[1] ?? File
77
+
78
+ const count = (n: number) => `${n} ${n === 1 ? 'file' : 'files'}`
79
+
80
+ interface TileProps {
81
+ file: ShelfFile
82
+ index: number
83
+ onOpen?: (file: ShelfFile) => void
84
+ onReveal?: (file: ShelfFile) => void
85
+ onRemove: (file: ShelfFile) => void
86
+ onDragOut?: (file: ShelfFile) => void
87
+ }
88
+
89
+ function Thumbnail({ file }: { file: ShelfFile }) {
90
+ const Icon = iconFor(file.name)
91
+ return (
92
+ <span className="flex size-14 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-surface-3 text-muted-foreground">
93
+ {typeof file.thumbnail === 'string' ? (
94
+ <img alt="" src={file.thumbnail} draggable={false} className="size-full object-cover" />
95
+ ) : (
96
+ (file.thumbnail ?? <Icon size={20} strokeWidth={1.5} />)
97
+ )}
98
+ </span>
99
+ )
100
+ }
101
+
102
+ function Tile({ file, index, onOpen, onReveal, onRemove, onDragOut }: TileProps) {
103
+ const reduced = useReduceMotion()
104
+ // The drag starts once the pointer moves: started on press, it would swallow the click and double-click.
105
+ const press = useRef<{ x: number; y: number }>(undefined)
106
+ return (
107
+ <motion.div
108
+ layout={!reduced}
109
+ initial={{ opacity: 0, scale: reduced ? 1 : 0.9 }}
110
+ animate={{ opacity: 1, scale: 1 }}
111
+ exit={{ opacity: 0, scale: reduced ? 1 : 0.9, transition: spring.moderate.exit }}
112
+ transition={spring.moderate}
113
+ >
114
+ <ContextMenu size="compact">
115
+ <ContextMenu.Trigger>
116
+ <FluidHover.Item
117
+ index={index}
118
+ title={file.name}
119
+ className="h-auto w-20 flex-col items-center justify-start gap-1.5 p-1.5"
120
+ onPointerDown={event => {
121
+ if (event.button === 0) press.current = { x: event.clientX, y: event.clientY }
122
+ }}
123
+ onPointerMove={event => {
124
+ const start = press.current
125
+ if (!start || Math.hypot(event.clientX - start.x, event.clientY - start.y) < DRAG_SLOP_PX) return
126
+ press.current = undefined
127
+ onDragOut?.(file)
128
+ }}
129
+ onPointerUp={() => {
130
+ press.current = undefined
131
+ }}
132
+ onDoubleClick={() => onOpen?.(file)}
133
+ >
134
+ <Thumbnail file={file} />
135
+ <span className="w-full truncate text-center text-micro text-foreground">{file.name}</span>
136
+ </FluidHover.Item>
137
+ </ContextMenu.Trigger>
138
+ <ContextMenu.Content className="dark text-foreground">
139
+ <ContextMenu.Item index={0} label="Open" onSelect={() => onOpen?.(file)} />
140
+ <ContextMenu.Item index={1} label="Show in Finder" onSelect={() => onReveal?.(file)} />
141
+ <ContextMenu.Separator />
142
+ <ContextMenu.Item index={2} icon={Trash2} label="Remove from shelf" onSelect={() => onRemove(file)} />
143
+ </ContextMenu.Content>
144
+ </ContextMenu>
145
+ </motion.div>
146
+ )
147
+ }
148
+
149
+ /** The compact island's left wing: the shelf's glyph. */
150
+ function ShelfLeading() {
151
+ return <Files size={16} strokeWidth={1.5} className="text-foreground" />
152
+ }
153
+
154
+ /** The compact island's right wing: how many files are on the shelf. */
155
+ function ShelfTrailing({ count: n }: { count: number }) {
156
+ return <span className="text-caption weight-medium tabular-nums text-foreground">{n}</span>
157
+ }
158
+
159
+ interface ShelfDropProps {
160
+ /** `dragging` while files hover over the notch, `added` once they dropped. */
161
+ phase: 'dragging' | 'added'
162
+ /** How many files are being dragged, or were added. */
163
+ count: number
164
+ /** How many files the shelf holds once they dropped. Defaults to `count`. */
165
+ total?: number
166
+ /** Classes for the target. */
167
+ className?: string
168
+ }
169
+
170
+ /** The island's flash while files are dragged over the notch: a dashed drop target, then a check once they land. */
171
+ function ShelfDrop({ phase, count: n, total = n, className }: ShelfDropProps) {
172
+ const reduced = useReduceMotion()
173
+ const added = phase === 'added'
174
+ return (
175
+ <div
176
+ className={cn(
177
+ 'flex h-10 items-center gap-3 rounded-xl border px-3 transition-[border-color] duration-moderate',
178
+ added ? 'border-transparent' : 'border-dashed border-brand',
179
+ className,
180
+ )}
181
+ >
182
+ <AnimatePresence initial={false} mode="popLayout">
183
+ <motion.span
184
+ key={phase}
185
+ className={cn('flex shrink-0', added ? 'text-status-success' : 'text-brand')}
186
+ initial={{ opacity: 0, scale: reduced ? 1 : 0.6 }}
187
+ animate={{ opacity: 1, scale: 1 }}
188
+ exit={{ opacity: 0, scale: reduced ? 1 : 0.6, transition: spring.fast.exit }}
189
+ transition={spring.moderate}
190
+ >
191
+ {added ? <Check size={16} strokeWidth={2} /> : <ArrowDownToLine size={16} strokeWidth={1.5} />}
192
+ </motion.span>
193
+ </AnimatePresence>
194
+ <span className="min-w-0 flex-1 truncate text-body weight-semibold text-foreground">
195
+ {added ? 'Added to shelf' : 'Drop to shelf'}
196
+ </span>
197
+ <span className="shrink-0 text-caption tabular-nums text-muted-foreground">
198
+ {added ? `${total} on shelf` : count(n)}
199
+ </span>
200
+ </div>
201
+ )
202
+ }
203
+
204
+ /**
205
+ * A notch app's shelf: files dragged onto the notch, kept in a strip to drag
206
+ * out again, open, AirDrop or clear.
207
+ *
208
+ * Each file is a tile with its thumbnail, or an icon for its type, and its
209
+ * name. A double-click opens it; a right-click (a long press on touch) opens
210
+ * a ContextMenu with Open, Show in Finder and Remove from shelf, grown from
211
+ * the press point; one fluid hover highlight runs along the strip, which
212
+ * scrolls sideways when it holds more than fits. Moving a pressed tile calls
213
+ * `onDragOut`, for the host to start a native drag. A header counts the
214
+ * files and holds AirDrop and Clear. Removing and clearing change the files
215
+ * through `value` / `onValueChange`, or here from `defaultValue`; tiles fade
216
+ * in and out as the strip closes up. An empty shelf says how to fill it.
217
+ *
218
+ * The other forms are parts: `Shelf.Drop`, the flash while files hover over
219
+ * the notch (a dashed drop target in the brand hue) and once they land;
220
+ * `Shelf.Leading` and `Shelf.Trailing` for the compact island's wings.
221
+ *
222
+ * @example {@include ./examples.mdx}
223
+ */
224
+ function Shelf({
225
+ value,
226
+ defaultValue = [],
227
+ onValueChange,
228
+ onOpen,
229
+ onReveal,
230
+ onAirDrop,
231
+ onDragOut,
232
+ className,
233
+ }: ShelfProps) {
234
+ const [files, setFiles] = useControllableState(value, defaultValue, onValueChange)
235
+
236
+ if (files.length === 0)
237
+ return (
238
+ <div className={cn('flex size-full items-center justify-center', className)}>
239
+ <EmptyState
240
+ size="compact"
241
+ icon={Files}
242
+ title="Shelf is empty"
243
+ description="Drag files onto the notch to keep them here."
244
+ />
245
+ </div>
246
+ )
247
+
248
+ return (
249
+ <div className={cn('flex size-full flex-col gap-2', className)}>
250
+ <div className="flex shrink-0 items-center justify-between gap-3">
251
+ <span className="text-caption tabular-nums text-muted-foreground">{count(files.length)}</span>
252
+ <div className="-mr-3 flex items-center gap-1">
253
+ {onAirDrop && (
254
+ <Button variant="ghost" size="compact" leadingIcon={Send} onClick={() => onAirDrop(files)}>
255
+ AirDrop
256
+ </Button>
257
+ )}
258
+ <Button variant="ghost" size="compact" leadingIcon={Trash2} onClick={() => setFiles([])}>
259
+ Clear
260
+ </Button>
261
+ </div>
262
+ </div>
263
+ <FluidHover axis="x" className="-mx-3 flex min-h-0 flex-1 items-start overflow-x-auto overflow-y-hidden px-1.5">
264
+ <AnimatePresence initial={false}>
265
+ {files.map((file, i) => (
266
+ <Tile
267
+ key={file.id}
268
+ file={file}
269
+ index={i}
270
+ onOpen={onOpen}
271
+ onReveal={onReveal}
272
+ onRemove={removed => setFiles(files.filter(f => f.id !== removed.id))}
273
+ onDragOut={onDragOut}
274
+ />
275
+ ))}
276
+ </AnimatePresence>
277
+ </FluidHover>
278
+ </div>
279
+ )
280
+ }
281
+
282
+ Shelf.Drop = ShelfDrop
283
+ Shelf.Leading = ShelfLeading
284
+ Shelf.Trailing = ShelfTrailing
285
+
286
+ export default Shelf
287
+
288
+ export type { ShelfDropProps, ShelfFile, ShelfProps }
289
+ export { Shelf, ShelfDrop, ShelfLeading, ShelfTrailing }
@@ -0,0 +1,52 @@
1
+ import Timer from './index'
2
+ import { FlashIsland, WidgetIsland } from '../../../mock/island-content'
3
+ import { RunningTimer, TimerSplit, TimerWings } from '../../../mock/activities'
4
+
5
+ # Picker
6
+
7
+ Quick lengths, a Pomodoro focus run, or any number of minutes.
8
+
9
+ <WidgetIsland tab="timer">
10
+ <Timer />
11
+ </WidgetIsland>
12
+
13
+ # Running
14
+
15
+ The ring and the time left, with +1 min, pause and cancel. Pause it: the time holds.
16
+
17
+ <WidgetIsland tab="timer">
18
+ <RunningTimer />
19
+ </WidgetIsland>
20
+
21
+ # Pomodoro
22
+
23
+ With `pomodoro`, a focus run hands over to a break at zero, then back to focus.
24
+
25
+ <WidgetIsland tab="timer">
26
+ <Timer pomodoro />
27
+ </WidgetIsland>
28
+
29
+ # Compact
30
+
31
+ `Timer.Leading` and `Timer.Trailing` in the wings.
32
+
33
+ <TimerWings />
34
+
35
+ # Minimal
36
+
37
+ `Timer.Minimal`, a ring of the time left, in the split island's bubble.
38
+
39
+ <TimerSplit />
40
+
41
+ # Time's up
42
+
43
+ `Timer.Done`, and what a Pomodoro cycle starts next.
44
+
45
+ <div className="flex w-full flex-col gap-3">
46
+ <FlashIsland activity="custom">
47
+ <Timer.Done />
48
+ </FlashIsland>
49
+ <FlashIsland activity="focus">
50
+ <Timer.Done kind="focus" next="break" minutes={5} />
51
+ </FlashIsland>
52
+ </div>