@justanarthur/modo-ui-notch 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/blocks/activities/agenda/examples.mdx +29 -5
- package/blocks/activities/agenda/index.tsx +438 -181
- package/blocks/activities/clock/examples.mdx +89 -0
- package/blocks/activities/clock/index.tsx +917 -0
- package/blocks/activities/now-playing/examples.mdx +40 -13
- package/blocks/activities/now-playing/index.tsx +399 -120
- package/blocks/activities/weather/examples.mdx +123 -0
- package/blocks/activities/weather/index.tsx +863 -0
- package/blocks/app/expanded-island/examples.mdx +8 -7
- package/blocks/app/expanded-island/index.tsx +22 -4
- package/blocks/app/settings-window/examples.mdx +14 -2
- package/blocks/app/settings-window/index.tsx +33 -10
- package/blocks/system/clipboard/examples.mdx +91 -0
- package/blocks/system/clipboard/index.tsx +773 -0
- package/blocks/system/recent-files/examples.mdx +80 -0
- package/blocks/system/recent-files/index.tsx +627 -0
- package/blocks/system/system-stats/examples.mdx +46 -9
- package/blocks/system/system-stats/index.tsx +445 -104
- package/components/indicators/media-scrubber/examples.mdx +8 -0
- package/components/indicators/media-scrubber/index.tsx +37 -13
- package/components/island/island/examples.mdx +4 -4
- package/components/island/island/index.tsx +2 -2
- package/components/island/island-flash/examples.mdx +15 -18
- package/components/island/island-flash/index.tsx +4 -4
- package/components/island/island-tabs/examples.mdx +5 -5
- package/components/island/widget/examples.mdx +76 -0
- package/components/island/widget/index.tsx +465 -0
- package/dist/blocks/activities/agenda/index.d.ts +2 -1
- package/dist/blocks/activities/agenda/index.js +3 -3
- package/dist/blocks/activities/clock/index.d.ts +3 -0
- package/dist/blocks/activities/clock/index.js +25 -0
- package/dist/blocks/activities/now-playing/index.d.ts +4 -2
- package/dist/blocks/activities/now-playing/index.js +5 -3
- package/dist/blocks/activities/weather/index.d.ts +3 -0
- package/dist/blocks/activities/weather/index.js +21 -0
- package/dist/blocks/app/expanded-island/index.d.ts +1 -1
- package/dist/blocks/app/expanded-island/index.js +4 -3
- package/dist/blocks/app/settings-window/index.d.ts +1 -1
- package/dist/blocks/app/settings-window/index.js +1 -1
- package/dist/blocks/system/clipboard/index.d.ts +3 -0
- package/dist/blocks/system/clipboard/index.js +17 -0
- package/dist/blocks/system/recent-files/index.d.ts +3 -0
- package/dist/blocks/system/recent-files/index.js +19 -0
- package/dist/blocks/system/system-stats/index.d.ts +3 -2
- package/dist/blocks/system/system-stats/index.js +4 -1
- package/dist/components/indicators/media-scrubber/index.d.ts +1 -1
- package/dist/components/indicators/media-scrubber/index.js +1 -1
- package/dist/components/island/island/index.d.ts +1 -1
- package/dist/components/island/island/index.js +2 -2
- package/dist/components/island/island-flash/index.d.ts +1 -1
- package/dist/components/island/island-flash/index.js +1 -1
- package/dist/components/island/island-tabs/index.js +2 -2
- package/dist/components/island/widget/index.d.ts +2 -0
- package/dist/components/island/widget/index.js +32 -0
- package/dist/index.d.ts +15 -15
- package/dist/index.js +104 -58
- package/dist/lib/artwork.d.ts +2 -0
- package/dist/lib/artwork.js +8 -0
- package/dist/lib/geometry.js +1 -1
- package/dist/shared/{chunk-yngkkxz2.d.ts → chunk-0ym9mcqc.d.ts} +10 -6
- package/dist/shared/chunk-2b6gpn8k.js +444 -0
- package/dist/shared/chunk-3hcnf4yx.js +481 -0
- package/dist/shared/chunk-42wab62s.d.ts +197 -0
- package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
- package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-6tnq6p89.d.ts} +9 -1
- package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
- package/dist/shared/chunk-93dtpjz7.js +789 -0
- package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
- package/dist/shared/chunk-a6njb8db.d.ts +129 -0
- package/dist/shared/chunk-ab8mdg0n.d.ts +149 -0
- package/dist/shared/chunk-evqpf92s.d.ts +168 -0
- package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
- package/dist/shared/chunk-gcyspvgr.js +582 -0
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/chunk-gkj0hjrn.d.ts +136 -0
- package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
- package/dist/shared/chunk-n739am8j.d.ts +112 -0
- package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
- package/dist/shared/chunk-nwzpekvy.js +774 -0
- package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
- package/dist/shared/chunk-sbrtesdg.d.ts +138 -0
- package/dist/shared/chunk-swc7dqpw.d.ts +115 -0
- package/dist/shared/chunk-t9wqhgzt.js +765 -0
- package/dist/shared/chunk-w5h6ay93.js +72 -0
- package/dist/shared/{chunk-mp1nx0ez.js → chunk-wayv5rhr.js} +15 -4
- package/dist/shared/chunk-wf0jtzhs.js +295 -0
- package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
- package/dist/shared/chunk-yq5svpk7.js +524 -0
- package/dist/shared/{chunk-s33y1pcq.js → chunk-z3tj1ydg.js} +23 -10
- package/dist/styles.css +151 -49
- package/index.ts +7 -6
- package/lib/artwork.ts +112 -0
- package/lib/geometry.ts +1 -1
- package/mock/activities.tsx +9 -32
- package/mock/artwork.tsx +13 -1
- package/mock/clipboard.tsx +113 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +78 -44
- package/mock/files.tsx +83 -0
- package/mock/island-content.tsx +79 -122
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +370 -91
- package/mock/system.ts +49 -0
- package/mock/weather.tsx +135 -0
- package/package.json +7 -2
- package/blocks/activities/shelf/examples.mdx +0 -33
- package/blocks/activities/shelf/index.tsx +0 -289
- package/blocks/activities/timer/examples.mdx +0 -52
- package/blocks/activities/timer/index.tsx +0 -292
- package/blocks/system/controls/examples.mdx +0 -34
- package/blocks/system/controls/index.tsx +0 -167
- package/blocks/system/devices/examples.mdx +0 -25
- package/blocks/system/devices/index.tsx +0 -172
- package/blocks/system/power-alert/examples.mdx +0 -32
- package/blocks/system/power-alert/index.tsx +0 -89
- package/components/indicators/battery-glyph/examples.mdx +0 -22
- package/components/indicators/battery-glyph/index.tsx +0 -91
- package/dist/blocks/activities/shelf/index.d.ts +0 -2
- package/dist/blocks/activities/shelf/index.js +0 -14
- package/dist/blocks/activities/timer/index.d.ts +0 -2
- package/dist/blocks/activities/timer/index.js +0 -19
- package/dist/blocks/system/controls/index.d.ts +0 -2
- package/dist/blocks/system/controls/index.js +0 -10
- package/dist/blocks/system/devices/index.d.ts +0 -2
- package/dist/blocks/system/devices/index.js +0 -12
- package/dist/blocks/system/power-alert/index.d.ts +0 -2
- package/dist/blocks/system/power-alert/index.js +0 -9
- package/dist/components/indicators/battery-glyph/index.d.ts +0 -2
- package/dist/components/indicators/battery-glyph/index.js +0 -9
- package/dist/shared/chunk-2qpcsv5h.d.ts +0 -45
- package/dist/shared/chunk-45gytfr1.d.ts +0 -84
- package/dist/shared/chunk-50ffk4r7.d.ts +0 -69
- package/dist/shared/chunk-5w0yck07.d.ts +0 -32
- package/dist/shared/chunk-7hr53mby.js +0 -116
- package/dist/shared/chunk-b8jb1w72.js +0 -145
- package/dist/shared/chunk-cpewy6yg.js +0 -178
- package/dist/shared/chunk-e3e4s4ds.d.ts +0 -77
- package/dist/shared/chunk-enm6td0p.js +0 -280
- package/dist/shared/chunk-fvedaas2.d.ts +0 -33
- package/dist/shared/chunk-gex38j8x.d.ts +0 -82
- package/dist/shared/chunk-hwtxpzg0.js +0 -69
- package/dist/shared/chunk-phb53x1f.js +0 -252
- package/dist/shared/chunk-r8esmjfs.d.ts +0 -42
- package/dist/shared/chunk-rcp1g9ca.js +0 -70
- package/dist/shared/chunk-rx9sphz2.js +0 -266
- package/dist/shared/chunk-xdeek16r.d.ts +0 -58
- package/dist/shared/chunk-xkzjk1tq.js +0 -206
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Local addition: a notch app's timer, from picking a length to "Time's up".
|
|
3
|
-
* Rebuilt from Just Notch's timer plugin (`Picker`, `Running`, `Ring`,
|
|
4
|
-
* `TimeUp`) as presentational parts: the run is a value the host may own.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use client'
|
|
8
|
-
|
|
9
|
-
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
10
|
-
import Meter from '@justanarthur/modo-ui/components/feedback/meter'
|
|
11
|
-
import NumberInput from '@justanarthur/modo-ui/components/inputs/number-input'
|
|
12
|
-
import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
|
|
13
|
-
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
14
|
-
import { Pause, Play, Plus, Timer as TimerIcon, X } from 'lucide-react'
|
|
15
|
-
import { type FormEvent, useState } from 'react'
|
|
16
|
-
import Countdown from '../../../components/indicators/countdown'
|
|
17
|
-
import IslandFlash from '../../../components/island/island-flash'
|
|
18
|
-
import { formatClock, MINUTE, SECOND, useEdgeClock } from '../../../lib/clock'
|
|
19
|
-
|
|
20
|
-
type TimerKind = 'focus' | 'break' | 'custom'
|
|
21
|
-
|
|
22
|
-
/** A run: running while it has `endsAt`, paused while it has `remaining`. */
|
|
23
|
-
interface TimerRun {
|
|
24
|
-
kind: TimerKind
|
|
25
|
-
/** Its whole length, in ms. */
|
|
26
|
-
total: number
|
|
27
|
-
/** When it ends, in epoch ms, while it runs. */
|
|
28
|
-
endsAt?: number
|
|
29
|
-
/** The time left, in ms, while it is paused. */
|
|
30
|
-
remaining?: number
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface TimerProps {
|
|
34
|
-
/** The run (controlled); `null` shows the picker. */
|
|
35
|
-
value?: TimerRun | null
|
|
36
|
-
/** The run at first (uncontrolled). Defaults to `null`. */
|
|
37
|
-
defaultValue?: TimerRun | null
|
|
38
|
-
/** Called with the run a start, pause, resume, +1 min or cancel leaves, and `null` when it ends. */
|
|
39
|
-
onValueChange?: (run: TimerRun | null) => void
|
|
40
|
-
/** Called when a run reaches zero, with the kind that starts next in a Pomodoro cycle. */
|
|
41
|
-
onEnd?: (run: TimerRun, next?: TimerKind) => void
|
|
42
|
-
/** The picker's quick lengths, in minutes, before the Pomodoro preset. Defaults to `[1, 5, 10]`. */
|
|
43
|
-
presets?: number[]
|
|
44
|
-
/** Pomodoro cycles: when a focus run ends a break starts on its own, then focus again. Defaults to `false`. */
|
|
45
|
-
pomodoro?: boolean
|
|
46
|
-
/** A focus run's length, in minutes. Defaults to `25`. */
|
|
47
|
-
focusMinutes?: number
|
|
48
|
-
/** A break's length, in minutes. Defaults to `5`. */
|
|
49
|
-
breakMinutes?: number
|
|
50
|
-
/** Classes for the root, which fills its container. */
|
|
51
|
-
className?: string
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const LABEL: Record<TimerKind, string> = { focus: 'Focus', break: 'Break', custom: 'Timer' }
|
|
55
|
-
|
|
56
|
-
const start = (minutes: number, kind: TimerKind): TimerRun => ({
|
|
57
|
-
kind,
|
|
58
|
-
total: minutes * MINUTE,
|
|
59
|
-
endsAt: Date.now() + minutes * MINUTE,
|
|
60
|
-
})
|
|
61
|
-
const pause = (run: TimerRun): TimerRun => ({ kind: run.kind, total: run.total, remaining: timeLeft(run, Date.now()) })
|
|
62
|
-
const resume = (run: TimerRun): TimerRun => ({
|
|
63
|
-
kind: run.kind,
|
|
64
|
-
total: run.total,
|
|
65
|
-
endsAt: Date.now() + (run.remaining ?? 0),
|
|
66
|
-
})
|
|
67
|
-
const addMinute = (run: TimerRun): TimerRun =>
|
|
68
|
-
run.endsAt === undefined
|
|
69
|
-
? { ...run, total: run.total + MINUTE, remaining: (run.remaining ?? 0) + MINUTE }
|
|
70
|
-
: { ...run, total: run.total + MINUTE, endsAt: run.endsAt + MINUTE }
|
|
71
|
-
|
|
72
|
-
/** The time a run has left at `now`, in ms. */
|
|
73
|
-
function timeLeft(run: TimerRun, now: number) {
|
|
74
|
-
return run.endsAt === undefined ? (run.remaining ?? 0) : Math.max(0, run.endsAt - now)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** The time left, re-read on each second's edge while the run runs, never in between. */
|
|
78
|
-
function useTimeLeft(run: TimerRun) {
|
|
79
|
-
const end = run.endsAt ?? 0
|
|
80
|
-
const now = useEdgeClock(end, run.endsAt !== undefined && Date.now() < end + SECOND)
|
|
81
|
-
return timeLeft(run, now)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function Ring({ run, className }: { run: TimerRun; className: string }) {
|
|
85
|
-
const left = useTimeLeft(run)
|
|
86
|
-
return (
|
|
87
|
-
<Meter
|
|
88
|
-
variant="ring"
|
|
89
|
-
label={`${LABEL[run.kind]}, ${formatClock(Math.ceil(left / SECOND))} left`}
|
|
90
|
-
value={run.total ? left / run.total : 0}
|
|
91
|
-
tone="default"
|
|
92
|
-
animate={false}
|
|
93
|
-
className={className}
|
|
94
|
-
/>
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function Clock({ run, className, onEnd }: { run: TimerRun; className: string; onEnd?: () => void }) {
|
|
99
|
-
const paused = run.endsAt === undefined
|
|
100
|
-
return (
|
|
101
|
-
<Countdown
|
|
102
|
-
endsAt={run.endsAt}
|
|
103
|
-
paused={paused}
|
|
104
|
-
remaining={run.remaining}
|
|
105
|
-
onEnd={onEnd}
|
|
106
|
-
className={cn(className, paused ? 'text-muted-foreground' : 'text-status-warning')}
|
|
107
|
-
/>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** The compact island's left wing: the timer's glyph. */
|
|
112
|
-
function TimerLeading() {
|
|
113
|
-
return <TimerIcon size={16} strokeWidth={1.5} className="text-status-warning" />
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** The compact island's right wing: the time left, muted while paused. */
|
|
117
|
-
function TimerTrailing({ run }: { run: TimerRun }) {
|
|
118
|
-
return <Clock run={run} className="text-caption weight-medium" />
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** The split island's bubble: a ring of the time left. */
|
|
122
|
-
function TimerMinimal({ run }: { run: TimerRun }) {
|
|
123
|
-
return <Ring run={run} className="size-5.5" />
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
interface TimerDoneProps {
|
|
127
|
-
/** The run that ended. Defaults to `'custom'`. */
|
|
128
|
-
kind?: TimerKind
|
|
129
|
-
/** The kind a Pomodoro cycle starts next. */
|
|
130
|
-
next?: TimerKind
|
|
131
|
-
/** The next run's length, in minutes. */
|
|
132
|
-
minutes?: number
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** The island's flash when a run reaches zero: "Time's up", and what starts next in a Pomodoro cycle. */
|
|
136
|
-
function TimerDone({ kind = 'custom', next, minutes }: TimerDoneProps) {
|
|
137
|
-
const detail = next ? `${LABEL[next]} starts now${minutes ? ` · ${minutes} min` : ''}` : `${LABEL[kind]} finished`
|
|
138
|
-
return (
|
|
139
|
-
<IslandFlash icon={<TimerIcon size={20} strokeWidth={1.5} />} tone="warning" title="Time's up" caption={detail} />
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
interface PickerProps {
|
|
144
|
-
presets: number[]
|
|
145
|
-
focusMinutes: number
|
|
146
|
-
onStart: (run: TimerRun) => void
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function Picker({ presets, focusMinutes, onStart }: PickerProps) {
|
|
150
|
-
const [minutes, setMinutes] = useState<number | null>(null)
|
|
151
|
-
const valid = minutes !== null && Number.isInteger(minutes) && minutes >= 1 && minutes <= 99
|
|
152
|
-
const submit = (event: FormEvent) => {
|
|
153
|
-
event.preventDefault()
|
|
154
|
-
if (valid) onStart(start(minutes, 'custom'))
|
|
155
|
-
}
|
|
156
|
-
return (
|
|
157
|
-
<div className="flex size-full flex-col justify-center gap-3">
|
|
158
|
-
<div className="grid grid-cols-4 gap-2">
|
|
159
|
-
{presets.map(m => (
|
|
160
|
-
<Button key={m} variant="tertiary" onClick={() => onStart(start(m, 'custom'))}>
|
|
161
|
-
{m} min
|
|
162
|
-
</Button>
|
|
163
|
-
))}
|
|
164
|
-
<Button variant="tertiary" onClick={() => onStart(start(focusMinutes, 'focus'))}>
|
|
165
|
-
Pomodoro
|
|
166
|
-
</Button>
|
|
167
|
-
</div>
|
|
168
|
-
<form className="flex items-center gap-2" onSubmit={submit}>
|
|
169
|
-
<div className="min-w-0 flex-1">
|
|
170
|
-
<NumberInput
|
|
171
|
-
className="w-full"
|
|
172
|
-
variant="bordered"
|
|
173
|
-
min={1}
|
|
174
|
-
max={99}
|
|
175
|
-
placeholder="Custom minutes"
|
|
176
|
-
aria-label="Custom minutes"
|
|
177
|
-
endAdornment="min"
|
|
178
|
-
value={minutes}
|
|
179
|
-
onValueChange={setMinutes}
|
|
180
|
-
/>
|
|
181
|
-
</div>
|
|
182
|
-
<Button type="submit" variant="primary" leadingIcon={Play} disabled={!valid}>
|
|
183
|
-
Start
|
|
184
|
-
</Button>
|
|
185
|
-
</form>
|
|
186
|
-
</div>
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
interface RunningProps {
|
|
191
|
-
run: TimerRun
|
|
192
|
-
onChange: (run: TimerRun | null) => void
|
|
193
|
-
onEnd: () => void
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function Running({ run, onChange, onEnd }: RunningProps) {
|
|
197
|
-
const paused = run.endsAt === undefined
|
|
198
|
-
return (
|
|
199
|
-
<div className="flex size-full items-center gap-5">
|
|
200
|
-
<Ring run={run} className="size-16" />
|
|
201
|
-
<div className="flex min-w-0 flex-1 flex-col">
|
|
202
|
-
<span className="truncate text-caption text-muted-foreground">
|
|
203
|
-
{LABEL[run.kind]} · {Math.round(run.total / MINUTE)} min{paused ? ' · Paused' : ''}
|
|
204
|
-
</span>
|
|
205
|
-
<Clock run={run} className="text-display" onEnd={onEnd} />
|
|
206
|
-
</div>
|
|
207
|
-
<div className="flex shrink-0 items-center gap-2">
|
|
208
|
-
<Button variant="tertiary" leadingIcon={Plus} onClick={() => onChange(addMinute(run))}>
|
|
209
|
-
1 min
|
|
210
|
-
</Button>
|
|
211
|
-
<Button
|
|
212
|
-
variant="tertiary"
|
|
213
|
-
size="icon"
|
|
214
|
-
className="text-status-warning"
|
|
215
|
-
aria-label={paused ? 'Resume' : 'Pause'}
|
|
216
|
-
onClick={() => onChange(paused ? resume(run) : pause(run))}
|
|
217
|
-
>
|
|
218
|
-
{paused ? (
|
|
219
|
-
<Play size={16} strokeWidth={1.5} fill="currentColor" />
|
|
220
|
-
) : (
|
|
221
|
-
<Pause size={16} strokeWidth={1.5} fill="currentColor" />
|
|
222
|
-
)}
|
|
223
|
-
</Button>
|
|
224
|
-
<Button variant="tertiary" size="icon" aria-label="Cancel" onClick={() => onChange(null)}>
|
|
225
|
-
<X size={16} strokeWidth={1.5} />
|
|
226
|
-
</Button>
|
|
227
|
-
</div>
|
|
228
|
-
</div>
|
|
229
|
-
)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* A notch app's timer: pick a length, watch it run down, hear when it's up.
|
|
234
|
-
*
|
|
235
|
-
* Without a run it shows the picker: quick lengths (`presets`), a Pomodoro
|
|
236
|
-
* focus run and a custom length in minutes on a NumberInput. A run shows a
|
|
237
|
-
* Meter ring of the time left beside the time itself in display type, with
|
|
238
|
-
* +1 min, pause / resume and cancel. The run is a value (`value` /
|
|
239
|
-
* `onValueChange`, or kept here from `defaultValue`): a running one carries
|
|
240
|
-
* when it ends, a paused one the time it had left, so a host can persist it
|
|
241
|
-
* and resume after a reload. The time re-renders once a second, on the
|
|
242
|
-
* second's edge, and nothing runs while it is paused.
|
|
243
|
-
*
|
|
244
|
-
* At zero it calls `onEnd` and clears the run, unless `pomodoro` cycles:
|
|
245
|
-
* then a focus run hands over to a break and a break back to focus.
|
|
246
|
-
*
|
|
247
|
-
* The other forms are parts: `Timer.Leading` and `Timer.Trailing` for the
|
|
248
|
-
* compact island's wings (the glyph and the time left), `Timer.Minimal` for
|
|
249
|
-
* the split island's bubble (the ring) and `Timer.Done`, the "Time's up"
|
|
250
|
-
* flash.
|
|
251
|
-
*
|
|
252
|
-
* @example {@include ./examples.mdx}
|
|
253
|
-
*/
|
|
254
|
-
function Timer({
|
|
255
|
-
value,
|
|
256
|
-
defaultValue = null,
|
|
257
|
-
onValueChange,
|
|
258
|
-
onEnd,
|
|
259
|
-
presets = [1, 5, 10],
|
|
260
|
-
pomodoro = false,
|
|
261
|
-
focusMinutes = 25,
|
|
262
|
-
breakMinutes = 5,
|
|
263
|
-
className,
|
|
264
|
-
}: TimerProps) {
|
|
265
|
-
const [run, setRun] = useControllableState(value, defaultValue, onValueChange)
|
|
266
|
-
|
|
267
|
-
const complete = (ended: TimerRun) => {
|
|
268
|
-
const next = pomodoro && ended.kind !== 'custom' ? (ended.kind === 'focus' ? 'break' : 'focus') : undefined
|
|
269
|
-
onEnd?.(ended, next)
|
|
270
|
-
setRun(next ? start(next === 'break' ? breakMinutes : focusMinutes, next) : null)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return (
|
|
274
|
-
<div className={cn('size-full', className)}>
|
|
275
|
-
{run ? (
|
|
276
|
-
<Running run={run} onChange={setRun} onEnd={() => complete(run)} />
|
|
277
|
-
) : (
|
|
278
|
-
<Picker presets={presets} focusMinutes={focusMinutes} onStart={setRun} />
|
|
279
|
-
)}
|
|
280
|
-
</div>
|
|
281
|
-
)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
Timer.Leading = TimerLeading
|
|
285
|
-
Timer.Trailing = TimerTrailing
|
|
286
|
-
Timer.Minimal = TimerMinimal
|
|
287
|
-
Timer.Done = TimerDone
|
|
288
|
-
|
|
289
|
-
export default Timer
|
|
290
|
-
|
|
291
|
-
export type { TimerDoneProps, TimerKind, TimerProps, TimerRun }
|
|
292
|
-
export { Timer, TimerDone, TimerLeading, TimerMinimal, TimerTrailing }
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import Controls from './index'
|
|
2
|
-
import { FlashIsland, WidgetIsland } from '../../../mock/island-content'
|
|
3
|
-
|
|
4
|
-
# Controls
|
|
5
|
-
|
|
6
|
-
Volume, brightness and the keyboard backlight; each glyph follows its level.
|
|
7
|
-
|
|
8
|
-
<WidgetIsland tab="controls">
|
|
9
|
-
<Controls defaultValue={{ volume: 0.6, brightness: 0.8, keyboard: 0.35 }} output="MacBook Pro Speakers" />
|
|
10
|
-
</WidgetIsland>
|
|
11
|
-
|
|
12
|
-
# Volume only
|
|
13
|
-
|
|
14
|
-
An external display without a brightness reading, muted.
|
|
15
|
-
|
|
16
|
-
<WidgetIsland tab="controls">
|
|
17
|
-
<Controls defaultValue={{ volume: 0.4, muted: true }} output="Studio Display Speakers" />
|
|
18
|
-
</WidgetIsland>
|
|
19
|
-
|
|
20
|
-
# HUD
|
|
21
|
-
|
|
22
|
-
`Controls.Level` replaces the system's overlay, keyed by kind.
|
|
23
|
-
|
|
24
|
-
<div className="flex w-full flex-col gap-3">
|
|
25
|
-
<FlashIsland activity="volume">
|
|
26
|
-
<Controls.Level kind="volume" defaultValue={0.7} />
|
|
27
|
-
</FlashIsland>
|
|
28
|
-
<FlashIsland activity="brightness">
|
|
29
|
-
<Controls.Level kind="brightness" defaultValue={0.25} />
|
|
30
|
-
</FlashIsland>
|
|
31
|
-
<FlashIsland activity="keyboard">
|
|
32
|
-
<Controls.Level kind="keyboard" defaultValue={0} />
|
|
33
|
-
</FlashIsland>
|
|
34
|
-
</div>
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Local addition: a notch app's system controls and their HUD, the level the
|
|
3
|
-
* island shows in place of the system's volume and brightness overlay.
|
|
4
|
-
* Rebuilt from Just Notch's HUD plugin (`Level`, `Controls`, `Flash`) as
|
|
5
|
-
* presentational parts: the levels come in as values.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use client'
|
|
9
|
-
|
|
10
|
-
import Slider from '@justanarthur/modo-ui/components/inputs/slider'
|
|
11
|
-
import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
|
|
12
|
-
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
13
|
-
import {
|
|
14
|
-
Keyboard,
|
|
15
|
-
KeyboardOff,
|
|
16
|
-
type LucideIcon,
|
|
17
|
-
Speaker,
|
|
18
|
-
Sun,
|
|
19
|
-
SunDim,
|
|
20
|
-
SunMedium,
|
|
21
|
-
Volume,
|
|
22
|
-
Volume1,
|
|
23
|
-
Volume2,
|
|
24
|
-
VolumeX,
|
|
25
|
-
} from 'lucide-react'
|
|
26
|
-
|
|
27
|
-
type ControlKind = 'volume' | 'brightness' | 'keyboard'
|
|
28
|
-
|
|
29
|
-
/** The levels, from 0 to 1. A missing brightness or keyboard level hides its row (no built-in display, no backlight). */
|
|
30
|
-
interface ControlLevels {
|
|
31
|
-
volume: number
|
|
32
|
-
muted?: boolean
|
|
33
|
-
brightness?: number
|
|
34
|
-
keyboard?: number
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface ControlsProps {
|
|
38
|
-
/** The levels (controlled). */
|
|
39
|
-
value?: ControlLevels
|
|
40
|
-
/** The levels at first (uncontrolled). Defaults to the volume at half. */
|
|
41
|
-
defaultValue?: ControlLevels
|
|
42
|
-
/** Called with every level when a slider moves one; moving volume unmutes it. */
|
|
43
|
-
onValueChange?: (levels: ControlLevels) => void
|
|
44
|
-
/** The audio output's name, on a muted row under the sliders. */
|
|
45
|
-
output?: string
|
|
46
|
-
/** Classes for the root, which fills its container. */
|
|
47
|
-
className?: string
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const LABEL: Record<ControlKind, string> = {
|
|
51
|
-
volume: 'Volume',
|
|
52
|
-
brightness: 'Brightness',
|
|
53
|
-
keyboard: 'Keyboard brightness',
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** The glyph for a level: the speaker's waves, the sun's rays, the backlight on or off. */
|
|
57
|
-
function glyph(kind: ControlKind, value: number, muted?: boolean): LucideIcon {
|
|
58
|
-
if (kind === 'volume') {
|
|
59
|
-
if (muted || value === 0) return VolumeX
|
|
60
|
-
return value < 0.34 ? Volume : value < 0.67 ? Volume1 : Volume2
|
|
61
|
-
}
|
|
62
|
-
if (kind === 'brightness') return value < 0.34 ? SunDim : value < 0.67 ? SunMedium : Sun
|
|
63
|
-
return value === 0 ? KeyboardOff : Keyboard
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
interface ControlsLevelProps {
|
|
67
|
-
/** What it sets. */
|
|
68
|
-
kind: ControlKind
|
|
69
|
-
/** The level, from 0 to 1 (controlled). */
|
|
70
|
-
value?: number
|
|
71
|
-
/** The level at first (uncontrolled). Defaults to `0`. */
|
|
72
|
-
defaultValue?: number
|
|
73
|
-
/** Called with the level, from 0 to 1, as the slider moves. */
|
|
74
|
-
onValueChange?: (value: number) => void
|
|
75
|
-
/** Volume only: it is muted, so it reads 0 and shows the crossed speaker until moved. */
|
|
76
|
-
muted?: boolean
|
|
77
|
-
/** Classes for the row. */
|
|
78
|
-
className?: string
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** One level as a row: a glyph that follows it, a compact slider and the percent. Pass it as the HUD's flash, keyed by kind. */
|
|
82
|
-
function ControlsLevel({
|
|
83
|
-
kind,
|
|
84
|
-
value: valueProp,
|
|
85
|
-
defaultValue = 0,
|
|
86
|
-
onValueChange,
|
|
87
|
-
muted,
|
|
88
|
-
className,
|
|
89
|
-
}: ControlsLevelProps) {
|
|
90
|
-
const [value, setValue] = useControllableState(valueProp, defaultValue, onValueChange)
|
|
91
|
-
const shown = muted ? 0 : value
|
|
92
|
-
const Icon = glyph(kind, shown, muted)
|
|
93
|
-
const percent = Math.round(shown * 100)
|
|
94
|
-
return (
|
|
95
|
-
<div className={cn('flex h-7 items-center gap-3', className)}>
|
|
96
|
-
<Icon size={16} strokeWidth={1.5} className="shrink-0 text-foreground" />
|
|
97
|
-
<Slider
|
|
98
|
-
className="mb-0 min-w-0 flex-1"
|
|
99
|
-
size="compact"
|
|
100
|
-
label={LABEL[kind]}
|
|
101
|
-
showValue={false}
|
|
102
|
-
value={percent}
|
|
103
|
-
onValueChange={v => setValue((v as number) / 100)}
|
|
104
|
-
/>
|
|
105
|
-
<span className="w-7 shrink-0 text-right text-caption tabular-nums text-muted-foreground">{percent}</span>
|
|
106
|
-
</div>
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* A notch app's system controls: volume, display brightness and keyboard
|
|
112
|
-
* backlight as sliders, and the audio output.
|
|
113
|
-
*
|
|
114
|
-
* Each row is a glyph that follows its level (the speaker's waves, a muted
|
|
115
|
-
* cross, the sun's rays, the backlight off), modo-ui's compact Slider and the
|
|
116
|
-
* level in percent. A display without a brightness reading, or a keyboard
|
|
117
|
-
* without a backlight, leaves its level out and so its row. The levels are
|
|
118
|
-
* one value from 0 to 1 each (`value` / `onValueChange`, or kept here from
|
|
119
|
-
* `defaultValue`); moving the volume unmutes it.
|
|
120
|
-
*
|
|
121
|
-
* `Controls.Level` is one row on its own: the HUD flash that replaces the
|
|
122
|
-
* system's overlay when a volume or brightness key is pressed. Key it by
|
|
123
|
-
* kind, so pressing a brightness key while the volume shows swaps the flash
|
|
124
|
-
* instead of repainting it.
|
|
125
|
-
*
|
|
126
|
-
* @example {@include ./examples.mdx}
|
|
127
|
-
*/
|
|
128
|
-
function Controls({ value, defaultValue = { volume: 0.5 }, onValueChange, output, className }: ControlsProps) {
|
|
129
|
-
const [levels, setLevels] = useControllableState(value, defaultValue, onValueChange)
|
|
130
|
-
return (
|
|
131
|
-
<div className={cn('flex size-full flex-col justify-center gap-1', className)}>
|
|
132
|
-
<ControlsLevel
|
|
133
|
-
kind="volume"
|
|
134
|
-
value={levels.volume}
|
|
135
|
-
muted={levels.muted}
|
|
136
|
-
onValueChange={volume => setLevels({ ...levels, volume, muted: false })}
|
|
137
|
-
/>
|
|
138
|
-
{levels.brightness !== undefined && (
|
|
139
|
-
<ControlsLevel
|
|
140
|
-
kind="brightness"
|
|
141
|
-
value={levels.brightness}
|
|
142
|
-
onValueChange={brightness => setLevels({ ...levels, brightness })}
|
|
143
|
-
/>
|
|
144
|
-
)}
|
|
145
|
-
{levels.keyboard !== undefined && (
|
|
146
|
-
<ControlsLevel
|
|
147
|
-
kind="keyboard"
|
|
148
|
-
value={levels.keyboard}
|
|
149
|
-
onValueChange={keyboard => setLevels({ ...levels, keyboard })}
|
|
150
|
-
/>
|
|
151
|
-
)}
|
|
152
|
-
{output && (
|
|
153
|
-
<div className="flex h-7 items-center gap-3">
|
|
154
|
-
<Speaker size={16} strokeWidth={1.5} className="shrink-0 text-muted-foreground" />
|
|
155
|
-
<span className="min-w-0 truncate text-caption text-muted-foreground">{output}</span>
|
|
156
|
-
</div>
|
|
157
|
-
)}
|
|
158
|
-
</div>
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
Controls.Level = ControlsLevel
|
|
163
|
-
|
|
164
|
-
export default Controls
|
|
165
|
-
|
|
166
|
-
export type { ControlKind, ControlLevels, ControlsLevelProps, ControlsProps }
|
|
167
|
-
export { Controls, ControlsLevel }
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import Devices from './index'
|
|
2
|
-
import { FlashIsland, WidgetIsland } from '../../../mock/island-content'
|
|
3
|
-
import { DEVICES } from '../../../mock/data'
|
|
4
|
-
|
|
5
|
-
# Devices
|
|
6
|
-
|
|
7
|
-
Connected first, each with its charge; a low one turns to the warning and error hues.
|
|
8
|
-
|
|
9
|
-
<WidgetIsland tab="devices">
|
|
10
|
-
<Devices devices={DEVICES} />
|
|
11
|
-
</WidgetIsland>
|
|
12
|
-
|
|
13
|
-
# None paired
|
|
14
|
-
|
|
15
|
-
<WidgetIsland tab="devices">
|
|
16
|
-
<Devices devices={[]} onOpenSettings={() => {}} />
|
|
17
|
-
</WidgetIsland>
|
|
18
|
-
|
|
19
|
-
# Connected
|
|
20
|
-
|
|
21
|
-
`Devices.Connected`, the flash when a device connects.
|
|
22
|
-
|
|
23
|
-
<FlashIsland>
|
|
24
|
-
<Devices.Connected device={DEVICES[0]} />
|
|
25
|
-
</FlashIsland>
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Local addition: a notch app's Bluetooth devices and their batteries.
|
|
3
|
-
* Rebuilt from Just Notch's devices plugin (`Devices`, `Device`, `Connected`)
|
|
4
|
-
* as presentational parts: the devices come in as props.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use client'
|
|
8
|
-
|
|
9
|
-
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
10
|
-
import EmptyState from '@justanarthur/modo-ui/components/feedback/empty-state'
|
|
11
|
-
import StatusDot from '@justanarthur/modo-ui/components/feedback/status-dot'
|
|
12
|
-
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
13
|
-
import {
|
|
14
|
-
Bluetooth,
|
|
15
|
-
Gamepad2,
|
|
16
|
-
Headphones,
|
|
17
|
-
Keyboard,
|
|
18
|
-
type LucideIcon,
|
|
19
|
-
Mouse,
|
|
20
|
-
Smartphone,
|
|
21
|
-
Speaker,
|
|
22
|
-
Watch,
|
|
23
|
-
} from 'lucide-react'
|
|
24
|
-
import BatteryGlyph from '../../../components/indicators/battery-glyph'
|
|
25
|
-
import IslandFlash from '../../../components/island/island-flash'
|
|
26
|
-
|
|
27
|
-
type DeviceKind = 'headphones' | 'keyboard' | 'mouse' | 'speaker' | 'gamepad' | 'phone' | 'watch' | 'other'
|
|
28
|
-
|
|
29
|
-
interface DeviceInfo {
|
|
30
|
-
id: string
|
|
31
|
-
name: string
|
|
32
|
-
/** What it is, for its glyph. */
|
|
33
|
-
kind: DeviceKind
|
|
34
|
-
connected: boolean
|
|
35
|
-
/** Its charge in percent, when it reports one. */
|
|
36
|
-
battery?: number
|
|
37
|
-
charging?: boolean
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface DevicesProps {
|
|
41
|
-
/** The paired devices; connected ones list first, then by name. */
|
|
42
|
-
devices: DeviceInfo[]
|
|
43
|
-
/** Called by the empty state's Open Bluetooth Settings; without it the button hides. */
|
|
44
|
-
onOpenSettings?: () => void
|
|
45
|
-
/** Classes for the root, which fills its container. */
|
|
46
|
-
className?: string
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const KIND: Record<DeviceKind, LucideIcon> = {
|
|
50
|
-
headphones: Headphones,
|
|
51
|
-
keyboard: Keyboard,
|
|
52
|
-
mouse: Mouse,
|
|
53
|
-
speaker: Speaker,
|
|
54
|
-
gamepad: Gamepad2,
|
|
55
|
-
phone: Smartphone,
|
|
56
|
-
watch: Watch,
|
|
57
|
-
other: Bluetooth,
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function Charge({ device }: { device: DeviceInfo }) {
|
|
61
|
-
if (device.battery === undefined) return null
|
|
62
|
-
return (
|
|
63
|
-
<span className="flex shrink-0 items-center gap-2 text-caption tabular-nums text-muted-foreground">
|
|
64
|
-
{device.battery}%
|
|
65
|
-
<BatteryGlyph level={device.battery} charging={device.charging} fillIn={false} />
|
|
66
|
-
</span>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function Glyph({ device }: { device: DeviceInfo }) {
|
|
71
|
-
const Icon = KIND[device.kind]
|
|
72
|
-
return (
|
|
73
|
-
<span
|
|
74
|
-
className={cn(
|
|
75
|
-
'flex size-8 shrink-0 items-center justify-center rounded-full',
|
|
76
|
-
device.connected ? 'bg-surface-3 text-foreground' : 'bg-surface-2 text-muted-foreground',
|
|
77
|
-
)}
|
|
78
|
-
>
|
|
79
|
-
<Icon size={16} strokeWidth={1.5} />
|
|
80
|
-
</span>
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function Device({ device }: { device: DeviceInfo }) {
|
|
85
|
-
return (
|
|
86
|
-
<li className="flex h-11 min-w-0 items-center gap-3">
|
|
87
|
-
<Glyph device={device} />
|
|
88
|
-
<div className="flex min-w-0 flex-1 flex-col">
|
|
89
|
-
<span className={cn('truncate text-body', device.connected ? 'text-foreground' : 'text-muted-foreground')}>
|
|
90
|
-
{device.name}
|
|
91
|
-
</span>
|
|
92
|
-
<span className="flex items-center gap-1.5 text-caption text-muted-foreground">
|
|
93
|
-
<StatusDot status={device.connected ? 'success' : 'idle'} size="compact" />
|
|
94
|
-
{device.connected ? 'Connected' : 'Not connected'}
|
|
95
|
-
</span>
|
|
96
|
-
</div>
|
|
97
|
-
{device.connected && <Charge device={device} />}
|
|
98
|
-
</li>
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** The island's flash when a device connects: its glyph, name and battery. */
|
|
103
|
-
function DevicesConnected({ device }: { device: DeviceInfo }) {
|
|
104
|
-
const Icon = KIND[device.kind]
|
|
105
|
-
return (
|
|
106
|
-
<IslandFlash
|
|
107
|
-
icon={
|
|
108
|
-
<span className="flex size-8 items-center justify-center rounded-full bg-surface-3 text-foreground">
|
|
109
|
-
<Icon size={16} strokeWidth={1.5} />
|
|
110
|
-
</span>
|
|
111
|
-
}
|
|
112
|
-
title={device.name}
|
|
113
|
-
caption="Connected"
|
|
114
|
-
value={device.battery === undefined ? undefined : `${device.battery}%`}
|
|
115
|
-
trailing={
|
|
116
|
-
device.battery === undefined ? undefined : <BatteryGlyph level={device.battery} charging={device.charging} />
|
|
117
|
-
}
|
|
118
|
-
/>
|
|
119
|
-
)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* A notch app's Bluetooth devices: what's paired, what's connected and how
|
|
124
|
-
* much charge each has left.
|
|
125
|
-
*
|
|
126
|
-
* Devices list in two columns, connected first: a glyph for the kind of
|
|
127
|
-
* device (raised while connected), the name, a StatusDot with Connected or
|
|
128
|
-
* Not connected, and for a connected device that reports one, its charge as
|
|
129
|
-
* a figure and a BatteryGlyph, which turns to the warning and error hues as
|
|
130
|
-
* it runs low. Without devices it says how to pair one, with a button to the
|
|
131
|
-
* system's Bluetooth settings when `onOpenSettings` is given.
|
|
132
|
-
*
|
|
133
|
-
* `Devices.Connected` is the island's flash when a device connects.
|
|
134
|
-
*
|
|
135
|
-
* @example {@include ./examples.mdx}
|
|
136
|
-
*/
|
|
137
|
-
function Devices({ devices, onOpenSettings, className }: DevicesProps) {
|
|
138
|
-
if (devices.length === 0)
|
|
139
|
-
return (
|
|
140
|
-
<div className={cn('flex size-full items-center justify-center', className)}>
|
|
141
|
-
<EmptyState
|
|
142
|
-
size="compact"
|
|
143
|
-
icon={Bluetooth}
|
|
144
|
-
title="No Bluetooth devices"
|
|
145
|
-
description="Pair headphones, a keyboard or a mouse to see them here."
|
|
146
|
-
actions={
|
|
147
|
-
onOpenSettings && (
|
|
148
|
-
<Button variant="secondary" size="compact" onClick={onOpenSettings}>
|
|
149
|
-
Open Bluetooth Settings
|
|
150
|
-
</Button>
|
|
151
|
-
)
|
|
152
|
-
}
|
|
153
|
-
/>
|
|
154
|
-
</div>
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
const sorted = [...devices].sort((a, b) => Number(b.connected) - Number(a.connected) || a.name.localeCompare(b.name))
|
|
158
|
-
return (
|
|
159
|
-
<ul className={cn('m-0 grid list-none grid-cols-2 content-start gap-x-8 p-0', className)}>
|
|
160
|
-
{sorted.map(device => (
|
|
161
|
-
<Device key={device.id} device={device} />
|
|
162
|
-
))}
|
|
163
|
-
</ul>
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
Devices.Connected = DevicesConnected
|
|
168
|
-
|
|
169
|
-
export default Devices
|
|
170
|
-
|
|
171
|
-
export type { DeviceInfo, DeviceKind, DevicesProps }
|
|
172
|
-
export { Devices, DevicesConnected }
|