@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,122 @@
|
|
|
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
|
+
/** At rest a thin line of progress; the scrubber fades in on hover and focus, and always shows on touch. Defaults to `false`. */
|
|
31
|
+
quiet?: boolean
|
|
32
|
+
/** Classes for the row. */
|
|
33
|
+
className?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Where a track is: elapsed time, a scrubber, and the time remaining.
|
|
38
|
+
*
|
|
39
|
+
* The scrubber is modo-ui's Slider at the compact step. While playing, the
|
|
40
|
+
* position runs on by itself a second at a time, on the second's edge, from
|
|
41
|
+
* the last `position` it got. Dragging shows the dragged value, and the
|
|
42
|
+
* remaining time follows it; `onSeek` fires once, when the drag or the key
|
|
43
|
+
* press ends, and playback runs on from the seek until the player reports
|
|
44
|
+
* its next `position`, so the thumb never jumps back to the stale one.
|
|
45
|
+
*
|
|
46
|
+
* `quiet` is the player's form: at rest a thin line of progress, so the
|
|
47
|
+
* track reads before the control; the scrubber fades in on hover or focus,
|
|
48
|
+
* and always shows on touch.
|
|
49
|
+
*
|
|
50
|
+
* @example {@include ./examples.mdx}
|
|
51
|
+
*/
|
|
52
|
+
export default function MediaScrubber({
|
|
53
|
+
position,
|
|
54
|
+
duration,
|
|
55
|
+
playing = false,
|
|
56
|
+
onSeek,
|
|
57
|
+
size = 'compact',
|
|
58
|
+
label = 'Position',
|
|
59
|
+
disabled = false,
|
|
60
|
+
quiet = false,
|
|
61
|
+
className,
|
|
62
|
+
}: MediaScrubberProps) {
|
|
63
|
+
// Where it runs on from: the last position the player reported, or the last seek.
|
|
64
|
+
const [base, setBase] = useState(() => ({ seconds: position, since: Date.now() }))
|
|
65
|
+
const [dragged, setDragged] = useState<number>()
|
|
66
|
+
|
|
67
|
+
useEffect(() => setBase({ seconds: position, since: Date.now() }), [position])
|
|
68
|
+
|
|
69
|
+
const now = useEdgeClock(base.since, playing && dragged === undefined)
|
|
70
|
+
const live = Math.min(duration, base.seconds + (playing ? Math.max(0, now - base.since) / SECOND : 0))
|
|
71
|
+
const value = dragged ?? live
|
|
72
|
+
|
|
73
|
+
const commit = () => {
|
|
74
|
+
if (dragged === undefined) return
|
|
75
|
+
setBase({ seconds: dragged, since: Date.now() })
|
|
76
|
+
setDragged(undefined)
|
|
77
|
+
onSeek?.(dragged)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: commits the Slider's drag or key press when it ends
|
|
82
|
+
<div className={cn('flex items-center gap-3', className)} onPointerUp={commit} onKeyUp={commit}>
|
|
83
|
+
<span className="w-9 shrink-0 text-micro tabular-nums text-muted-foreground">{formatClock(value)}</span>
|
|
84
|
+
<span className="group/scrub relative flex min-w-0 flex-1 items-center">
|
|
85
|
+
<Slider
|
|
86
|
+
className={cn(
|
|
87
|
+
'mb-0 min-w-0 flex-1',
|
|
88
|
+
quiet &&
|
|
89
|
+
'opacity-0 transition-[opacity] duration-fast group-hover/scrub:opacity-100 group-focus-within/scrub:opacity-100 pointer-coarse:opacity-100',
|
|
90
|
+
)}
|
|
91
|
+
size={size}
|
|
92
|
+
label={label}
|
|
93
|
+
showValue={false}
|
|
94
|
+
formatValue={formatClock}
|
|
95
|
+
min={0}
|
|
96
|
+
max={Math.max(1, duration)}
|
|
97
|
+
step={1}
|
|
98
|
+
value={value}
|
|
99
|
+
disabled={disabled}
|
|
100
|
+
onValueChange={v => setDragged(v as number)}
|
|
101
|
+
/>
|
|
102
|
+
{quiet && (
|
|
103
|
+
<span
|
|
104
|
+
aria-hidden
|
|
105
|
+
className="pointer-events-none absolute inset-x-0 h-1 overflow-hidden rounded-full bg-active transition-[opacity] duration-fast group-hover/scrub:opacity-0 group-focus-within/scrub:opacity-0 pointer-coarse:opacity-0"
|
|
106
|
+
>
|
|
107
|
+
<span
|
|
108
|
+
className="block size-full rounded-full bg-foreground"
|
|
109
|
+
style={{ transform: `translateX(${(value / Math.max(1, duration) - 1) * 100}%)` }}
|
|
110
|
+
/>
|
|
111
|
+
</span>
|
|
112
|
+
)}
|
|
113
|
+
</span>
|
|
114
|
+
<span className="w-9 shrink-0 text-right text-micro tabular-nums text-muted-foreground">
|
|
115
|
+
-{formatClock(Math.max(0, duration - value))}
|
|
116
|
+
</span>
|
|
117
|
+
</div>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type { MediaScrubberProps }
|
|
122
|
+
export { MediaScrubber }
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Island from './index'
|
|
2
|
+
import { ArtworkTile, DemoIsland, DownloadedFlash, ExpandedPanel, IslandPlayground, PomodoroBubble, ScreenEdge } 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={<PomodoroBubble />} />
|
|
33
|
+
</ScreenEdge>
|
|
34
|
+
|
|
35
|
+
# Flash
|
|
36
|
+
|
|
37
|
+
A moment's alert below the notch.
|
|
38
|
+
|
|
39
|
+
<ScreenEdge height={112}>
|
|
40
|
+
<Island defaultState="flash" flash={<DownloadedFlash />} />
|
|
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={260}>
|
|
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>
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the island of a notch app, the black outline that hangs
|
|
3
|
+
* from the top edge and grows out of the hardware notch. Rebuilt from Just
|
|
4
|
+
* Notch's runtime (`island/island.tsx`) as a presentational component: no
|
|
5
|
+
* host, no activity store; state, geometry and content come in as props.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use client'
|
|
9
|
+
|
|
10
|
+
import { GooLayer } from '@justanarthur/modo-ui/lib/goo-indicator'
|
|
11
|
+
import { useReduceMotion } from '@justanarthur/modo-ui/lib/reduced-motion'
|
|
12
|
+
import { SurfaceProvider } from '@justanarthur/modo-ui/lib/surface-context'
|
|
13
|
+
import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
|
|
14
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
15
|
+
import { AnimatePresence, animate, motion, useMotionValue, useTransform } from 'motion/react'
|
|
16
|
+
import { type MouseEvent, type ReactNode, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
17
|
+
import {
|
|
18
|
+
bubbleFor,
|
|
19
|
+
type IslandGeometry,
|
|
20
|
+
type IslandState,
|
|
21
|
+
islandPath,
|
|
22
|
+
type Shape,
|
|
23
|
+
shapeFor,
|
|
24
|
+
slotWidth,
|
|
25
|
+
} from '../../../lib/geometry'
|
|
26
|
+
import { IslandContext } from '../../../lib/island-context'
|
|
27
|
+
import {
|
|
28
|
+
bubbleTransition,
|
|
29
|
+
contentEnter,
|
|
30
|
+
contentHidden,
|
|
31
|
+
contentLeave,
|
|
32
|
+
contentShown,
|
|
33
|
+
shapeTransition,
|
|
34
|
+
} from '../../../lib/motion'
|
|
35
|
+
|
|
36
|
+
type CollapsedState = 'idle' | 'compact' | 'split'
|
|
37
|
+
|
|
38
|
+
const HOVER_INTENT_MS = 120
|
|
39
|
+
const HOVER_LEAVE_MS = 400
|
|
40
|
+
// Room below the outline while it moves, so the goo tier's overshoot isn't cut off.
|
|
41
|
+
const OVERSHOOT = 24
|
|
42
|
+
const GOO_BLUR = 6
|
|
43
|
+
const INTERACTIVE =
|
|
44
|
+
'button, a, input, select, textarea, label, [role=slider], [role=switch], [role=tab], [role=menuitem], [contenteditable]'
|
|
45
|
+
|
|
46
|
+
const isCollapsed = (state: IslandState): state is CollapsedState =>
|
|
47
|
+
state === 'idle' || state === 'compact' || state === 'split'
|
|
48
|
+
|
|
49
|
+
interface IslandProps {
|
|
50
|
+
/** What it shows (controlled). */
|
|
51
|
+
state?: IslandState
|
|
52
|
+
/** What it shows at first (uncontrolled). Defaults to `'idle'`. */
|
|
53
|
+
defaultState?: IslandState
|
|
54
|
+
/** Called with the state a press, a hover or Escape asks for. */
|
|
55
|
+
onStateChange?: (state: IslandState) => void
|
|
56
|
+
/** Where Escape and leaving the open island go back to. Defaults to the last of `idle`, `compact` or `split` it showed. */
|
|
57
|
+
collapsedState?: CollapsedState
|
|
58
|
+
/** Opens after a short hover and closes a moment after the pointer leaves. Defaults to `false`. */
|
|
59
|
+
expandOnHover?: boolean
|
|
60
|
+
/** The hardware notch's width in px. Defaults to `185`. */
|
|
61
|
+
notchWidth?: number
|
|
62
|
+
/** The notch's height in px: the compact island's and the menu bar's. Defaults to `32`. */
|
|
63
|
+
notchHeight?: number
|
|
64
|
+
/** The open island's width in px; it shrinks to the room it has. Defaults to `720`. */
|
|
65
|
+
panelWidth?: number
|
|
66
|
+
/** The open island's height in px. Defaults to `240`. */
|
|
67
|
+
panelHeight?: number
|
|
68
|
+
/** The compact left wing: the activity's glyph (`compact` and `split`). */
|
|
69
|
+
leading?: ReactNode
|
|
70
|
+
/** The compact right wing: its live value (`compact` and `split`). */
|
|
71
|
+
trailing?: ReactNode
|
|
72
|
+
/** The second activity, in the bubble that melts off the island's right end (`split`). */
|
|
73
|
+
minimal?: ReactNode
|
|
74
|
+
/** The open island's content, from its top edge: leave the notch's height free for tabs (`expanded`). */
|
|
75
|
+
expanded?: ReactNode
|
|
76
|
+
/** The alert below the notch (`flash`), such as an IslandFlash. */
|
|
77
|
+
flash?: ReactNode
|
|
78
|
+
/** Names what the wings or the flash show; a new one swaps them with the blur, so one alert replacing another reads as new. Defaults to the state. */
|
|
79
|
+
activity?: string
|
|
80
|
+
/** The accessible name of the press that opens it. Defaults to `'Open the island'`. */
|
|
81
|
+
label?: string
|
|
82
|
+
/** Classes for the root, which spans its container's width. */
|
|
83
|
+
className?: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface LayerProps {
|
|
87
|
+
shape: Shape
|
|
88
|
+
top?: number
|
|
89
|
+
reduced: boolean
|
|
90
|
+
interactive: boolean
|
|
91
|
+
children: ReactNode
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** One presentation's content, swapped with the blur and scale. */
|
|
95
|
+
function Layer({ shape, top = 0, reduced, interactive, children }: LayerProps) {
|
|
96
|
+
const hidden = reduced ? { opacity: 0 } : contentHidden
|
|
97
|
+
return (
|
|
98
|
+
<motion.div
|
|
99
|
+
className={cn('absolute', interactive ? 'pointer-events-auto' : 'pointer-events-none')}
|
|
100
|
+
style={{
|
|
101
|
+
left: `calc(50% - ${shape.w / 2}px)`,
|
|
102
|
+
top: 0,
|
|
103
|
+
width: shape.w,
|
|
104
|
+
height: shape.h,
|
|
105
|
+
transformOrigin: '50% 0',
|
|
106
|
+
}}
|
|
107
|
+
initial={hidden}
|
|
108
|
+
animate={reduced ? { opacity: 1 } : contentShown}
|
|
109
|
+
exit={{ ...hidden, transition: contentLeave }}
|
|
110
|
+
transition={contentEnter}
|
|
111
|
+
>
|
|
112
|
+
<div className="absolute inset-x-0 bottom-0" style={{ top }}>
|
|
113
|
+
{children}
|
|
114
|
+
</div>
|
|
115
|
+
</motion.div>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The island of a notch app: one black outline that hangs from the top edge,
|
|
121
|
+
* flows into it through concave shoulders and grows out of the hardware notch
|
|
122
|
+
* as its activities need room.
|
|
123
|
+
*
|
|
124
|
+
* Five states. `idle` is the bare notch. `compact` widens into two wings for
|
|
125
|
+
* an activity's `leading` glyph and `trailing` value. `split` keeps them and
|
|
126
|
+
* melts a second activity's `minimal` bubble off the right end through
|
|
127
|
+
* modo-ui's goo. `flash` drops below the notch for a moment's alert, and
|
|
128
|
+
* `expanded` opens the panel, whose `expanded` content starts at the top
|
|
129
|
+
* edge: leave the notch's height for an IslandTabs strip.
|
|
130
|
+
*
|
|
131
|
+
* The outline is one SVG path on motion values, so a change of state animates
|
|
132
|
+
* without layout: growing on the target state's spring tier, shrinking on the
|
|
133
|
+
* source's exit tween. The content swaps the way Apple's island does, the
|
|
134
|
+
* leaving content blurring out as the arriving one sharpens and grows in;
|
|
135
|
+
* under reduced motion the shape jumps and the content only fades. At rest
|
|
136
|
+
* nothing is clipped or filtered: the clip runs only while the outline moves,
|
|
137
|
+
* the goo only while the bubble detaches or rejoins.
|
|
138
|
+
*
|
|
139
|
+
* It is always true black (`fill-ink`), the color of the notch it grows from,
|
|
140
|
+
* and its content takes modo-ui's dark scope one surface up, so a tile inside
|
|
141
|
+
* reads as raised. Content reads the island's state and geometry with
|
|
142
|
+
* `useIsland()`.
|
|
143
|
+
*
|
|
144
|
+
* A press on the island opens it (a press on a control inside it is the
|
|
145
|
+
* control's); Escape, and with `expandOnHover` the pointer leaving, closes it
|
|
146
|
+
* back to the state it came from. Controlled through `state` /
|
|
147
|
+
* `onStateChange`, or uncontrolled from `defaultState`.
|
|
148
|
+
*
|
|
149
|
+
* @example {@include ./examples.mdx}
|
|
150
|
+
*/
|
|
151
|
+
export default function Island({
|
|
152
|
+
state: stateProp,
|
|
153
|
+
defaultState = 'idle',
|
|
154
|
+
onStateChange,
|
|
155
|
+
collapsedState,
|
|
156
|
+
expandOnHover = false,
|
|
157
|
+
notchWidth = 185,
|
|
158
|
+
notchHeight = 32,
|
|
159
|
+
panelWidth = 720,
|
|
160
|
+
panelHeight = 240,
|
|
161
|
+
leading,
|
|
162
|
+
trailing,
|
|
163
|
+
minimal,
|
|
164
|
+
expanded,
|
|
165
|
+
flash,
|
|
166
|
+
activity,
|
|
167
|
+
label = 'Open the island',
|
|
168
|
+
className,
|
|
169
|
+
}: IslandProps) {
|
|
170
|
+
const [state, setState] = useControllableState(stateProp, defaultState, onStateChange)
|
|
171
|
+
const reduced = useReduceMotion()
|
|
172
|
+
const root = useRef<HTMLDivElement>(null)
|
|
173
|
+
const [room, setRoom] = useState<number>()
|
|
174
|
+
|
|
175
|
+
useLayoutEffect(() => {
|
|
176
|
+
const el = root.current
|
|
177
|
+
if (!el) return
|
|
178
|
+
setRoom(el.clientWidth)
|
|
179
|
+
const observer = new ResizeObserver(([entry]) => entry && setRoom(entry.contentRect.width))
|
|
180
|
+
observer.observe(el)
|
|
181
|
+
return () => observer.disconnect()
|
|
182
|
+
}, [])
|
|
183
|
+
|
|
184
|
+
const geometry: IslandGeometry = useMemo(
|
|
185
|
+
() => ({ notch: { width: notchWidth, height: notchHeight }, panel: { width: panelWidth, height: panelHeight } }),
|
|
186
|
+
[notchWidth, notchHeight, panelWidth, panelHeight],
|
|
187
|
+
)
|
|
188
|
+
const { notch } = geometry
|
|
189
|
+
const shape = shapeFor(state, geometry, room)
|
|
190
|
+
const split = state === 'split'
|
|
191
|
+
const bubble = bubbleFor(shape, notch, split)
|
|
192
|
+
|
|
193
|
+
const rest = useRef<CollapsedState>(isCollapsed(defaultState) ? defaultState : 'idle')
|
|
194
|
+
if (isCollapsed(state)) rest.current = state
|
|
195
|
+
const collapse = () => setState(collapsedState ?? rest.current)
|
|
196
|
+
|
|
197
|
+
const w = useMotionValue(shape.w)
|
|
198
|
+
const h = useMotionValue(shape.h)
|
|
199
|
+
const radius = useMotionValue(shape.radius)
|
|
200
|
+
const shoulder = useMotionValue(shape.shoulder)
|
|
201
|
+
const bubbleX = useMotionValue(bubble.x)
|
|
202
|
+
const bubbleR = useMotionValue(bubble.r)
|
|
203
|
+
const [moving, setMoving] = useState(false)
|
|
204
|
+
const [reserve, setReserve] = useState(shape.h)
|
|
205
|
+
const [goo, setGoo] = useState<{ left: number; top: number; width: number; height: number } | null>(null)
|
|
206
|
+
const [bubbleShown, setBubbleShown] = useState(split)
|
|
207
|
+
|
|
208
|
+
const d = useTransform(() =>
|
|
209
|
+
islandPath(0, { w: w.get(), h: h.get(), radius: radius.get(), shoulder: shoulder.get() }),
|
|
210
|
+
)
|
|
211
|
+
const clipPath = useTransform(() => {
|
|
212
|
+
const side = `calc(50% - ${w.get() / 2}px)`
|
|
213
|
+
const r = radius.get()
|
|
214
|
+
return `inset(0px ${side} calc(100% - ${h.get()}px) ${side} round 0px 0px ${r}px ${r}px)`
|
|
215
|
+
})
|
|
216
|
+
const bodyX = useTransform(() => -w.get() / 2)
|
|
217
|
+
const bodyY = useTransform(() => -radius.get())
|
|
218
|
+
const bodyHeight = useTransform(() => h.get() + radius.get())
|
|
219
|
+
const bubbleLeft = useTransform(() => bubbleX.get() - bubbleR.get())
|
|
220
|
+
const bubbleTop = useTransform(() => notch.height / 2 - bubbleR.get())
|
|
221
|
+
const bubbleSize = useTransform(() => bubbleR.get() * 2)
|
|
222
|
+
|
|
223
|
+
const previous = useRef(state)
|
|
224
|
+
const token = useRef(0)
|
|
225
|
+
useLayoutEffect(() => {
|
|
226
|
+
const from = previous.current
|
|
227
|
+
previous.current = state
|
|
228
|
+
const run = ++token.current
|
|
229
|
+
const values = [w, h, radius, shoulder, bubbleX, bubbleR] as const
|
|
230
|
+
const targets = [shape.w, shape.h, shape.radius, shape.shoulder, bubble.x, bubble.r]
|
|
231
|
+
|
|
232
|
+
// A resize, or reduced motion: no travel.
|
|
233
|
+
if (from === state || reduced) {
|
|
234
|
+
for (const [i, value] of values.entries()) value.jump(targets[i]!)
|
|
235
|
+
setMoving(false)
|
|
236
|
+
setGoo(null)
|
|
237
|
+
setBubbleShown(split)
|
|
238
|
+
setReserve(shape.h)
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const transition = shapeTransition(from, state)
|
|
243
|
+
const splitChanged = (from === 'split') !== split
|
|
244
|
+
const bubbleMove = splitChanged ? bubbleTransition(split) : transition
|
|
245
|
+
setMoving(true)
|
|
246
|
+
setReserve(Math.max(h.get(), shape.h) + OVERSHOOT)
|
|
247
|
+
if (splitChanged) {
|
|
248
|
+
const half = Math.max(w.get(), shape.w) / 2
|
|
249
|
+
const reach = Math.max(half, bubbleFor(shape, notch, true).x + bubble.r * 2)
|
|
250
|
+
const top = Math.max(radius.get(), shape.radius)
|
|
251
|
+
setGoo({ left: -reach, top: -top, width: reach * 2, height: Math.max(h.get(), shape.h) + top })
|
|
252
|
+
if (split) setBubbleShown(true)
|
|
253
|
+
}
|
|
254
|
+
const controls = values.map((value, i) => animate(value, targets[i]!, i >= 4 ? bubbleMove : transition))
|
|
255
|
+
void Promise.all(controls.map(c => c.finished)).then(() => {
|
|
256
|
+
if (run !== token.current) return
|
|
257
|
+
setMoving(false)
|
|
258
|
+
setGoo(null)
|
|
259
|
+
setBubbleShown(split)
|
|
260
|
+
setReserve(shape.h)
|
|
261
|
+
})
|
|
262
|
+
}, [state, shape.w, shape.h, shape.radius, shape.shoulder, bubble.x, bubble.r, reduced])
|
|
263
|
+
|
|
264
|
+
const hover = useRef<ReturnType<typeof setTimeout>>(undefined)
|
|
265
|
+
useEffect(() => () => clearTimeout(hover.current), [])
|
|
266
|
+
const intend = (open: boolean) => {
|
|
267
|
+
if (!expandOnHover) return
|
|
268
|
+
clearTimeout(hover.current)
|
|
269
|
+
hover.current = setTimeout(
|
|
270
|
+
() => {
|
|
271
|
+
if (open && isCollapsed(state)) setState('expanded')
|
|
272
|
+
if (!open && state === 'expanded') collapse()
|
|
273
|
+
},
|
|
274
|
+
open ? HOVER_INTENT_MS : HOVER_LEAVE_MS,
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const open = state === 'expanded'
|
|
279
|
+
useEffect(() => {
|
|
280
|
+
if (!open) return
|
|
281
|
+
const onKey = (event: KeyboardEvent) => event.key === 'Escape' && collapse()
|
|
282
|
+
window.addEventListener('keydown', onKey)
|
|
283
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
// A press that reached the island untouched by a control opens it.
|
|
287
|
+
const onClick = (event: MouseEvent) => {
|
|
288
|
+
if (open || event.defaultPrevented) return
|
|
289
|
+
if (event.target instanceof Element && event.target.closest(INTERACTIVE)) return
|
|
290
|
+
setState('expanded')
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const slot = slotWidth(notch)
|
|
294
|
+
const context = useMemo(
|
|
295
|
+
() => ({ state, geometry, shape }),
|
|
296
|
+
[state, geometry, shape.w, shape.h, shape.radius, shape.shoulder],
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
let content: ReactNode = null
|
|
300
|
+
if (state === 'expanded' && expanded)
|
|
301
|
+
content = (
|
|
302
|
+
<Layer key="expanded" shape={shape} reduced={reduced} interactive>
|
|
303
|
+
{expanded}
|
|
304
|
+
</Layer>
|
|
305
|
+
)
|
|
306
|
+
else if (state === 'flash' && flash)
|
|
307
|
+
content = (
|
|
308
|
+
<Layer key={`flash:${activity ?? ''}`} shape={shape} top={notch.height} reduced={reduced} interactive>
|
|
309
|
+
<div className="flex size-full items-center px-5 pb-1">
|
|
310
|
+
<div className="min-w-0 flex-1">{flash}</div>
|
|
311
|
+
</div>
|
|
312
|
+
</Layer>
|
|
313
|
+
)
|
|
314
|
+
else if ((state === 'compact' || split) && (leading || trailing))
|
|
315
|
+
content = (
|
|
316
|
+
<Layer key={`wings:${activity ?? 'compact'}`} shape={shape} reduced={reduced} interactive={false}>
|
|
317
|
+
<div className="absolute inset-y-0 left-0 flex items-center justify-center" style={{ width: slot }}>
|
|
318
|
+
{leading}
|
|
319
|
+
</div>
|
|
320
|
+
<div className="absolute inset-y-0 right-0 flex items-center justify-center" style={{ width: slot }}>
|
|
321
|
+
{trailing}
|
|
322
|
+
</div>
|
|
323
|
+
</Layer>
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
return (
|
|
327
|
+
<IslandContext.Provider value={context}>
|
|
328
|
+
{/* biome-ignore lint/a11y/noStaticElementInteractions: a press anywhere on the shape opens it; the button below is its keyboard path */}
|
|
329
|
+
{/* biome-ignore lint/a11y/useKeyWithClickEvents: the button below opens it from the keyboard */}
|
|
330
|
+
<div
|
|
331
|
+
ref={root}
|
|
332
|
+
data-state={state}
|
|
333
|
+
className={cn('pointer-events-none relative w-full overflow-hidden', className)}
|
|
334
|
+
style={{ height: reserve }}
|
|
335
|
+
onClick={onClick}
|
|
336
|
+
onPointerEnter={() => intend(true)}
|
|
337
|
+
onPointerLeave={() => intend(false)}
|
|
338
|
+
>
|
|
339
|
+
{goo && (
|
|
340
|
+
<div aria-hidden className="absolute top-0 left-1/2">
|
|
341
|
+
<GooLayer active blur={GOO_BLUR} box={goo} fill="bg-ink">
|
|
342
|
+
<motion.div
|
|
343
|
+
className="absolute top-0 left-0 bg-ink"
|
|
344
|
+
style={{ x: bodyX, y: bodyY, width: w, height: bodyHeight, borderRadius: radius }}
|
|
345
|
+
/>
|
|
346
|
+
<motion.div
|
|
347
|
+
className="absolute top-0 left-0 rounded-full bg-ink"
|
|
348
|
+
style={{ x: bubbleLeft, y: bubbleTop, width: bubbleSize, height: bubbleSize }}
|
|
349
|
+
/>
|
|
350
|
+
</GooLayer>
|
|
351
|
+
</div>
|
|
352
|
+
)}
|
|
353
|
+
|
|
354
|
+
<svg aria-hidden className="absolute top-0 left-1/2 overflow-visible" width="1" height="1">
|
|
355
|
+
<g className="pointer-events-auto fill-ink">
|
|
356
|
+
<motion.path d={d} />
|
|
357
|
+
{bubbleShown && <motion.circle cx={bubbleX} cy={notch.height / 2} r={bubbleR} />}
|
|
358
|
+
</g>
|
|
359
|
+
</svg>
|
|
360
|
+
|
|
361
|
+
{!open && (
|
|
362
|
+
<button
|
|
363
|
+
type="button"
|
|
364
|
+
aria-label={label}
|
|
365
|
+
aria-expanded={false}
|
|
366
|
+
className="pointer-events-auto absolute top-0 cursor-pointer outline-none focus-visible:ring-1 focus-visible:ring-focus-ring"
|
|
367
|
+
style={{
|
|
368
|
+
left: `calc(50% - ${shape.w / 2}px)`,
|
|
369
|
+
width: shape.w,
|
|
370
|
+
height: shape.h,
|
|
371
|
+
borderBottomLeftRadius: shape.radius,
|
|
372
|
+
borderBottomRightRadius: shape.radius,
|
|
373
|
+
}}
|
|
374
|
+
onClick={() => setState('expanded')}
|
|
375
|
+
/>
|
|
376
|
+
)}
|
|
377
|
+
|
|
378
|
+
<motion.div
|
|
379
|
+
className="dark pointer-events-none absolute inset-0 text-foreground"
|
|
380
|
+
// 'none' at rest, not unset: motion keeps the last value it wrote.
|
|
381
|
+
style={{ clipPath: moving ? clipPath : 'none' }}
|
|
382
|
+
>
|
|
383
|
+
<SurfaceProvider value={1}>
|
|
384
|
+
<AnimatePresence initial={false}>{content}</AnimatePresence>
|
|
385
|
+
</SurfaceProvider>
|
|
386
|
+
</motion.div>
|
|
387
|
+
|
|
388
|
+
{(split || bubbleShown) && (
|
|
389
|
+
<motion.div
|
|
390
|
+
className="dark pointer-events-auto absolute top-0 left-1/2 flex items-center justify-center text-foreground"
|
|
391
|
+
style={{ x: bubbleLeft, y: notch.height / 2 - bubble.r, width: bubble.r * 2, height: bubble.r * 2 }}
|
|
392
|
+
>
|
|
393
|
+
<AnimatePresence initial={false}>
|
|
394
|
+
{split && minimal && (
|
|
395
|
+
<motion.div
|
|
396
|
+
key={activity ?? 'minimal'}
|
|
397
|
+
className="flex size-full items-center justify-center"
|
|
398
|
+
initial={reduced ? { opacity: 0 } : contentHidden}
|
|
399
|
+
animate={reduced ? { opacity: 1 } : contentShown}
|
|
400
|
+
exit={{ opacity: 0, transition: contentLeave }}
|
|
401
|
+
transition={contentEnter}
|
|
402
|
+
>
|
|
403
|
+
{minimal}
|
|
404
|
+
</motion.div>
|
|
405
|
+
)}
|
|
406
|
+
</AnimatePresence>
|
|
407
|
+
</motion.div>
|
|
408
|
+
)}
|
|
409
|
+
</div>
|
|
410
|
+
</IslandContext.Provider>
|
|
411
|
+
)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export type { CollapsedState, IslandProps }
|
|
415
|
+
export { Island }
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import IslandFlash from './index'
|
|
2
|
+
import Equalizer from '../../indicators/equalizer'
|
|
3
|
+
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
4
|
+
import { ClipboardCheck, CloudRain, Music, Target } from 'lucide-react'
|
|
5
|
+
|
|
6
|
+
# Focus done
|
|
7
|
+
|
|
8
|
+
The icon and the figure take the tone's hue.
|
|
9
|
+
|
|
10
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
11
|
+
<IslandFlash
|
|
12
|
+
icon={<Target size={18} strokeWidth={1.5} />}
|
|
13
|
+
tone="success"
|
|
14
|
+
title="Focus done"
|
|
15
|
+
caption="Round 2 of 4 · a short break next"
|
|
16
|
+
value="5 min"
|
|
17
|
+
/>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
# Rain soon
|
|
21
|
+
|
|
22
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
23
|
+
<IslandFlash
|
|
24
|
+
icon={<CloudRain size={18} strokeWidth={1.5} />}
|
|
25
|
+
tone="warning"
|
|
26
|
+
title="Rain soon"
|
|
27
|
+
caption="Light rain for about an hour"
|
|
28
|
+
value="15 min"
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
# With an action
|
|
33
|
+
|
|
34
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
35
|
+
<IslandFlash
|
|
36
|
+
icon={<ClipboardCheck size={18} strokeWidth={1.5} />}
|
|
37
|
+
title="Copied"
|
|
38
|
+
caption="bun run build && bun run check"
|
|
39
|
+
action={<Button variant="ghost" size="compact">Pin</Button>}
|
|
40
|
+
/>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
# Next track
|
|
44
|
+
|
|
45
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
46
|
+
<IslandFlash
|
|
47
|
+
icon={<span className="flex size-8 items-center justify-center rounded-box bg-surface-3 text-muted-foreground"><Music size={14} strokeWidth={1.5} /></span>}
|
|
48
|
+
title="Midnight City"
|
|
49
|
+
caption="M83"
|
|
50
|
+
trailing={<Equalizer />}
|
|
51
|
+
/>
|
|
52
|
+
</div>
|