@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.
- package/LICENSE +21 -0
- package/README.md +75 -2
- package/blocks/activities/agenda/examples.mdx +58 -0
- package/blocks/activities/agenda/index.tsx +332 -0
- package/blocks/activities/now-playing/examples.mdx +49 -0
- package/blocks/activities/now-playing/index.tsx +218 -0
- package/blocks/activities/shelf/examples.mdx +33 -0
- package/blocks/activities/shelf/index.tsx +289 -0
- package/blocks/activities/timer/examples.mdx +52 -0
- package/blocks/activities/timer/index.tsx +292 -0
- package/blocks/app/expanded-island/examples.mdx +45 -0
- package/blocks/app/expanded-island/index.tsx +127 -0
- package/blocks/app/settings-window/examples.mdx +30 -0
- package/blocks/app/settings-window/index.tsx +357 -0
- package/blocks/system/controls/examples.mdx +34 -0
- package/blocks/system/controls/index.tsx +167 -0
- package/blocks/system/devices/examples.mdx +25 -0
- package/blocks/system/devices/index.tsx +172 -0
- package/blocks/system/power-alert/examples.mdx +32 -0
- package/blocks/system/power-alert/index.tsx +89 -0
- package/blocks/system/system-stats/examples.mdx +23 -0
- package/blocks/system/system-stats/index.tsx +178 -0
- package/components/indicators/battery-glyph/examples.mdx +22 -0
- package/components/indicators/battery-glyph/index.tsx +91 -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 +21 -0
- package/components/indicators/media-scrubber/index.tsx +98 -0
- package/components/island/island/examples.mdx +57 -0
- package/components/island/island/index.tsx +415 -0
- package/components/island/island-flash/examples.mdx +55 -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/dist/blocks/activities/agenda/index.d.ts +2 -0
- package/dist/blocks/activities/agenda/index.js +21 -0
- package/dist/blocks/activities/now-playing/index.d.ts +2 -0
- package/dist/blocks/activities/now-playing/index.js +22 -0
- package/dist/blocks/activities/shelf/index.d.ts +2 -0
- package/dist/blocks/activities/shelf/index.js +14 -0
- package/dist/blocks/activities/timer/index.d.ts +2 -0
- package/dist/blocks/activities/timer/index.js +19 -0
- package/dist/blocks/app/expanded-island/index.d.ts +3 -0
- package/dist/blocks/app/expanded-island/index.js +10 -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/controls/index.d.ts +2 -0
- package/dist/blocks/system/controls/index.js +10 -0
- package/dist/blocks/system/devices/index.d.ts +2 -0
- package/dist/blocks/system/devices/index.js +12 -0
- package/dist/blocks/system/power-alert/index.d.ts +2 -0
- package/dist/blocks/system/power-alert/index.js +9 -0
- package/dist/blocks/system/system-stats/index.d.ts +2 -0
- package/dist/blocks/system/system-stats/index.js +12 -0
- package/dist/components/indicators/battery-glyph/index.d.ts +2 -0
- package/dist/components/indicators/battery-glyph/index.js +9 -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/index.d.ts +21 -0
- package/dist/index.js +151 -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-2f7zxrbk.js +65 -0
- package/dist/shared/chunk-2qpcsv5h.d.ts +45 -0
- package/dist/shared/chunk-2s4q6mt0.js +27 -0
- package/dist/shared/chunk-45gytfr1.d.ts +84 -0
- package/dist/shared/chunk-502rmtap.js +54 -0
- package/dist/shared/chunk-50ffk4r7.d.ts +69 -0
- package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
- package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
- package/dist/shared/chunk-5w0yck07.d.ts +32 -0
- package/dist/shared/chunk-6c1jbefs.d.ts +36 -0
- package/dist/shared/chunk-78w7qwp0.js +58 -0
- package/dist/shared/chunk-7hr53mby.js +116 -0
- package/dist/shared/chunk-9nhpg9t8.d.ts +47 -0
- package/dist/shared/chunk-b8jb1w72.js +145 -0
- package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
- package/dist/shared/chunk-cpewy6yg.js +178 -0
- package/dist/shared/chunk-d5qm9cps.js +10 -0
- package/dist/shared/chunk-e3e4s4ds.d.ts +77 -0
- package/dist/shared/chunk-enm6td0p.js +280 -0
- package/dist/shared/chunk-fvedaas2.d.ts +33 -0
- package/dist/shared/chunk-gb56m10p.js +39 -0
- package/dist/shared/chunk-gex38j8x.d.ts +82 -0
- package/dist/shared/chunk-hpsabfsd.d.ts +75 -0
- package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
- package/dist/shared/chunk-hwtxpzg0.js +69 -0
- package/dist/shared/chunk-mp1nx0ez.js +101 -0
- package/dist/shared/chunk-phb53x1f.js +252 -0
- package/dist/shared/chunk-r8esmjfs.d.ts +42 -0
- package/dist/shared/chunk-rcp1g9ca.js +70 -0
- package/dist/shared/chunk-rpfwv3pz.js +209 -0
- package/dist/shared/chunk-rr5e0g15.d.ts +35 -0
- package/dist/shared/chunk-rx9sphz2.js +266 -0
- package/dist/shared/chunk-s33y1pcq.js +305 -0
- package/dist/shared/chunk-sbnrhy5m.js +331 -0
- package/dist/shared/chunk-w48eyvfr.d.ts +56 -0
- package/dist/shared/chunk-wwjxs75m.js +74 -0
- package/dist/shared/chunk-xdeek16r.d.ts +58 -0
- package/dist/shared/chunk-xkzjk1tq.js +206 -0
- package/dist/shared/chunk-yngkkxz2.d.ts +88 -0
- package/dist/shared/chunk-zvh0d3qb.js +63 -0
- package/dist/styles.css +222 -0
- package/index.ts +21 -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 +100 -0
- package/mock/artwork.tsx +25 -0
- package/mock/data.ts +153 -0
- package/mock/desktop.tsx +83 -0
- package/mock/fit.ts +26 -0
- package/mock/island-content.tsx +217 -0
- package/mock/scene.tsx +52 -0
- package/mock/settings.tsx +210 -0
- package/package.json +117 -4
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the time left on a notch app's timer, as text that ticks
|
|
3
|
+
* only on second edges. Rebuilt from Just Notch's timer plugin (`Countdown`,
|
|
4
|
+
* `useRemaining`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use client'
|
|
8
|
+
|
|
9
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
10
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
11
|
+
import { formatClock, formatShort, MINUTE, SECOND, useEdgeClock } from '../../../lib/clock'
|
|
12
|
+
|
|
13
|
+
type CountdownFormat = 'clock' | 'short'
|
|
14
|
+
|
|
15
|
+
interface CountdownProps {
|
|
16
|
+
/** When it ends, in epoch ms. */
|
|
17
|
+
endsAt?: number
|
|
18
|
+
/** How long it runs from when it mounts, in ms, when there is no `endsAt`. Defaults to `0`. */
|
|
19
|
+
duration?: number
|
|
20
|
+
/** Stop the clock: it holds the time left when it paused, or `remaining`. Defaults to `false`. */
|
|
21
|
+
paused?: boolean
|
|
22
|
+
/** The time left to show while paused, in ms. */
|
|
23
|
+
remaining?: number
|
|
24
|
+
/** `clock` is `4:05`; `short` is the largest unit, rounded up: `4m`, then `45s` in the last minute. Defaults to `'clock'`. */
|
|
25
|
+
format?: CountdownFormat
|
|
26
|
+
/** Called once when it reaches zero. */
|
|
27
|
+
onEnd?: () => void
|
|
28
|
+
/** Classes for the text, such as its role and weight. */
|
|
29
|
+
className?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The time left, as text: `4:05`, or `4m` where room is short (a compact
|
|
34
|
+
* wing).
|
|
35
|
+
*
|
|
36
|
+
* It re-renders once per shown unit, on the unit's edge counted from the end,
|
|
37
|
+
* never in between: a second for the clock, a minute for the short form until
|
|
38
|
+
* its last minute. So a running timer costs one render a second at most, and
|
|
39
|
+
* the digits change exactly when a second has passed. Digits are tabular, so
|
|
40
|
+
* the text holds its width as it ticks. Paused, it holds the time left.
|
|
41
|
+
*
|
|
42
|
+
* @example {@include ./examples.mdx}
|
|
43
|
+
*/
|
|
44
|
+
export default function Countdown({
|
|
45
|
+
endsAt,
|
|
46
|
+
duration = 0,
|
|
47
|
+
paused = false,
|
|
48
|
+
remaining,
|
|
49
|
+
format = 'clock',
|
|
50
|
+
onEnd,
|
|
51
|
+
className,
|
|
52
|
+
}: CountdownProps) {
|
|
53
|
+
const [mounted] = useState(Date.now)
|
|
54
|
+
const end = endsAt ?? mounted + duration
|
|
55
|
+
const [coarse, setCoarse] = useState(format === 'short' && end - Date.now() > MINUTE)
|
|
56
|
+
// Past the end there is nothing left to tick.
|
|
57
|
+
const now = useEdgeClock(end, !paused && Date.now() < end + SECOND, coarse ? MINUTE : SECOND)
|
|
58
|
+
const pausedLeft = useMemo(() => end - Date.now(), [paused, end])
|
|
59
|
+
const left = Math.max(0, paused ? (remaining ?? pausedLeft) : end - now)
|
|
60
|
+
|
|
61
|
+
useEffect(() => setCoarse(format === 'short' && left > MINUTE), [format, left])
|
|
62
|
+
|
|
63
|
+
const ended = useRef(false)
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (left > 0 || paused) {
|
|
66
|
+
ended.current = false
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
if (ended.current) return
|
|
70
|
+
ended.current = true
|
|
71
|
+
onEnd?.()
|
|
72
|
+
}, [left, paused, onEnd])
|
|
73
|
+
|
|
74
|
+
const seconds = left / SECOND
|
|
75
|
+
return (
|
|
76
|
+
<span role="timer" className={cn('tabular-nums', className)}>
|
|
77
|
+
{format === 'short' ? formatShort(seconds) : formatClock(Math.ceil(seconds))}
|
|
78
|
+
</span>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type { CountdownFormat, CountdownProps }
|
|
83
|
+
export { Countdown }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Equalizer from './index'
|
|
2
|
+
|
|
3
|
+
# Playing and paused
|
|
4
|
+
|
|
5
|
+
Playing, each bar loops at its own pace; paused, they settle low.
|
|
6
|
+
|
|
7
|
+
<div className="dark flex items-center gap-6 rounded-box bg-ink px-5 py-3 text-foreground">
|
|
8
|
+
<Equalizer label="Playing" />
|
|
9
|
+
<Equalizer playing={false} label="Paused" />
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
# Tinted
|
|
13
|
+
|
|
14
|
+
Any fill through `barClassName`, such as the artwork's tint, and fewer or more bars.
|
|
15
|
+
|
|
16
|
+
<div className="flex items-center gap-6">
|
|
17
|
+
<Equalizer barClassName="bg-status-success" bars={3} />
|
|
18
|
+
<Equalizer barClassName="bg-brand" bars={5} className="h-5" />
|
|
19
|
+
<Equalizer barClassName="bg-muted-foreground" />
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the now-playing level bars of a notch app's compact wing.
|
|
3
|
+
* Rebuilt from Just Notch's now-playing plugin (`Bars`).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use client'
|
|
7
|
+
|
|
8
|
+
import { useReduceMotion } from '@justanarthur/modo-ui/lib/reduced-motion'
|
|
9
|
+
import { spring } from '@justanarthur/modo-ui/lib/springs'
|
|
10
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
11
|
+
import { motion } from 'motion/react'
|
|
12
|
+
import { useEffect, useRef } from 'react'
|
|
13
|
+
|
|
14
|
+
// Each bar loops its own levels at its own pace, so together they read as random.
|
|
15
|
+
const LOOPS = [
|
|
16
|
+
{ levels: [0.35, 1, 0.5, 0.8, 0.35], beats: 5 },
|
|
17
|
+
{ levels: [0.7, 0.4, 0.95, 0.55, 0.7], beats: 4 },
|
|
18
|
+
{ levels: [0.5, 0.9, 0.3, 1, 0.5], beats: 6 },
|
|
19
|
+
{ levels: [0.4, 0.75, 0.6, 0.3, 0.4], beats: 4.5 },
|
|
20
|
+
{ levels: [0.6, 0.3, 0.85, 0.45, 0.6], beats: 5.5 },
|
|
21
|
+
]
|
|
22
|
+
const REST = 0.2
|
|
23
|
+
const STILL = [0.5, 0.85, 0.65, 0.4, 0.7]
|
|
24
|
+
|
|
25
|
+
interface EqualizerProps {
|
|
26
|
+
/** Music is playing: the bars move. Paused, they settle low. Defaults to `true`. */
|
|
27
|
+
playing?: boolean
|
|
28
|
+
/** How many bars, from 1 to 5. Defaults to `4`. */
|
|
29
|
+
bars?: number
|
|
30
|
+
/** What screen readers hear. Without one the bars are hidden from them. */
|
|
31
|
+
label?: string
|
|
32
|
+
/** Classes for the bars' fill. Defaults to `'bg-foreground'`. */
|
|
33
|
+
barClassName?: string
|
|
34
|
+
/** Classes for the row, such as its height. Defaults to `'h-3.5'`. */
|
|
35
|
+
className?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface BarProps {
|
|
39
|
+
loop: (typeof LOOPS)[number]
|
|
40
|
+
live: boolean
|
|
41
|
+
level: number
|
|
42
|
+
className: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Playing, the bar loops on the Web Animations API: a `transform` keyframe loop the compositor runs, no JS per frame. */
|
|
46
|
+
function Bar({ loop, live, level, className }: BarProps) {
|
|
47
|
+
const ref = useRef<HTMLSpanElement>(null)
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const bar = ref.current
|
|
51
|
+
if (!live || !bar) return
|
|
52
|
+
const animation = bar.animate(
|
|
53
|
+
loop.levels.map(l => ({ transform: `scaleY(${l})` })),
|
|
54
|
+
{
|
|
55
|
+
duration: spring.slow.duration * loop.beats * 1000,
|
|
56
|
+
easing: 'ease-in-out',
|
|
57
|
+
iterations: Number.POSITIVE_INFINITY,
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
return () => animation.cancel()
|
|
61
|
+
}, [live, loop])
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<motion.span
|
|
65
|
+
ref={ref}
|
|
66
|
+
className={cn('h-full w-0.75 rounded-full', className)}
|
|
67
|
+
initial={false}
|
|
68
|
+
animate={{ scaleY: level }}
|
|
69
|
+
transition={spring.moderate}
|
|
70
|
+
/>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Level bars for what's playing: they dance while music plays and settle low
|
|
76
|
+
* when it pauses.
|
|
77
|
+
*
|
|
78
|
+
* Each bar loops its own levels at its own pace on the Web Animations API, a
|
|
79
|
+
* `transform` loop the compositor runs, so playing music costs no JavaScript
|
|
80
|
+
* per frame. Pausing springs the bars down to rest; under reduced motion they
|
|
81
|
+
* hold still at a level instead of dancing. They take the text color, or any
|
|
82
|
+
* fill through `barClassName` (an artwork's tint).
|
|
83
|
+
*
|
|
84
|
+
* @example {@include ./examples.mdx}
|
|
85
|
+
*/
|
|
86
|
+
export default function Equalizer({
|
|
87
|
+
playing = true,
|
|
88
|
+
bars = 4,
|
|
89
|
+
label,
|
|
90
|
+
barClassName = 'bg-foreground',
|
|
91
|
+
className,
|
|
92
|
+
}: EqualizerProps) {
|
|
93
|
+
const reduced = useReduceMotion()
|
|
94
|
+
const live = playing && !reduced
|
|
95
|
+
const count = Math.min(Math.max(1, Math.round(bars)), LOOPS.length)
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<span
|
|
99
|
+
{...(label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true })}
|
|
100
|
+
className={cn('inline-flex h-3.5 shrink-0 items-center gap-0.5', className)}
|
|
101
|
+
>
|
|
102
|
+
{LOOPS.slice(0, count).map((loop, i) => (
|
|
103
|
+
<Bar
|
|
104
|
+
key={loop.beats}
|
|
105
|
+
loop={loop}
|
|
106
|
+
live={live}
|
|
107
|
+
level={playing ? (STILL[i] ?? REST) : REST}
|
|
108
|
+
className={barClassName}
|
|
109
|
+
/>
|
|
110
|
+
))}
|
|
111
|
+
</span>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type { EqualizerProps }
|
|
116
|
+
export { Equalizer }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import MediaScrubber from './index'
|
|
2
|
+
|
|
3
|
+
# Playing
|
|
4
|
+
|
|
5
|
+
Elapsed, the scrubber and the time remaining, running on a second at a time. Drag to seek.
|
|
6
|
+
|
|
7
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
8
|
+
<MediaScrubber position={71} duration={243} playing />
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
# Paused
|
|
12
|
+
|
|
13
|
+
<div className="w-full max-w-md">
|
|
14
|
+
<MediaScrubber position={190} duration={258} />
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
# Default size
|
|
18
|
+
|
|
19
|
+
<div className="w-full max-w-md">
|
|
20
|
+
<MediaScrubber position={12} duration={330} size="default" />
|
|
21
|
+
</div>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the playback position of a notch app's now-playing view,
|
|
3
|
+
* on modo-ui's Slider. Rebuilt from Just Notch's now-playing plugin
|
|
4
|
+
* (`Scrubber`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use client'
|
|
8
|
+
|
|
9
|
+
import Slider from '@justanarthur/modo-ui/components/inputs/slider'
|
|
10
|
+
import type { SizeVariant } from '@justanarthur/modo-ui/lib/size-context'
|
|
11
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
12
|
+
import { useEffect, useState } from 'react'
|
|
13
|
+
import { formatClock, SECOND, useEdgeClock } from '../../../lib/clock'
|
|
14
|
+
|
|
15
|
+
interface MediaScrubberProps {
|
|
16
|
+
/** Where playback is, in seconds. */
|
|
17
|
+
position: number
|
|
18
|
+
/** The track's length, in seconds. */
|
|
19
|
+
duration: number
|
|
20
|
+
/** It plays: the position runs on from `position`, a second at a time. Defaults to `false`. */
|
|
21
|
+
playing?: boolean
|
|
22
|
+
/** Called with the position to seek to, once, when a drag or a key press ends. */
|
|
23
|
+
onSeek?: (seconds: number) => void
|
|
24
|
+
/** Step on the size ladder. Defaults to `'compact'`. */
|
|
25
|
+
size?: SizeVariant
|
|
26
|
+
/** The slider's accessible name. Defaults to `'Position'`. */
|
|
27
|
+
label?: string
|
|
28
|
+
/** No seeking. Defaults to `false`. */
|
|
29
|
+
disabled?: boolean
|
|
30
|
+
/** Classes for the row. */
|
|
31
|
+
className?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Where a track is: elapsed time, a scrubber, and the time remaining.
|
|
36
|
+
*
|
|
37
|
+
* The scrubber is modo-ui's Slider at the compact step. While playing, the
|
|
38
|
+
* position runs on by itself a second at a time, on the second's edge, from
|
|
39
|
+
* the last `position` it got. Dragging shows the dragged value, and the
|
|
40
|
+
* remaining time follows it; `onSeek` fires once, when the drag or the key
|
|
41
|
+
* press ends, and playback runs on from the seek until the player reports
|
|
42
|
+
* its next `position`, so the thumb never jumps back to the stale one.
|
|
43
|
+
*
|
|
44
|
+
* @example {@include ./examples.mdx}
|
|
45
|
+
*/
|
|
46
|
+
export default function MediaScrubber({
|
|
47
|
+
position,
|
|
48
|
+
duration,
|
|
49
|
+
playing = false,
|
|
50
|
+
onSeek,
|
|
51
|
+
size = 'compact',
|
|
52
|
+
label = 'Position',
|
|
53
|
+
disabled = false,
|
|
54
|
+
className,
|
|
55
|
+
}: MediaScrubberProps) {
|
|
56
|
+
// Where it runs on from: the last position the player reported, or the last seek.
|
|
57
|
+
const [base, setBase] = useState(() => ({ seconds: position, since: Date.now() }))
|
|
58
|
+
const [dragged, setDragged] = useState<number>()
|
|
59
|
+
|
|
60
|
+
useEffect(() => setBase({ seconds: position, since: Date.now() }), [position])
|
|
61
|
+
|
|
62
|
+
const now = useEdgeClock(base.since, playing && dragged === undefined)
|
|
63
|
+
const live = Math.min(duration, base.seconds + (playing ? Math.max(0, now - base.since) / SECOND : 0))
|
|
64
|
+
const value = dragged ?? live
|
|
65
|
+
|
|
66
|
+
const commit = () => {
|
|
67
|
+
if (dragged === undefined) return
|
|
68
|
+
setBase({ seconds: dragged, since: Date.now() })
|
|
69
|
+
setDragged(undefined)
|
|
70
|
+
onSeek?.(dragged)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: commits the Slider's drag or key press when it ends
|
|
75
|
+
<div className={cn('flex items-center gap-3', className)} onPointerUp={commit} onKeyUp={commit}>
|
|
76
|
+
<span className="w-9 shrink-0 text-micro tabular-nums text-muted-foreground">{formatClock(value)}</span>
|
|
77
|
+
<Slider
|
|
78
|
+
className="mb-0 min-w-0 flex-1"
|
|
79
|
+
size={size}
|
|
80
|
+
label={label}
|
|
81
|
+
showValue={false}
|
|
82
|
+
formatValue={formatClock}
|
|
83
|
+
min={0}
|
|
84
|
+
max={Math.max(1, duration)}
|
|
85
|
+
step={1}
|
|
86
|
+
value={value}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
onValueChange={v => setDragged(v as number)}
|
|
89
|
+
/>
|
|
90
|
+
<span className="w-9 shrink-0 text-right text-micro tabular-nums text-muted-foreground">
|
|
91
|
+
-{formatClock(Math.max(0, duration - value))}
|
|
92
|
+
</span>
|
|
93
|
+
</div>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type { MediaScrubberProps }
|
|
98
|
+
export { MediaScrubber }
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Island from './index'
|
|
2
|
+
import { ArtworkTile, ChargingFlash, DemoIsland, ExpandedPanel, IslandPlayground, ScreenEdge, TimerBubble } from '../../../mock/island-content'
|
|
3
|
+
import Equalizer from '../../indicators/equalizer'
|
|
4
|
+
|
|
5
|
+
# States
|
|
6
|
+
|
|
7
|
+
Pick a state, or press the island: a press opens it, a hover keeps it open, and leaving or Escape closes it back to where it was.
|
|
8
|
+
|
|
9
|
+
<IslandPlayground />
|
|
10
|
+
|
|
11
|
+
# Idle
|
|
12
|
+
|
|
13
|
+
The bare notch, hanging from the top edge through its concave shoulders.
|
|
14
|
+
|
|
15
|
+
<ScreenEdge height={64}>
|
|
16
|
+
<Island />
|
|
17
|
+
</ScreenEdge>
|
|
18
|
+
|
|
19
|
+
# Compact
|
|
20
|
+
|
|
21
|
+
An activity in the wings: its glyph on the left, its live value on the right.
|
|
22
|
+
|
|
23
|
+
<ScreenEdge height={64}>
|
|
24
|
+
<Island defaultState="compact" leading={<ArtworkTile />} trailing={<Equalizer />} />
|
|
25
|
+
</ScreenEdge>
|
|
26
|
+
|
|
27
|
+
# Split
|
|
28
|
+
|
|
29
|
+
A second activity in a bubble off the right end; it melts off and back through the goo.
|
|
30
|
+
|
|
31
|
+
<ScreenEdge height={64}>
|
|
32
|
+
<Island defaultState="split" leading={<ArtworkTile />} trailing={<Equalizer />} minimal={<TimerBubble />} />
|
|
33
|
+
</ScreenEdge>
|
|
34
|
+
|
|
35
|
+
# Flash
|
|
36
|
+
|
|
37
|
+
A moment's alert below the notch.
|
|
38
|
+
|
|
39
|
+
<ScreenEdge height={112}>
|
|
40
|
+
<Island defaultState="flash" flash={<ChargingFlash />} />
|
|
41
|
+
</ScreenEdge>
|
|
42
|
+
|
|
43
|
+
# Expanded
|
|
44
|
+
|
|
45
|
+
The open panel: tabs in the wings around the notch, the tab's title and its widget.
|
|
46
|
+
|
|
47
|
+
<ScreenEdge height={340}>
|
|
48
|
+
<Island defaultState="expanded" collapsedState="compact" leading={<ArtworkTile />} trailing={<Equalizer />} expanded={<ExpandedPanel />} />
|
|
49
|
+
</ScreenEdge>
|
|
50
|
+
|
|
51
|
+
# Geometry
|
|
52
|
+
|
|
53
|
+
A wider notch and a smaller panel; the panel also shrinks to the room it has.
|
|
54
|
+
|
|
55
|
+
<ScreenEdge height={240}>
|
|
56
|
+
<DemoIsland defaultState="expanded" notchWidth={220} notchHeight={38} panelWidth={560} panelHeight={220} />
|
|
57
|
+
</ScreenEdge>
|