@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.
- package/README.md +11 -11
- package/blocks/activities/agenda/examples.mdx +29 -5
- package/blocks/activities/agenda/index.tsx +438 -181
- package/blocks/activities/clock/examples.mdx +89 -0
- package/blocks/activities/clock/index.tsx +917 -0
- package/blocks/activities/now-playing/examples.mdx +40 -13
- package/blocks/activities/now-playing/index.tsx +399 -120
- package/blocks/activities/weather/examples.mdx +123 -0
- package/blocks/activities/weather/index.tsx +863 -0
- package/blocks/app/expanded-island/examples.mdx +8 -7
- package/blocks/app/expanded-island/index.tsx +22 -4
- package/blocks/app/settings-window/examples.mdx +14 -2
- package/blocks/app/settings-window/index.tsx +33 -10
- package/blocks/system/clipboard/examples.mdx +91 -0
- package/blocks/system/clipboard/index.tsx +773 -0
- package/blocks/system/recent-files/examples.mdx +80 -0
- package/blocks/system/recent-files/index.tsx +627 -0
- package/blocks/system/system-stats/examples.mdx +46 -9
- package/blocks/system/system-stats/index.tsx +445 -104
- 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 +465 -0
- package/dist/blocks/activities/agenda/index.d.ts +2 -1
- package/dist/blocks/activities/agenda/index.js +3 -3
- package/dist/blocks/activities/clock/index.d.ts +3 -0
- package/dist/blocks/activities/clock/index.js +25 -0
- package/dist/blocks/activities/now-playing/index.d.ts +4 -2
- package/dist/blocks/activities/now-playing/index.js +5 -3
- package/dist/blocks/activities/weather/index.d.ts +3 -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 +3 -0
- package/dist/blocks/system/clipboard/index.js +17 -0
- package/dist/blocks/system/recent-files/index.d.ts +3 -0
- package/dist/blocks/system/recent-files/index.js +19 -0
- package/dist/blocks/system/system-stats/index.d.ts +3 -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 +32 -0
- package/dist/index.d.ts +15 -15
- package/dist/index.js +104 -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-yngkkxz2.d.ts → chunk-0ym9mcqc.d.ts} +10 -6
- package/dist/shared/chunk-2b6gpn8k.js +444 -0
- package/dist/shared/chunk-3hcnf4yx.js +481 -0
- package/dist/shared/chunk-42wab62s.d.ts +197 -0
- package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
- package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-6tnq6p89.d.ts} +9 -1
- package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
- package/dist/shared/chunk-93dtpjz7.js +789 -0
- package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
- package/dist/shared/chunk-a6njb8db.d.ts +129 -0
- package/dist/shared/chunk-ab8mdg0n.d.ts +149 -0
- package/dist/shared/chunk-evqpf92s.d.ts +168 -0
- package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
- package/dist/shared/chunk-gcyspvgr.js +582 -0
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/chunk-gkj0hjrn.d.ts +136 -0
- package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
- package/dist/shared/chunk-n739am8j.d.ts +112 -0
- package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
- package/dist/shared/chunk-nwzpekvy.js +774 -0
- package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
- package/dist/shared/chunk-sbrtesdg.d.ts +138 -0
- package/dist/shared/chunk-swc7dqpw.d.ts +115 -0
- package/dist/shared/chunk-t9wqhgzt.js +765 -0
- package/dist/shared/chunk-w5h6ay93.js +72 -0
- package/dist/shared/{chunk-mp1nx0ez.js → chunk-wayv5rhr.js} +15 -4
- package/dist/shared/chunk-wf0jtzhs.js +295 -0
- package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
- package/dist/shared/chunk-yq5svpk7.js +524 -0
- package/dist/shared/{chunk-s33y1pcq.js → chunk-z3tj1ydg.js} +23 -10
- package/dist/styles.css +151 -49
- 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 +113 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +78 -44
- package/mock/files.tsx +83 -0
- package/mock/island-content.tsx +79 -122
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +370 -91
- package/mock/system.ts +49 -0
- package/mock/weather.tsx +135 -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
|
@@ -7,24 +7,60 @@
|
|
|
7
7
|
|
|
8
8
|
'use client'
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import { useReduceMotion } from '@justanarthur/modo-ui/lib/reduced-motion'
|
|
11
|
+
import { useSize } from '@justanarthur/modo-ui/lib/size-context'
|
|
12
|
+
import { spring } from '@justanarthur/modo-ui/lib/springs'
|
|
13
|
+
import { SURFACE_BG } from '@justanarthur/modo-ui/lib/surface-classes'
|
|
14
|
+
import { useLift } from '@justanarthur/modo-ui/lib/surface-context'
|
|
12
15
|
import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
|
|
13
16
|
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
14
|
-
import {
|
|
15
|
-
|
|
17
|
+
import {
|
|
18
|
+
Airplay,
|
|
19
|
+
Disc3,
|
|
20
|
+
Headphones,
|
|
21
|
+
Heart,
|
|
22
|
+
Laptop,
|
|
23
|
+
Music,
|
|
24
|
+
Pause,
|
|
25
|
+
Play,
|
|
26
|
+
Repeat,
|
|
27
|
+
Repeat1,
|
|
28
|
+
Shuffle,
|
|
29
|
+
SkipBack,
|
|
30
|
+
SkipForward,
|
|
31
|
+
Speaker,
|
|
32
|
+
} from 'lucide-react'
|
|
33
|
+
import { motion } from 'motion/react'
|
|
34
|
+
import { type ReactNode, useState } from 'react'
|
|
16
35
|
import Equalizer from '../../../components/indicators/equalizer'
|
|
17
36
|
import MediaScrubber from '../../../components/indicators/media-scrubber'
|
|
18
37
|
import IslandFlash from '../../../components/island/island-flash'
|
|
38
|
+
import Widget, { type WidgetLayout } from '../../../components/island/widget'
|
|
39
|
+
import { type Artwork, type ShownArtwork, useArtworkTint, useStableArtwork } from '../../../lib/artwork'
|
|
40
|
+
|
|
41
|
+
type NowPlayingOutput = 'built-in' | 'headphones' | 'speaker' | 'airplay'
|
|
42
|
+
type NowPlayingRepeat = 'off' | 'all' | 'one'
|
|
19
43
|
|
|
20
44
|
interface NowPlayingTrack {
|
|
45
|
+
/** What tells two tracks apart; defaults to the title, artist and album. */
|
|
46
|
+
id?: string
|
|
21
47
|
title: string
|
|
22
48
|
artist?: string
|
|
23
49
|
album?: string
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
/**
|
|
51
|
+
* The artwork: an image URL, or any element. `null` when the track has
|
|
52
|
+
* none (the placeholder shows); left out while it isn't known yet, which
|
|
53
|
+
* keeps the last picture up.
|
|
54
|
+
*/
|
|
55
|
+
artwork?: Artwork | null
|
|
56
|
+
/** The color the artwork leans to, any CSS color: it tints the glow, the bars and the toggles. Read from an image URL when left out. */
|
|
57
|
+
tint?: string
|
|
58
|
+
/** The app it plays in. */
|
|
27
59
|
source?: string
|
|
60
|
+
/** Where it plays: a device's name. */
|
|
61
|
+
output?: string
|
|
62
|
+
/** What kind of device `output` is, for its glyph. Defaults to `'built-in'`. */
|
|
63
|
+
outputKind?: NowPlayingOutput
|
|
28
64
|
/** The track's length, in seconds; `0` for a stream, which hides the scrubber. */
|
|
29
65
|
duration: number
|
|
30
66
|
/** Where playback is, in seconds. */
|
|
@@ -46,173 +82,416 @@ interface NowPlayingProps {
|
|
|
46
82
|
onNext?: () => void
|
|
47
83
|
/** Called with the position to seek to, once, when a drag on the scrubber ends. */
|
|
48
84
|
onSeek?: (seconds: number) => void
|
|
49
|
-
/**
|
|
85
|
+
/** Shuffle is on (controlled). The toggle shows when this, `defaultShuffle` or `onShuffleChange` is given. */
|
|
86
|
+
shuffle?: boolean
|
|
87
|
+
/** Shuffle is on at first (uncontrolled). */
|
|
88
|
+
defaultShuffle?: boolean
|
|
89
|
+
/** Called with the new state when shuffle is pressed. */
|
|
90
|
+
onShuffleChange?: (shuffle: boolean) => void
|
|
91
|
+
/** The repeat mode (controlled): a press steps off → all → one. Shows like `shuffle`. */
|
|
92
|
+
repeat?: NowPlayingRepeat
|
|
93
|
+
/** The repeat mode at first (uncontrolled). */
|
|
94
|
+
defaultRepeat?: NowPlayingRepeat
|
|
95
|
+
/** Called with the next mode when repeat is pressed. */
|
|
96
|
+
onRepeatChange?: (repeat: NowPlayingRepeat) => void
|
|
97
|
+
/** The track is in the library (controlled). Shows like `shuffle`. */
|
|
98
|
+
liked?: boolean
|
|
99
|
+
/** The track is in the library at first (uncontrolled). */
|
|
100
|
+
defaultLiked?: boolean
|
|
101
|
+
/** Called with the new state when the heart is pressed. */
|
|
102
|
+
onLikedChange?: (liked: boolean) => void
|
|
103
|
+
/** The empty state's line. Defaults to `'Play something in Music, Spotify or a browser and it shows up here.'`. */
|
|
50
104
|
emptyDescription?: ReactNode
|
|
105
|
+
/** The empty state's way forward, such as a Button that opens a player. */
|
|
106
|
+
emptyActions?: ReactNode
|
|
107
|
+
/** `tall` is the open island's tall snap: the artwork large, the title on the display role, a full-width scrubber and the transport under it, and where it plays from and to as rows. Defaults to `'fit'`. */
|
|
108
|
+
layout?: WidgetLayout
|
|
51
109
|
/** Classes for the root, which fills its container. */
|
|
52
110
|
className?: string
|
|
53
111
|
}
|
|
54
112
|
|
|
55
|
-
const
|
|
113
|
+
const OUTPUT_LABEL: Record<NowPlayingOutput, string> = {
|
|
114
|
+
'built-in': 'Built-in speakers',
|
|
115
|
+
headphones: 'Headphones',
|
|
116
|
+
speaker: 'Speaker',
|
|
117
|
+
airplay: 'AirPlay',
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const OUTPUT_ICON = { 'built-in': Laptop, headphones: Headphones, speaker: Speaker, airplay: Airplay }
|
|
121
|
+
const NEXT_REPEAT: Record<NowPlayingRepeat, NowPlayingRepeat> = { off: 'all', all: 'one', one: 'off' }
|
|
122
|
+
const REPEAT_LABEL: Record<NowPlayingRepeat, string> = {
|
|
123
|
+
off: 'Repeat',
|
|
124
|
+
all: 'Repeat all',
|
|
125
|
+
one: 'Repeat one',
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type TrackIdentity = Pick<NowPlayingTrack, 'id' | 'title' | 'artist' | 'album' | 'artwork' | 'tint'>
|
|
129
|
+
|
|
130
|
+
const keyOf = (track?: TrackIdentity | null) =>
|
|
131
|
+
track ? (track.id ?? [track.title, track.artist, track.album].join('\u0000')) : ''
|
|
132
|
+
|
|
133
|
+
/** The track's tint: its own, else read from its image. */
|
|
134
|
+
function useTint(track?: TrackIdentity | null) {
|
|
135
|
+
const read = useArtworkTint(track?.tint || typeof track?.artwork !== 'string' ? undefined : track.artwork)
|
|
136
|
+
return track?.tint ?? read
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function Picture({ art, glyph }: { art: ShownArtwork['art']; glyph: number }) {
|
|
140
|
+
const level = useLift(1)
|
|
141
|
+
if (typeof art === 'string') return <img alt="" src={art} draggable={false} className="size-full object-cover" />
|
|
142
|
+
if (art != null) return art
|
|
143
|
+
return (
|
|
144
|
+
<span className={cn('flex size-full items-center justify-center text-muted-foreground', SURFACE_BG[level])}>
|
|
145
|
+
<Music size={glyph} strokeWidth={1.5} />
|
|
146
|
+
</span>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
56
149
|
|
|
57
150
|
interface ArtworkProps {
|
|
58
|
-
/** The track
|
|
59
|
-
|
|
60
|
-
/** The note's size in px
|
|
151
|
+
/** The track whose artwork it shows; without one, the placeholder. */
|
|
152
|
+
track?: TrackIdentity | null
|
|
153
|
+
/** The placeholder note's size in px. Defaults to `14`. */
|
|
61
154
|
glyph?: number
|
|
62
155
|
/** Classes for the tile: its size and radius. */
|
|
63
156
|
className?: string
|
|
64
157
|
}
|
|
65
158
|
|
|
66
|
-
/**
|
|
67
|
-
|
|
159
|
+
/**
|
|
160
|
+
* A track's artwork in a tile that never blinks: the last good picture stays
|
|
161
|
+
* while the next one loads or an update comes without one, the next
|
|
162
|
+
* crossfades in over it, and only a track without artwork shows the note.
|
|
163
|
+
*/
|
|
164
|
+
function NowPlayingArtwork({ track, glyph = 14, className }: ArtworkProps) {
|
|
165
|
+
const shown = useStableArtwork(track?.artwork, keyOf(track))
|
|
166
|
+
const reduced = useReduceMotion()
|
|
167
|
+
const [top, setTop] = useState(shown)
|
|
168
|
+
const [under, setUnder] = useState<ShownArtwork | null>(null)
|
|
169
|
+
if (top.id !== shown.id) {
|
|
170
|
+
setUnder(top)
|
|
171
|
+
setTop(shown)
|
|
172
|
+
}
|
|
173
|
+
|
|
68
174
|
return (
|
|
69
|
-
<span
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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} />)
|
|
175
|
+
<span className={cn('relative isolate block shrink-0 overflow-hidden', className)}>
|
|
176
|
+
{under && (
|
|
177
|
+
<span key={under.id} className="absolute inset-0">
|
|
178
|
+
<Picture art={under.art} glyph={glyph} />
|
|
179
|
+
</span>
|
|
79
180
|
)}
|
|
181
|
+
<motion.span
|
|
182
|
+
key={shown.id}
|
|
183
|
+
className="absolute inset-0"
|
|
184
|
+
initial={under ? { opacity: 0 } : false}
|
|
185
|
+
animate={{ opacity: 1 }}
|
|
186
|
+
transition={reduced ? spring.fast : spring.slow}
|
|
187
|
+
onAnimationComplete={() => setUnder(null)}
|
|
188
|
+
>
|
|
189
|
+
<Picture art={shown.art} glyph={glyph} />
|
|
190
|
+
</motion.span>
|
|
191
|
+
<span
|
|
192
|
+
aria-hidden
|
|
193
|
+
className="pointer-events-none absolute inset-0 rounded-[inherit] ring-1 ring-border ring-inset"
|
|
194
|
+
/>
|
|
195
|
+
</span>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface PartProps {
|
|
200
|
+
/** What plays. */
|
|
201
|
+
track?: TrackIdentity | null
|
|
202
|
+
/** It plays: the bars dance. Defaults to `true`. */
|
|
203
|
+
playing?: boolean
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Level bars in the artwork's tint. */
|
|
207
|
+
function TintedBars({ track, playing = true, className }: PartProps & { className?: string }) {
|
|
208
|
+
const tint = useTint(track)
|
|
209
|
+
return (
|
|
210
|
+
<span className={cn('inline-flex text-foreground', className)} style={tint ? { color: tint } : undefined}>
|
|
211
|
+
<Equalizer playing={playing} label={playing ? 'Playing' : 'Paused'} barClassName="bg-current" />
|
|
80
212
|
</span>
|
|
81
213
|
)
|
|
82
214
|
}
|
|
83
215
|
|
|
84
216
|
/** The compact island's left wing: the artwork, small. */
|
|
85
|
-
function NowPlayingLeading({ track }:
|
|
86
|
-
return <NowPlayingArtwork
|
|
217
|
+
function NowPlayingLeading({ track }: Pick<PartProps, 'track'>) {
|
|
218
|
+
return <NowPlayingArtwork track={track} glyph={12} className="size-5.5 rounded-md" />
|
|
87
219
|
}
|
|
88
220
|
|
|
89
|
-
/** The compact island's right wing: the level bars, low while paused. */
|
|
90
|
-
function NowPlayingTrailing(
|
|
91
|
-
return <
|
|
221
|
+
/** The compact island's right wing: the level bars in the artwork's tint, low while paused. */
|
|
222
|
+
function NowPlayingTrailing(props: PartProps) {
|
|
223
|
+
return <TintedBars {...props} />
|
|
92
224
|
}
|
|
93
225
|
|
|
94
226
|
/** The split island's bubble: the artwork as a disc. */
|
|
95
|
-
function NowPlayingMinimal({ track }:
|
|
96
|
-
return <NowPlayingArtwork
|
|
227
|
+
function NowPlayingMinimal({ track }: Pick<PartProps, 'track'>) {
|
|
228
|
+
return <NowPlayingArtwork track={track} glyph={12} className="size-6 rounded-full" />
|
|
97
229
|
}
|
|
98
230
|
|
|
99
|
-
/** The island's flash when the track changes: its artwork, title and artist, and the bars. */
|
|
231
|
+
/** The island's flash when the track changes: its artwork, title and artist, and the tinted bars. */
|
|
100
232
|
function NowPlayingFlash({ track, playing = true }: { track: NowPlayingTrack; playing?: boolean }) {
|
|
101
233
|
return (
|
|
102
234
|
<IslandFlash
|
|
103
|
-
icon={<NowPlayingArtwork
|
|
235
|
+
icon={<NowPlayingArtwork track={track} className="size-9 rounded-lg" />}
|
|
104
236
|
title={track.title || 'Unknown title'}
|
|
105
|
-
caption={track.artist
|
|
106
|
-
trailing={<
|
|
237
|
+
caption={[track.artist, track.album].filter(Boolean).join(' — ') || track.source}
|
|
238
|
+
trailing={<TintedBars track={track} playing={playing} />}
|
|
107
239
|
/>
|
|
108
240
|
)
|
|
109
241
|
}
|
|
110
242
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
onNext?: () => void
|
|
116
|
-
}
|
|
243
|
+
// Literal tables: UnoCSS only generates the classes it can read whole.
|
|
244
|
+
const ART = { default: 'size-36 rounded-2xl', compact: 'size-28 rounded-xl' }
|
|
245
|
+
const SHEET_ART = { default: 'size-52 rounded-3xl', compact: 'size-44 rounded-2xl' }
|
|
246
|
+
const SHEET_TITLE = { default: 'text-display', compact: 'text-display-compact' }
|
|
117
247
|
|
|
118
|
-
function
|
|
248
|
+
function Glow({ tint, children }: { tint?: string; children: ReactNode }) {
|
|
119
249
|
return (
|
|
120
|
-
<
|
|
121
|
-
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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>
|
|
250
|
+
<span className="relative flex">
|
|
251
|
+
{tint && (
|
|
252
|
+
<span
|
|
253
|
+
aria-hidden
|
|
254
|
+
className="absolute -inset-x-8 -inset-y-4 -z-1 opacity-70"
|
|
255
|
+
style={{ backgroundImage: `radial-gradient(closest-side, ${tint}, transparent)` }}
|
|
256
|
+
/>
|
|
257
|
+
)}
|
|
258
|
+
{children}
|
|
259
|
+
</span>
|
|
137
260
|
)
|
|
138
261
|
}
|
|
139
262
|
|
|
140
263
|
/**
|
|
141
264
|
* What's playing, as a notch app's open island shows it: the artwork, the
|
|
142
|
-
* title and artist, where the track is, and
|
|
265
|
+
* title and artist, where the track is, the transport, and where it plays.
|
|
143
266
|
*
|
|
144
|
-
* The
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
267
|
+
* The artwork is the hero's picture, as tall as the widget, with a soft glow
|
|
268
|
+
* of its tint behind it (`track.tint`, else read from an image URL); the
|
|
269
|
+
* equalizer and any toggle that is on take the same tint, so the color
|
|
270
|
+
* comes from the music. The artwork never blinks: the last good picture
|
|
271
|
+
* stays up while a new one loads or an update arrives without one, the next
|
|
272
|
+
* crossfades in over it, and only a track whose `artwork` is `null` shows
|
|
273
|
+
* the placeholder note.
|
|
274
|
+
*
|
|
275
|
+
* Under the title and artist (with the album) runs the kit's MediaScrubber,
|
|
276
|
+
* which ticks on by itself while playing and seeks once when a drag ends
|
|
277
|
+
* (`onSeek`). The transport sits in the middle of the last row, the source
|
|
278
|
+
* app and the output device on its left, and shuffle, repeat and the heart
|
|
279
|
+
* on its right, each shown when its value or handler is given. Play / pause
|
|
280
|
+
* runs through `playing` / `onPlayingChange`, or is kept here from
|
|
281
|
+
* `defaultPlaying`; the toggles are the same. Without a track it says
|
|
282
|
+
* nothing is playing and how to change that.
|
|
283
|
+
*
|
|
284
|
+
* At the open island's tall snap (`layout="tall"`) it becomes a sheet: the
|
|
285
|
+
* artwork large beside the source, the title on the display role, the
|
|
286
|
+
* artist and the album on lines of their own; then the scrubber across the
|
|
287
|
+
* whole width with the transport and the toggles in one row under it; then
|
|
288
|
+
* where it plays from and to, the app and the output device, as rows.
|
|
150
289
|
*
|
|
151
290
|
* The other forms are parts: `NowPlaying.Leading` and `NowPlaying.Trailing`
|
|
152
|
-
* for the compact island's wings (the artwork, and
|
|
153
|
-
* when paused), `NowPlaying.Minimal` for the split island's bubble
|
|
154
|
-
* artwork as a disc), `NowPlaying.Flash` for the flash on a track
|
|
155
|
-
* `NowPlaying.Artwork` for the tile on its own.
|
|
291
|
+
* for the compact island's wings (the artwork, and the tinted Equalizer that
|
|
292
|
+
* settles when paused), `NowPlaying.Minimal` for the split island's bubble
|
|
293
|
+
* (the artwork as a disc), `NowPlaying.Flash` for the flash on a track
|
|
294
|
+
* change and `NowPlaying.Artwork` for the tile on its own.
|
|
156
295
|
*
|
|
157
296
|
* @example {@include ./examples.mdx}
|
|
158
297
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
298
|
+
const NowPlaying = Object.assign(
|
|
299
|
+
function NowPlaying({
|
|
300
|
+
track,
|
|
301
|
+
playing: playingProp,
|
|
302
|
+
defaultPlaying = true,
|
|
303
|
+
onPlayingChange,
|
|
304
|
+
onPrevious,
|
|
305
|
+
onNext,
|
|
306
|
+
onSeek,
|
|
307
|
+
shuffle: shuffleProp,
|
|
308
|
+
defaultShuffle,
|
|
309
|
+
onShuffleChange,
|
|
310
|
+
repeat: repeatProp,
|
|
311
|
+
defaultRepeat,
|
|
312
|
+
onRepeatChange,
|
|
313
|
+
liked: likedProp,
|
|
314
|
+
defaultLiked,
|
|
315
|
+
onLikedChange,
|
|
316
|
+
emptyDescription = 'Play something in Music, Spotify or a browser and it shows up here.',
|
|
317
|
+
emptyActions,
|
|
318
|
+
layout = 'fit',
|
|
319
|
+
className,
|
|
320
|
+
}: NowPlayingProps) {
|
|
321
|
+
const size = useSize()
|
|
322
|
+
const [playing, setPlaying] = useControllableState(playingProp, defaultPlaying, onPlayingChange)
|
|
323
|
+
const [shuffle, setShuffle] = useControllableState(shuffleProp, defaultShuffle ?? false, onShuffleChange)
|
|
324
|
+
const [repeat, setRepeat] = useControllableState(repeatProp, defaultRepeat ?? 'off', onRepeatChange)
|
|
325
|
+
const [liked, setLiked] = useControllableState(likedProp, defaultLiked ?? false, onLikedChange)
|
|
326
|
+
const tint = useTint(track)
|
|
327
|
+
|
|
328
|
+
if (!track)
|
|
329
|
+
return (
|
|
330
|
+
<Widget.Message
|
|
331
|
+
icon={Music}
|
|
332
|
+
title="Nothing playing"
|
|
333
|
+
description={emptyDescription}
|
|
334
|
+
actions={emptyActions}
|
|
335
|
+
className={className}
|
|
336
|
+
/>
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
const showShuffle = shuffleProp !== undefined || defaultShuffle !== undefined || onShuffleChange !== undefined
|
|
340
|
+
const showRepeat = repeatProp !== undefined || defaultRepeat !== undefined || onRepeatChange !== undefined
|
|
341
|
+
const showLiked = likedProp !== undefined || defaultLiked !== undefined || onLikedChange !== undefined
|
|
342
|
+
const byline = [track.artist, track.album].filter(Boolean).join(' — ')
|
|
343
|
+
const toggles = (
|
|
344
|
+
<>
|
|
345
|
+
{showShuffle && (
|
|
346
|
+
<Widget.Action
|
|
347
|
+
icon={Shuffle}
|
|
348
|
+
label="Shuffle"
|
|
349
|
+
pressed={shuffle}
|
|
350
|
+
color={tint}
|
|
351
|
+
onClick={() => setShuffle(!shuffle)}
|
|
352
|
+
/>
|
|
353
|
+
)}
|
|
354
|
+
{showRepeat && (
|
|
355
|
+
<Widget.Action
|
|
356
|
+
icon={repeat === 'one' ? Repeat1 : Repeat}
|
|
357
|
+
label={REPEAT_LABEL[repeat]}
|
|
358
|
+
pressed={repeat !== 'off'}
|
|
359
|
+
color={tint}
|
|
360
|
+
onClick={() => setRepeat(NEXT_REPEAT[repeat])}
|
|
361
|
+
/>
|
|
362
|
+
)}
|
|
363
|
+
{showLiked && (
|
|
364
|
+
<Widget.Action
|
|
365
|
+
icon={Heart}
|
|
366
|
+
label={liked ? 'Remove from library' : 'Add to library'}
|
|
367
|
+
pressed={liked}
|
|
368
|
+
filled={liked}
|
|
369
|
+
color={tint}
|
|
370
|
+
onClick={() => setLiked(!liked)}
|
|
371
|
+
/>
|
|
372
|
+
)}
|
|
373
|
+
</>
|
|
374
|
+
)
|
|
375
|
+
const transport = (
|
|
376
|
+
<div className="flex items-center gap-1">
|
|
377
|
+
<Widget.Action icon={SkipBack} label="Previous" filled onClick={onPrevious} />
|
|
378
|
+
<Widget.Action
|
|
379
|
+
icon={playing ? Pause : Play}
|
|
380
|
+
label={playing ? 'Pause' : 'Play'}
|
|
381
|
+
emphasis="primary"
|
|
382
|
+
filled
|
|
383
|
+
onClick={() => setPlaying(!playing)}
|
|
384
|
+
/>
|
|
385
|
+
<Widget.Action icon={SkipForward} label="Next" filled onClick={onNext} />
|
|
176
386
|
</div>
|
|
177
387
|
)
|
|
388
|
+
const OutputIcon = OUTPUT_ICON[track.outputKind ?? 'built-in']
|
|
178
389
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
390
|
+
if (layout === 'tall')
|
|
391
|
+
return (
|
|
392
|
+
<Widget.Sheet className={cn('relative isolate', className)}>
|
|
393
|
+
<div className="flex min-w-0 items-center gap-6">
|
|
394
|
+
<Glow tint={tint}>
|
|
395
|
+
<NowPlayingArtwork track={track} glyph={40} className={SHEET_ART[size.variant]} />
|
|
396
|
+
</Glow>
|
|
397
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
|
398
|
+
<Widget.Header icon={Disc3} trailing={<TintedBars track={track} playing={playing} />}>
|
|
399
|
+
{track.source ?? 'Now playing'}
|
|
400
|
+
</Widget.Header>
|
|
401
|
+
<span className={cn('line-clamp-2 weight-bold text-foreground text-balance', SHEET_TITLE[size.variant])}>
|
|
402
|
+
{track.title || 'Unknown title'}
|
|
403
|
+
</span>
|
|
404
|
+
{track.artist && <span className="truncate text-title text-foreground">{track.artist}</span>}
|
|
405
|
+
{track.album && <Widget.Subtitle>{track.album}</Widget.Subtitle>}
|
|
406
|
+
</div>
|
|
407
|
+
</div>
|
|
408
|
+
|
|
409
|
+
<div className="flex flex-col gap-2">
|
|
410
|
+
{track.duration > 0 && (
|
|
411
|
+
<MediaScrubber position={track.position} duration={track.duration} playing={playing} onSeek={onSeek} />
|
|
192
412
|
)}
|
|
413
|
+
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2">
|
|
414
|
+
<span />
|
|
415
|
+
{transport}
|
|
416
|
+
<div className="flex items-center justify-end">{toggles}</div>
|
|
417
|
+
</div>
|
|
193
418
|
</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
419
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
420
|
+
{(track.source || track.output) && (
|
|
421
|
+
<Widget.Section label="Playing">
|
|
422
|
+
{track.source && (
|
|
423
|
+
<Widget.Row trailing={<Disc3 size={14} strokeWidth={1.5} />} leading="From">
|
|
424
|
+
{track.source}
|
|
425
|
+
</Widget.Row>
|
|
426
|
+
)}
|
|
427
|
+
{track.output && (
|
|
428
|
+
<Widget.Row
|
|
429
|
+
leading="On"
|
|
430
|
+
trailing={
|
|
431
|
+
<>
|
|
432
|
+
<OutputIcon size={14} strokeWidth={1.5} />
|
|
433
|
+
{OUTPUT_LABEL[track.outputKind ?? 'built-in']}
|
|
434
|
+
</>
|
|
435
|
+
}
|
|
436
|
+
>
|
|
437
|
+
{track.output}
|
|
438
|
+
</Widget.Row>
|
|
439
|
+
)}
|
|
440
|
+
</Widget.Section>
|
|
441
|
+
)}
|
|
442
|
+
</Widget.Sheet>
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
return (
|
|
446
|
+
<div className={cn('relative isolate flex w-full flex-col justify-center', className)}>
|
|
447
|
+
<Widget
|
|
448
|
+
media={
|
|
449
|
+
<Glow tint={tint}>
|
|
450
|
+
<NowPlayingArtwork track={track} glyph={28} className={ART[size.variant]} />
|
|
451
|
+
</Glow>
|
|
452
|
+
}
|
|
453
|
+
>
|
|
454
|
+
<div className="flex min-w-0 items-start gap-3">
|
|
455
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
456
|
+
<Widget.Title>{track.title || 'Unknown title'}</Widget.Title>
|
|
457
|
+
{byline && <Widget.Subtitle>{byline}</Widget.Subtitle>}
|
|
458
|
+
</div>
|
|
459
|
+
<TintedBars track={track} playing={playing} className="mt-1.5" />
|
|
460
|
+
</div>
|
|
461
|
+
|
|
462
|
+
{track.duration > 0 && (
|
|
463
|
+
<MediaScrubber
|
|
464
|
+
className="mt-2"
|
|
465
|
+
quiet
|
|
466
|
+
position={track.position}
|
|
467
|
+
duration={track.duration}
|
|
468
|
+
playing={playing}
|
|
469
|
+
onSeek={onSeek}
|
|
470
|
+
/>
|
|
471
|
+
)}
|
|
472
|
+
|
|
473
|
+
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2">
|
|
474
|
+
<Widget.Meta>
|
|
475
|
+
{track.source && <Widget.MetaItem icon={Disc3}>{track.source}</Widget.MetaItem>}
|
|
476
|
+
{track.output && <Widget.MetaItem icon={OutputIcon}>{track.output}</Widget.MetaItem>}
|
|
477
|
+
</Widget.Meta>
|
|
478
|
+
{transport}
|
|
479
|
+
<div className="flex items-center justify-end">{toggles}</div>
|
|
480
|
+
</div>
|
|
481
|
+
</Widget>
|
|
482
|
+
</div>
|
|
483
|
+
)
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
Artwork: NowPlayingArtwork,
|
|
487
|
+
Leading: NowPlayingLeading,
|
|
488
|
+
Trailing: NowPlayingTrailing,
|
|
489
|
+
Minimal: NowPlayingMinimal,
|
|
490
|
+
Flash: NowPlayingFlash,
|
|
491
|
+
},
|
|
492
|
+
)
|
|
214
493
|
|
|
215
494
|
export default NowPlaying
|
|
216
495
|
|
|
217
|
-
export type { NowPlayingProps, NowPlayingTrack }
|
|
496
|
+
export type { NowPlayingOutput, NowPlayingProps, NowPlayingRepeat, NowPlayingTrack }
|
|
218
497
|
export { NowPlaying, NowPlayingArtwork, NowPlayingFlash, NowPlayingLeading, NowPlayingMinimal, NowPlayingTrailing }
|