@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.
Files changed (148) hide show
  1. package/README.md +11 -11
  2. package/blocks/activities/agenda/examples.mdx +29 -5
  3. package/blocks/activities/agenda/index.tsx +438 -181
  4. package/blocks/activities/clock/examples.mdx +89 -0
  5. package/blocks/activities/clock/index.tsx +917 -0
  6. package/blocks/activities/now-playing/examples.mdx +40 -13
  7. package/blocks/activities/now-playing/index.tsx +399 -120
  8. package/blocks/activities/weather/examples.mdx +123 -0
  9. package/blocks/activities/weather/index.tsx +863 -0
  10. package/blocks/app/expanded-island/examples.mdx +8 -7
  11. package/blocks/app/expanded-island/index.tsx +22 -4
  12. package/blocks/app/settings-window/examples.mdx +14 -2
  13. package/blocks/app/settings-window/index.tsx +33 -10
  14. package/blocks/system/clipboard/examples.mdx +91 -0
  15. package/blocks/system/clipboard/index.tsx +773 -0
  16. package/blocks/system/recent-files/examples.mdx +80 -0
  17. package/blocks/system/recent-files/index.tsx +627 -0
  18. package/blocks/system/system-stats/examples.mdx +46 -9
  19. package/blocks/system/system-stats/index.tsx +445 -104
  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 +465 -0
  29. package/dist/blocks/activities/agenda/index.d.ts +2 -1
  30. package/dist/blocks/activities/agenda/index.js +3 -3
  31. package/dist/blocks/activities/clock/index.d.ts +3 -0
  32. package/dist/blocks/activities/clock/index.js +25 -0
  33. package/dist/blocks/activities/now-playing/index.d.ts +4 -2
  34. package/dist/blocks/activities/now-playing/index.js +5 -3
  35. package/dist/blocks/activities/weather/index.d.ts +3 -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 +3 -0
  42. package/dist/blocks/system/clipboard/index.js +17 -0
  43. package/dist/blocks/system/recent-files/index.d.ts +3 -0
  44. package/dist/blocks/system/recent-files/index.js +19 -0
  45. package/dist/blocks/system/system-stats/index.d.ts +3 -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 +32 -0
  56. package/dist/index.d.ts +15 -15
  57. package/dist/index.js +104 -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-yngkkxz2.d.ts → chunk-0ym9mcqc.d.ts} +10 -6
  62. package/dist/shared/chunk-2b6gpn8k.js +444 -0
  63. package/dist/shared/chunk-3hcnf4yx.js +481 -0
  64. package/dist/shared/chunk-42wab62s.d.ts +197 -0
  65. package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
  66. package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-6tnq6p89.d.ts} +9 -1
  67. package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
  68. package/dist/shared/chunk-93dtpjz7.js +789 -0
  69. package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
  70. package/dist/shared/chunk-a6njb8db.d.ts +129 -0
  71. package/dist/shared/chunk-ab8mdg0n.d.ts +149 -0
  72. package/dist/shared/chunk-evqpf92s.d.ts +168 -0
  73. package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
  74. package/dist/shared/chunk-gcyspvgr.js +582 -0
  75. package/dist/shared/chunk-gejenfap.d.ts +25 -0
  76. package/dist/shared/chunk-gkj0hjrn.d.ts +136 -0
  77. package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
  78. package/dist/shared/chunk-n739am8j.d.ts +112 -0
  79. package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
  80. package/dist/shared/chunk-nwzpekvy.js +774 -0
  81. package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
  82. package/dist/shared/chunk-sbrtesdg.d.ts +138 -0
  83. package/dist/shared/chunk-swc7dqpw.d.ts +115 -0
  84. package/dist/shared/chunk-t9wqhgzt.js +765 -0
  85. package/dist/shared/chunk-w5h6ay93.js +72 -0
  86. package/dist/shared/{chunk-mp1nx0ez.js → chunk-wayv5rhr.js} +15 -4
  87. package/dist/shared/chunk-wf0jtzhs.js +295 -0
  88. package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
  89. package/dist/shared/chunk-yq5svpk7.js +524 -0
  90. package/dist/shared/{chunk-s33y1pcq.js → chunk-z3tj1ydg.js} +23 -10
  91. package/dist/styles.css +151 -49
  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 +113 -0
  98. package/mock/clock.tsx +77 -0
  99. package/mock/data.ts +78 -44
  100. package/mock/files.tsx +83 -0
  101. package/mock/island-content.tsx +79 -122
  102. package/mock/screen.tsx +76 -0
  103. package/mock/settings.tsx +370 -91
  104. package/mock/system.ts +49 -0
  105. package/mock/weather.tsx +135 -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, { type WidgetLayout } 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,74 @@ 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, and at the tall snap by every call's. */
51
57
  onJoin?: (event: AgendaEvent) => void
58
+ /** `tall` is the open island's tall snap: the next event as the hero, then today and tomorrow listed in full, each event with its times, place or call and Join, then the rest of the week by day. Defaults to `'fit'`. */
59
+ layout?: WidgetLayout
52
60
  /** Classes for the root, which fills its container. */
53
61
  className?: string
54
62
  }
55
63
 
56
- const clock = (ms: number, locale?: Intl.LocalesArgument) =>
64
+ /** Rows the timeline lists per day before it says how many more. */
65
+ const ROWS = 3
66
+ /** Days the tall layout lists, today included. */
67
+ const WEEK = 7
68
+
69
+ const addDays = (ms: number, days: number) => {
70
+ const date = new Date(ms)
71
+ date.setDate(date.getDate() + days)
72
+ return date.getTime()
73
+ }
74
+
75
+ /** Whether an event covers any of the day from `start` to `end`. */
76
+ const covers = (event: AgendaEvent, start: number, end: number) => event.start < end && event.end > start
77
+
78
+ const time = (ms: number, locale?: Intl.LocalesArgument) =>
57
79
  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`
80
+
81
+ /** A time split into its figure and its day period: `4:00` and `PM`, or `16:00` alone. */
82
+ function timeParts(ms: number, locale?: Intl.LocalesArgument) {
83
+ const parts = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: '2-digit' }).formatToParts(ms)
84
+ const period = parts.find(part => part.type === 'dayPeriod')?.value
85
+ const value = parts
86
+ .filter(part => part.type !== 'dayPeriod')
87
+ .map(part => part.value)
88
+ .join('')
89
+ .trim()
90
+ return { value, period }
91
+ }
92
+
93
+ const range = (event: AgendaEvent, locale?: Intl.LocalesArgument) =>
94
+ `${time(event.start, locale)} – ${time(event.end, locale)}`
95
+
96
+ function length(ms: number) {
97
+ const minutes = Math.round(ms / MINUTE)
98
+ if (minutes < 60) return `${minutes} min`
99
+ const hours = Math.floor(minutes / 60)
100
+ return minutes % 60 ? `${hours} h ${minutes % 60} min` : `${hours} h`
67
101
  }
68
102
 
69
103
  /** The time until `start`, re-read on each `unit` edge before it, never in between. */
@@ -72,6 +106,12 @@ function useUntil(start: number, unit = MINUTE) {
72
106
  return start - now
73
107
  }
74
108
 
109
+ function Dot({ color, className }: { color: string; className?: string }) {
110
+ return (
111
+ <span aria-hidden className={cn('size-2.5 shrink-0 rounded-full', className)} style={{ backgroundColor: color }} />
112
+ )
113
+ }
114
+
75
115
  function Join({
76
116
  event,
77
117
  size,
@@ -82,12 +122,148 @@ function Join({
82
122
  onJoin?: (event: AgendaEvent) => void
83
123
  }) {
84
124
  return (
85
- <Button variant="secondary" size={size} leadingIcon={Video} onClick={() => onJoin?.(event)}>
125
+ <Button variant="primary" size={size} leadingIcon={Video} onClick={() => onJoin?.(event)}>
86
126
  Join
87
127
  </Button>
88
128
  )
89
129
  }
90
130
 
131
+ interface HeroProps {
132
+ event: AgendaEvent
133
+ now: number
134
+ midnight: number
135
+ locale?: Intl.LocalesArgument
136
+ onJoin?: (event: AgendaEvent) => void
137
+ }
138
+
139
+ /** How soon, as the figure: `in 12 min` within the hour, `Now` while on, else the start time. */
140
+ function When({ event, now, midnight, locale }: Omit<HeroProps, 'onJoin'>) {
141
+ if (event.start <= now) return <Widget.Figure value="Now" unit={`${length(event.end - now)} left`} />
142
+ if (event.start - now < 60 * MINUTE)
143
+ return <Widget.Figure prefix="in" value={Math.max(1, Math.ceil((event.start - now) / MINUTE))} unit="min" />
144
+ const { value, period } = timeParts(event.start, locale)
145
+ const prefix =
146
+ event.start >= addDays(midnight, 1)
147
+ ? new Date(event.start).toLocaleDateString(locale, { weekday: 'long' })
148
+ : event.start >= midnight
149
+ ? 'Tomorrow'
150
+ : 'at'
151
+ return <Widget.Figure prefix={prefix} value={value} unit={period} />
152
+ }
153
+
154
+ /** The next event, set as the widget's hero: how soon, its title in its calendar's color, when and where, and Join. */
155
+ function Hero({ event, now, midnight, locale, onJoin }: HeroProps) {
156
+ return (
157
+ <div className="flex min-w-0 flex-col gap-1.5">
158
+ <div className="flex min-w-0 items-end justify-between gap-3">
159
+ <When event={event} now={now} midnight={midnight} locale={locale} />
160
+ {event.meetingUrl && <Join event={event} size="compact" onJoin={onJoin} />}
161
+ </div>
162
+ <div className="flex min-w-0 flex-col gap-0.5">
163
+ <Widget.Title leading={<Dot color={event.color} />}>{event.title}</Widget.Title>
164
+ <Widget.Meta className="pl-4.5">
165
+ <Widget.MetaItem icon={Clock}>{range(event, locale)}</Widget.MetaItem>
166
+ {event.meetingUrl && <Widget.MetaItem icon={Video}>Video call</Widget.MetaItem>}
167
+ {event.location && <Widget.MetaItem icon={MapPin}>{event.location}</Widget.MetaItem>}
168
+ </Widget.Meta>
169
+ </div>
170
+ </div>
171
+ )
172
+ }
173
+
174
+ function Rows({ events, locale }: { events: AgendaEvent[]; locale?: Intl.LocalesArgument }) {
175
+ return events.map(event => (
176
+ <Widget.Row
177
+ key={event.id}
178
+ leading={time(event.start, locale)}
179
+ color={event.color}
180
+ trailing={
181
+ event.meetingUrl ? (
182
+ <Video size={12} strokeWidth={1.5} aria-label="Video call" />
183
+ ) : (
184
+ event.location && <span className="max-w-24 truncate">{event.location}</span>
185
+ )
186
+ }
187
+ >
188
+ {event.title}
189
+ </Widget.Row>
190
+ ))
191
+ }
192
+
193
+ interface EntryProps {
194
+ event: AgendaEvent
195
+ locale?: Intl.LocalesArgument
196
+ onJoin?: (event: AgendaEvent) => void
197
+ }
198
+
199
+ /** An event in the tall layout's list: its start over its end, its calendar's mark, the title over how long and where, and Join for a call. */
200
+ function Entry({ event, locale, onJoin }: EntryProps) {
201
+ return (
202
+ <div className="flex min-w-0 items-center gap-2.5 py-1.5">
203
+ <span className="flex w-15 shrink-0 flex-col whitespace-nowrap text-caption tabular-nums">
204
+ <span className="text-foreground">{time(event.start, locale)}</span>
205
+ <span className="text-muted-foreground">{time(event.end, locale)}</span>
206
+ </span>
207
+ <span
208
+ aria-hidden
209
+ className="w-0.75 shrink-0 self-stretch rounded-full"
210
+ style={{ backgroundColor: event.color }}
211
+ />
212
+ <span className="flex min-w-0 flex-1 flex-col">
213
+ <span className="truncate text-body text-foreground">{event.title}</span>
214
+ <Widget.Meta>
215
+ <Widget.MetaItem icon={Clock}>{length(event.end - event.start)}</Widget.MetaItem>
216
+ {event.meetingUrl && <Widget.MetaItem icon={Video}>Video call</Widget.MetaItem>}
217
+ {event.location && <Widget.MetaItem icon={MapPin}>{event.location}</Widget.MetaItem>}
218
+ </Widget.Meta>
219
+ </span>
220
+ {event.meetingUrl && (
221
+ <Button variant="secondary" size="compact" leadingIcon={Video} onClick={() => onJoin?.(event)}>
222
+ Join
223
+ </Button>
224
+ )}
225
+ </div>
226
+ )
227
+ }
228
+
229
+ interface DayProps {
230
+ label: string
231
+ /** The day's timed events, in order. */
232
+ events: AgendaEvent[]
233
+ /** The day's all-day events: chips on the label's line. */
234
+ allDay?: AgendaEvent[]
235
+ /** What to say when the day has no timed events. */
236
+ empty?: string
237
+ locale?: Intl.LocalesArgument
238
+ onJoin?: (event: AgendaEvent) => void
239
+ }
240
+
241
+ /** A day of the tall layout's list: its name with its all-day chips, then its events. */
242
+ function Day({ label, events, allDay = [], empty, locale, onJoin }: DayProps) {
243
+ return (
244
+ <Widget.Section
245
+ label={label}
246
+ trailing={allDay.map(event => (
247
+ <Widget.Chip key={event.id} color={event.color}>
248
+ {event.title}
249
+ </Widget.Chip>
250
+ ))}
251
+ >
252
+ {events.map(event => (
253
+ <Entry key={event.id} event={event} locale={locale} onJoin={onJoin} />
254
+ ))}
255
+ {!events.length && empty && (
256
+ <span className="flex h-7 items-center text-body text-muted-foreground">{empty}</span>
257
+ )}
258
+ </Widget.Section>
259
+ )
260
+ }
261
+
262
+ function More({ count }: { count: number }) {
263
+ if (count <= 0) return null
264
+ return <span className="flex h-6 items-center pl-17.5 text-caption text-muted-foreground">{count} more</span>
265
+ }
266
+
91
267
  interface PartProps {
92
268
  /** The event the activity counts down to. */
93
269
  event: AgendaEvent
@@ -98,11 +274,13 @@ function AgendaLeading({ event }: PartProps) {
98
274
  return <CalendarDays size={16} strokeWidth={1.5} style={{ color: event.color }} />
99
275
  }
100
276
 
101
- /** The compact island's right wing: the time until it starts, `4m` then `45s`. */
277
+ /** The compact island's right wing: the event's color dot and the time until it starts, `12m` then `45s`. */
102
278
  function AgendaTrailing({ event }: PartProps) {
279
+ const left = useUntil(event.start)
103
280
  return (
104
- <span className="text-caption weight-semibold" style={{ color: event.color }}>
105
- <Countdown endsAt={event.start} format="short" />
281
+ <span className="flex items-center gap-1 text-caption weight-semibold text-foreground tabular-nums">
282
+ <Dot color={event.color} className="size-1.5" />
283
+ {left > 0 ? formatShort(left / SECOND) : 'now'}
106
284
  </span>
107
285
  )
108
286
  }
@@ -112,18 +290,32 @@ interface MinimalProps extends PartProps {
112
290
  lead?: number
113
291
  }
114
292
 
115
- /** The split island's bubble: a ring that empties as the start nears. */
293
+ const RING = 2 * Math.PI * 8
294
+
295
+ /** The split island's bubble: a ring in the event's color that empties as the start nears. */
116
296
  function AgendaMinimal({ event, lead = 10 * MINUTE }: MinimalProps) {
117
297
  const left = Math.max(0, useUntil(event.start, SECOND))
298
+ const share = Math.min(1, left / lead)
118
299
  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
- />
300
+ <svg
301
+ role="img"
302
+ aria-label={`${event.title}, in ${formatShort(left / SECOND)}`}
303
+ viewBox="0 0 20 20"
304
+ className="size-5.5 -rotate-90"
305
+ >
306
+ <circle cx="10" cy="10" r="8" fill="none" strokeWidth="2.5" className="stroke-current text-border" />
307
+ <circle
308
+ cx="10"
309
+ cy="10"
310
+ r="8"
311
+ fill="none"
312
+ strokeWidth="2.5"
313
+ strokeLinecap="round"
314
+ strokeDasharray={RING}
315
+ strokeDashoffset={RING * (1 - share)}
316
+ style={{ stroke: event.color }}
317
+ />
318
+ </svg>
127
319
  )
128
320
  }
129
321
 
@@ -134,197 +326,262 @@ interface ActivityProps extends PartProps {
134
326
  onJoin?: (event: AgendaEvent) => void
135
327
  }
136
328
 
137
- /** The open island's "Up next" view: how soon, the title, the time and place, and Join. */
329
+ /** The open island's "Up next" view: the next event alone, as the agenda's hero. */
138
330
  function AgendaUpNext({ event, locale, onJoin }: ActivityProps) {
139
- const left = useUntil(event.start)
331
+ const now = event.start - useUntil(event.start)
140
332
  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>
333
+ <Widget>
334
+ <Hero event={event} now={now} midnight={new Date(now).setHours(24, 0, 0, 0)} locale={locale} onJoin={onJoin} />
335
+ </Widget>
152
336
  )
153
337
  }
154
338
 
155
- /** The island's flash a minute before the start: the title, how soon, and Join. */
339
+ /** The island's flash a minute before the start: the calendar's color, the title, how soon and where, and Join. */
156
340
  function AgendaStarting({ event, onJoin }: Omit<ActivityProps, 'locale'>) {
157
341
  const left = useUntil(event.start, SECOND)
342
+ const when = left > 0 ? `Starts in ${formatShort(left / SECOND)}` : 'Starting now'
158
343
  return (
159
344
  <IslandFlash
160
- icon={<span className="size-2.5 rounded-full" style={{ backgroundColor: event.color }} />}
345
+ icon={
346
+ <span
347
+ className="flex size-9 items-center justify-center rounded-lg"
348
+ style={{ color: event.color, backgroundColor: `color-mix(in oklab, ${event.color} 22%, transparent)` }}
349
+ >
350
+ {event.meetingUrl ? <Video size={16} strokeWidth={1.5} /> : <CalendarDays size={16} strokeWidth={1.5} />}
351
+ </span>
352
+ }
161
353
  title={event.title}
162
- caption={relative(left)}
354
+ caption={event.location ? `${when} · ${event.location}` : when}
163
355
  action={event.meetingUrl && <Join event={event} size="compact" onJoin={onJoin} />}
164
356
  />
165
357
  )
166
358
  }
167
359
 
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
360
  /**
221
- * A notch app's calendar: what's left of today and what's on tomorrow, side
222
- * by side.
361
+ * A notch app's calendar: the next event as the hero, the rest of today and
362
+ * tomorrow beside it.
363
+ *
364
+ * The hero is how soon the next event is, set large: `in 12 min` within the
365
+ * hour, `Now` with the time left while it runs, else its start time. Under
366
+ * it the title after its calendar's color, the time range, the place and
367
+ * whether it's a call, and a Join button when it has a `meetingUrl`. Today's
368
+ * all-day events are chips on the date line above. Beside it, past a
369
+ * hairline, the timeline: the rest of today as rows of start time, color
370
+ * mark and title, then tomorrow folded to its first event
371
+ * (`tomorrowOpen` / `onTomorrowOpenChange`, or kept here). Ended events drop
372
+ * off; `now` follows the clock on each minute unless you pin it.
223
373
  *
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"`).
374
+ * At the open island's tall snap (`layout="tall"`) it becomes a sheet: the
375
+ * date and the hero as above, then the rest of today and all of tomorrow
376
+ * listed in full, each event with its start over its end, its calendar's
377
+ * mark, the title over how long it runs and where (or that it's a call),
378
+ * and Join for every call; then the rest of the week, a section per day
379
+ * with events, named by its weekday and date, its all-day events as chips
380
+ * on the name's line.
381
+ *
382
+ * Before the calendar may be read it asks to connect
383
+ * (`access="undetermined"`), and when access is off it says where to turn it
384
+ * on (`"denied"`).
230
385
  *
231
386
  * The countdown to the next event is an activity of parts:
232
387
  * `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.
388
+ * glyph in the event's color, and its dot with `12m` that turns to seconds
389
+ * in the last minute), `Agenda.Minimal`, a ring in its color that empties
390
+ * toward the start, for the split island's bubble, `Agenda.UpNext` for the
391
+ * open island and `Agenda.Starting`, the flash a minute before. Each
392
+ * re-renders only on the edge of the unit it shows.
238
393
  *
239
394
  * @example {@include ./examples.mdx}
240
395
  */
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
396
+ const Agenda = Object.assign(
397
+ function Agenda({
398
+ events,
399
+ access = 'granted',
400
+ now: nowProp,
401
+ locale,
402
+ tomorrowOpen: tomorrowOpenProp,
403
+ defaultTomorrowOpen = false,
404
+ onTomorrowOpenChange,
405
+ onRequestAccess,
406
+ onOpenSettings,
407
+ onJoin,
408
+ layout = 'fit',
409
+ className,
410
+ }: AgendaProps) {
411
+ const ticking = useEdgeClock(0, nowProp === undefined, MINUTE)
412
+ const now = nowProp ?? ticking
413
+ const [tomorrowOpen, setTomorrowOpen] = useControllableState(
414
+ tomorrowOpenProp,
415
+ defaultTomorrowOpen,
416
+ onTomorrowOpenChange,
417
+ )
253
418
 
254
- if (access === 'undetermined')
255
- return (
256
- <div className={cn('flex size-full items-center justify-center', className)}>
257
- <EmptyState
258
- size="compact"
419
+ if (access === 'undetermined')
420
+ return (
421
+ <Widget.Message
259
422
  icon={CalendarDays}
260
423
  title="See what's next"
261
- description="Today's and tomorrow's events, with a countdown before each one starts."
424
+ description="Your next event with a countdown, and the rest of today and tomorrow."
262
425
  actions={
263
426
  <Button variant="primary" size="compact" onClick={onRequestAccess}>
264
427
  Connect calendar
265
428
  </Button>
266
429
  }
430
+ className={className}
267
431
  />
268
- </div>
269
- )
432
+ )
270
433
 
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}
434
+ if (access === 'denied')
435
+ return (
436
+ <Widget.Message
437
+ icon={Lock}
277
438
  title="Calendar access is off"
278
- description="Turn it on in Privacy & Security › Calendars."
439
+ description="Turn it on in System Settings › Privacy & Security › Calendars."
279
440
  actions={
280
441
  <Button variant="secondary" size="compact" onClick={onOpenSettings}>
281
442
  Open System Settings
282
443
  </Button>
283
444
  }
445
+ className={className}
284
446
  />
285
- </div>
286
- )
447
+ )
287
448
 
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"
449
+ const midnight = new Date(now).setHours(24, 0, 0, 0)
450
+ const next = new Date(midnight).setHours(24, 0, 0, 0)
451
+ const until = layout === 'tall' ? addDays(midnight, WEEK - 1) : next
452
+ const live = events.filter(event => event.end > now && event.start < until).sort((a, b) => a.start - b.start)
453
+ const allDay = live.filter(event => event.allDay && event.start < midnight)
454
+ const timed = live.filter(event => !event.allDay)
455
+ const [hero] = timed
456
+
457
+ if (!hero)
458
+ return (
459
+ <Widget.Message
296
460
  icon={CalendarCheck}
297
- title="Nothing planned"
298
- description="No events for the rest of today or tomorrow."
461
+ title={allDay.length ? allDay.map(event => event.title).join(', ') : 'Nothing planned'}
462
+ description={
463
+ allDay.length ? 'All day today; nothing else on the calendar.' : 'No more events today or tomorrow.'
464
+ }
465
+ className={className}
299
466
  />
300
- </div>
467
+ )
468
+
469
+ const today = timed.filter(event => event !== hero && event.start < midnight)
470
+ const tomorrow = timed.filter(event => event !== hero && event.start >= midnight && event.start < next)
471
+ const tomorrowShown = tomorrowOpen ? tomorrow.slice(0, ROWS) : tomorrow.slice(0, 1)
472
+ const date = new Date(now).toLocaleDateString(locale, { weekday: 'long', month: 'long', day: 'numeric' })
473
+ const header = (
474
+ <Widget.Header
475
+ icon={CalendarDays}
476
+ trailing={allDay.map(event => (
477
+ <Widget.Chip key={event.id} color={event.color}>
478
+ {event.title}
479
+ </Widget.Chip>
480
+ ))}
481
+ >
482
+ {date}
483
+ </Widget.Header>
301
484
  )
485
+ const heroBlock = <Hero event={hero} now={now} midnight={midnight} locale={locale} onJoin={onJoin} />
302
486
 
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
- }
487
+ if (layout === 'tall') {
488
+ const later = Array.from({ length: WEEK - 2 }, (_, i) => {
489
+ const start = addDays(next, i)
490
+ const end = addDays(next, i + 1)
491
+ return {
492
+ start,
493
+ events: timed.filter(event => event !== hero && event.start >= start && event.start < end),
494
+ allDay: live.filter(event => event.allDay && covers(event, start, end)),
495
+ }
496
+ }).filter(day => day.events.length || day.allDay.length)
497
+ return (
498
+ <Widget.Sheet className={className}>
499
+ <div className="flex min-w-0 flex-col gap-2">
500
+ {header}
501
+ {heroBlock}
502
+ </div>
322
503
 
323
- Agenda.Leading = AgendaLeading
324
- Agenda.Trailing = AgendaTrailing
325
- Agenda.Minimal = AgendaMinimal
326
- Agenda.UpNext = AgendaUpNext
327
- Agenda.Starting = AgendaStarting
504
+ <div className="flex min-w-0 flex-col gap-3">
505
+ <Day label="Later today" events={today} empty="Nothing else today" locale={locale} onJoin={onJoin} />
506
+ <Day
507
+ label="Tomorrow"
508
+ events={tomorrow}
509
+ allDay={live.filter(event => event.allDay && covers(event, midnight, next))}
510
+ empty="Nothing planned"
511
+ locale={locale}
512
+ onJoin={onJoin}
513
+ />
514
+ {later.map(day => (
515
+ <Day
516
+ key={day.start}
517
+ label={new Date(day.start).toLocaleDateString(locale, {
518
+ weekday: 'long',
519
+ month: 'long',
520
+ day: 'numeric',
521
+ })}
522
+ events={day.events}
523
+ allDay={day.allDay}
524
+ locale={locale}
525
+ onJoin={onJoin}
526
+ />
527
+ ))}
528
+ </div>
529
+ </Widget.Sheet>
530
+ )
531
+ }
532
+
533
+ return (
534
+ <Widget
535
+ className={className}
536
+ aside={
537
+ <>
538
+ <Widget.Section label="Later today">
539
+ {today.length ? (
540
+ <Rows events={today.slice(0, ROWS)} locale={locale} />
541
+ ) : (
542
+ <span className="flex h-7 items-center text-body text-muted-foreground">Nothing else today</span>
543
+ )}
544
+ <More count={today.length - ROWS} />
545
+ </Widget.Section>
546
+ {tomorrow.length > 0 && (
547
+ <Widget.Section
548
+ className="mt-1"
549
+ label="Tomorrow"
550
+ trailing={
551
+ tomorrow.length > 1 && (
552
+ <Button
553
+ variant="ghost"
554
+ size="compact"
555
+ className="-mr-2 h-6 px-2"
556
+ aria-expanded={tomorrowOpen}
557
+ trailingIcon={tomorrowOpen ? ChevronUp : ChevronDown}
558
+ onClick={() => setTomorrowOpen(!tomorrowOpen)}
559
+ >
560
+ {tomorrowOpen ? 'Less' : `${tomorrow.length - 1} more`}
561
+ </Button>
562
+ )
563
+ }
564
+ >
565
+ <Rows events={tomorrowShown} locale={locale} />
566
+ {tomorrowOpen && <More count={tomorrow.length - ROWS} />}
567
+ </Widget.Section>
568
+ )}
569
+ </>
570
+ }
571
+ >
572
+ {header}
573
+ {heroBlock}
574
+ </Widget>
575
+ )
576
+ },
577
+ {
578
+ Leading: AgendaLeading,
579
+ Trailing: AgendaTrailing,
580
+ Minimal: AgendaMinimal,
581
+ UpNext: AgendaUpNext,
582
+ Starting: AgendaStarting,
583
+ },
584
+ )
328
585
 
329
586
  export default Agenda
330
587