@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
|
@@ -0,0 +1,917 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: a notch app's clock, the time, the date and a few world
|
|
3
|
+
* clocks, with a Pomodoro cycle that takes the widget over while it runs.
|
|
4
|
+
* The run is a value the host may own and persist.
|
|
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 { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
|
|
12
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
13
|
+
import {
|
|
14
|
+
CalendarDays,
|
|
15
|
+
Check,
|
|
16
|
+
Clock3,
|
|
17
|
+
Coffee,
|
|
18
|
+
Moon,
|
|
19
|
+
Pause,
|
|
20
|
+
Play,
|
|
21
|
+
Plus,
|
|
22
|
+
Repeat,
|
|
23
|
+
RotateCcw,
|
|
24
|
+
SkipForward,
|
|
25
|
+
Sun,
|
|
26
|
+
Target,
|
|
27
|
+
Timer,
|
|
28
|
+
} from 'lucide-react'
|
|
29
|
+
import { useEffect } from 'react'
|
|
30
|
+
import IslandFlash from '../../../components/island/island-flash'
|
|
31
|
+
import Widget, { type WidgetLayout } from '../../../components/island/widget'
|
|
32
|
+
import { formatClock, MINUTE, SECOND, useEdgeClock } from '../../../lib/clock'
|
|
33
|
+
|
|
34
|
+
type PomodoroPhase = 'focus' | 'short-break' | 'long-break'
|
|
35
|
+
|
|
36
|
+
/** A Pomodoro cycle's lengths, in minutes, and how many focus rounds come before the long break. */
|
|
37
|
+
interface PomodoroSettings {
|
|
38
|
+
focus: number
|
|
39
|
+
shortBreak: number
|
|
40
|
+
longBreak: number
|
|
41
|
+
rounds: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A Pomodoro phase: running while it has `endsAt`, paused while it has `remaining`. */
|
|
45
|
+
interface PomodoroRun {
|
|
46
|
+
phase: PomodoroPhase
|
|
47
|
+
/** The focus round it belongs to, from 1: a break follows its round. */
|
|
48
|
+
round: number
|
|
49
|
+
/** The phase's whole length, in ms. */
|
|
50
|
+
total: number
|
|
51
|
+
/** When it ends, in epoch ms, while it runs. */
|
|
52
|
+
endsAt?: number
|
|
53
|
+
/** The time left, in ms, while it is paused. */
|
|
54
|
+
remaining?: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A world clock: a city and its IANA time zone. */
|
|
58
|
+
interface ClockZone {
|
|
59
|
+
city: string
|
|
60
|
+
/** An IANA time zone: `America/Chicago`. */
|
|
61
|
+
timeZone: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface ClockProps {
|
|
65
|
+
/** The world clocks beside the time, two or three. */
|
|
66
|
+
zones?: ClockZone[]
|
|
67
|
+
/** Shows the seconds, re-rendering on each second's edge instead of each minute's. Defaults to `false`. */
|
|
68
|
+
seconds?: boolean
|
|
69
|
+
/** A 12-hour clock (`true`) or a 24-hour one (`false`). Defaults to the locale's. */
|
|
70
|
+
hour12?: boolean
|
|
71
|
+
/** The time zone of the main clock. Defaults to the system's. */
|
|
72
|
+
timeZone?: string
|
|
73
|
+
/** Formats the time and the date. Defaults to the browser's locale. */
|
|
74
|
+
locale?: Intl.LocalesArgument
|
|
75
|
+
/** The moment the clock shows, in epoch ms. Defaults to now, re-read on each minute (or second). */
|
|
76
|
+
now?: number
|
|
77
|
+
/** The Pomodoro cycle's lengths, merged over 25 / 5 / 15 minutes and 4 rounds; `false` leaves the Pomodoro out. */
|
|
78
|
+
pomodoro?: Partial<PomodoroSettings> | false
|
|
79
|
+
/** The Pomodoro run (controlled); `null` shows the clock. */
|
|
80
|
+
value?: PomodoroRun | null
|
|
81
|
+
/** The run at first (uncontrolled). Defaults to `null`. */
|
|
82
|
+
defaultValue?: PomodoroRun | null
|
|
83
|
+
/** Called with the run a start, pause, resume, skip, +1 min or reset leaves (`null` after a reset). */
|
|
84
|
+
onValueChange?: (run: PomodoroRun | null) => void
|
|
85
|
+
/** Called when a phase reaches zero, with the next one, which waits paused to be started: show `Clock.PhaseDone`. */
|
|
86
|
+
onPhaseEnd?: (ended: PomodoroRun, next: PomodoroRun) => void
|
|
87
|
+
/** The focus rounds finished today, shown at the tall snap as a row of dots and the time focused. Left out, the tall view leaves the line out. */
|
|
88
|
+
completedToday?: number
|
|
89
|
+
/** `tall` is the open island's tall snap: the time larger, every world clock as a column, the Pomodoro's whole cycle as a strip and its lengths, today's finished rounds; a run lists every phase of its cycle. Defaults to `'fit'`. */
|
|
90
|
+
layout?: WidgetLayout
|
|
91
|
+
/** Classes for the root, which fills its container. */
|
|
92
|
+
className?: string
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const DEFAULTS: PomodoroSettings = { focus: 25, shortBreak: 5, longBreak: 15, rounds: 4 }
|
|
96
|
+
|
|
97
|
+
// Literal tables: UnoCSS only generates the classes it can read whole. Focus is warm, a break green.
|
|
98
|
+
const RING: Record<PomodoroPhase, string> = {
|
|
99
|
+
focus: '[&_circle:last-child]:text-status-warning',
|
|
100
|
+
'short-break': '[&_circle:last-child]:text-status-success',
|
|
101
|
+
'long-break': '[&_circle:last-child]:text-status-success',
|
|
102
|
+
}
|
|
103
|
+
const DOT: Record<PomodoroPhase, string> = {
|
|
104
|
+
focus: 'bg-status-warning',
|
|
105
|
+
'short-break': 'bg-status-success',
|
|
106
|
+
'long-break': 'bg-status-success',
|
|
107
|
+
}
|
|
108
|
+
const TILE: Record<PomodoroPhase, string> = {
|
|
109
|
+
focus: 'bg-status-warning/16 text-status-warning',
|
|
110
|
+
'short-break': 'bg-status-success/16 text-status-success',
|
|
111
|
+
'long-break': 'bg-status-success/16 text-status-success',
|
|
112
|
+
}
|
|
113
|
+
const MARK: Record<PomodoroPhase, string> = {
|
|
114
|
+
focus: 'var(--status-warning)',
|
|
115
|
+
'short-break': 'var(--status-success)',
|
|
116
|
+
'long-break': 'var(--status-success)',
|
|
117
|
+
}
|
|
118
|
+
const WASH: Record<PomodoroPhase, string> = {
|
|
119
|
+
focus: 'bg-status-warning/16',
|
|
120
|
+
'short-break': 'bg-status-success/16',
|
|
121
|
+
'long-break': 'bg-status-success/16',
|
|
122
|
+
}
|
|
123
|
+
const GLYPH = { focus: Target, 'short-break': Coffee, 'long-break': Coffee }
|
|
124
|
+
const PHASES: PomodoroPhase[] = ['focus', 'short-break', 'long-break']
|
|
125
|
+
|
|
126
|
+
const settingsOf = (pomodoro?: Partial<PomodoroSettings> | false): PomodoroSettings => ({
|
|
127
|
+
...DEFAULTS,
|
|
128
|
+
...(pomodoro || {}),
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const lengthOf = (phase: PomodoroPhase, settings: PomodoroSettings) =>
|
|
132
|
+
(phase === 'focus' ? settings.focus : phase === 'short-break' ? settings.shortBreak : settings.longBreak) * MINUTE
|
|
133
|
+
|
|
134
|
+
/** The phase after `run`'s and its round: a break after focus (the long one after the last round), then the next round. */
|
|
135
|
+
function following(run: Pick<PomodoroRun, 'phase' | 'round'>, settings: PomodoroSettings) {
|
|
136
|
+
if (run.phase === 'focus')
|
|
137
|
+
return { phase: run.round >= settings.rounds ? 'long-break' : 'short-break', round: run.round } as const
|
|
138
|
+
return { phase: 'focus', round: run.phase === 'long-break' ? 1 : run.round + 1 } as const
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The first focus round, running from now. */
|
|
142
|
+
function startPomodoro(pomodoro?: Partial<PomodoroSettings>): PomodoroRun {
|
|
143
|
+
const total = lengthOf('focus', settingsOf(pomodoro))
|
|
144
|
+
return { phase: 'focus', round: 1, total, endsAt: Date.now() + total }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The phase after `run`, paused at its whole length until it is started: what a phase reaching zero leaves. */
|
|
148
|
+
function advancePomodoro(run: PomodoroRun, pomodoro?: Partial<PomodoroSettings>): PomodoroRun {
|
|
149
|
+
const settings = settingsOf(pomodoro)
|
|
150
|
+
const next = following(run, settings)
|
|
151
|
+
const total = lengthOf(next.phase, settings)
|
|
152
|
+
return { ...next, total, remaining: total }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** `run` running from now, from the time it had left. */
|
|
156
|
+
function resumePomodoro(run: PomodoroRun): PomodoroRun {
|
|
157
|
+
return { phase: run.phase, round: run.round, total: run.total, endsAt: Date.now() + (run.remaining ?? run.total) }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const pause = (run: PomodoroRun, left: number): PomodoroRun => ({
|
|
161
|
+
phase: run.phase,
|
|
162
|
+
round: run.round,
|
|
163
|
+
total: run.total,
|
|
164
|
+
remaining: left,
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const addMinute = (run: PomodoroRun): PomodoroRun =>
|
|
168
|
+
run.endsAt === undefined
|
|
169
|
+
? { ...run, total: run.total + MINUTE, remaining: (run.remaining ?? run.total) + MINUTE }
|
|
170
|
+
: { ...run, total: run.total + MINUTE, endsAt: run.endsAt + MINUTE }
|
|
171
|
+
|
|
172
|
+
/** The time `run` has left, re-read on each second's edge while it runs, never in between. */
|
|
173
|
+
function useLeft(run: PomodoroRun) {
|
|
174
|
+
const end = run.endsAt ?? 0
|
|
175
|
+
const now = useEdgeClock(end, run.endsAt !== undefined && Date.now() < end + SECOND)
|
|
176
|
+
return run.endsAt === undefined ? (run.remaining ?? run.total) : Math.max(0, end - now)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Every phase of one cycle, in order: each focus round and the break after it, the last one long. */
|
|
180
|
+
function cycleOf(settings: PomodoroSettings) {
|
|
181
|
+
return Array.from({ length: settings.rounds }, (_, i) => [
|
|
182
|
+
{ phase: 'focus' as const, round: i + 1 },
|
|
183
|
+
{ phase: i + 1 === settings.rounds ? ('long-break' as const) : ('short-break' as const), round: i + 1 },
|
|
184
|
+
]).flat()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Where `run` sits in its cycle. */
|
|
188
|
+
const indexIn = (run: Pick<PomodoroRun, 'phase' | 'round'>, settings: PomodoroSettings) =>
|
|
189
|
+
Math.min(settings.rounds * 2 - 1, (run.round - 1) * 2 + (run.phase === 'focus' ? 0 : 1))
|
|
190
|
+
|
|
191
|
+
/** Minutes as `2 h 10 min`, `1 h` or `50 min`. */
|
|
192
|
+
function minutesLabel(minutes: number) {
|
|
193
|
+
const h = Math.floor(minutes / 60)
|
|
194
|
+
const m = minutes % 60
|
|
195
|
+
if (!h) return `${m} min`
|
|
196
|
+
return m ? `${h} h ${m} min` : `${h} h`
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function phaseName(run: Pick<PomodoroRun, 'phase' | 'round'>, rounds: number) {
|
|
200
|
+
if (run.phase === 'focus') return `Focus ${run.round} of ${rounds}`
|
|
201
|
+
return run.phase === 'long-break' ? 'Long break' : 'Short break'
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** A time split into its figure and its day period: `4:05` and `PM`, or `16:05` alone. */
|
|
205
|
+
function timeParts(
|
|
206
|
+
ms: number,
|
|
207
|
+
{ locale, hour12, timeZone, seconds }: Pick<ClockProps, 'locale' | 'hour12' | 'timeZone' | 'seconds'>,
|
|
208
|
+
) {
|
|
209
|
+
const parts = new Intl.DateTimeFormat(locale, {
|
|
210
|
+
hour: 'numeric',
|
|
211
|
+
minute: '2-digit',
|
|
212
|
+
second: seconds ? '2-digit' : undefined,
|
|
213
|
+
hour12,
|
|
214
|
+
timeZone,
|
|
215
|
+
}).formatToParts(ms)
|
|
216
|
+
const period = parts.find(part => part.type === 'dayPeriod')?.value
|
|
217
|
+
const text = parts
|
|
218
|
+
.filter(part => part.type !== 'dayPeriod')
|
|
219
|
+
.map(part => part.value)
|
|
220
|
+
.join('')
|
|
221
|
+
.trim()
|
|
222
|
+
return { text, period }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const shortTime = (ms: number, options: Pick<ClockProps, 'locale' | 'hour12' | 'timeZone'>) =>
|
|
226
|
+
new Date(ms).toLocaleTimeString(options.locale, {
|
|
227
|
+
hour: 'numeric',
|
|
228
|
+
minute: '2-digit',
|
|
229
|
+
hour12: options.hour12,
|
|
230
|
+
timeZone: options.timeZone,
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
/** A zone's offset from UTC at `ms`, in minutes; the system's without a zone. */
|
|
234
|
+
function offsetOf(ms: number, timeZone?: string) {
|
|
235
|
+
if (!timeZone) return -new Date(ms).getTimezoneOffset()
|
|
236
|
+
const name = new Intl.DateTimeFormat('en-US', { timeZone, timeZoneName: 'longOffset' })
|
|
237
|
+
.formatToParts(ms)
|
|
238
|
+
.find(part => part.type === 'timeZoneName')?.value
|
|
239
|
+
const match = name?.match(/([+-])(\d{2}):(\d{2})/)
|
|
240
|
+
if (!match) return 0
|
|
241
|
+
const minutes = Number(match[2]) * 60 + Number(match[3])
|
|
242
|
+
return match[1] === '-' ? -minutes : minutes
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** An offset difference as `+9h`, `−6h`, `+5:30`. */
|
|
246
|
+
function offsetLabel(minutes: number) {
|
|
247
|
+
if (minutes === 0) return 'Same time'
|
|
248
|
+
const sign = minutes > 0 ? '+' : '−'
|
|
249
|
+
const h = Math.floor(Math.abs(minutes) / 60)
|
|
250
|
+
const m = Math.abs(minutes) % 60
|
|
251
|
+
return m ? `${sign}${h}:${String(m).padStart(2, '0')}` : `${sign}${h}h`
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const dayKey = (ms: number, timeZone?: string) =>
|
|
255
|
+
new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(ms)
|
|
256
|
+
|
|
257
|
+
const hourIn = (ms: number, timeZone: string) =>
|
|
258
|
+
Number(new Intl.DateTimeFormat('en-US', { timeZone, hour: 'numeric', hourCycle: 'h23' }).format(ms))
|
|
259
|
+
|
|
260
|
+
interface ZoneRowProps extends Pick<ClockProps, 'locale' | 'hour12' | 'timeZone'> {
|
|
261
|
+
zone: ClockZone
|
|
262
|
+
now: number
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** How a zone differs from here at `now`: its day if not today, its offset, and whether it's day there. */
|
|
266
|
+
function zoneFacts(zone: ClockZone, now: number, timeZone?: string) {
|
|
267
|
+
const there = dayKey(now, zone.timeZone)
|
|
268
|
+
const here = dayKey(now, timeZone)
|
|
269
|
+
const hour = hourIn(now, zone.timeZone)
|
|
270
|
+
return {
|
|
271
|
+
day: there > here ? 'Tomorrow' : there < here ? 'Yesterday' : undefined,
|
|
272
|
+
offset: offsetLabel(offsetOf(now, zone.timeZone) - offsetOf(now, timeZone)),
|
|
273
|
+
DayGlyph: hour >= 6 && hour < 18 ? Sun : Moon,
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function ZoneRow({ zone, now, locale, hour12, timeZone }: ZoneRowProps) {
|
|
278
|
+
const { day, offset, DayGlyph } = zoneFacts(zone, now, timeZone)
|
|
279
|
+
return (
|
|
280
|
+
<Widget.Row
|
|
281
|
+
leading={shortTime(now, { locale, hour12, timeZone: zone.timeZone })}
|
|
282
|
+
trailing={
|
|
283
|
+
<>
|
|
284
|
+
{day && <span>{day} ·</span>}
|
|
285
|
+
<span className="tabular-nums">{offset}</span>
|
|
286
|
+
<DayGlyph size={12} strokeWidth={1.5} aria-label={DayGlyph === Sun ? 'Day' : 'Night'} className="ml-1" />
|
|
287
|
+
</>
|
|
288
|
+
}
|
|
289
|
+
>
|
|
290
|
+
{zone.city}
|
|
291
|
+
</Widget.Row>
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** A world clock at the tall snap, a column: the city, the time large, its day and offset. */
|
|
296
|
+
function ZoneTile({ zone, now, locale, hour12, timeZone }: ZoneRowProps) {
|
|
297
|
+
const { day, offset, DayGlyph } = zoneFacts(zone, now, timeZone)
|
|
298
|
+
const time = timeParts(now, { locale, hour12, timeZone: zone.timeZone })
|
|
299
|
+
return (
|
|
300
|
+
<div className="flex min-w-0 flex-col gap-0.5 px-5 first:pl-0 last:pr-0">
|
|
301
|
+
<span className="truncate text-body text-foreground">{zone.city}</span>
|
|
302
|
+
<span className="flex items-baseline gap-1 whitespace-nowrap tabular-nums">
|
|
303
|
+
<span className="text-title weight-semibold text-foreground">{time.text}</span>
|
|
304
|
+
{time.period && <span className="text-caption text-muted-foreground">{time.period}</span>}
|
|
305
|
+
</span>
|
|
306
|
+
<span className="flex min-w-0 items-center gap-1.5 text-caption text-muted-foreground">
|
|
307
|
+
<DayGlyph size={12} strokeWidth={1.5} aria-label={DayGlyph === Sun ? 'Day' : 'Night'} className="shrink-0" />
|
|
308
|
+
<span className="truncate tabular-nums">
|
|
309
|
+
{day ?? 'Today'}, {offset}
|
|
310
|
+
</span>
|
|
311
|
+
</span>
|
|
312
|
+
</div>
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
interface WorldClocksProps extends Pick<ClockProps, 'locale' | 'hour12' | 'timeZone'> {
|
|
317
|
+
zones: ClockZone[]
|
|
318
|
+
now: number
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The tall snap's world clocks: every zone, a column each, split by hairlines. */
|
|
322
|
+
function WorldClocks({ zones, ...rest }: WorldClocksProps) {
|
|
323
|
+
return (
|
|
324
|
+
<Widget.Section label="World clock">
|
|
325
|
+
<div className="grid auto-cols-fr grid-flow-col divide-x divide-border pt-1">
|
|
326
|
+
{zones.map(zone => (
|
|
327
|
+
<ZoneTile key={zone.timeZone + zone.city} zone={zone} {...rest} />
|
|
328
|
+
))}
|
|
329
|
+
</div>
|
|
330
|
+
</Widget.Section>
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
interface CycleStripProps {
|
|
335
|
+
settings: PomodoroSettings
|
|
336
|
+
/** The phase running, by its place in the cycle: those before it fill, it fills to `progress`. Left out, nothing has run. */
|
|
337
|
+
at?: number
|
|
338
|
+
/** How far the phase at `at` has run, from 0 to 1. */
|
|
339
|
+
progress?: number
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** One cycle as a strip, each phase as long as its minutes, in its hue. */
|
|
343
|
+
function CycleStrip({ settings, at = -1, progress = 0 }: CycleStripProps) {
|
|
344
|
+
return (
|
|
345
|
+
<div aria-hidden className="flex h-1.5 w-full gap-1">
|
|
346
|
+
{cycleOf(settings).map((step, i) => (
|
|
347
|
+
<span
|
|
348
|
+
key={`${step.phase}-${step.round}`}
|
|
349
|
+
className={cn('relative basis-0 overflow-hidden rounded-full', i < at ? DOT[step.phase] : WASH[step.phase])}
|
|
350
|
+
style={{ flexGrow: lengthOf(step.phase, settings) }}
|
|
351
|
+
>
|
|
352
|
+
{i === at && (
|
|
353
|
+
<span
|
|
354
|
+
className={cn('absolute inset-y-0 left-0', DOT[step.phase])}
|
|
355
|
+
style={{ width: `${progress * 100}%` }}
|
|
356
|
+
/>
|
|
357
|
+
)}
|
|
358
|
+
</span>
|
|
359
|
+
))}
|
|
360
|
+
</div>
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Today's finished focus rounds: a dot for each, the cycle's open ones washed, and the time focused. */
|
|
365
|
+
function Today({ completed, settings }: { completed: number; settings: PomodoroSettings }) {
|
|
366
|
+
const slots = Math.min(24, Math.max(1, Math.ceil(completed / settings.rounds)) * settings.rounds)
|
|
367
|
+
return (
|
|
368
|
+
<Widget.Section
|
|
369
|
+
label="Today"
|
|
370
|
+
trailing={
|
|
371
|
+
<span className="tabular-nums">
|
|
372
|
+
{completed} {completed === 1 ? 'round' : 'rounds'} · {minutesLabel(completed * settings.focus)} focused
|
|
373
|
+
</span>
|
|
374
|
+
}
|
|
375
|
+
>
|
|
376
|
+
<div className="flex flex-wrap items-center gap-1.5 py-1">
|
|
377
|
+
{Array.from({ length: slots }, (_, slot) => slot).map(slot => (
|
|
378
|
+
<span
|
|
379
|
+
key={slot}
|
|
380
|
+
aria-hidden
|
|
381
|
+
className={cn('size-2.5 rounded-full', slot < completed ? DOT.focus : WASH.focus)}
|
|
382
|
+
/>
|
|
383
|
+
))}
|
|
384
|
+
</div>
|
|
385
|
+
</Widget.Section>
|
|
386
|
+
)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
interface RingProps {
|
|
390
|
+
run: PomodoroRun
|
|
391
|
+
rounds?: number
|
|
392
|
+
className: string
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** The time left as a Meter ring in the phase's hue. */
|
|
396
|
+
function PhaseRing({ run, rounds = DEFAULTS.rounds, className }: RingProps) {
|
|
397
|
+
const left = useLeft(run)
|
|
398
|
+
return (
|
|
399
|
+
<Meter
|
|
400
|
+
variant="ring"
|
|
401
|
+
label={`${phaseName(run, rounds)}, ${formatClock(Math.ceil(left / SECOND))} left`}
|
|
402
|
+
value={run.total ? left / run.total : 0}
|
|
403
|
+
tone="default"
|
|
404
|
+
animate={false}
|
|
405
|
+
className={cn(RING[run.phase], className)}
|
|
406
|
+
/>
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
interface PartProps {
|
|
411
|
+
/** The Pomodoro run; without one the part shows nothing. */
|
|
412
|
+
run?: PomodoroRun | null
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/** The compact island's left wing: the ring of the phase's time left. */
|
|
416
|
+
function ClockLeading({ run }: PartProps) {
|
|
417
|
+
if (!run) return null
|
|
418
|
+
return <PhaseRing run={run} className="size-4" />
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function TimeLeft({ run }: { run: PomodoroRun }) {
|
|
422
|
+
const left = useLeft(run)
|
|
423
|
+
return (
|
|
424
|
+
<span
|
|
425
|
+
className={cn(
|
|
426
|
+
'text-caption weight-semibold tabular-nums',
|
|
427
|
+
run.endsAt === undefined ? 'text-muted-foreground' : 'text-foreground',
|
|
428
|
+
)}
|
|
429
|
+
>
|
|
430
|
+
{formatClock(Math.ceil(left / SECOND))}
|
|
431
|
+
</span>
|
|
432
|
+
)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** The compact island's right wing: the phase's time left as `mm:ss`, muted while paused. */
|
|
436
|
+
function ClockTrailing({ run }: PartProps) {
|
|
437
|
+
if (!run) return null
|
|
438
|
+
return <TimeLeft run={run} />
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** The split island's bubble: the ring of the phase's time left. */
|
|
442
|
+
function ClockMinimal({ run }: PartProps) {
|
|
443
|
+
if (!run) return null
|
|
444
|
+
return <PhaseRing run={run} className="size-5.5" />
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
interface ClockPhaseDoneProps {
|
|
448
|
+
/** The phase that reached zero. */
|
|
449
|
+
ended: Pick<PomodoroRun, 'phase' | 'round'>
|
|
450
|
+
/** The cycle's lengths, as given to the Clock. */
|
|
451
|
+
pomodoro?: Partial<PomodoroSettings>
|
|
452
|
+
/** Called by the button that starts the next phase; without it the button hides. */
|
|
453
|
+
onStart?: () => void
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** The island's flash when a phase reaches zero: "Focus done — break time" or "Break over", and a button to start the next. */
|
|
457
|
+
function ClockPhaseDone({ ended, pomodoro, onStart }: ClockPhaseDoneProps) {
|
|
458
|
+
const settings = settingsOf(pomodoro)
|
|
459
|
+
const next = following(ended, settings)
|
|
460
|
+
const minutes = lengthOf(next.phase, settings) / MINUTE
|
|
461
|
+
const Glyph = GLYPH[next.phase]
|
|
462
|
+
const breakNext = next.phase !== 'focus'
|
|
463
|
+
const title = !breakNext
|
|
464
|
+
? 'Break over'
|
|
465
|
+
: next.phase === 'long-break'
|
|
466
|
+
? 'Focus done — long break'
|
|
467
|
+
: 'Focus done — break time'
|
|
468
|
+
const caption = !breakNext
|
|
469
|
+
? `${phaseName(next, settings.rounds)} · ${minutes} min`
|
|
470
|
+
: next.phase === 'long-break'
|
|
471
|
+
? `${minutes} min break · all ${settings.rounds} rounds done`
|
|
472
|
+
: `${minutes} min break · ${ended.round} of ${settings.rounds} rounds done`
|
|
473
|
+
return (
|
|
474
|
+
<IslandFlash
|
|
475
|
+
icon={
|
|
476
|
+
<span className={cn('flex size-9 items-center justify-center rounded-lg', TILE[next.phase])}>
|
|
477
|
+
<Glyph size={16} strokeWidth={1.5} />
|
|
478
|
+
</span>
|
|
479
|
+
}
|
|
480
|
+
title={title}
|
|
481
|
+
caption={caption}
|
|
482
|
+
action={
|
|
483
|
+
onStart && (
|
|
484
|
+
<Button variant="secondary" size="compact" onClick={onStart}>
|
|
485
|
+
{breakNext ? 'Start break' : 'Start focus'}
|
|
486
|
+
</Button>
|
|
487
|
+
)
|
|
488
|
+
}
|
|
489
|
+
/>
|
|
490
|
+
)
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
interface RunningProps
|
|
494
|
+
extends Pick<
|
|
495
|
+
ClockProps,
|
|
496
|
+
'zones' | 'locale' | 'hour12' | 'timeZone' | 'onPhaseEnd' | 'completedToday' | 'layout' | 'className'
|
|
497
|
+
> {
|
|
498
|
+
run: PomodoroRun
|
|
499
|
+
settings: PomodoroSettings
|
|
500
|
+
onChange: (run: PomodoroRun | null) => void
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** The coming phases from `run`'s end, each with when it starts. */
|
|
504
|
+
function schedule(run: PomodoroRun, start: number, settings: PomodoroSettings, count: number) {
|
|
505
|
+
const phases: { phase: PomodoroPhase; round: number; start: number; length: number }[] = []
|
|
506
|
+
let at: Pick<PomodoroRun, 'phase' | 'round'> = run
|
|
507
|
+
let when = start
|
|
508
|
+
for (let i = 0; i < count; i++) {
|
|
509
|
+
at = following(at, settings)
|
|
510
|
+
const length = lengthOf(at.phase, settings)
|
|
511
|
+
phases.push({ ...at, start: when, length })
|
|
512
|
+
when += length
|
|
513
|
+
}
|
|
514
|
+
return phases
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function Running({
|
|
518
|
+
run,
|
|
519
|
+
settings,
|
|
520
|
+
onChange,
|
|
521
|
+
onPhaseEnd,
|
|
522
|
+
zones = [],
|
|
523
|
+
locale,
|
|
524
|
+
hour12,
|
|
525
|
+
timeZone,
|
|
526
|
+
completedToday,
|
|
527
|
+
layout = 'fit',
|
|
528
|
+
className,
|
|
529
|
+
}: RunningProps) {
|
|
530
|
+
const left = useLeft(run)
|
|
531
|
+
const running = run.endsAt !== undefined
|
|
532
|
+
const now = running ? (run.endsAt ?? 0) - left : Date.now()
|
|
533
|
+
|
|
534
|
+
useEffect(() => {
|
|
535
|
+
if (!running || left > 0) return
|
|
536
|
+
const next = advancePomodoro(run, settings)
|
|
537
|
+
onPhaseEnd?.(run, next)
|
|
538
|
+
onChange(next)
|
|
539
|
+
}, [running, left, run, settings, onChange, onPhaseEnd])
|
|
540
|
+
|
|
541
|
+
const ends = now + left
|
|
542
|
+
const ready = !running && left === run.total
|
|
543
|
+
const next = following(run, settings)
|
|
544
|
+
const options = { locale, hour12, timeZone }
|
|
545
|
+
const status = running
|
|
546
|
+
? `Until ${shortTime(ends, options)}`
|
|
547
|
+
: ready
|
|
548
|
+
? `Ready · ${Math.round(run.total / MINUTE)} min`
|
|
549
|
+
: 'Paused'
|
|
550
|
+
const nextLabel =
|
|
551
|
+
next.phase === 'focus'
|
|
552
|
+
? `${phaseName(next, settings.rounds)} next`
|
|
553
|
+
: `${lengthOf(next.phase, settings) / MINUTE} min ${next.phase === 'long-break' ? 'long break' : 'break'} next`
|
|
554
|
+
const figure = <Widget.Figure value={formatClock(Math.ceil(left / SECOND))} />
|
|
555
|
+
const controls = (
|
|
556
|
+
<div className="-mr-1 flex shrink-0 items-center gap-1">
|
|
557
|
+
<Widget.Action icon={Plus} label="Add a minute" onClick={() => onChange(addMinute(run))} />
|
|
558
|
+
<Widget.Action
|
|
559
|
+
icon={running ? Pause : Play}
|
|
560
|
+
label={running ? 'Pause' : ready ? 'Start' : 'Resume'}
|
|
561
|
+
emphasis="primary"
|
|
562
|
+
filled
|
|
563
|
+
onClick={() => onChange(running ? pause(run, left) : resumePomodoro(run))}
|
|
564
|
+
/>
|
|
565
|
+
<Widget.Action
|
|
566
|
+
icon={SkipForward}
|
|
567
|
+
label={next.phase === 'focus' ? 'Skip to focus' : 'Skip to break'}
|
|
568
|
+
filled
|
|
569
|
+
onClick={() => onChange(resumePomodoro(advancePomodoro(run, settings)))}
|
|
570
|
+
/>
|
|
571
|
+
</div>
|
|
572
|
+
)
|
|
573
|
+
const header = (
|
|
574
|
+
<Widget.Header
|
|
575
|
+
icon={Timer}
|
|
576
|
+
trailing={<Widget.Action icon={RotateCcw} label="Reset" onClick={() => onChange(null)} />}
|
|
577
|
+
>
|
|
578
|
+
Pomodoro
|
|
579
|
+
</Widget.Header>
|
|
580
|
+
)
|
|
581
|
+
const phase = (
|
|
582
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
583
|
+
<Widget.Title leading={<span aria-hidden className={cn('size-2.5 shrink-0 rounded-full', DOT[run.phase])} />}>
|
|
584
|
+
{phaseName(run, settings.rounds)}
|
|
585
|
+
</Widget.Title>
|
|
586
|
+
<Widget.Meta className="pl-4.5">
|
|
587
|
+
<Widget.MetaItem icon={running ? Clock3 : Pause}>{status}</Widget.MetaItem>
|
|
588
|
+
<Widget.MetaItem icon={GLYPH[next.phase]}>{nextLabel}</Widget.MetaItem>
|
|
589
|
+
</Widget.Meta>
|
|
590
|
+
</div>
|
|
591
|
+
)
|
|
592
|
+
|
|
593
|
+
if (layout === 'tall') {
|
|
594
|
+
const cycle = cycleOf(settings)
|
|
595
|
+
const at = indexIn(run, settings)
|
|
596
|
+
const starts: number[] = []
|
|
597
|
+
let when = ends
|
|
598
|
+
for (const step of cycle.slice(at + 1)) {
|
|
599
|
+
starts.push(when)
|
|
600
|
+
when += lengthOf(step.phase, settings)
|
|
601
|
+
}
|
|
602
|
+
return (
|
|
603
|
+
<Widget.Sheet className={className}>
|
|
604
|
+
<div className="flex min-w-0 items-center gap-8">
|
|
605
|
+
<PhaseRing run={run} rounds={settings.rounds} className="size-36 shrink-0" />
|
|
606
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
|
607
|
+
{header}
|
|
608
|
+
<div className="flex min-w-0 items-center justify-between gap-3">
|
|
609
|
+
{figure}
|
|
610
|
+
{controls}
|
|
611
|
+
</div>
|
|
612
|
+
{phase}
|
|
613
|
+
</div>
|
|
614
|
+
</div>
|
|
615
|
+
|
|
616
|
+
<Widget.Section
|
|
617
|
+
label="This cycle"
|
|
618
|
+
trailing={<span className="tabular-nums">Ends at {shortTime(when, options)}</span>}
|
|
619
|
+
>
|
|
620
|
+
<div className="pt-1 pb-2">
|
|
621
|
+
<CycleStrip settings={settings} at={at} progress={run.total ? 1 - left / run.total : 0} />
|
|
622
|
+
</div>
|
|
623
|
+
<div className="grid grid-cols-2 gap-x-8">
|
|
624
|
+
{cycle.map((step, i) => (
|
|
625
|
+
<Widget.Row
|
|
626
|
+
key={`${step.phase}-${step.round}`}
|
|
627
|
+
leading={i < at ? 'Done' : i === at ? 'Now' : shortTime(starts[i - at - 1] ?? when, options)}
|
|
628
|
+
color={MARK[step.phase]}
|
|
629
|
+
trailing={
|
|
630
|
+
i < at ? (
|
|
631
|
+
<Check size={14} strokeWidth={1.5} aria-label="Done" />
|
|
632
|
+
) : i === at ? (
|
|
633
|
+
`${formatClock(Math.ceil(left / SECOND))} left`
|
|
634
|
+
) : (
|
|
635
|
+
`${lengthOf(step.phase, settings) / MINUTE} min`
|
|
636
|
+
)
|
|
637
|
+
}
|
|
638
|
+
>
|
|
639
|
+
{phaseName(step, settings.rounds)}
|
|
640
|
+
</Widget.Row>
|
|
641
|
+
))}
|
|
642
|
+
</div>
|
|
643
|
+
</Widget.Section>
|
|
644
|
+
|
|
645
|
+
{completedToday !== undefined && <Today completed={completedToday} settings={settings} />}
|
|
646
|
+
{zones.length > 0 && (
|
|
647
|
+
<WorldClocks zones={zones} now={now} locale={locale} hour12={hour12} timeZone={timeZone} />
|
|
648
|
+
)}
|
|
649
|
+
</Widget.Sheet>
|
|
650
|
+
)
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return (
|
|
654
|
+
<Widget
|
|
655
|
+
className={className}
|
|
656
|
+
media={<PhaseRing run={run} rounds={settings.rounds} className="size-24" />}
|
|
657
|
+
aside={
|
|
658
|
+
<Widget.Section
|
|
659
|
+
label="Up next"
|
|
660
|
+
trailing={<span className="tabular-nums">{shortTime(Date.now(), options)}</span>}
|
|
661
|
+
>
|
|
662
|
+
{schedule(run, ends, settings, 3).map(phase => (
|
|
663
|
+
<Widget.Row
|
|
664
|
+
key={`${phase.phase}-${phase.round}-${phase.start}`}
|
|
665
|
+
leading={shortTime(phase.start, options)}
|
|
666
|
+
color={MARK[phase.phase]}
|
|
667
|
+
trailing={`${phase.length / MINUTE} min`}
|
|
668
|
+
>
|
|
669
|
+
{phaseName(phase, settings.rounds)}
|
|
670
|
+
</Widget.Row>
|
|
671
|
+
))}
|
|
672
|
+
</Widget.Section>
|
|
673
|
+
}
|
|
674
|
+
>
|
|
675
|
+
{header}
|
|
676
|
+
<div className="flex min-w-0 items-center justify-between gap-3">
|
|
677
|
+
{figure}
|
|
678
|
+
{controls}
|
|
679
|
+
</div>
|
|
680
|
+
{phase}
|
|
681
|
+
</Widget>
|
|
682
|
+
)
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* A notch app's clock: the time as the hero, the date above it, the world
|
|
687
|
+
* clocks beside it, and a Pomodoro cycle that takes over while it runs.
|
|
688
|
+
*
|
|
689
|
+
* The time is set large in hours and minutes (`seconds` adds them, muted,
|
|
690
|
+
* and a tick on each second), on the locale's clock or the one `hour12`
|
|
691
|
+
* picks, with the time zone's name under it and the date on the line above.
|
|
692
|
+
* Beside it, past a hairline, the world clocks (`zones`): each city's time,
|
|
693
|
+
* how far it is from here (`−6h`), whether it's day or night there, and
|
|
694
|
+
* `Tomorrow` or `Yesterday` when its date differs. Nothing ticks between
|
|
695
|
+
* minutes; `now` pins the moment.
|
|
696
|
+
*
|
|
697
|
+
* Under the time the Pomodoro waits with its lengths (`pomodoro`: focus,
|
|
698
|
+
* short and long break in minutes, and the rounds before the long one) and
|
|
699
|
+
* a Start focus button. A run takes the widget over: the phase's ring in
|
|
700
|
+
* its hue (focus warm, a break green) as the picture, the time left as the
|
|
701
|
+
* hero, its round (`Focus 2 of 4`), when it ends and what comes next, and
|
|
702
|
+
* the next phases with their start times beside it. Pause / resume is the
|
|
703
|
+
* main action, with +1 min and skip beside it and reset at the top.
|
|
704
|
+
*
|
|
705
|
+
* The run is a value (`value` / `onValueChange`, or kept here from
|
|
706
|
+
* `defaultValue`): a running phase carries when it ends, a paused one the
|
|
707
|
+
* time it had left, so a host can persist it and pick it up after a
|
|
708
|
+
* reload. When a phase reaches zero the next one waits paused at its whole
|
|
709
|
+
* length and `onPhaseEnd` is called; the helpers `startPomodoro`,
|
|
710
|
+
* `advancePomodoro` and `resumePomodoro` build the same runs for a host
|
|
711
|
+
* that keeps time itself.
|
|
712
|
+
*
|
|
713
|
+
* At the open island's tall snap (`layout="tall"`) it becomes a sheet: the
|
|
714
|
+
* time and the date as the hero with Start focus beside them; every world
|
|
715
|
+
* clock as a column, the city, the time large, and its day, offset and
|
|
716
|
+
* whether it's day or night there; the Pomodoro's whole cycle as a strip, each phase
|
|
717
|
+
* as long as its minutes in its hue, over its three lengths in columns;
|
|
718
|
+
* and today's finished rounds (`completedToday`) as dots with the time
|
|
719
|
+
* focused. A run puts its ring large beside the time left and the
|
|
720
|
+
* controls, then lists every phase of its cycle, done, now and when each
|
|
721
|
+
* starts, under the strip filling as it goes.
|
|
722
|
+
*
|
|
723
|
+
* The other forms are parts: `Clock.Leading` and `Clock.Trailing` for the
|
|
724
|
+
* compact island's wings (the ring and `mm:ss`, nothing without a run),
|
|
725
|
+
* `Clock.Minimal`, the ring, for the split island's bubble, and
|
|
726
|
+
* `Clock.PhaseDone`, the flash at a phase's end with a button to start the
|
|
727
|
+
* next.
|
|
728
|
+
*
|
|
729
|
+
* @example {@include ./examples.mdx}
|
|
730
|
+
*/
|
|
731
|
+
const Clock = Object.assign(
|
|
732
|
+
function Clock({
|
|
733
|
+
zones = [],
|
|
734
|
+
seconds = false,
|
|
735
|
+
hour12,
|
|
736
|
+
timeZone,
|
|
737
|
+
locale,
|
|
738
|
+
now: nowProp,
|
|
739
|
+
pomodoro,
|
|
740
|
+
value,
|
|
741
|
+
defaultValue = null,
|
|
742
|
+
onValueChange,
|
|
743
|
+
onPhaseEnd,
|
|
744
|
+
completedToday,
|
|
745
|
+
layout = 'fit',
|
|
746
|
+
className,
|
|
747
|
+
}: ClockProps) {
|
|
748
|
+
const [run, setRun] = useControllableState(value, defaultValue, onValueChange)
|
|
749
|
+
const ticking = useEdgeClock(0, nowProp === undefined && !run, seconds ? SECOND : MINUTE)
|
|
750
|
+
const settings = settingsOf(pomodoro)
|
|
751
|
+
|
|
752
|
+
if (run)
|
|
753
|
+
return (
|
|
754
|
+
<Running
|
|
755
|
+
run={run}
|
|
756
|
+
settings={settings}
|
|
757
|
+
onChange={setRun}
|
|
758
|
+
onPhaseEnd={onPhaseEnd}
|
|
759
|
+
zones={zones}
|
|
760
|
+
completedToday={completedToday}
|
|
761
|
+
layout={layout}
|
|
762
|
+
locale={locale}
|
|
763
|
+
hour12={hour12}
|
|
764
|
+
timeZone={timeZone}
|
|
765
|
+
className={className}
|
|
766
|
+
/>
|
|
767
|
+
)
|
|
768
|
+
|
|
769
|
+
const now = nowProp ?? ticking
|
|
770
|
+
const time = timeParts(now, { locale, hour12, timeZone })
|
|
771
|
+
const second = seconds && new Intl.DateTimeFormat('en-US', { second: '2-digit', timeZone }).format(now)
|
|
772
|
+
const date = new Date(now).toLocaleDateString(locale, { weekday: 'long', month: 'long', day: 'numeric', timeZone })
|
|
773
|
+
const zoneName = new Intl.DateTimeFormat(locale, { timeZone, timeZoneName: 'long' })
|
|
774
|
+
.formatToParts(now)
|
|
775
|
+
.find(part => part.type === 'timeZoneName')?.value
|
|
776
|
+
const figure = (
|
|
777
|
+
<Widget.Figure
|
|
778
|
+
value={
|
|
779
|
+
<>
|
|
780
|
+
{time.text}
|
|
781
|
+
{second && <span className="text-muted-foreground">:{second.padStart(2, '0')}</span>}
|
|
782
|
+
</>
|
|
783
|
+
}
|
|
784
|
+
unit={time.period}
|
|
785
|
+
/>
|
|
786
|
+
)
|
|
787
|
+
const start = pomodoro !== false && (
|
|
788
|
+
<Button
|
|
789
|
+
variant="secondary"
|
|
790
|
+
size="compact"
|
|
791
|
+
leadingIcon={Play}
|
|
792
|
+
className="mb-1"
|
|
793
|
+
onClick={() => setRun(startPomodoro(settings))}
|
|
794
|
+
>
|
|
795
|
+
Start focus
|
|
796
|
+
</Button>
|
|
797
|
+
)
|
|
798
|
+
|
|
799
|
+
if (layout === 'tall')
|
|
800
|
+
return (
|
|
801
|
+
<Widget.Sheet className={className}>
|
|
802
|
+
<div className="flex min-w-0 items-end justify-between gap-6">
|
|
803
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
804
|
+
<Widget.Header icon={CalendarDays}>{date}</Widget.Header>
|
|
805
|
+
{figure}
|
|
806
|
+
{zoneName && <Widget.Subtitle>{zoneName}</Widget.Subtitle>}
|
|
807
|
+
</div>
|
|
808
|
+
{start}
|
|
809
|
+
</div>
|
|
810
|
+
|
|
811
|
+
{zones.length > 0 && (
|
|
812
|
+
<WorldClocks zones={zones} now={now} locale={locale} hour12={hour12} timeZone={timeZone} />
|
|
813
|
+
)}
|
|
814
|
+
|
|
815
|
+
{pomodoro !== false && (
|
|
816
|
+
<Widget.Section
|
|
817
|
+
label="Pomodoro"
|
|
818
|
+
trailing={
|
|
819
|
+
<span className="tabular-nums">
|
|
820
|
+
{minutesLabel(
|
|
821
|
+
cycleOf(settings).reduce((sum, step) => sum + lengthOf(step.phase, settings), 0) / MINUTE,
|
|
822
|
+
)}{' '}
|
|
823
|
+
a cycle
|
|
824
|
+
</span>
|
|
825
|
+
}
|
|
826
|
+
>
|
|
827
|
+
<div className="pt-1 pb-3">
|
|
828
|
+
<CycleStrip settings={settings} />
|
|
829
|
+
</div>
|
|
830
|
+
<div className="grid grid-cols-3 divide-x divide-border">
|
|
831
|
+
{PHASES.map(phase => (
|
|
832
|
+
<div key={phase} className="flex min-w-0 flex-col gap-0.5 px-5 first:pl-0">
|
|
833
|
+
<span className="flex items-center gap-2 text-caption text-muted-foreground">
|
|
834
|
+
<span aria-hidden className={cn('size-2 shrink-0 rounded-full', DOT[phase])} />
|
|
835
|
+
{phase === 'focus' ? 'Focus' : phase === 'long-break' ? 'Long break' : 'Short break'}
|
|
836
|
+
</span>
|
|
837
|
+
<span className="text-title weight-semibold tabular-nums text-foreground">
|
|
838
|
+
{lengthOf(phase, settings) / MINUTE} min
|
|
839
|
+
</span>
|
|
840
|
+
<span className="truncate text-caption text-muted-foreground">
|
|
841
|
+
{phase === 'focus'
|
|
842
|
+
? `${settings.rounds} rounds`
|
|
843
|
+
: phase === 'long-break'
|
|
844
|
+
? `After round ${settings.rounds}`
|
|
845
|
+
: `Between rounds`}
|
|
846
|
+
</span>
|
|
847
|
+
</div>
|
|
848
|
+
))}
|
|
849
|
+
</div>
|
|
850
|
+
</Widget.Section>
|
|
851
|
+
)}
|
|
852
|
+
|
|
853
|
+
{pomodoro !== false && completedToday !== undefined && (
|
|
854
|
+
<Today completed={completedToday} settings={settings} />
|
|
855
|
+
)}
|
|
856
|
+
</Widget.Sheet>
|
|
857
|
+
)
|
|
858
|
+
|
|
859
|
+
return (
|
|
860
|
+
<Widget
|
|
861
|
+
className={className}
|
|
862
|
+
aside={
|
|
863
|
+
zones.length > 0 && (
|
|
864
|
+
<Widget.Section label="World clock">
|
|
865
|
+
{zones.slice(0, 3).map(zone => (
|
|
866
|
+
<ZoneRow
|
|
867
|
+
key={zone.timeZone + zone.city}
|
|
868
|
+
zone={zone}
|
|
869
|
+
now={now}
|
|
870
|
+
locale={locale}
|
|
871
|
+
hour12={hour12}
|
|
872
|
+
timeZone={timeZone}
|
|
873
|
+
/>
|
|
874
|
+
))}
|
|
875
|
+
</Widget.Section>
|
|
876
|
+
)
|
|
877
|
+
}
|
|
878
|
+
>
|
|
879
|
+
<Widget.Header icon={CalendarDays}>{date}</Widget.Header>
|
|
880
|
+
<div className="flex min-w-0 items-end justify-between gap-3">
|
|
881
|
+
{figure}
|
|
882
|
+
{start}
|
|
883
|
+
</div>
|
|
884
|
+
{zoneName && <Widget.Subtitle>{zoneName}</Widget.Subtitle>}
|
|
885
|
+
{pomodoro !== false && (
|
|
886
|
+
<Widget.Meta className="mt-1">
|
|
887
|
+
<Widget.MetaItem icon={Target}>{settings.focus} min focus</Widget.MetaItem>
|
|
888
|
+
<Widget.MetaItem icon={Coffee}>
|
|
889
|
+
{settings.shortBreak} / {settings.longBreak} min breaks
|
|
890
|
+
</Widget.MetaItem>
|
|
891
|
+
<Widget.MetaItem icon={Repeat}>{settings.rounds} rounds</Widget.MetaItem>
|
|
892
|
+
</Widget.Meta>
|
|
893
|
+
)}
|
|
894
|
+
</Widget>
|
|
895
|
+
)
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
Leading: ClockLeading,
|
|
899
|
+
Trailing: ClockTrailing,
|
|
900
|
+
Minimal: ClockMinimal,
|
|
901
|
+
PhaseDone: ClockPhaseDone,
|
|
902
|
+
},
|
|
903
|
+
)
|
|
904
|
+
|
|
905
|
+
export default Clock
|
|
906
|
+
|
|
907
|
+
export type { ClockPhaseDoneProps, ClockProps, ClockZone, PomodoroPhase, PomodoroRun, PomodoroSettings }
|
|
908
|
+
export {
|
|
909
|
+
advancePomodoro,
|
|
910
|
+
Clock,
|
|
911
|
+
ClockLeading,
|
|
912
|
+
ClockMinimal,
|
|
913
|
+
ClockPhaseDone,
|
|
914
|
+
ClockTrailing,
|
|
915
|
+
resumePomodoro,
|
|
916
|
+
startPomodoro,
|
|
917
|
+
}
|