@justanarthur/modo-ui-notch 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +75 -2
- package/blocks/activities/agenda/examples.mdx +74 -0
- package/blocks/activities/agenda/index.tsx +441 -0
- package/blocks/activities/clock/examples.mdx +73 -0
- package/blocks/activities/clock/index.tsx +619 -0
- package/blocks/activities/now-playing/examples.mdx +68 -0
- package/blocks/activities/now-playing/index.tsx +411 -0
- package/blocks/activities/weather/examples.mdx +115 -0
- package/blocks/activities/weather/index.tsx +634 -0
- package/blocks/app/expanded-island/examples.mdx +46 -0
- package/blocks/app/expanded-island/index.tsx +143 -0
- package/blocks/app/settings-window/examples.mdx +34 -0
- package/blocks/app/settings-window/index.tsx +375 -0
- 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 +52 -0
- package/blocks/system/system-stats/index.tsx +312 -0
- package/components/indicators/countdown/examples.mdx +25 -0
- package/components/indicators/countdown/index.tsx +83 -0
- package/components/indicators/equalizer/examples.mdx +20 -0
- package/components/indicators/equalizer/index.tsx +116 -0
- package/components/indicators/media-scrubber/examples.mdx +29 -0
- package/components/indicators/media-scrubber/index.tsx +122 -0
- package/components/island/island/examples.mdx +57 -0
- package/components/island/island/index.tsx +415 -0
- package/components/island/island-flash/examples.mdx +52 -0
- package/components/island/island-flash/index.tsx +79 -0
- package/components/island/island-tabs/examples.mdx +53 -0
- package/components/island/island-tabs/index.tsx +285 -0
- package/components/island/widget/examples.mdx +76 -0
- package/components/island/widget/index.tsx +431 -0
- package/dist/blocks/activities/agenda/index.d.ts +2 -0
- package/dist/blocks/activities/agenda/index.js +21 -0
- 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 -0
- package/dist/blocks/activities/now-playing/index.js +24 -0
- 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 +3 -0
- package/dist/blocks/app/expanded-island/index.js +11 -0
- package/dist/blocks/app/settings-window/index.d.ts +2 -0
- package/dist/blocks/app/settings-window/index.js +7 -0
- 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 -0
- package/dist/blocks/system/system-stats/index.js +15 -0
- package/dist/components/indicators/countdown/index.d.ts +2 -0
- package/dist/components/indicators/countdown/index.js +8 -0
- package/dist/components/indicators/equalizer/index.d.ts +2 -0
- package/dist/components/indicators/equalizer/index.js +7 -0
- package/dist/components/indicators/media-scrubber/index.d.ts +2 -0
- package/dist/components/indicators/media-scrubber/index.js +8 -0
- package/dist/components/island/island/index.d.ts +3 -0
- package/dist/components/island/island/index.js +10 -0
- package/dist/components/island/island-flash/index.d.ts +2 -0
- package/dist/components/island/island-flash/index.js +7 -0
- package/dist/components/island/island-tabs/index.d.ts +2 -0
- package/dist/components/island/island-tabs/index.js +9 -0
- package/dist/components/island/widget/index.d.ts +2 -0
- package/dist/components/island/widget/index.js +30 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +195 -0
- package/dist/lib/artwork.d.ts +2 -0
- package/dist/lib/artwork.js +8 -0
- package/dist/lib/clock.d.ts +2 -0
- package/dist/lib/clock.js +14 -0
- package/dist/lib/geometry.d.ts +2 -0
- package/dist/lib/geometry.js +24 -0
- package/dist/lib/island-context.d.ts +3 -0
- package/dist/lib/island-context.js +8 -0
- package/dist/lib/motion.d.ts +21 -0
- package/dist/lib/motion.js +16 -0
- package/dist/shared/chunk-152gpyq3.d.ts +13 -0
- package/dist/shared/chunk-2818esrq.d.ts +140 -0
- package/dist/shared/chunk-2f7zxrbk.js +65 -0
- package/dist/shared/chunk-2m5dz8nf.d.ts +88 -0
- package/dist/shared/chunk-2s4q6mt0.js +27 -0
- package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
- package/dist/shared/chunk-416tsgbc.d.ts +175 -0
- package/dist/shared/chunk-502rmtap.js +54 -0
- package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
- package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
- package/dist/shared/chunk-61t2dfte.js +63 -0
- package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
- package/dist/shared/chunk-81fpptwp.d.ts +75 -0
- package/dist/shared/chunk-9c7ewvkk.js +381 -0
- package/dist/shared/chunk-9m0xbg5v.js +112 -0
- package/dist/shared/chunk-9xtcv3sy.js +88 -0
- package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
- package/dist/shared/chunk-cc9nwbtf.js +315 -0
- package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
- package/dist/shared/chunk-d5qm9cps.js +10 -0
- package/dist/shared/chunk-da177e8r.d.ts +114 -0
- package/dist/shared/chunk-fexwzycv.d.ts +36 -0
- package/dist/shared/chunk-gb56m10p.js +39 -0
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
- package/dist/shared/chunk-j755a1a5.d.ts +41 -0
- package/dist/shared/chunk-j77cx8dp.js +498 -0
- package/dist/shared/chunk-mt0k6v8x.js +474 -0
- package/dist/shared/chunk-ndf79pv5.js +58 -0
- package/dist/shared/chunk-pfhy5e4q.d.ts +53 -0
- package/dist/shared/chunk-qdzemt2v.js +477 -0
- package/dist/shared/chunk-r471sknr.js +209 -0
- package/dist/shared/chunk-s2jeqqan.js +243 -0
- package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
- package/dist/shared/chunk-w48eyvfr.d.ts +56 -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-y0188bbn.js +331 -0
- package/dist/shared/chunk-ym0xbses.js +518 -0
- package/dist/styles.css +264 -0
- package/index.ts +22 -0
- package/lib/artwork.ts +112 -0
- package/lib/clock.ts +53 -0
- package/lib/geometry.ts +130 -0
- package/lib/island-context.tsx +24 -0
- package/lib/motion.ts +42 -0
- package/mock/activities.tsx +77 -0
- package/mock/artwork.tsx +37 -0
- package/mock/clipboard.tsx +79 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +139 -0
- package/mock/desktop.tsx +83 -0
- package/mock/files.tsx +70 -0
- package/mock/fit.ts +26 -0
- package/mock/island-content.tsx +142 -0
- package/mock/scene.tsx +52 -0
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +489 -0
- package/mock/system.ts +46 -0
- package/mock/weather.tsx +105 -0
- package/package.json +122 -4
|
@@ -0,0 +1,411 @@
|
|
|
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 { 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'
|
|
15
|
+
import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
|
|
16
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
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'
|
|
35
|
+
import Equalizer from '../../../components/indicators/equalizer'
|
|
36
|
+
import MediaScrubber from '../../../components/indicators/media-scrubber'
|
|
37
|
+
import IslandFlash from '../../../components/island/island-flash'
|
|
38
|
+
import Widget 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'
|
|
43
|
+
|
|
44
|
+
interface NowPlayingTrack {
|
|
45
|
+
/** What tells two tracks apart; defaults to the title, artist and album. */
|
|
46
|
+
id?: string
|
|
47
|
+
title: string
|
|
48
|
+
artist?: string
|
|
49
|
+
album?: string
|
|
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. */
|
|
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
|
|
64
|
+
/** The track's length, in seconds; `0` for a stream, which hides the scrubber. */
|
|
65
|
+
duration: number
|
|
66
|
+
/** Where playback is, in seconds. */
|
|
67
|
+
position: number
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface NowPlayingProps {
|
|
71
|
+
/** What plays; without one the player says nothing is playing. */
|
|
72
|
+
track?: NowPlayingTrack | null
|
|
73
|
+
/** It plays (controlled). */
|
|
74
|
+
playing?: boolean
|
|
75
|
+
/** It plays at first (uncontrolled). Defaults to `true`. */
|
|
76
|
+
defaultPlaying?: boolean
|
|
77
|
+
/** Called with the new state when play / pause is pressed. */
|
|
78
|
+
onPlayingChange?: (playing: boolean) => void
|
|
79
|
+
/** Called when the previous button is pressed. */
|
|
80
|
+
onPrevious?: () => void
|
|
81
|
+
/** Called when the next button is pressed. */
|
|
82
|
+
onNext?: () => void
|
|
83
|
+
/** Called with the position to seek to, once, when a drag on the scrubber ends. */
|
|
84
|
+
onSeek?: (seconds: number) => void
|
|
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.'`. */
|
|
104
|
+
emptyDescription?: ReactNode
|
|
105
|
+
/** The empty state's way forward, such as a Button that opens a player. */
|
|
106
|
+
emptyActions?: ReactNode
|
|
107
|
+
/** Classes for the root, which fills its container. */
|
|
108
|
+
className?: string
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const OUTPUT_ICON = { 'built-in': Laptop, headphones: Headphones, speaker: Speaker, airplay: Airplay }
|
|
112
|
+
const NEXT_REPEAT: Record<NowPlayingRepeat, NowPlayingRepeat> = { off: 'all', all: 'one', one: 'off' }
|
|
113
|
+
const REPEAT_LABEL: Record<NowPlayingRepeat, string> = {
|
|
114
|
+
off: 'Repeat',
|
|
115
|
+
all: 'Repeat all',
|
|
116
|
+
one: 'Repeat one',
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
type TrackIdentity = Pick<NowPlayingTrack, 'id' | 'title' | 'artist' | 'album' | 'artwork' | 'tint'>
|
|
120
|
+
|
|
121
|
+
const keyOf = (track?: TrackIdentity | null) =>
|
|
122
|
+
track ? (track.id ?? [track.title, track.artist, track.album].join('\u0000')) : ''
|
|
123
|
+
|
|
124
|
+
/** The track's tint: its own, else read from its image. */
|
|
125
|
+
function useTint(track?: TrackIdentity | null) {
|
|
126
|
+
const read = useArtworkTint(track?.tint || typeof track?.artwork !== 'string' ? undefined : track.artwork)
|
|
127
|
+
return track?.tint ?? read
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function Picture({ art, glyph }: { art: ShownArtwork['art']; glyph: number }) {
|
|
131
|
+
const level = useLift(1)
|
|
132
|
+
if (typeof art === 'string') return <img alt="" src={art} draggable={false} className="size-full object-cover" />
|
|
133
|
+
if (art != null) return art
|
|
134
|
+
return (
|
|
135
|
+
<span className={cn('flex size-full items-center justify-center text-muted-foreground', SURFACE_BG[level])}>
|
|
136
|
+
<Music size={glyph} strokeWidth={1.5} />
|
|
137
|
+
</span>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface ArtworkProps {
|
|
142
|
+
/** The track whose artwork it shows; without one, the placeholder. */
|
|
143
|
+
track?: TrackIdentity | null
|
|
144
|
+
/** The placeholder note's size in px. Defaults to `14`. */
|
|
145
|
+
glyph?: number
|
|
146
|
+
/** Classes for the tile: its size and radius. */
|
|
147
|
+
className?: string
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A track's artwork in a tile that never blinks: the last good picture stays
|
|
152
|
+
* while the next one loads or an update comes without one, the next
|
|
153
|
+
* crossfades in over it, and only a track without artwork shows the note.
|
|
154
|
+
*/
|
|
155
|
+
function NowPlayingArtwork({ track, glyph = 14, className }: ArtworkProps) {
|
|
156
|
+
const shown = useStableArtwork(track?.artwork, keyOf(track))
|
|
157
|
+
const reduced = useReduceMotion()
|
|
158
|
+
const [top, setTop] = useState(shown)
|
|
159
|
+
const [under, setUnder] = useState<ShownArtwork | null>(null)
|
|
160
|
+
if (top.id !== shown.id) {
|
|
161
|
+
setUnder(top)
|
|
162
|
+
setTop(shown)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<span className={cn('relative isolate block shrink-0 overflow-hidden', className)}>
|
|
167
|
+
{under && (
|
|
168
|
+
<span key={under.id} className="absolute inset-0">
|
|
169
|
+
<Picture art={under.art} glyph={glyph} />
|
|
170
|
+
</span>
|
|
171
|
+
)}
|
|
172
|
+
<motion.span
|
|
173
|
+
key={shown.id}
|
|
174
|
+
className="absolute inset-0"
|
|
175
|
+
initial={under ? { opacity: 0 } : false}
|
|
176
|
+
animate={{ opacity: 1 }}
|
|
177
|
+
transition={reduced ? spring.fast : spring.slow}
|
|
178
|
+
onAnimationComplete={() => setUnder(null)}
|
|
179
|
+
>
|
|
180
|
+
<Picture art={shown.art} glyph={glyph} />
|
|
181
|
+
</motion.span>
|
|
182
|
+
<span
|
|
183
|
+
aria-hidden
|
|
184
|
+
className="pointer-events-none absolute inset-0 rounded-[inherit] ring-1 ring-border ring-inset"
|
|
185
|
+
/>
|
|
186
|
+
</span>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
interface PartProps {
|
|
191
|
+
/** What plays. */
|
|
192
|
+
track?: TrackIdentity | null
|
|
193
|
+
/** It plays: the bars dance. Defaults to `true`. */
|
|
194
|
+
playing?: boolean
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Level bars in the artwork's tint. */
|
|
198
|
+
function TintedBars({ track, playing = true, className }: PartProps & { className?: string }) {
|
|
199
|
+
const tint = useTint(track)
|
|
200
|
+
return (
|
|
201
|
+
<span className={cn('inline-flex text-foreground', className)} style={tint ? { color: tint } : undefined}>
|
|
202
|
+
<Equalizer playing={playing} label={playing ? 'Playing' : 'Paused'} barClassName="bg-current" />
|
|
203
|
+
</span>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The compact island's left wing: the artwork, small. */
|
|
208
|
+
function NowPlayingLeading({ track }: Pick<PartProps, 'track'>) {
|
|
209
|
+
return <NowPlayingArtwork track={track} glyph={12} className="size-5.5 rounded-md" />
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The compact island's right wing: the level bars in the artwork's tint, low while paused. */
|
|
213
|
+
function NowPlayingTrailing(props: PartProps) {
|
|
214
|
+
return <TintedBars {...props} />
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** The split island's bubble: the artwork as a disc. */
|
|
218
|
+
function NowPlayingMinimal({ track }: Pick<PartProps, 'track'>) {
|
|
219
|
+
return <NowPlayingArtwork track={track} glyph={12} className="size-6 rounded-full" />
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** The island's flash when the track changes: its artwork, title and artist, and the tinted bars. */
|
|
223
|
+
function NowPlayingFlash({ track, playing = true }: { track: NowPlayingTrack; playing?: boolean }) {
|
|
224
|
+
return (
|
|
225
|
+
<IslandFlash
|
|
226
|
+
icon={<NowPlayingArtwork track={track} className="size-9 rounded-lg" />}
|
|
227
|
+
title={track.title || 'Unknown title'}
|
|
228
|
+
caption={[track.artist, track.album].filter(Boolean).join(' — ') || track.source}
|
|
229
|
+
trailing={<TintedBars track={track} playing={playing} />}
|
|
230
|
+
/>
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Literal tables: UnoCSS only generates the classes it can read whole.
|
|
235
|
+
const ART = { default: 'size-36 rounded-2xl', compact: 'size-28 rounded-xl' }
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* What's playing, as a notch app's open island shows it: the artwork, the
|
|
239
|
+
* title and artist, where the track is, the transport, and where it plays.
|
|
240
|
+
*
|
|
241
|
+
* The artwork is the hero's picture, as tall as the widget, with a soft glow
|
|
242
|
+
* of its tint behind it (`track.tint`, else read from an image URL); the
|
|
243
|
+
* equalizer and any toggle that is on take the same tint, so the color
|
|
244
|
+
* comes from the music. The artwork never blinks: the last good picture
|
|
245
|
+
* stays up while a new one loads or an update arrives without one, the next
|
|
246
|
+
* crossfades in over it, and only a track whose `artwork` is `null` shows
|
|
247
|
+
* the placeholder note.
|
|
248
|
+
*
|
|
249
|
+
* Under the title and artist (with the album) runs the kit's MediaScrubber,
|
|
250
|
+
* which ticks on by itself while playing and seeks once when a drag ends
|
|
251
|
+
* (`onSeek`). The transport sits in the middle of the last row, the source
|
|
252
|
+
* app and the output device on its left, and shuffle, repeat and the heart
|
|
253
|
+
* on its right, each shown when its value or handler is given. Play / pause
|
|
254
|
+
* runs through `playing` / `onPlayingChange`, or is kept here from
|
|
255
|
+
* `defaultPlaying`; the toggles are the same. Without a track it says
|
|
256
|
+
* nothing is playing and how to change that.
|
|
257
|
+
*
|
|
258
|
+
* The other forms are parts: `NowPlaying.Leading` and `NowPlaying.Trailing`
|
|
259
|
+
* for the compact island's wings (the artwork, and the tinted Equalizer that
|
|
260
|
+
* settles when paused), `NowPlaying.Minimal` for the split island's bubble
|
|
261
|
+
* (the artwork as a disc), `NowPlaying.Flash` for the flash on a track
|
|
262
|
+
* change and `NowPlaying.Artwork` for the tile on its own.
|
|
263
|
+
*
|
|
264
|
+
* @example {@include ./examples.mdx}
|
|
265
|
+
*/
|
|
266
|
+
const NowPlaying = Object.assign(
|
|
267
|
+
function NowPlaying({
|
|
268
|
+
track,
|
|
269
|
+
playing: playingProp,
|
|
270
|
+
defaultPlaying = true,
|
|
271
|
+
onPlayingChange,
|
|
272
|
+
onPrevious,
|
|
273
|
+
onNext,
|
|
274
|
+
onSeek,
|
|
275
|
+
shuffle: shuffleProp,
|
|
276
|
+
defaultShuffle,
|
|
277
|
+
onShuffleChange,
|
|
278
|
+
repeat: repeatProp,
|
|
279
|
+
defaultRepeat,
|
|
280
|
+
onRepeatChange,
|
|
281
|
+
liked: likedProp,
|
|
282
|
+
defaultLiked,
|
|
283
|
+
onLikedChange,
|
|
284
|
+
emptyDescription = 'Play something in Music, Spotify or a browser and it shows up here.',
|
|
285
|
+
emptyActions,
|
|
286
|
+
className,
|
|
287
|
+
}: NowPlayingProps) {
|
|
288
|
+
const size = useSize()
|
|
289
|
+
const [playing, setPlaying] = useControllableState(playingProp, defaultPlaying, onPlayingChange)
|
|
290
|
+
const [shuffle, setShuffle] = useControllableState(shuffleProp, defaultShuffle ?? false, onShuffleChange)
|
|
291
|
+
const [repeat, setRepeat] = useControllableState(repeatProp, defaultRepeat ?? 'off', onRepeatChange)
|
|
292
|
+
const [liked, setLiked] = useControllableState(likedProp, defaultLiked ?? false, onLikedChange)
|
|
293
|
+
const tint = useTint(track)
|
|
294
|
+
|
|
295
|
+
if (!track)
|
|
296
|
+
return (
|
|
297
|
+
<Widget.Message
|
|
298
|
+
icon={Music}
|
|
299
|
+
title="Nothing playing"
|
|
300
|
+
description={emptyDescription}
|
|
301
|
+
actions={emptyActions}
|
|
302
|
+
className={className}
|
|
303
|
+
/>
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
const showShuffle = shuffleProp !== undefined || defaultShuffle !== undefined || onShuffleChange !== undefined
|
|
307
|
+
const showRepeat = repeatProp !== undefined || defaultRepeat !== undefined || onRepeatChange !== undefined
|
|
308
|
+
const showLiked = likedProp !== undefined || defaultLiked !== undefined || onLikedChange !== undefined
|
|
309
|
+
const byline = [track.artist, track.album].filter(Boolean).join(' — ')
|
|
310
|
+
|
|
311
|
+
return (
|
|
312
|
+
<div className={cn('relative isolate flex w-full flex-col justify-center', className)}>
|
|
313
|
+
<Widget
|
|
314
|
+
media={
|
|
315
|
+
<span className="relative flex">
|
|
316
|
+
{tint && (
|
|
317
|
+
<span
|
|
318
|
+
aria-hidden
|
|
319
|
+
className="absolute -inset-x-8 -inset-y-4 -z-1 opacity-70"
|
|
320
|
+
style={{ backgroundImage: `radial-gradient(closest-side, ${tint}, transparent)` }}
|
|
321
|
+
/>
|
|
322
|
+
)}
|
|
323
|
+
<NowPlayingArtwork track={track} glyph={28} className={ART[size.variant]} />
|
|
324
|
+
</span>
|
|
325
|
+
}
|
|
326
|
+
>
|
|
327
|
+
<div className="flex min-w-0 items-start gap-3">
|
|
328
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
329
|
+
<Widget.Title>{track.title || 'Unknown title'}</Widget.Title>
|
|
330
|
+
{byline && <Widget.Subtitle>{byline}</Widget.Subtitle>}
|
|
331
|
+
</div>
|
|
332
|
+
<TintedBars track={track} playing={playing} className="mt-1.5" />
|
|
333
|
+
</div>
|
|
334
|
+
|
|
335
|
+
{track.duration > 0 && (
|
|
336
|
+
<MediaScrubber
|
|
337
|
+
className="mt-2"
|
|
338
|
+
quiet
|
|
339
|
+
position={track.position}
|
|
340
|
+
duration={track.duration}
|
|
341
|
+
playing={playing}
|
|
342
|
+
onSeek={onSeek}
|
|
343
|
+
/>
|
|
344
|
+
)}
|
|
345
|
+
|
|
346
|
+
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2">
|
|
347
|
+
<Widget.Meta>
|
|
348
|
+
{track.source && <Widget.MetaItem icon={Disc3}>{track.source}</Widget.MetaItem>}
|
|
349
|
+
{track.output && (
|
|
350
|
+
<Widget.MetaItem icon={OUTPUT_ICON[track.outputKind ?? 'built-in']}>{track.output}</Widget.MetaItem>
|
|
351
|
+
)}
|
|
352
|
+
</Widget.Meta>
|
|
353
|
+
<div className="flex items-center gap-1">
|
|
354
|
+
<Widget.Action icon={SkipBack} label="Previous" filled onClick={onPrevious} />
|
|
355
|
+
<Widget.Action
|
|
356
|
+
icon={playing ? Pause : Play}
|
|
357
|
+
label={playing ? 'Pause' : 'Play'}
|
|
358
|
+
emphasis="primary"
|
|
359
|
+
filled
|
|
360
|
+
onClick={() => setPlaying(!playing)}
|
|
361
|
+
/>
|
|
362
|
+
<Widget.Action icon={SkipForward} label="Next" filled onClick={onNext} />
|
|
363
|
+
</div>
|
|
364
|
+
<div className="flex items-center justify-end">
|
|
365
|
+
{showShuffle && (
|
|
366
|
+
<Widget.Action
|
|
367
|
+
icon={Shuffle}
|
|
368
|
+
label="Shuffle"
|
|
369
|
+
pressed={shuffle}
|
|
370
|
+
color={tint}
|
|
371
|
+
onClick={() => setShuffle(!shuffle)}
|
|
372
|
+
/>
|
|
373
|
+
)}
|
|
374
|
+
{showRepeat && (
|
|
375
|
+
<Widget.Action
|
|
376
|
+
icon={repeat === 'one' ? Repeat1 : Repeat}
|
|
377
|
+
label={REPEAT_LABEL[repeat]}
|
|
378
|
+
pressed={repeat !== 'off'}
|
|
379
|
+
color={tint}
|
|
380
|
+
onClick={() => setRepeat(NEXT_REPEAT[repeat])}
|
|
381
|
+
/>
|
|
382
|
+
)}
|
|
383
|
+
{showLiked && (
|
|
384
|
+
<Widget.Action
|
|
385
|
+
icon={Heart}
|
|
386
|
+
label={liked ? 'Remove from library' : 'Add to library'}
|
|
387
|
+
pressed={liked}
|
|
388
|
+
filled={liked}
|
|
389
|
+
color={tint}
|
|
390
|
+
onClick={() => setLiked(!liked)}
|
|
391
|
+
/>
|
|
392
|
+
)}
|
|
393
|
+
</div>
|
|
394
|
+
</div>
|
|
395
|
+
</Widget>
|
|
396
|
+
</div>
|
|
397
|
+
)
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
Artwork: NowPlayingArtwork,
|
|
401
|
+
Leading: NowPlayingLeading,
|
|
402
|
+
Trailing: NowPlayingTrailing,
|
|
403
|
+
Minimal: NowPlayingMinimal,
|
|
404
|
+
Flash: NowPlayingFlash,
|
|
405
|
+
},
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
export default NowPlaying
|
|
409
|
+
|
|
410
|
+
export type { NowPlayingOutput, NowPlayingProps, NowPlayingRepeat, NowPlayingTrack }
|
|
411
|
+
export { NowPlaying, NowPlayingArtwork, NowPlayingFlash, NowPlayingLeading, NowPlayingMinimal, NowPlayingTrailing }
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import Weather from './index'
|
|
2
|
+
import { DAYS, FORECAST, NIGHT, RainSoonFlash, WEATHER_NOW, WeatherSplit, WeatherWings } from '../../../mock/weather'
|
|
3
|
+
import { FlashIsland, WidgetIsland } from '../../../mock/island-content'
|
|
4
|
+
|
|
5
|
+
# Now and the next hours
|
|
6
|
+
|
|
7
|
+
The temperature as the hero after the condition's glyph, how warm it feels and when the rain comes, today's high, low, rain, wind, humidity and UV; the next six hours beside it with the chance of rain once it turns wet, and tomorrow.
|
|
8
|
+
|
|
9
|
+
<WidgetIsland tab="weather">
|
|
10
|
+
<Weather {...FORECAST} onRefresh={() => {}} />
|
|
11
|
+
</WidgetIsland>
|
|
12
|
+
|
|
13
|
+
# Fahrenheit
|
|
14
|
+
|
|
15
|
+
`unit="fahrenheit"` converts what it shows, the wind to mph; the data stays in °C and km/h.
|
|
16
|
+
|
|
17
|
+
<WidgetIsland tab="weather">
|
|
18
|
+
<Weather {...FORECAST} unit="fahrenheit" />
|
|
19
|
+
</WidgetIsland>
|
|
20
|
+
|
|
21
|
+
# A clear night
|
|
22
|
+
|
|
23
|
+
The moon's glyph by night, the hue plain; a dry strip leaves the chance of rain out.
|
|
24
|
+
|
|
25
|
+
<WidgetIsland tab="weather">
|
|
26
|
+
<Weather location="Bratislava" current={NIGHT.current} hours={NIGHT.hours} days={DAYS} now={NIGHT.current.time + 10 * 60_000} />
|
|
27
|
+
</WidgetIsland>
|
|
28
|
+
|
|
29
|
+
# Offline
|
|
30
|
+
|
|
31
|
+
The last forecast stays up; the header says how old it is.
|
|
32
|
+
|
|
33
|
+
<WidgetIsland tab="weather">
|
|
34
|
+
<Weather {...FORECAST} now={WEATHER_NOW + 2 * 60 * 60_000} status="offline" />
|
|
35
|
+
</WidgetIsland>
|
|
36
|
+
|
|
37
|
+
# Loading
|
|
38
|
+
|
|
39
|
+
The first fetch shows the widget's shape.
|
|
40
|
+
|
|
41
|
+
<WidgetIsland tab="weather">
|
|
42
|
+
<Weather location="Bratislava" status="loading" />
|
|
43
|
+
</WidgetIsland>
|
|
44
|
+
|
|
45
|
+
# Couldn't load
|
|
46
|
+
|
|
47
|
+
<WidgetIsland tab="weather">
|
|
48
|
+
<Weather status="error" onRefresh={() => {}} />
|
|
49
|
+
</WidgetIsland>
|
|
50
|
+
|
|
51
|
+
# Asking for location
|
|
52
|
+
|
|
53
|
+
`access="undetermined"` asks for the location.
|
|
54
|
+
|
|
55
|
+
<WidgetIsland tab="weather">
|
|
56
|
+
<Weather access="undetermined" />
|
|
57
|
+
</WidgetIsland>
|
|
58
|
+
|
|
59
|
+
# Location off
|
|
60
|
+
|
|
61
|
+
`access="denied"` says where to turn it on.
|
|
62
|
+
|
|
63
|
+
<WidgetIsland tab="weather">
|
|
64
|
+
<Weather access="denied" />
|
|
65
|
+
</WidgetIsland>
|
|
66
|
+
|
|
67
|
+
# Compact
|
|
68
|
+
|
|
69
|
+
`Weather.Leading` and `Weather.Trailing` in the wings: the glyph in its hue and the temperature.
|
|
70
|
+
|
|
71
|
+
<WeatherWings />
|
|
72
|
+
|
|
73
|
+
# Minimal
|
|
74
|
+
|
|
75
|
+
`Weather.Minimal`, the glyph on a disc, in the split island's bubble.
|
|
76
|
+
|
|
77
|
+
<WeatherSplit />
|
|
78
|
+
|
|
79
|
+
# Rain soon
|
|
80
|
+
|
|
81
|
+
`Weather.Alert` counts down to the rain on each minute.
|
|
82
|
+
|
|
83
|
+
<RainSoonFlash />
|
|
84
|
+
|
|
85
|
+
# A warning
|
|
86
|
+
|
|
87
|
+
A `title` and `severity` for a warning in place of the countdown.
|
|
88
|
+
|
|
89
|
+
<FlashIsland>
|
|
90
|
+
<Weather.Alert condition="thunderstorm" title="Thunderstorm warning" caption="Strong gusts and hail until 19:00" severity="severe" onAction={() => {}} />
|
|
91
|
+
</FlashIsland>
|
|
92
|
+
|
|
93
|
+
# From Open-Meteo
|
|
94
|
+
|
|
95
|
+
`conditionFromCode` reads a WMO weather code; zip the arrays into objects and keep the units in °C and km/h.
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { conditionFromCode, type WeatherHour } from '@justanarthur/modo-ui-notch'
|
|
99
|
+
|
|
100
|
+
const res = await fetch(
|
|
101
|
+
`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&timeformat=unixtime&timezone=auto` +
|
|
102
|
+
'¤t=temperature_2m,apparent_temperature,is_day,weather_code,wind_speed_10m,relative_humidity_2m,uv_index' +
|
|
103
|
+
'&hourly=temperature_2m,weather_code,is_day,precipitation_probability' +
|
|
104
|
+
'&daily=weather_code,temperature_2m_max,temperature_2m_min,precipitation_probability_max&forecast_days=2',
|
|
105
|
+
)
|
|
106
|
+
const { current, hourly, daily } = await res.json()
|
|
107
|
+
|
|
108
|
+
const hours: WeatherHour[] = hourly.time.map((time: number, i: number) => ({
|
|
109
|
+
time: time * 1000,
|
|
110
|
+
temperature: hourly.temperature_2m[i],
|
|
111
|
+
condition: conditionFromCode(hourly.weather_code[i]),
|
|
112
|
+
isDay: hourly.is_day[i] === 1,
|
|
113
|
+
precipitation: hourly.precipitation_probability[i],
|
|
114
|
+
}))
|
|
115
|
+
```
|