@justanarthur/modo-ui-notch 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +11 -11
  2. package/blocks/activities/agenda/examples.mdx +21 -5
  3. package/blocks/activities/agenda/index.tsx +291 -182
  4. package/blocks/activities/clock/examples.mdx +73 -0
  5. package/blocks/activities/clock/index.tsx +619 -0
  6. package/blocks/activities/now-playing/examples.mdx +32 -13
  7. package/blocks/activities/now-playing/index.tsx +319 -126
  8. package/blocks/activities/weather/examples.mdx +115 -0
  9. package/blocks/activities/weather/index.tsx +634 -0
  10. package/blocks/app/expanded-island/examples.mdx +8 -7
  11. package/blocks/app/expanded-island/index.tsx +19 -3
  12. package/blocks/app/settings-window/examples.mdx +6 -2
  13. package/blocks/app/settings-window/index.tsx +25 -7
  14. package/blocks/system/clipboard/examples.mdx +83 -0
  15. package/blocks/system/clipboard/index.tsx +563 -0
  16. package/blocks/system/recent-files/examples.mdx +66 -0
  17. package/blocks/system/recent-files/index.tsx +542 -0
  18. package/blocks/system/system-stats/examples.mdx +38 -9
  19. package/blocks/system/system-stats/index.tsx +241 -107
  20. package/components/indicators/media-scrubber/examples.mdx +8 -0
  21. package/components/indicators/media-scrubber/index.tsx +37 -13
  22. package/components/island/island/examples.mdx +4 -4
  23. package/components/island/island/index.tsx +2 -2
  24. package/components/island/island-flash/examples.mdx +15 -18
  25. package/components/island/island-flash/index.tsx +4 -4
  26. package/components/island/island-tabs/examples.mdx +5 -5
  27. package/components/island/widget/examples.mdx +76 -0
  28. package/components/island/widget/index.tsx +431 -0
  29. package/dist/blocks/activities/agenda/index.d.ts +1 -1
  30. package/dist/blocks/activities/agenda/index.js +3 -3
  31. package/dist/blocks/activities/clock/index.d.ts +2 -0
  32. package/dist/blocks/activities/clock/index.js +25 -0
  33. package/dist/blocks/activities/now-playing/index.d.ts +3 -2
  34. package/dist/blocks/activities/now-playing/index.js +5 -3
  35. package/dist/blocks/activities/weather/index.d.ts +2 -0
  36. package/dist/blocks/activities/weather/index.js +21 -0
  37. package/dist/blocks/app/expanded-island/index.d.ts +1 -1
  38. package/dist/blocks/app/expanded-island/index.js +4 -3
  39. package/dist/blocks/app/settings-window/index.d.ts +1 -1
  40. package/dist/blocks/app/settings-window/index.js +1 -1
  41. package/dist/blocks/system/clipboard/index.d.ts +2 -0
  42. package/dist/blocks/system/clipboard/index.js +17 -0
  43. package/dist/blocks/system/recent-files/index.d.ts +2 -0
  44. package/dist/blocks/system/recent-files/index.js +19 -0
  45. package/dist/blocks/system/system-stats/index.d.ts +2 -2
  46. package/dist/blocks/system/system-stats/index.js +4 -1
  47. package/dist/components/indicators/media-scrubber/index.d.ts +1 -1
  48. package/dist/components/indicators/media-scrubber/index.js +1 -1
  49. package/dist/components/island/island/index.d.ts +1 -1
  50. package/dist/components/island/island/index.js +2 -2
  51. package/dist/components/island/island-flash/index.d.ts +1 -1
  52. package/dist/components/island/island-flash/index.js +1 -1
  53. package/dist/components/island/island-tabs/index.js +2 -2
  54. package/dist/components/island/widget/index.d.ts +2 -0
  55. package/dist/components/island/widget/index.js +30 -0
  56. package/dist/index.d.ts +15 -15
  57. package/dist/index.js +102 -58
  58. package/dist/lib/artwork.d.ts +2 -0
  59. package/dist/lib/artwork.js +8 -0
  60. package/dist/lib/geometry.js +1 -1
  61. package/dist/shared/chunk-2818esrq.d.ts +140 -0
  62. package/dist/shared/{chunk-yngkkxz2.d.ts → chunk-2m5dz8nf.d.ts} +4 -4
  63. package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
  64. package/dist/shared/chunk-416tsgbc.d.ts +175 -0
  65. package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
  66. package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
  67. package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
  68. package/dist/shared/chunk-9c7ewvkk.js +381 -0
  69. package/dist/shared/{chunk-mp1nx0ez.js → chunk-9m0xbg5v.js} +14 -3
  70. package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
  71. package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
  72. package/dist/shared/{chunk-s33y1pcq.js → chunk-cc9nwbtf.js} +20 -10
  73. package/dist/shared/chunk-da177e8r.d.ts +114 -0
  74. package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
  75. package/dist/shared/chunk-gejenfap.d.ts +25 -0
  76. package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
  77. package/dist/shared/chunk-j77cx8dp.js +498 -0
  78. package/dist/shared/chunk-mt0k6v8x.js +474 -0
  79. package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
  80. package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-pfhy5e4q.d.ts} +7 -1
  81. package/dist/shared/chunk-qdzemt2v.js +477 -0
  82. package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
  83. package/dist/shared/chunk-s2jeqqan.js +243 -0
  84. package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
  85. package/dist/shared/chunk-w5h6ay93.js +72 -0
  86. package/dist/shared/chunk-wkg17nxs.d.ts +101 -0
  87. package/dist/shared/chunk-x7f3g82r.js +285 -0
  88. package/dist/shared/chunk-xq5hc5gv.js +333 -0
  89. package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
  90. package/dist/shared/chunk-ym0xbses.js +518 -0
  91. package/dist/styles.css +97 -55
  92. package/index.ts +7 -6
  93. package/lib/artwork.ts +112 -0
  94. package/lib/geometry.ts +1 -1
  95. package/mock/activities.tsx +9 -32
  96. package/mock/artwork.tsx +13 -1
  97. package/mock/clipboard.tsx +79 -0
  98. package/mock/clock.tsx +77 -0
  99. package/mock/data.ts +30 -44
  100. package/mock/files.tsx +70 -0
  101. package/mock/island-content.tsx +43 -118
  102. package/mock/screen.tsx +76 -0
  103. package/mock/settings.tsx +370 -91
  104. package/mock/system.ts +46 -0
  105. package/mock/weather.tsx +105 -0
  106. package/package.json +7 -2
  107. package/blocks/activities/shelf/examples.mdx +0 -33
  108. package/blocks/activities/shelf/index.tsx +0 -289
  109. package/blocks/activities/timer/examples.mdx +0 -52
  110. package/blocks/activities/timer/index.tsx +0 -292
  111. package/blocks/system/controls/examples.mdx +0 -34
  112. package/blocks/system/controls/index.tsx +0 -167
  113. package/blocks/system/devices/examples.mdx +0 -25
  114. package/blocks/system/devices/index.tsx +0 -172
  115. package/blocks/system/power-alert/examples.mdx +0 -32
  116. package/blocks/system/power-alert/index.tsx +0 -89
  117. package/components/indicators/battery-glyph/examples.mdx +0 -22
  118. package/components/indicators/battery-glyph/index.tsx +0 -91
  119. package/dist/blocks/activities/shelf/index.d.ts +0 -2
  120. package/dist/blocks/activities/shelf/index.js +0 -14
  121. package/dist/blocks/activities/timer/index.d.ts +0 -2
  122. package/dist/blocks/activities/timer/index.js +0 -19
  123. package/dist/blocks/system/controls/index.d.ts +0 -2
  124. package/dist/blocks/system/controls/index.js +0 -10
  125. package/dist/blocks/system/devices/index.d.ts +0 -2
  126. package/dist/blocks/system/devices/index.js +0 -12
  127. package/dist/blocks/system/power-alert/index.d.ts +0 -2
  128. package/dist/blocks/system/power-alert/index.js +0 -9
  129. package/dist/components/indicators/battery-glyph/index.d.ts +0 -2
  130. package/dist/components/indicators/battery-glyph/index.js +0 -9
  131. package/dist/shared/chunk-2qpcsv5h.d.ts +0 -45
  132. package/dist/shared/chunk-45gytfr1.d.ts +0 -84
  133. package/dist/shared/chunk-50ffk4r7.d.ts +0 -69
  134. package/dist/shared/chunk-5w0yck07.d.ts +0 -32
  135. package/dist/shared/chunk-7hr53mby.js +0 -116
  136. package/dist/shared/chunk-b8jb1w72.js +0 -145
  137. package/dist/shared/chunk-cpewy6yg.js +0 -178
  138. package/dist/shared/chunk-e3e4s4ds.d.ts +0 -77
  139. package/dist/shared/chunk-enm6td0p.js +0 -280
  140. package/dist/shared/chunk-fvedaas2.d.ts +0 -33
  141. package/dist/shared/chunk-gex38j8x.d.ts +0 -82
  142. package/dist/shared/chunk-hwtxpzg0.js +0 -69
  143. package/dist/shared/chunk-phb53x1f.js +0 -252
  144. package/dist/shared/chunk-r8esmjfs.d.ts +0 -42
  145. package/dist/shared/chunk-rcp1g9ca.js +0 -70
  146. package/dist/shared/chunk-rx9sphz2.js +0 -266
  147. package/dist/shared/chunk-xdeek16r.d.ts +0 -58
  148. package/dist/shared/chunk-xkzjk1tq.js +0 -206
@@ -1,20 +1,20 @@
1
1
  /*!
2
- * Local addition: a notch app's calendar, today's and tomorrow's events and
3
- * the countdown to the next one. Rebuilt from Just Notch's calendar plugin
4
- * (`Agenda`, `Upcoming`, `Starting`, `Ring`, `Countdown`) as presentational
5
- * parts: events, access and actions come in as props.
2
+ * Local addition: a notch app's calendar, the next event and the rest of
3
+ * today and tomorrow, with the countdown to the next one. Rebuilt from Just
4
+ * Notch's calendar plugin (`Agenda`, `Upcoming`, `Starting`, `Ring`,
5
+ * `Countdown`) as presentational parts: events, access and actions come in
6
+ * as props.
6
7
  */
7
8
 
8
9
  'use client'
9
10
 
10
11
  import Button from '@justanarthur/modo-ui/components/actions/button'
11
- import EmptyState from '@justanarthur/modo-ui/components/feedback/empty-state'
12
- import Meter from '@justanarthur/modo-ui/components/feedback/meter'
13
- import { type SizeVariant, useSize } from '@justanarthur/modo-ui/lib/size-context'
12
+ import type { SizeVariant } from '@justanarthur/modo-ui/lib/size-context'
13
+ import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
14
14
  import { cn } from '@justanarthur/modo-ui/lib/utils'
15
- import { CalendarCheck, CalendarDays, Video } from 'lucide-react'
16
- import Countdown from '../../../components/indicators/countdown'
15
+ import { CalendarCheck, CalendarDays, ChevronDown, ChevronUp, Clock, Lock, MapPin, Video } from 'lucide-react'
17
16
  import IslandFlash from '../../../components/island/island-flash'
17
+ import Widget from '../../../components/island/widget'
18
18
  import { formatShort, MINUTE, SECOND, useEdgeClock } from '../../../lib/clock'
19
19
 
20
20
  type AgendaAccess = 'granted' | 'undetermined' | 'denied'
@@ -30,40 +30,61 @@ interface AgendaEvent {
30
30
  location?: string
31
31
  /** A video call's link: the event gets a Join button. */
32
32
  meetingUrl?: string
33
- /** Its calendar's color, any CSS color: data, so it paints the dot and the countdown inline. */
33
+ /** Its calendar's color, any CSS color: data, so it paints the dot, the mark and the ring inline. */
34
34
  color: string
35
35
  }
36
36
 
37
37
  interface AgendaProps {
38
- /** The events, in start order. */
38
+ /** The events, in any order. */
39
39
  events: AgendaEvent[]
40
40
  /** Whether the calendar may be read: undetermined asks, denied points to the system's settings. Defaults to `'granted'`. */
41
41
  access?: AgendaAccess
42
42
  /** The moment the agenda is read at, in epoch ms. Defaults to now, re-read on each minute. */
43
43
  now?: number
44
- /** Formats the times. Defaults to the browser's locale. */
44
+ /** Formats the times and the date. Defaults to the browser's locale. */
45
45
  locale?: Intl.LocalesArgument
46
+ /** Tomorrow's events are unfolded (controlled); folded, only its first shows. */
47
+ tomorrowOpen?: boolean
48
+ /** Tomorrow's events are unfolded at first (uncontrolled). Defaults to `false`. */
49
+ defaultTomorrowOpen?: boolean
50
+ /** Called with the new state when tomorrow's fold is pressed. */
51
+ onTomorrowOpenChange?: (open: boolean) => void
46
52
  /** Called by Connect calendar while access is undetermined. */
47
53
  onRequestAccess?: () => void
48
54
  /** Called by Open System Settings while access is denied. */
49
55
  onOpenSettings?: () => void
50
- /** Called by an event's Join button. */
56
+ /** Called by the next event's Join button. */
51
57
  onJoin?: (event: AgendaEvent) => void
52
58
  /** Classes for the root, which fills its container. */
53
59
  className?: string
54
60
  }
55
61
 
56
- const clock = (ms: number, locale?: Intl.LocalesArgument) =>
62
+ /** Rows the timeline lists per day before it says how many more. */
63
+ const ROWS = 3
64
+
65
+ const time = (ms: number, locale?: Intl.LocalesArgument) =>
57
66
  new Date(ms).toLocaleTimeString(locale, { hour: 'numeric', minute: '2-digit' })
58
- const span = (event: AgendaEvent, locale?: Intl.LocalesArgument) =>
59
- event.allDay ? 'All day' : `${clock(event.start, locale)} – ${clock(event.end, locale)}`
60
- const meta = (event: AgendaEvent, locale?: Intl.LocalesArgument) =>
61
- event.location ? `${span(event, locale)} · ${event.location}` : span(event, locale)
62
-
63
- function relative(ms: number) {
64
- if (ms <= 0) return 'Now'
65
- if (ms < MINUTE) return 'In less than a minute'
66
- return `In ${Math.ceil(ms / MINUTE)} min`
67
+
68
+ /** A time split into its figure and its day period: `4:00` and `PM`, or `16:00` alone. */
69
+ function timeParts(ms: number, locale?: Intl.LocalesArgument) {
70
+ const parts = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: '2-digit' }).formatToParts(ms)
71
+ const period = parts.find(part => part.type === 'dayPeriod')?.value
72
+ const value = parts
73
+ .filter(part => part.type !== 'dayPeriod')
74
+ .map(part => part.value)
75
+ .join('')
76
+ .trim()
77
+ return { value, period }
78
+ }
79
+
80
+ const range = (event: AgendaEvent, locale?: Intl.LocalesArgument) =>
81
+ `${time(event.start, locale)} – ${time(event.end, locale)}`
82
+
83
+ function length(ms: number) {
84
+ const minutes = Math.round(ms / MINUTE)
85
+ if (minutes < 60) return `${minutes} min`
86
+ const hours = Math.floor(minutes / 60)
87
+ return minutes % 60 ? `${hours} h ${minutes % 60} min` : `${hours} h`
67
88
  }
68
89
 
69
90
  /** The time until `start`, re-read on each `unit` edge before it, never in between. */
@@ -72,6 +93,12 @@ function useUntil(start: number, unit = MINUTE) {
72
93
  return start - now
73
94
  }
74
95
 
96
+ function Dot({ color, className }: { color: string; className?: string }) {
97
+ return (
98
+ <span aria-hidden className={cn('size-2.5 shrink-0 rounded-full', className)} style={{ backgroundColor: color }} />
99
+ )
100
+ }
101
+
75
102
  function Join({
76
103
  event,
77
104
  size,
@@ -82,12 +109,73 @@ function Join({
82
109
  onJoin?: (event: AgendaEvent) => void
83
110
  }) {
84
111
  return (
85
- <Button variant="secondary" size={size} leadingIcon={Video} onClick={() => onJoin?.(event)}>
112
+ <Button variant="primary" size={size} leadingIcon={Video} onClick={() => onJoin?.(event)}>
86
113
  Join
87
114
  </Button>
88
115
  )
89
116
  }
90
117
 
118
+ interface HeroProps {
119
+ event: AgendaEvent
120
+ now: number
121
+ midnight: number
122
+ locale?: Intl.LocalesArgument
123
+ onJoin?: (event: AgendaEvent) => void
124
+ }
125
+
126
+ /** How soon, as the figure: `in 12 min` within the hour, `Now` while on, else the start time. */
127
+ function When({ event, now, midnight, locale }: Omit<HeroProps, 'onJoin'>) {
128
+ if (event.start <= now) return <Widget.Figure value="Now" unit={`${length(event.end - now)} left`} />
129
+ if (event.start - now < 60 * MINUTE)
130
+ return <Widget.Figure prefix="in" value={Math.max(1, Math.ceil((event.start - now) / MINUTE))} unit="min" />
131
+ const { value, period } = timeParts(event.start, locale)
132
+ return <Widget.Figure prefix={event.start >= midnight ? 'Tomorrow' : 'at'} value={value} unit={period} />
133
+ }
134
+
135
+ /** The next event, set as the widget's hero: how soon, its title in its calendar's color, when and where, and Join. */
136
+ function Hero({ event, now, midnight, locale, onJoin }: HeroProps) {
137
+ return (
138
+ <div className="flex min-w-0 flex-col gap-1.5">
139
+ <div className="flex min-w-0 items-end justify-between gap-3">
140
+ <When event={event} now={now} midnight={midnight} locale={locale} />
141
+ {event.meetingUrl && <Join event={event} size="compact" onJoin={onJoin} />}
142
+ </div>
143
+ <div className="flex min-w-0 flex-col gap-0.5">
144
+ <Widget.Title leading={<Dot color={event.color} />}>{event.title}</Widget.Title>
145
+ <Widget.Meta className="pl-4.5">
146
+ <Widget.MetaItem icon={Clock}>{range(event, locale)}</Widget.MetaItem>
147
+ {event.meetingUrl && <Widget.MetaItem icon={Video}>Video call</Widget.MetaItem>}
148
+ {event.location && <Widget.MetaItem icon={MapPin}>{event.location}</Widget.MetaItem>}
149
+ </Widget.Meta>
150
+ </div>
151
+ </div>
152
+ )
153
+ }
154
+
155
+ function Rows({ events, locale }: { events: AgendaEvent[]; locale?: Intl.LocalesArgument }) {
156
+ return events.map(event => (
157
+ <Widget.Row
158
+ key={event.id}
159
+ leading={time(event.start, locale)}
160
+ color={event.color}
161
+ trailing={
162
+ event.meetingUrl ? (
163
+ <Video size={12} strokeWidth={1.5} aria-label="Video call" />
164
+ ) : (
165
+ event.location && <span className="max-w-24 truncate">{event.location}</span>
166
+ )
167
+ }
168
+ >
169
+ {event.title}
170
+ </Widget.Row>
171
+ ))
172
+ }
173
+
174
+ function More({ count }: { count: number }) {
175
+ if (count <= 0) return null
176
+ return <span className="flex h-6 items-center pl-17.5 text-caption text-muted-foreground">{count} more</span>
177
+ }
178
+
91
179
  interface PartProps {
92
180
  /** The event the activity counts down to. */
93
181
  event: AgendaEvent
@@ -98,11 +186,13 @@ function AgendaLeading({ event }: PartProps) {
98
186
  return <CalendarDays size={16} strokeWidth={1.5} style={{ color: event.color }} />
99
187
  }
100
188
 
101
- /** The compact island's right wing: the time until it starts, `4m` then `45s`. */
189
+ /** The compact island's right wing: the event's color dot and the time until it starts, `12m` then `45s`. */
102
190
  function AgendaTrailing({ event }: PartProps) {
191
+ const left = useUntil(event.start)
103
192
  return (
104
- <span className="text-caption weight-semibold" style={{ color: event.color }}>
105
- <Countdown endsAt={event.start} format="short" />
193
+ <span className="flex items-center gap-1 text-caption weight-semibold text-foreground tabular-nums">
194
+ <Dot color={event.color} className="size-1.5" />
195
+ {left > 0 ? formatShort(left / SECOND) : 'now'}
106
196
  </span>
107
197
  )
108
198
  }
@@ -112,18 +202,32 @@ interface MinimalProps extends PartProps {
112
202
  lead?: number
113
203
  }
114
204
 
115
- /** The split island's bubble: a ring that empties as the start nears. */
205
+ const RING = 2 * Math.PI * 8
206
+
207
+ /** The split island's bubble: a ring in the event's color that empties as the start nears. */
116
208
  function AgendaMinimal({ event, lead = 10 * MINUTE }: MinimalProps) {
117
209
  const left = Math.max(0, useUntil(event.start, SECOND))
210
+ const share = Math.min(1, left / lead)
118
211
  return (
119
- <Meter
120
- variant="ring"
121
- label={`${event.title}, in ${formatShort(left / SECOND)}`}
122
- value={Math.min(1, left / lead)}
123
- tone="default"
124
- animate={false}
125
- className="size-5.5"
126
- />
212
+ <svg
213
+ role="img"
214
+ aria-label={`${event.title}, in ${formatShort(left / SECOND)}`}
215
+ viewBox="0 0 20 20"
216
+ className="size-5.5 -rotate-90"
217
+ >
218
+ <circle cx="10" cy="10" r="8" fill="none" strokeWidth="2.5" className="stroke-current text-border" />
219
+ <circle
220
+ cx="10"
221
+ cy="10"
222
+ r="8"
223
+ fill="none"
224
+ strokeWidth="2.5"
225
+ strokeLinecap="round"
226
+ strokeDasharray={RING}
227
+ strokeDashoffset={RING * (1 - share)}
228
+ style={{ stroke: event.color }}
229
+ />
230
+ </svg>
127
231
  )
128
232
  }
129
233
 
@@ -134,197 +238,202 @@ interface ActivityProps extends PartProps {
134
238
  onJoin?: (event: AgendaEvent) => void
135
239
  }
136
240
 
137
- /** The open island's "Up next" view: how soon, the title, the time and place, and Join. */
241
+ /** The open island's "Up next" view: the next event alone, as the agenda's hero. */
138
242
  function AgendaUpNext({ event, locale, onJoin }: ActivityProps) {
139
- const left = useUntil(event.start)
243
+ const now = event.start - useUntil(event.start)
140
244
  return (
141
- <div className="flex size-full items-center gap-4">
142
- <span className="h-14 w-1 shrink-0 rounded-full" style={{ backgroundColor: event.color }} />
143
- <div className="flex min-w-0 flex-1 flex-col gap-1">
144
- <span className="text-caption weight-semibold tabular-nums" style={{ color: event.color }}>
145
- {relative(left)}
146
- </span>
147
- <span className="truncate text-title weight-semibold text-foreground">{event.title}</span>
148
- <span className="truncate text-body text-muted-foreground">{meta(event, locale)}</span>
149
- </div>
150
- {event.meetingUrl && <Join event={event} size="default" onJoin={onJoin} />}
151
- </div>
245
+ <Widget>
246
+ <Hero event={event} now={now} midnight={new Date(now).setHours(24, 0, 0, 0)} locale={locale} onJoin={onJoin} />
247
+ </Widget>
152
248
  )
153
249
  }
154
250
 
155
- /** The island's flash a minute before the start: the title, how soon, and Join. */
251
+ /** The island's flash a minute before the start: the calendar's color, the title, how soon and where, and Join. */
156
252
  function AgendaStarting({ event, onJoin }: Omit<ActivityProps, 'locale'>) {
157
253
  const left = useUntil(event.start, SECOND)
254
+ const when = left > 0 ? `Starts in ${formatShort(left / SECOND)}` : 'Starting now'
158
255
  return (
159
256
  <IslandFlash
160
- icon={<span className="size-2.5 rounded-full" style={{ backgroundColor: event.color }} />}
257
+ icon={
258
+ <span
259
+ className="flex size-9 items-center justify-center rounded-lg"
260
+ style={{ color: event.color, backgroundColor: `color-mix(in oklab, ${event.color} 22%, transparent)` }}
261
+ >
262
+ {event.meetingUrl ? <Video size={16} strokeWidth={1.5} /> : <CalendarDays size={16} strokeWidth={1.5} />}
263
+ </span>
264
+ }
161
265
  title={event.title}
162
- caption={relative(left)}
266
+ caption={event.location ? `${when} · ${event.location}` : when}
163
267
  action={event.meetingUrl && <Join event={event} size="compact" onJoin={onJoin} />}
164
268
  />
165
269
  )
166
270
  }
167
271
 
168
- function Row({
169
- event,
170
- locale,
171
- onJoin,
172
- }: {
173
- event: AgendaEvent
174
- locale?: Intl.LocalesArgument
175
- onJoin?: (event: AgendaEvent) => void
176
- }) {
177
- const size = useSize()
178
- return (
179
- <li className={cn('flex items-center gap-3', size.control)}>
180
- <span className="size-2 shrink-0 rounded-full" style={{ backgroundColor: event.color }} />
181
- <span className="w-16 shrink-0 whitespace-nowrap text-caption tabular-nums text-muted-foreground">
182
- {event.allDay ? 'All day' : clock(event.start, locale)}
183
- </span>
184
- <span className="flex min-w-0 flex-1 items-baseline gap-2">
185
- <span className="min-w-0 truncate text-body text-foreground">{event.title}</span>
186
- {event.location && !event.meetingUrl && (
187
- <span className="min-w-0 shrink-[100] truncate text-caption text-muted-foreground">{event.location}</span>
188
- )}
189
- </span>
190
- {event.meetingUrl && <Join event={event} size="compact" onJoin={onJoin} />}
191
- </li>
192
- )
193
- }
194
-
195
- interface DayProps {
196
- title: string
197
- events: AgendaEvent[]
198
- empty: string
199
- locale?: Intl.LocalesArgument
200
- onJoin?: (event: AgendaEvent) => void
201
- }
202
-
203
- function Day({ title, events, empty, locale, onJoin }: DayProps) {
204
- return (
205
- <section aria-label={title} className="flex min-w-0 flex-1 flex-col">
206
- <h3 className="m-0 flex h-5 items-center text-caption weight-normal text-muted-foreground">{title}</h3>
207
- {events.length === 0 ? (
208
- <p className="m-0 flex h-9 items-center text-body text-muted-foreground">{empty}</p>
209
- ) : (
210
- <ul className="m-0 flex list-none flex-col p-0">
211
- {events.map(event => (
212
- <Row key={event.id} event={event} locale={locale} onJoin={onJoin} />
213
- ))}
214
- </ul>
215
- )}
216
- </section>
217
- )
218
- }
219
-
220
272
  /**
221
- * A notch app's calendar: what's left of today and what's on tomorrow, side
222
- * by side.
273
+ * A notch app's calendar: the next event as the hero, the rest of today and
274
+ * tomorrow beside it.
275
+ *
276
+ * The hero is how soon the next event is, set large: `in 12 min` within the
277
+ * hour, `Now` with the time left while it runs, else its start time. Under
278
+ * it the title after its calendar's color, the time range, the place and
279
+ * whether it's a call, and a Join button when it has a `meetingUrl`. Today's
280
+ * all-day events are chips on the date line above. Beside it, past a
281
+ * hairline, the timeline: the rest of today as rows of start time, color
282
+ * mark and title, then tomorrow folded to its first event
283
+ * (`tomorrowOpen` / `onTomorrowOpenChange`, or kept here). Ended events drop
284
+ * off; `now` follows the clock on each minute unless you pin it.
223
285
  *
224
- * Each event is a row with its calendar's color as a dot, its start time (or
225
- * All day), its title and place, and a Join button when it has a video call.
226
- * Events that have ended drop off; the day boundary is read from `now`, which
227
- * follows the clock on each minute unless you pin it. Before the calendar may
228
- * be read it asks to connect (`access="undetermined"`), and when access is
229
- * off it points to the system's settings (`"denied"`).
286
+ * Before the calendar may be read it asks to connect
287
+ * (`access="undetermined"`), and when access is off it says where to turn it
288
+ * on (`"denied"`).
230
289
  *
231
290
  * The countdown to the next event is an activity of parts:
232
291
  * `Agenda.Leading` and `Agenda.Trailing` for the compact island's wings (the
233
- * glyph in the event's color, and `4m` that turns to seconds in the last
234
- * minute), `Agenda.Minimal`, a ring that empties toward the start, for the
235
- * split island's bubble, `Agenda.UpNext` for the open island and
236
- * `Agenda.Starting`, the flash a minute before. Each re-renders only on the
237
- * edge of the unit it shows.
292
+ * glyph in the event's color, and its dot with `12m` that turns to seconds
293
+ * in the last minute), `Agenda.Minimal`, a ring in its color that empties
294
+ * toward the start, for the split island's bubble, `Agenda.UpNext` for the
295
+ * open island and `Agenda.Starting`, the flash a minute before. Each
296
+ * re-renders only on the edge of the unit it shows.
238
297
  *
239
298
  * @example {@include ./examples.mdx}
240
299
  */
241
- function Agenda({
242
- events,
243
- access = 'granted',
244
- now: nowProp,
245
- locale,
246
- onRequestAccess,
247
- onOpenSettings,
248
- onJoin,
249
- className,
250
- }: AgendaProps) {
251
- const ticking = useEdgeClock(0, nowProp === undefined, MINUTE)
252
- const now = nowProp ?? ticking
300
+ const Agenda = Object.assign(
301
+ function Agenda({
302
+ events,
303
+ access = 'granted',
304
+ now: nowProp,
305
+ locale,
306
+ tomorrowOpen: tomorrowOpenProp,
307
+ defaultTomorrowOpen = false,
308
+ onTomorrowOpenChange,
309
+ onRequestAccess,
310
+ onOpenSettings,
311
+ onJoin,
312
+ className,
313
+ }: AgendaProps) {
314
+ const ticking = useEdgeClock(0, nowProp === undefined, MINUTE)
315
+ const now = nowProp ?? ticking
316
+ const [tomorrowOpen, setTomorrowOpen] = useControllableState(
317
+ tomorrowOpenProp,
318
+ defaultTomorrowOpen,
319
+ onTomorrowOpenChange,
320
+ )
253
321
 
254
- if (access === 'undetermined')
255
- return (
256
- <div className={cn('flex size-full items-center justify-center', className)}>
257
- <EmptyState
258
- size="compact"
322
+ if (access === 'undetermined')
323
+ return (
324
+ <Widget.Message
259
325
  icon={CalendarDays}
260
326
  title="See what's next"
261
- description="Today's and tomorrow's events, with a countdown before each one starts."
327
+ description="Your next event with a countdown, and the rest of today and tomorrow."
262
328
  actions={
263
329
  <Button variant="primary" size="compact" onClick={onRequestAccess}>
264
330
  Connect calendar
265
331
  </Button>
266
332
  }
333
+ className={className}
267
334
  />
268
- </div>
269
- )
335
+ )
270
336
 
271
- if (access === 'denied')
272
- return (
273
- <div className={cn('flex size-full items-center justify-center', className)}>
274
- <EmptyState
275
- size="compact"
276
- icon={CalendarDays}
337
+ if (access === 'denied')
338
+ return (
339
+ <Widget.Message
340
+ icon={Lock}
277
341
  title="Calendar access is off"
278
- description="Turn it on in Privacy & Security › Calendars."
342
+ description="Turn it on in System Settings › Privacy & Security › Calendars."
279
343
  actions={
280
344
  <Button variant="secondary" size="compact" onClick={onOpenSettings}>
281
345
  Open System Settings
282
346
  </Button>
283
347
  }
348
+ className={className}
284
349
  />
285
- </div>
286
- )
350
+ )
287
351
 
288
- const midnight = new Date(now).setHours(24, 0, 0, 0)
289
- const next = new Date(midnight).setHours(24, 0, 0, 0)
290
- const live = events.filter(event => event.end > now && event.start < next)
291
- if (live.length === 0)
292
- return (
293
- <div className={cn('flex size-full items-center justify-center', className)}>
294
- <EmptyState
295
- size="compact"
352
+ const midnight = new Date(now).setHours(24, 0, 0, 0)
353
+ const next = new Date(midnight).setHours(24, 0, 0, 0)
354
+ const live = events.filter(event => event.end > now && event.start < next).sort((a, b) => a.start - b.start)
355
+ const allDay = live.filter(event => event.allDay && event.start < midnight)
356
+ const timed = live.filter(event => !event.allDay)
357
+ const [hero] = timed
358
+
359
+ if (!hero)
360
+ return (
361
+ <Widget.Message
296
362
  icon={CalendarCheck}
297
- title="Nothing planned"
298
- description="No events for the rest of today or tomorrow."
363
+ title={allDay.length ? allDay.map(event => event.title).join(', ') : 'Nothing planned'}
364
+ description={
365
+ allDay.length ? 'All day today; nothing else on the calendar.' : 'No more events today or tomorrow.'
366
+ }
367
+ className={className}
299
368
  />
300
- </div>
301
- )
369
+ )
302
370
 
303
- return (
304
- <div className={cn('flex min-h-full gap-8', className)}>
305
- <Day
306
- title="Today"
307
- events={live.filter(event => event.start < midnight)}
308
- empty="Nothing else today"
309
- locale={locale}
310
- onJoin={onJoin}
311
- />
312
- <Day
313
- title="Tomorrow"
314
- events={live.filter(event => event.start >= midnight)}
315
- empty="Nothing planned"
316
- locale={locale}
317
- onJoin={onJoin}
318
- />
319
- </div>
320
- )
321
- }
371
+ const today = timed.filter(event => event !== hero && event.start < midnight)
372
+ const tomorrow = timed.filter(event => event !== hero && event.start >= midnight)
373
+ const tomorrowShown = tomorrowOpen ? tomorrow.slice(0, ROWS) : tomorrow.slice(0, 1)
374
+ const date = new Date(now).toLocaleDateString(locale, { weekday: 'long', month: 'long', day: 'numeric' })
322
375
 
323
- Agenda.Leading = AgendaLeading
324
- Agenda.Trailing = AgendaTrailing
325
- Agenda.Minimal = AgendaMinimal
326
- Agenda.UpNext = AgendaUpNext
327
- Agenda.Starting = AgendaStarting
376
+ return (
377
+ <Widget
378
+ className={className}
379
+ aside={
380
+ <>
381
+ <Widget.Section label="Later today">
382
+ {today.length ? (
383
+ <Rows events={today.slice(0, ROWS)} locale={locale} />
384
+ ) : (
385
+ <span className="flex h-7 items-center text-body text-muted-foreground">Nothing else today</span>
386
+ )}
387
+ <More count={today.length - ROWS} />
388
+ </Widget.Section>
389
+ {tomorrow.length > 0 && (
390
+ <Widget.Section
391
+ className="mt-1"
392
+ label="Tomorrow"
393
+ trailing={
394
+ tomorrow.length > 1 && (
395
+ <Button
396
+ variant="ghost"
397
+ size="compact"
398
+ className="-mr-2 h-6 px-2"
399
+ aria-expanded={tomorrowOpen}
400
+ trailingIcon={tomorrowOpen ? ChevronUp : ChevronDown}
401
+ onClick={() => setTomorrowOpen(!tomorrowOpen)}
402
+ >
403
+ {tomorrowOpen ? 'Less' : `${tomorrow.length - 1} more`}
404
+ </Button>
405
+ )
406
+ }
407
+ >
408
+ <Rows events={tomorrowShown} locale={locale} />
409
+ {tomorrowOpen && <More count={tomorrow.length - ROWS} />}
410
+ </Widget.Section>
411
+ )}
412
+ </>
413
+ }
414
+ >
415
+ <Widget.Header
416
+ icon={CalendarDays}
417
+ trailing={allDay.map(event => (
418
+ <Widget.Chip key={event.id} color={event.color}>
419
+ {event.title}
420
+ </Widget.Chip>
421
+ ))}
422
+ >
423
+ {date}
424
+ </Widget.Header>
425
+ <Hero event={hero} now={now} midnight={midnight} locale={locale} onJoin={onJoin} />
426
+ </Widget>
427
+ )
428
+ },
429
+ {
430
+ Leading: AgendaLeading,
431
+ Trailing: AgendaTrailing,
432
+ Minimal: AgendaMinimal,
433
+ UpNext: AgendaUpNext,
434
+ Starting: AgendaStarting,
435
+ },
436
+ )
328
437
 
329
438
  export default Agenda
330
439
 
@@ -0,0 +1,73 @@
1
+ import Clock from './index'
2
+ import { WidgetIsland } from '../../../mock/island-content'
3
+ import { CLOCK_NOW, ClockSplit, ClockWings, FocusClock, PausedBreak, PhaseDoneFlash, ZONES } from '../../../mock/clock'
4
+
5
+ # Clock
6
+
7
+ The time as the hero, the date above it and the time zone under it, the Pomodoro waiting with its lengths; beside it the world clocks, each with how far it is, day or night, and Tomorrow when its date differs.
8
+
9
+ <WidgetIsland tab="clock">
10
+ <Clock zones={ZONES} now={CLOCK_NOW} />
11
+ </WidgetIsland>
12
+
13
+ # 24 hours, with seconds
14
+
15
+ `hour12={false}` and `seconds`: the seconds tick muted, on each second's edge.
16
+
17
+ <WidgetIsland tab="clock">
18
+ <Clock zones={ZONES} hour12={false} seconds pomodoro={{ focus: 50, shortBreak: 10, longBreak: 30, rounds: 3 }} />
19
+ </WidgetIsland>
20
+
21
+ # Focus
22
+
23
+ A run takes the widget over: the ring in the phase's hue, the time left, the round, when it ends and what's next, and the next phases with their start times. Pause, skip, +1 min or reset it.
24
+
25
+ <WidgetIsland tab="clock">
26
+ <FocusClock />
27
+ </WidgetIsland>
28
+
29
+ # A break, paused
30
+
31
+ A paused phase keeps the time it had left and says so.
32
+
33
+ <WidgetIsland tab="clock">
34
+ <PausedBreak />
35
+ </WidgetIsland>
36
+
37
+ # Ready to start
38
+
39
+ `Start focus` begins the first round; at a phase's end the next one waits here, paused at its whole length.
40
+
41
+ <WidgetIsland tab="clock">
42
+ <Clock zones={ZONES} now={CLOCK_NOW} defaultValue={{ phase: 'long-break', round: 4, total: 15 * 60_000, remaining: 15 * 60_000 }} />
43
+ </WidgetIsland>
44
+
45
+ # Clock only
46
+
47
+ `pomodoro={false}` leaves the Pomodoro out.
48
+
49
+ <WidgetIsland tab="clock">
50
+ <Clock zones={ZONES.slice(0, 2)} now={CLOCK_NOW} pomodoro={false} />
51
+ </WidgetIsland>
52
+
53
+ # Compact
54
+
55
+ `Clock.Leading` and `Clock.Trailing` in the wings while a phase runs: the ring and the time left. Without a run they show nothing.
56
+
57
+ <ClockWings />
58
+
59
+ # Minimal
60
+
61
+ `Clock.Minimal`, the ring, in the split island's bubble.
62
+
63
+ <ClockSplit />
64
+
65
+ # Focus done
66
+
67
+ `Clock.PhaseDone` at the end of a focus round, with a button to start the break.
68
+
69
+ <PhaseDoneFlash ended={{ phase: 'focus', round: 2 }} />
70
+
71
+ # Break over
72
+
73
+ <PhaseDoneFlash ended={{ phase: 'short-break', round: 2 }} />