@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,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 `320`. */
|
|
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 = 320,
|
|
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,55 @@
|
|
|
1
|
+
import IslandFlash from './index'
|
|
2
|
+
import BatteryGlyph from '../../indicators/battery-glyph'
|
|
3
|
+
import Equalizer from '../../indicators/equalizer'
|
|
4
|
+
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
5
|
+
import { BatteryLow, Headphones, Music, Zap } from 'lucide-react'
|
|
6
|
+
|
|
7
|
+
# Charging
|
|
8
|
+
|
|
9
|
+
The icon and the figure take the tone's hue.
|
|
10
|
+
|
|
11
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
12
|
+
<IslandFlash
|
|
13
|
+
icon={<Zap size={18} strokeWidth={1.5} fill="currentColor" />}
|
|
14
|
+
tone="success"
|
|
15
|
+
title="Charging"
|
|
16
|
+
caption="38 min until full"
|
|
17
|
+
value="82%"
|
|
18
|
+
trailing={<BatteryGlyph level={82} charging />}
|
|
19
|
+
/>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
# Low battery
|
|
23
|
+
|
|
24
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
25
|
+
<IslandFlash
|
|
26
|
+
icon={<BatteryLow size={18} strokeWidth={1.5} />}
|
|
27
|
+
tone="warning"
|
|
28
|
+
title="Low battery"
|
|
29
|
+
caption="Plug in soon"
|
|
30
|
+
value="18%"
|
|
31
|
+
trailing={<BatteryGlyph level={18} />}
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
# With an action
|
|
36
|
+
|
|
37
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
38
|
+
<IslandFlash
|
|
39
|
+
icon={<Headphones size={18} strokeWidth={1.5} />}
|
|
40
|
+
title="AirPods Pro"
|
|
41
|
+
caption="Connected"
|
|
42
|
+
action={<Button variant="ghost" size="compact">Settings</Button>}
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
# Next track
|
|
47
|
+
|
|
48
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
49
|
+
<IslandFlash
|
|
50
|
+
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>}
|
|
51
|
+
title="Midnight City"
|
|
52
|
+
caption="M83"
|
|
53
|
+
trailing={<Equalizer />}
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the layout of a notch app's transient alert, the island's
|
|
3
|
+
* `flash` content. Generalised from Just Notch's power, HUD and now-playing
|
|
4
|
+
* flashes.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
8
|
+
import type { ReactNode } from 'react'
|
|
9
|
+
|
|
10
|
+
type IslandFlashTone = 'default' | 'success' | 'warning' | 'error' | 'info'
|
|
11
|
+
|
|
12
|
+
// Literal table: UnoCSS only generates the classes it can read whole.
|
|
13
|
+
const TONE: Record<IslandFlashTone, string> = {
|
|
14
|
+
default: 'text-foreground',
|
|
15
|
+
success: 'text-status-success',
|
|
16
|
+
warning: 'text-status-warning',
|
|
17
|
+
error: 'text-status-error',
|
|
18
|
+
info: 'text-status-info',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IslandFlashProps {
|
|
22
|
+
/** What happened, in a few words. */
|
|
23
|
+
title: ReactNode
|
|
24
|
+
/** One line more: how long, what to do. */
|
|
25
|
+
caption?: ReactNode
|
|
26
|
+
/** The glyph at the start: an icon, an artwork tile. It takes the tone's hue. */
|
|
27
|
+
icon?: ReactNode
|
|
28
|
+
/** The hue of the icon and the `value`. Defaults to `'default'`. */
|
|
29
|
+
tone?: IslandFlashTone
|
|
30
|
+
/** A figure at the end, in the tone's hue: `82%`, a level. */
|
|
31
|
+
value?: ReactNode
|
|
32
|
+
/** Content after it, such as a BatteryGlyph or an Equalizer. */
|
|
33
|
+
trailing?: ReactNode
|
|
34
|
+
/** One control at the far end, such as a ghost Button. */
|
|
35
|
+
action?: ReactNode
|
|
36
|
+
/** Classes for the row. */
|
|
37
|
+
className?: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A moment's alert in the island: an icon, what happened, a line more, and
|
|
42
|
+
* the figure or control it's about.
|
|
43
|
+
*
|
|
44
|
+
* It lays out one row the height of the island's flash: the icon in a fixed
|
|
45
|
+
* square, the title and caption truncating beside it, then the `value`, any
|
|
46
|
+
* `trailing` glyph and an `action`. The icon and the value take the tone's
|
|
47
|
+
* status hue (a charge in success, a low battery in warning); everything else
|
|
48
|
+
* keeps the two text colors. Pass it as the Island's `flash`.
|
|
49
|
+
*
|
|
50
|
+
* @example {@include ./examples.mdx}
|
|
51
|
+
*/
|
|
52
|
+
export default function IslandFlash({
|
|
53
|
+
title,
|
|
54
|
+
caption,
|
|
55
|
+
icon,
|
|
56
|
+
tone = 'default',
|
|
57
|
+
value,
|
|
58
|
+
trailing,
|
|
59
|
+
action,
|
|
60
|
+
className,
|
|
61
|
+
}: IslandFlashProps) {
|
|
62
|
+
return (
|
|
63
|
+
<div className={cn('flex min-w-0 items-center gap-3', className)}>
|
|
64
|
+
{icon && <span className={cn('flex size-8 shrink-0 items-center justify-center', TONE[tone])}>{icon}</span>}
|
|
65
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
66
|
+
<span className="truncate text-body weight-semibold text-foreground">{title}</span>
|
|
67
|
+
{caption && <span className="truncate text-caption text-muted-foreground">{caption}</span>}
|
|
68
|
+
</div>
|
|
69
|
+
{value !== undefined && (
|
|
70
|
+
<span className={cn('shrink-0 text-subtitle weight-semibold tabular-nums', TONE[tone])}>{value}</span>
|
|
71
|
+
)}
|
|
72
|
+
{trailing}
|
|
73
|
+
{action && <span className="flex shrink-0 items-center">{action}</span>}
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type { IslandFlashProps, IslandFlashTone }
|
|
79
|
+
export { IslandFlash }
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import IslandTabs from './index'
|
|
2
|
+
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
3
|
+
import { CalendarDays, Music, Settings, Timer } from 'lucide-react'
|
|
4
|
+
import { TABS } from '../../../mock/data'
|
|
5
|
+
import { Fit } from '../../../mock/island-content'
|
|
6
|
+
|
|
7
|
+
# Both wings
|
|
8
|
+
|
|
9
|
+
Six tabs balance across the wings, three on each side of the notch; the pill melts across the gap.
|
|
10
|
+
|
|
11
|
+
<Fit width={720}>
|
|
12
|
+
<div className="dark w-full rounded-box bg-ink px-5 text-foreground">
|
|
13
|
+
<IslandTabs tabs={TABS} size="compact" trailing={<Button variant="ghost" size="icon-compact" aria-label="Settings"><Settings size={14} strokeWidth={1.5} /></Button>} />
|
|
14
|
+
</div>
|
|
15
|
+
</Fit>
|
|
16
|
+
|
|
17
|
+
# Few tabs
|
|
18
|
+
|
|
19
|
+
Three tabs balance too, the left wing taking the odd one.
|
|
20
|
+
|
|
21
|
+
<Fit width={720}>
|
|
22
|
+
<div className="dark w-full rounded-box bg-ink px-5 text-foreground">
|
|
23
|
+
<IslandTabs
|
|
24
|
+
size="compact"
|
|
25
|
+
defaultValue="timer"
|
|
26
|
+
tabs={[
|
|
27
|
+
{ value: 'now-playing', label: 'Now Playing', icon: Music },
|
|
28
|
+
{ value: 'timer', label: 'Timer', icon: Timer },
|
|
29
|
+
{ value: 'calendar', label: 'Calendar', icon: CalendarDays },
|
|
30
|
+
]}
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
</Fit>
|
|
34
|
+
|
|
35
|
+
# Overflow
|
|
36
|
+
|
|
37
|
+
Past what both wings hold, the strip scrolls behind the notch; its edges fade and a vertical wheel scrolls it sideways.
|
|
38
|
+
|
|
39
|
+
<Fit width={420}>
|
|
40
|
+
<div className="dark w-full rounded-box bg-ink px-5 text-foreground">
|
|
41
|
+
<IslandTabs tabs={[...TABS, ...TABS.map(t => ({ ...t, value: t.value + '-2' }))]} size="compact" />
|
|
42
|
+
</div>
|
|
43
|
+
</Fit>
|
|
44
|
+
|
|
45
|
+
# Default size
|
|
46
|
+
|
|
47
|
+
The default step: 36px tabs for a roomier panel.
|
|
48
|
+
|
|
49
|
+
<Fit width={720}>
|
|
50
|
+
<div className="dark w-full rounded-box bg-ink px-5 text-foreground">
|
|
51
|
+
<IslandTabs tabs={TABS} defaultValue="devices" />
|
|
52
|
+
</div>
|
|
53
|
+
</Fit>
|