@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.
- package/README.md +11 -11
- package/blocks/activities/agenda/examples.mdx +21 -5
- package/blocks/activities/agenda/index.tsx +291 -182
- package/blocks/activities/clock/examples.mdx +73 -0
- package/blocks/activities/clock/index.tsx +619 -0
- package/blocks/activities/now-playing/examples.mdx +32 -13
- package/blocks/activities/now-playing/index.tsx +319 -126
- package/blocks/activities/weather/examples.mdx +115 -0
- package/blocks/activities/weather/index.tsx +634 -0
- package/blocks/app/expanded-island/examples.mdx +8 -7
- package/blocks/app/expanded-island/index.tsx +19 -3
- package/blocks/app/settings-window/examples.mdx +6 -2
- package/blocks/app/settings-window/index.tsx +25 -7
- package/blocks/system/clipboard/examples.mdx +83 -0
- package/blocks/system/clipboard/index.tsx +563 -0
- package/blocks/system/recent-files/examples.mdx +66 -0
- package/blocks/system/recent-files/index.tsx +542 -0
- package/blocks/system/system-stats/examples.mdx +38 -9
- package/blocks/system/system-stats/index.tsx +241 -107
- 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 +431 -0
- package/dist/blocks/activities/agenda/index.d.ts +1 -1
- package/dist/blocks/activities/agenda/index.js +3 -3
- package/dist/blocks/activities/clock/index.d.ts +2 -0
- package/dist/blocks/activities/clock/index.js +25 -0
- package/dist/blocks/activities/now-playing/index.d.ts +3 -2
- package/dist/blocks/activities/now-playing/index.js +5 -3
- package/dist/blocks/activities/weather/index.d.ts +2 -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 +2 -0
- package/dist/blocks/system/clipboard/index.js +17 -0
- package/dist/blocks/system/recent-files/index.d.ts +2 -0
- package/dist/blocks/system/recent-files/index.js +19 -0
- package/dist/blocks/system/system-stats/index.d.ts +2 -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 +30 -0
- package/dist/index.d.ts +15 -15
- package/dist/index.js +102 -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-2818esrq.d.ts +140 -0
- package/dist/shared/{chunk-yngkkxz2.d.ts → chunk-2m5dz8nf.d.ts} +4 -4
- package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
- package/dist/shared/chunk-416tsgbc.d.ts +175 -0
- package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
- package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
- package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
- package/dist/shared/chunk-9c7ewvkk.js +381 -0
- package/dist/shared/{chunk-mp1nx0ez.js → chunk-9m0xbg5v.js} +14 -3
- package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
- package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
- package/dist/shared/{chunk-s33y1pcq.js → chunk-cc9nwbtf.js} +20 -10
- package/dist/shared/chunk-da177e8r.d.ts +114 -0
- package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
- package/dist/shared/chunk-j77cx8dp.js +498 -0
- package/dist/shared/chunk-mt0k6v8x.js +474 -0
- package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
- package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-pfhy5e4q.d.ts} +7 -1
- package/dist/shared/chunk-qdzemt2v.js +477 -0
- package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
- package/dist/shared/chunk-s2jeqqan.js +243 -0
- package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
- package/dist/shared/chunk-w5h6ay93.js +72 -0
- package/dist/shared/chunk-wkg17nxs.d.ts +101 -0
- package/dist/shared/chunk-x7f3g82r.js +285 -0
- package/dist/shared/chunk-xq5hc5gv.js +333 -0
- package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
- package/dist/shared/chunk-ym0xbses.js +518 -0
- package/dist/styles.css +97 -55
- 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 +79 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +30 -44
- package/mock/files.tsx +70 -0
- package/mock/island-content.tsx +43 -118
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +370 -91
- package/mock/system.ts +46 -0
- package/mock/weather.tsx +105 -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,634 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: a notch app's weather, the temperature now, the next
|
|
3
|
+
* hours and tomorrow, with the location and loading states around it and a
|
|
4
|
+
* flash before rain. Presentational: the forecast comes in as props, shaped
|
|
5
|
+
* so a host can fill it from Open-Meteo (`conditionFromCode` reads its WMO
|
|
6
|
+
* weather codes).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use client'
|
|
10
|
+
|
|
11
|
+
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
12
|
+
import { type SizeVariant, useSize } from '@justanarthur/modo-ui/lib/size-context'
|
|
13
|
+
import { SURFACE_BG } from '@justanarthur/modo-ui/lib/surface-classes'
|
|
14
|
+
import { useLift } from '@justanarthur/modo-ui/lib/surface-context'
|
|
15
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
16
|
+
import Skeleton from '@justanarthur/modo-ui/primitives/content/skeleton'
|
|
17
|
+
import {
|
|
18
|
+
ArrowDown,
|
|
19
|
+
ArrowUp,
|
|
20
|
+
Cloud,
|
|
21
|
+
CloudDrizzle,
|
|
22
|
+
CloudFog,
|
|
23
|
+
CloudHail,
|
|
24
|
+
CloudLightning,
|
|
25
|
+
CloudMoon,
|
|
26
|
+
CloudOff,
|
|
27
|
+
CloudRain,
|
|
28
|
+
CloudRainWind,
|
|
29
|
+
CloudSnow,
|
|
30
|
+
CloudSun,
|
|
31
|
+
Droplets,
|
|
32
|
+
LocateOff,
|
|
33
|
+
type LucideIcon,
|
|
34
|
+
MapPin,
|
|
35
|
+
Moon,
|
|
36
|
+
RotateCw,
|
|
37
|
+
Sun,
|
|
38
|
+
Umbrella,
|
|
39
|
+
WifiOff,
|
|
40
|
+
Wind,
|
|
41
|
+
} from 'lucide-react'
|
|
42
|
+
import IslandFlash from '../../../components/island/island-flash'
|
|
43
|
+
import Widget from '../../../components/island/widget'
|
|
44
|
+
import { MINUTE, useEdgeClock } from '../../../lib/clock'
|
|
45
|
+
|
|
46
|
+
type WeatherCondition =
|
|
47
|
+
| 'clear'
|
|
48
|
+
| 'partly-cloudy'
|
|
49
|
+
| 'cloudy'
|
|
50
|
+
| 'fog'
|
|
51
|
+
| 'drizzle'
|
|
52
|
+
| 'rain'
|
|
53
|
+
| 'heavy-rain'
|
|
54
|
+
| 'sleet'
|
|
55
|
+
| 'snow'
|
|
56
|
+
| 'thunderstorm'
|
|
57
|
+
|
|
58
|
+
type WeatherUnit = 'celsius' | 'fahrenheit'
|
|
59
|
+
type WeatherAccess = 'granted' | 'undetermined' | 'denied'
|
|
60
|
+
type WeatherStatus = 'ready' | 'loading' | 'error' | 'offline'
|
|
61
|
+
|
|
62
|
+
/** The weather now: Open-Meteo's `current` block. Temperatures in °C, wind in km/h. */
|
|
63
|
+
interface WeatherNow {
|
|
64
|
+
/** When it was read, in epoch ms: the "updated" line counts from it. */
|
|
65
|
+
time: number
|
|
66
|
+
temperature: number
|
|
67
|
+
/** How warm it feels, in °C: `apparent_temperature`. */
|
|
68
|
+
apparent?: number
|
|
69
|
+
condition: WeatherCondition
|
|
70
|
+
/** Daylight, for the sun or the moon in the glyph: `is_day`. Defaults to `true`. */
|
|
71
|
+
isDay?: boolean
|
|
72
|
+
/** Wind speed in km/h. */
|
|
73
|
+
wind?: number
|
|
74
|
+
/** Relative humidity, 0–100. */
|
|
75
|
+
humidity?: number
|
|
76
|
+
/** The UV index. */
|
|
77
|
+
uv?: number
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One hour of the forecast: Open-Meteo's `hourly` arrays, zipped. */
|
|
81
|
+
interface WeatherHour {
|
|
82
|
+
/** The hour's start, in epoch ms. */
|
|
83
|
+
time: number
|
|
84
|
+
temperature: number
|
|
85
|
+
condition: WeatherCondition
|
|
86
|
+
/** Defaults to `true`. */
|
|
87
|
+
isDay?: boolean
|
|
88
|
+
/** The chance of rain or snow, 0–100: `precipitation_probability`. */
|
|
89
|
+
precipitation?: number
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** One day of the forecast: Open-Meteo's `daily` arrays, zipped. */
|
|
93
|
+
interface WeatherDay {
|
|
94
|
+
/** The day's start, in epoch ms. */
|
|
95
|
+
date: number
|
|
96
|
+
condition: WeatherCondition
|
|
97
|
+
high: number
|
|
98
|
+
low: number
|
|
99
|
+
/** The day's highest chance of rain or snow, 0–100: `precipitation_probability_max`. */
|
|
100
|
+
precipitation?: number
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface WeatherProps {
|
|
104
|
+
/** Where the forecast is for: a city's name. */
|
|
105
|
+
location?: string
|
|
106
|
+
/** The weather now; without it the widget shows its state (`status`, `access`) or loads. */
|
|
107
|
+
current?: WeatherNow | null
|
|
108
|
+
/** The hourly forecast, in any order: the hours from now on fill the strip. */
|
|
109
|
+
hours?: WeatherHour[]
|
|
110
|
+
/** The daily forecast, today first: today gives the high and low, the next day the Tomorrow row. */
|
|
111
|
+
days?: WeatherDay[]
|
|
112
|
+
/** Shows temperatures in this unit (and wind in mph for `'fahrenheit'`); the data stays in °C and km/h. Defaults to `'celsius'`. */
|
|
113
|
+
unit?: WeatherUnit
|
|
114
|
+
/** Whether the location may be read: undetermined asks, denied points to the system's settings. Defaults to `'granted'`. */
|
|
115
|
+
access?: WeatherAccess
|
|
116
|
+
/** How the last fetch went. `loading` shows placeholders until there is a `current`; `error` and `offline` keep the last forecast up and say so, or explain without one. Defaults to `'ready'`. */
|
|
117
|
+
status?: WeatherStatus
|
|
118
|
+
/** The moment the forecast is read at, in epoch ms. Defaults to now, re-read on each minute. */
|
|
119
|
+
now?: number
|
|
120
|
+
/** Formats the hours. Defaults to the browser's locale. */
|
|
121
|
+
locale?: Intl.LocalesArgument
|
|
122
|
+
/** Called by the refresh button, and by Try again after an error; without it neither shows. */
|
|
123
|
+
onRefresh?: () => void
|
|
124
|
+
/** Called by Allow location while access is undetermined. */
|
|
125
|
+
onRequestAccess?: () => void
|
|
126
|
+
/** Called by Open System Settings while access is denied. */
|
|
127
|
+
onOpenSettings?: () => void
|
|
128
|
+
/** Classes for the root, which fills its container. */
|
|
129
|
+
className?: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const LABEL: Record<WeatherCondition, string> = {
|
|
133
|
+
clear: 'Clear',
|
|
134
|
+
'partly-cloudy': 'Partly cloudy',
|
|
135
|
+
cloudy: 'Cloudy',
|
|
136
|
+
fog: 'Fog',
|
|
137
|
+
drizzle: 'Drizzle',
|
|
138
|
+
rain: 'Rain',
|
|
139
|
+
'heavy-rain': 'Heavy rain',
|
|
140
|
+
sleet: 'Sleet',
|
|
141
|
+
snow: 'Snow',
|
|
142
|
+
thunderstorm: 'Thunderstorm',
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const GLYPH: Record<WeatherCondition, LucideIcon> = {
|
|
146
|
+
clear: Sun,
|
|
147
|
+
'partly-cloudy': CloudSun,
|
|
148
|
+
cloudy: Cloud,
|
|
149
|
+
fog: CloudFog,
|
|
150
|
+
drizzle: CloudDrizzle,
|
|
151
|
+
rain: CloudRain,
|
|
152
|
+
'heavy-rain': CloudRainWind,
|
|
153
|
+
sleet: CloudHail,
|
|
154
|
+
snow: CloudSnow,
|
|
155
|
+
thunderstorm: CloudLightning,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Literal table: UnoCSS only generates the classes it can read whole. The hue is the condition's: sun, water, the rest plain.
|
|
159
|
+
const HUE: Record<WeatherCondition, string> = {
|
|
160
|
+
clear: 'text-status-warning',
|
|
161
|
+
'partly-cloudy': 'text-status-warning',
|
|
162
|
+
cloudy: 'text-foreground',
|
|
163
|
+
fog: 'text-foreground',
|
|
164
|
+
drizzle: 'text-status-info',
|
|
165
|
+
rain: 'text-status-info',
|
|
166
|
+
'heavy-rain': 'text-status-info',
|
|
167
|
+
sleet: 'text-status-info',
|
|
168
|
+
snow: 'text-foreground',
|
|
169
|
+
thunderstorm: 'text-status-info',
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const HERO_GLYPH: Record<SizeVariant, number> = { default: 30, compact: 24 }
|
|
173
|
+
const STRIP_GLYPH: Record<SizeVariant, number> = { default: 16, compact: 14 }
|
|
174
|
+
|
|
175
|
+
/** A chance of rain worth showing, in %. */
|
|
176
|
+
const WET = 30
|
|
177
|
+
/** Hours the strip shows. */
|
|
178
|
+
const HOURS = 6
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Open-Meteo's `weather_code` (WMO 4677) as a condition.
|
|
182
|
+
*
|
|
183
|
+
* @example conditionFromCode(61) // 'rain'
|
|
184
|
+
*/
|
|
185
|
+
function conditionFromCode(code: number): WeatherCondition {
|
|
186
|
+
if (code === 0) return 'clear'
|
|
187
|
+
if (code <= 2) return 'partly-cloudy'
|
|
188
|
+
if (code === 3) return 'cloudy'
|
|
189
|
+
if (code === 45 || code === 48) return 'fog'
|
|
190
|
+
if (code >= 51 && code <= 55) return 'drizzle'
|
|
191
|
+
if (code === 56 || code === 57 || code === 66 || code === 67) return 'sleet'
|
|
192
|
+
if (code === 65 || code === 82) return 'heavy-rain'
|
|
193
|
+
if ((code >= 61 && code <= 63) || code === 80 || code === 81) return 'rain'
|
|
194
|
+
if ((code >= 71 && code <= 77) || code === 85 || code === 86) return 'snow'
|
|
195
|
+
if (code >= 95) return 'thunderstorm'
|
|
196
|
+
return 'cloudy'
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The glyph for a condition, the moon's at night. */
|
|
200
|
+
function glyphFor(condition: WeatherCondition, isDay = true): LucideIcon {
|
|
201
|
+
if (!isDay && condition === 'clear') return Moon
|
|
202
|
+
if (!isDay && condition === 'partly-cloudy') return CloudMoon
|
|
203
|
+
return GLYPH[condition]
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The hue for a condition: the sun's only by day. */
|
|
207
|
+
function hueFor(condition: WeatherCondition, isDay = true) {
|
|
208
|
+
if (!isDay && (condition === 'clear' || condition === 'partly-cloudy')) return 'text-foreground'
|
|
209
|
+
return HUE[condition]
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const degrees = (celsius: number, unit: WeatherUnit) =>
|
|
213
|
+
Math.round(unit === 'fahrenheit' ? (celsius * 9) / 5 + 32 : celsius)
|
|
214
|
+
|
|
215
|
+
const temp = (celsius: number, unit: WeatherUnit) => `${degrees(celsius, unit)}°`
|
|
216
|
+
|
|
217
|
+
const speed = (kmh: number, unit: WeatherUnit) =>
|
|
218
|
+
unit === 'fahrenheit' ? `${Math.round(kmh / 1.609)} mph` : `${Math.round(kmh)} km/h`
|
|
219
|
+
|
|
220
|
+
const hourOf = (ms: number, locale?: Intl.LocalesArgument) =>
|
|
221
|
+
new Date(ms).toLocaleTimeString(locale, { hour: 'numeric' })
|
|
222
|
+
|
|
223
|
+
function ago(ms: number) {
|
|
224
|
+
const minutes = Math.floor(ms / MINUTE)
|
|
225
|
+
if (minutes < 1) return 'Just now'
|
|
226
|
+
if (minutes < 60) return `${minutes} min ago`
|
|
227
|
+
return `${Math.floor(minutes / 60)} h ago`
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** The first hour, from `now`, with a chance of rain worth saying, while it isn't raining already. */
|
|
231
|
+
function rainAhead(current: WeatherNow, hours: WeatherHour[]) {
|
|
232
|
+
if (HUE[current.condition] === 'text-status-info') return undefined
|
|
233
|
+
return hours.find(hour => (hour.precipitation ?? 0) >= 50)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
interface GlyphProps {
|
|
237
|
+
condition: WeatherCondition
|
|
238
|
+
isDay?: boolean
|
|
239
|
+
size: number
|
|
240
|
+
className?: string
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function Glyph({ condition, isDay, size, className }: GlyphProps) {
|
|
244
|
+
const Icon = glyphFor(condition, isDay)
|
|
245
|
+
return <Icon aria-hidden size={size} strokeWidth={1.5} className={cn('shrink-0', className)} />
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function Hours({ hours, unit, locale }: { hours: WeatherHour[]; unit: WeatherUnit; locale?: Intl.LocalesArgument }) {
|
|
249
|
+
const size = useSize()
|
|
250
|
+
const wet = hours.some(hour => (hour.precipitation ?? 0) >= WET)
|
|
251
|
+
return (
|
|
252
|
+
<div className="flex min-w-0 justify-between">
|
|
253
|
+
{hours.map((hour, i) => (
|
|
254
|
+
<div key={hour.time} className="flex min-w-0 flex-1 flex-col items-center gap-1 tabular-nums">
|
|
255
|
+
<span className="whitespace-nowrap text-caption text-muted-foreground">
|
|
256
|
+
{i === 0 ? 'Now' : hourOf(hour.time, locale)}
|
|
257
|
+
</span>
|
|
258
|
+
<Glyph
|
|
259
|
+
condition={hour.condition}
|
|
260
|
+
isDay={hour.isDay}
|
|
261
|
+
size={STRIP_GLYPH[size.variant]}
|
|
262
|
+
className="text-foreground"
|
|
263
|
+
/>
|
|
264
|
+
<span className="text-body text-foreground">{temp(hour.temperature, unit)}</span>
|
|
265
|
+
{wet && (
|
|
266
|
+
<span className="h-4 text-caption text-status-info">
|
|
267
|
+
{(hour.precipitation ?? 0) >= WET && `${hour.precipitation}%`}
|
|
268
|
+
</span>
|
|
269
|
+
)}
|
|
270
|
+
</div>
|
|
271
|
+
))}
|
|
272
|
+
</div>
|
|
273
|
+
)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function Tomorrow({ day, unit }: { day: WeatherDay; unit: WeatherUnit }) {
|
|
277
|
+
return (
|
|
278
|
+
<Widget.Row
|
|
279
|
+
leading="Tomorrow"
|
|
280
|
+
trailing={
|
|
281
|
+
<>
|
|
282
|
+
{(day.precipitation ?? 0) >= WET && <span className="text-status-info">{day.precipitation}%</span>}
|
|
283
|
+
<span className="text-foreground">{temp(day.high, unit)}</span>
|
|
284
|
+
<span>{temp(day.low, unit)}</span>
|
|
285
|
+
</>
|
|
286
|
+
}
|
|
287
|
+
>
|
|
288
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
289
|
+
<Glyph condition={day.condition} size={14} className="text-muted-foreground" />
|
|
290
|
+
<span className="truncate">{LABEL[day.condition]}</span>
|
|
291
|
+
</span>
|
|
292
|
+
</Widget.Row>
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** The widget's shape while the first forecast loads: the header, the hero and the strip as placeholders. */
|
|
297
|
+
function Loading({ location, className }: { location?: string; className?: string }) {
|
|
298
|
+
return (
|
|
299
|
+
<Widget
|
|
300
|
+
className={className}
|
|
301
|
+
aside={
|
|
302
|
+
<div aria-hidden className="flex flex-col gap-3">
|
|
303
|
+
<Skeleton className="h-3 w-20" />
|
|
304
|
+
<div className="flex justify-between">
|
|
305
|
+
{Array.from({ length: HOURS }, (_, i) => (
|
|
306
|
+
<Skeleton key={i} className="h-14 w-7" />
|
|
307
|
+
))}
|
|
308
|
+
</div>
|
|
309
|
+
<Skeleton className="h-3 w-full" />
|
|
310
|
+
</div>
|
|
311
|
+
}
|
|
312
|
+
>
|
|
313
|
+
<div aria-busy className="flex min-w-0 flex-col gap-2">
|
|
314
|
+
<Widget.Header icon={MapPin}>{location ?? 'Finding you…'}</Widget.Header>
|
|
315
|
+
<Skeleton className="h-8 w-28" />
|
|
316
|
+
<Skeleton className="h-4 w-40" />
|
|
317
|
+
<Skeleton className="h-3 w-56" />
|
|
318
|
+
</div>
|
|
319
|
+
</Widget>
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface PartProps {
|
|
324
|
+
/** The weather now. */
|
|
325
|
+
current: WeatherNow
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** The compact island's left wing: the condition's glyph in its hue. */
|
|
329
|
+
function WeatherLeading({ current }: PartProps) {
|
|
330
|
+
return (
|
|
331
|
+
<Glyph
|
|
332
|
+
condition={current.condition}
|
|
333
|
+
isDay={current.isDay}
|
|
334
|
+
size={16}
|
|
335
|
+
className={hueFor(current.condition, current.isDay)}
|
|
336
|
+
/>
|
|
337
|
+
)
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** The compact island's right wing: the temperature. */
|
|
341
|
+
function WeatherTrailing({ current, unit = 'celsius' }: PartProps & { unit?: WeatherUnit }) {
|
|
342
|
+
return (
|
|
343
|
+
<span className="text-caption weight-semibold text-foreground tabular-nums">{temp(current.temperature, unit)}</span>
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** The split island's bubble: the condition's glyph on a disc. */
|
|
348
|
+
function WeatherMinimal({ current }: PartProps) {
|
|
349
|
+
const level = useLift(1)
|
|
350
|
+
return (
|
|
351
|
+
<span
|
|
352
|
+
role="img"
|
|
353
|
+
aria-label={LABEL[current.condition]}
|
|
354
|
+
className={cn(
|
|
355
|
+
'flex size-6 items-center justify-center rounded-full',
|
|
356
|
+
SURFACE_BG[level],
|
|
357
|
+
hueFor(current.condition, current.isDay),
|
|
358
|
+
)}
|
|
359
|
+
>
|
|
360
|
+
<Glyph condition={current.condition} isDay={current.isDay} size={14} />
|
|
361
|
+
</span>
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
type WeatherAlertSeverity = 'notice' | 'warning' | 'severe'
|
|
366
|
+
|
|
367
|
+
// Literal tables: UnoCSS only generates the classes it can read whole.
|
|
368
|
+
const ALERT_TILE: Record<WeatherAlertSeverity, string> = {
|
|
369
|
+
notice: 'bg-status-info/16 text-status-info',
|
|
370
|
+
warning: 'bg-status-warning/16 text-status-warning',
|
|
371
|
+
severe: 'bg-status-error/16 text-status-error',
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
interface WeatherAlertProps {
|
|
375
|
+
/** What is coming: its glyph, and the title's noun. */
|
|
376
|
+
condition: WeatherCondition
|
|
377
|
+
/** When it starts, in epoch ms: the title counts down to it, `Rain in 15 min`, on each minute. */
|
|
378
|
+
startsAt?: number
|
|
379
|
+
/** The title in place of the countdown, for a warning: `Thunderstorm warning`. */
|
|
380
|
+
title?: string
|
|
381
|
+
/** One line more: how long, how much. */
|
|
382
|
+
caption?: string
|
|
383
|
+
/** How serious: the tile's hue, info, warning or error. Defaults to `'notice'`. */
|
|
384
|
+
severity?: WeatherAlertSeverity
|
|
385
|
+
/** The button's label. Defaults to `'Details'`. */
|
|
386
|
+
actionLabel?: string
|
|
387
|
+
/** Called by the button; without it the button hides. */
|
|
388
|
+
onAction?: () => void
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** The island's flash before the weather turns: `Rain in 15 min`, or a warning, with one action. */
|
|
392
|
+
function WeatherAlert({
|
|
393
|
+
condition,
|
|
394
|
+
startsAt,
|
|
395
|
+
title,
|
|
396
|
+
caption,
|
|
397
|
+
severity = 'notice',
|
|
398
|
+
actionLabel = 'Details',
|
|
399
|
+
onAction,
|
|
400
|
+
}: WeatherAlertProps) {
|
|
401
|
+
const now = useEdgeClock(startsAt ?? 0, startsAt !== undefined && title === undefined, MINUTE)
|
|
402
|
+
const left = startsAt === undefined ? 0 : Math.ceil((startsAt - now) / MINUTE)
|
|
403
|
+
const heading = title ?? (left > 0 ? `${LABEL[condition]} in ${left} min` : `${LABEL[condition]} now`)
|
|
404
|
+
return (
|
|
405
|
+
<IslandFlash
|
|
406
|
+
icon={
|
|
407
|
+
<span className={cn('flex size-9 items-center justify-center rounded-lg', ALERT_TILE[severity])}>
|
|
408
|
+
<Glyph condition={condition} size={16} />
|
|
409
|
+
</span>
|
|
410
|
+
}
|
|
411
|
+
title={heading}
|
|
412
|
+
caption={caption}
|
|
413
|
+
action={
|
|
414
|
+
onAction && (
|
|
415
|
+
<Button variant="secondary" size="compact" onClick={onAction}>
|
|
416
|
+
{actionLabel}
|
|
417
|
+
</Button>
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
/>
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* A notch app's weather: the temperature now as the hero, the next hours
|
|
426
|
+
* and tomorrow beside it.
|
|
427
|
+
*
|
|
428
|
+
* The hero is the temperature in display type after the condition's glyph,
|
|
429
|
+
* in its hue (the sun's amber, rain's blue, the rest plain); under it the
|
|
430
|
+
* condition, how warm it feels and, when the next hours turn wet, around
|
|
431
|
+
* when. The meta line carries today's high and low, the chance of rain,
|
|
432
|
+
* the wind, and the humidity and UV index when given, the last giving way
|
|
433
|
+
* first. The header names the place and how long ago the forecast was
|
|
434
|
+
* read, with a refresh button when `onRefresh` is given. Beside it, past a
|
|
435
|
+
* hairline, the next six hours as a strip of hour, glyph and temperature,
|
|
436
|
+
* with the chance of rain under each once any hour is wet, then tomorrow as
|
|
437
|
+
* a row.
|
|
438
|
+
*
|
|
439
|
+
* The data is Open-Meteo's shape, zipped into objects: `current`, `hours`
|
|
440
|
+
* and `days` (today first), in °C and km/h; `unit="fahrenheit"` converts
|
|
441
|
+
* what it shows, wind in mph. `conditionFromCode` turns a WMO weather code
|
|
442
|
+
* into a condition.
|
|
443
|
+
*
|
|
444
|
+
* Before the location may be read it asks for it (`access="undetermined"`),
|
|
445
|
+
* and when access is off it says where to turn it on (`"denied"`). The
|
|
446
|
+
* first fetch shows placeholders (`status="loading"`); a failed one says so
|
|
447
|
+
* with Try again (`"error"`), and offline it says it will update when back
|
|
448
|
+
* (`"offline"`). Once there is a forecast, those keep it up and say so in
|
|
449
|
+
* the header instead.
|
|
450
|
+
*
|
|
451
|
+
* The other forms are parts: `Weather.Leading` and `Weather.Trailing` for
|
|
452
|
+
* the compact island's wings (the glyph and the temperature),
|
|
453
|
+
* `Weather.Minimal`, the glyph on a disc, for the split island's bubble,
|
|
454
|
+
* and `Weather.Alert`, the flash before rain or a warning. Nothing ticks but
|
|
455
|
+
* the minute of the "updated" line.
|
|
456
|
+
*
|
|
457
|
+
* @example {@include ./examples.mdx}
|
|
458
|
+
*/
|
|
459
|
+
const Weather = Object.assign(
|
|
460
|
+
function Weather({
|
|
461
|
+
location,
|
|
462
|
+
current,
|
|
463
|
+
hours = [],
|
|
464
|
+
days = [],
|
|
465
|
+
unit = 'celsius',
|
|
466
|
+
access = 'granted',
|
|
467
|
+
status = 'ready',
|
|
468
|
+
now: nowProp,
|
|
469
|
+
locale,
|
|
470
|
+
onRefresh,
|
|
471
|
+
onRequestAccess,
|
|
472
|
+
onOpenSettings,
|
|
473
|
+
className,
|
|
474
|
+
}: WeatherProps) {
|
|
475
|
+
const size = useSize()
|
|
476
|
+
const ticking = useEdgeClock(current?.time ?? 0, nowProp === undefined, MINUTE)
|
|
477
|
+
const now = nowProp ?? ticking
|
|
478
|
+
|
|
479
|
+
if (access === 'undetermined')
|
|
480
|
+
return (
|
|
481
|
+
<Widget.Message
|
|
482
|
+
icon={MapPin}
|
|
483
|
+
title="Weather where you are"
|
|
484
|
+
description="The temperature now, the next hours and tomorrow, for your location."
|
|
485
|
+
actions={
|
|
486
|
+
<Button variant="primary" size="compact" onClick={onRequestAccess}>
|
|
487
|
+
Allow location
|
|
488
|
+
</Button>
|
|
489
|
+
}
|
|
490
|
+
className={className}
|
|
491
|
+
/>
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
if (access === 'denied')
|
|
495
|
+
return (
|
|
496
|
+
<Widget.Message
|
|
497
|
+
icon={LocateOff}
|
|
498
|
+
title="Location access is off"
|
|
499
|
+
description="Turn it on in System Settings › Privacy & Security › Location Services."
|
|
500
|
+
actions={
|
|
501
|
+
<Button variant="secondary" size="compact" onClick={onOpenSettings}>
|
|
502
|
+
Open System Settings
|
|
503
|
+
</Button>
|
|
504
|
+
}
|
|
505
|
+
className={className}
|
|
506
|
+
/>
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
if (!current && status === 'error')
|
|
510
|
+
return (
|
|
511
|
+
<Widget.Message
|
|
512
|
+
icon={CloudOff}
|
|
513
|
+
title="Couldn't load the weather"
|
|
514
|
+
description="The forecast service didn't answer. It tries again on its own in a few minutes."
|
|
515
|
+
actions={
|
|
516
|
+
onRefresh && (
|
|
517
|
+
<Button variant="secondary" size="compact" onClick={onRefresh}>
|
|
518
|
+
Try again
|
|
519
|
+
</Button>
|
|
520
|
+
)
|
|
521
|
+
}
|
|
522
|
+
className={className}
|
|
523
|
+
/>
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
if (!current && status === 'offline')
|
|
527
|
+
return (
|
|
528
|
+
<Widget.Message
|
|
529
|
+
icon={WifiOff}
|
|
530
|
+
title="You're offline"
|
|
531
|
+
description="The forecast loads as soon as you're back online."
|
|
532
|
+
className={className}
|
|
533
|
+
/>
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
if (!current) return <Loading location={location} className={className} />
|
|
537
|
+
|
|
538
|
+
const hourStart = new Date(now).setMinutes(0, 0, 0)
|
|
539
|
+
const ahead = hours.filter(hour => hour.time >= hourStart).sort((a, b) => a.time - b.time)
|
|
540
|
+
const [today, tomorrow] = days
|
|
541
|
+
const rain = rainAhead(current, ahead)
|
|
542
|
+
const fresh = ago(Math.max(0, now - current.time))
|
|
543
|
+
const freshness =
|
|
544
|
+
status === 'offline' ? `Offline · ${fresh}` : status === 'error' ? `Not updated · ${fresh}` : fresh
|
|
545
|
+
const feels = current.apparent !== undefined && `Feels like ${temp(current.apparent, unit)}`
|
|
546
|
+
const soon = rain && `${LABEL[rain.condition]} around ${hourOf(rain.time, locale)}`
|
|
547
|
+
|
|
548
|
+
return (
|
|
549
|
+
<Widget
|
|
550
|
+
className={className}
|
|
551
|
+
aside={
|
|
552
|
+
ahead.length > 0 && (
|
|
553
|
+
<>
|
|
554
|
+
<Widget.Section label="Next hours">
|
|
555
|
+
<Hours hours={ahead.slice(0, HOURS)} unit={unit} locale={locale} />
|
|
556
|
+
</Widget.Section>
|
|
557
|
+
{tomorrow && (
|
|
558
|
+
<div className="mt-1.5">
|
|
559
|
+
<Tomorrow day={tomorrow} unit={unit} />
|
|
560
|
+
</div>
|
|
561
|
+
)}
|
|
562
|
+
</>
|
|
563
|
+
)
|
|
564
|
+
}
|
|
565
|
+
>
|
|
566
|
+
<Widget.Header
|
|
567
|
+
icon={MapPin}
|
|
568
|
+
trailing={
|
|
569
|
+
<>
|
|
570
|
+
<span className="whitespace-nowrap pr-1 text-caption">{freshness}</span>
|
|
571
|
+
{onRefresh && <Widget.Action icon={RotateCw} label="Refresh" onClick={onRefresh} />}
|
|
572
|
+
</>
|
|
573
|
+
}
|
|
574
|
+
>
|
|
575
|
+
{location ?? 'Current location'}
|
|
576
|
+
</Widget.Header>
|
|
577
|
+
|
|
578
|
+
<div className="flex min-w-0 items-center gap-2.5">
|
|
579
|
+
<Glyph
|
|
580
|
+
condition={current.condition}
|
|
581
|
+
isDay={current.isDay}
|
|
582
|
+
size={HERO_GLYPH[size.variant]}
|
|
583
|
+
className={hueFor(current.condition, current.isDay)}
|
|
584
|
+
/>
|
|
585
|
+
<Widget.Figure value={degrees(current.temperature, unit)} unit={unit === 'fahrenheit' ? '°F' : '°C'} />
|
|
586
|
+
</div>
|
|
587
|
+
|
|
588
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
589
|
+
<Widget.Title>{LABEL[current.condition]}</Widget.Title>
|
|
590
|
+
{(feels || soon) && <Widget.Subtitle>{[feels, soon].filter(Boolean).join(' · ')}</Widget.Subtitle>}
|
|
591
|
+
</div>
|
|
592
|
+
|
|
593
|
+
<Widget.Meta className="mt-1">
|
|
594
|
+
{today && (
|
|
595
|
+
<>
|
|
596
|
+
<Widget.MetaItem icon={ArrowUp}>{temp(today.high, unit)}</Widget.MetaItem>
|
|
597
|
+
<Widget.MetaItem icon={ArrowDown}>{temp(today.low, unit)}</Widget.MetaItem>
|
|
598
|
+
</>
|
|
599
|
+
)}
|
|
600
|
+
{today?.precipitation !== undefined && (
|
|
601
|
+
<Widget.MetaItem icon={Umbrella}>{today.precipitation}%</Widget.MetaItem>
|
|
602
|
+
)}
|
|
603
|
+
{current.wind !== undefined && <Widget.MetaItem icon={Wind}>{speed(current.wind, unit)}</Widget.MetaItem>}
|
|
604
|
+
{current.humidity !== undefined && (
|
|
605
|
+
<Widget.MetaItem icon={Droplets}>{Math.round(current.humidity)}%</Widget.MetaItem>
|
|
606
|
+
)}
|
|
607
|
+
{current.uv !== undefined && <Widget.MetaItem icon={Sun}>UV {Math.round(current.uv)}</Widget.MetaItem>}
|
|
608
|
+
</Widget.Meta>
|
|
609
|
+
</Widget>
|
|
610
|
+
)
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
Leading: WeatherLeading,
|
|
614
|
+
Trailing: WeatherTrailing,
|
|
615
|
+
Minimal: WeatherMinimal,
|
|
616
|
+
Alert: WeatherAlert,
|
|
617
|
+
},
|
|
618
|
+
)
|
|
619
|
+
|
|
620
|
+
export default Weather
|
|
621
|
+
|
|
622
|
+
export type {
|
|
623
|
+
WeatherAccess,
|
|
624
|
+
WeatherAlertProps,
|
|
625
|
+
WeatherAlertSeverity,
|
|
626
|
+
WeatherCondition,
|
|
627
|
+
WeatherDay,
|
|
628
|
+
WeatherHour,
|
|
629
|
+
WeatherNow,
|
|
630
|
+
WeatherProps,
|
|
631
|
+
WeatherStatus,
|
|
632
|
+
WeatherUnit,
|
|
633
|
+
}
|
|
634
|
+
export { conditionFromCode, Weather, WeatherAlert, WeatherLeading, WeatherMinimal, WeatherTrailing }
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import ExpandedIsland from './index'
|
|
2
2
|
import Island from '../../../components/island/island'
|
|
3
3
|
import NowPlaying from '../../activities/now-playing'
|
|
4
|
-
import
|
|
4
|
+
import Weather from '../../activities/weather'
|
|
5
5
|
import Agenda from '../../activities/agenda'
|
|
6
6
|
import { ExpandedPanel, PLAYING, ScreenEdge } from '../../../mock/island-content'
|
|
7
7
|
import { AGENDA_NOW, EVENTS } from '../../../mock/data'
|
|
8
|
-
import {
|
|
8
|
+
import { FORECAST } from '../../../mock/weather'
|
|
9
|
+
import { CalendarDays, CloudSun, Music } from 'lucide-react'
|
|
9
10
|
|
|
10
11
|
# Every widget
|
|
11
12
|
|
|
12
13
|
Tabs in the wings around the notch, settings at the far right; hover a tab to preview its title.
|
|
13
14
|
|
|
14
|
-
<ScreenEdge height={
|
|
15
|
+
<ScreenEdge height={260}>
|
|
15
16
|
<Island defaultState="expanded" collapsedState="idle" expanded={<ExpandedPanel />} />
|
|
16
17
|
</ScreenEdge>
|
|
17
18
|
|
|
@@ -19,7 +20,7 @@ Tabs in the wings around the notch, settings at the far right; hover a tab to pr
|
|
|
19
20
|
|
|
20
21
|
`tabs` takes each tab's icon, label and view.
|
|
21
22
|
|
|
22
|
-
<ScreenEdge height={
|
|
23
|
+
<ScreenEdge height={260}>
|
|
23
24
|
<Island
|
|
24
25
|
defaultState="expanded"
|
|
25
26
|
collapsedState="idle"
|
|
@@ -28,8 +29,8 @@ Tabs in the wings around the notch, settings at the far right; hover a tab to pr
|
|
|
28
29
|
defaultValue="calendar"
|
|
29
30
|
tabs={[
|
|
30
31
|
{ value: 'music', label: 'Now Playing', icon: Music, content: <NowPlaying track={PLAYING} /> },
|
|
31
|
-
{ value: 'timer', label: 'Timer', icon: TimerIcon, content: <Timer /> },
|
|
32
32
|
{ value: 'calendar', label: 'Calendar', icon: CalendarDays, content: <Agenda events={EVENTS} now={AGENDA_NOW} /> },
|
|
33
|
+
{ value: 'weather', label: 'Weather', icon: CloudSun, content: <Weather {...FORECAST} /> },
|
|
33
34
|
]}
|
|
34
35
|
/>
|
|
35
36
|
}
|
|
@@ -40,6 +41,6 @@ Tabs in the wings around the notch, settings at the far right; hover a tab to pr
|
|
|
40
41
|
|
|
41
42
|
The content area keeps its height and scrolls a taller view, its edges fading.
|
|
42
43
|
|
|
43
|
-
<ScreenEdge height={
|
|
44
|
-
<Island defaultState="expanded" collapsedState="idle" panelHeight={
|
|
44
|
+
<ScreenEdge height={220}>
|
|
45
|
+
<Island defaultState="expanded" collapsedState="idle" panelHeight={196} expanded={<ExpandedPanel defaultTab="calendar" />} />
|
|
45
46
|
</ScreenEdge>
|