@justanarthur/modo-ui-notch 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +75 -2
- package/blocks/activities/agenda/examples.mdx +58 -0
- package/blocks/activities/agenda/index.tsx +332 -0
- package/blocks/activities/now-playing/examples.mdx +49 -0
- package/blocks/activities/now-playing/index.tsx +218 -0
- package/blocks/activities/shelf/examples.mdx +33 -0
- package/blocks/activities/shelf/index.tsx +289 -0
- package/blocks/activities/timer/examples.mdx +52 -0
- package/blocks/activities/timer/index.tsx +292 -0
- package/blocks/app/expanded-island/examples.mdx +45 -0
- package/blocks/app/expanded-island/index.tsx +127 -0
- package/blocks/app/settings-window/examples.mdx +30 -0
- package/blocks/app/settings-window/index.tsx +357 -0
- package/blocks/system/controls/examples.mdx +34 -0
- package/blocks/system/controls/index.tsx +167 -0
- package/blocks/system/devices/examples.mdx +25 -0
- package/blocks/system/devices/index.tsx +172 -0
- package/blocks/system/power-alert/examples.mdx +32 -0
- package/blocks/system/power-alert/index.tsx +89 -0
- package/blocks/system/system-stats/examples.mdx +23 -0
- package/blocks/system/system-stats/index.tsx +178 -0
- package/components/indicators/battery-glyph/examples.mdx +22 -0
- package/components/indicators/battery-glyph/index.tsx +91 -0
- package/components/indicators/countdown/examples.mdx +25 -0
- package/components/indicators/countdown/index.tsx +83 -0
- package/components/indicators/equalizer/examples.mdx +20 -0
- package/components/indicators/equalizer/index.tsx +116 -0
- package/components/indicators/media-scrubber/examples.mdx +21 -0
- package/components/indicators/media-scrubber/index.tsx +98 -0
- package/components/island/island/examples.mdx +57 -0
- package/components/island/island/index.tsx +415 -0
- package/components/island/island-flash/examples.mdx +55 -0
- package/components/island/island-flash/index.tsx +79 -0
- package/components/island/island-tabs/examples.mdx +53 -0
- package/components/island/island-tabs/index.tsx +285 -0
- package/dist/blocks/activities/agenda/index.d.ts +2 -0
- package/dist/blocks/activities/agenda/index.js +21 -0
- package/dist/blocks/activities/now-playing/index.d.ts +2 -0
- package/dist/blocks/activities/now-playing/index.js +22 -0
- package/dist/blocks/activities/shelf/index.d.ts +2 -0
- package/dist/blocks/activities/shelf/index.js +14 -0
- package/dist/blocks/activities/timer/index.d.ts +2 -0
- package/dist/blocks/activities/timer/index.js +19 -0
- package/dist/blocks/app/expanded-island/index.d.ts +3 -0
- package/dist/blocks/app/expanded-island/index.js +10 -0
- package/dist/blocks/app/settings-window/index.d.ts +2 -0
- package/dist/blocks/app/settings-window/index.js +7 -0
- package/dist/blocks/system/controls/index.d.ts +2 -0
- package/dist/blocks/system/controls/index.js +10 -0
- package/dist/blocks/system/devices/index.d.ts +2 -0
- package/dist/blocks/system/devices/index.js +12 -0
- package/dist/blocks/system/power-alert/index.d.ts +2 -0
- package/dist/blocks/system/power-alert/index.js +9 -0
- package/dist/blocks/system/system-stats/index.d.ts +2 -0
- package/dist/blocks/system/system-stats/index.js +12 -0
- package/dist/components/indicators/battery-glyph/index.d.ts +2 -0
- package/dist/components/indicators/battery-glyph/index.js +9 -0
- package/dist/components/indicators/countdown/index.d.ts +2 -0
- package/dist/components/indicators/countdown/index.js +8 -0
- package/dist/components/indicators/equalizer/index.d.ts +2 -0
- package/dist/components/indicators/equalizer/index.js +7 -0
- package/dist/components/indicators/media-scrubber/index.d.ts +2 -0
- package/dist/components/indicators/media-scrubber/index.js +8 -0
- package/dist/components/island/island/index.d.ts +3 -0
- package/dist/components/island/island/index.js +10 -0
- package/dist/components/island/island-flash/index.d.ts +2 -0
- package/dist/components/island/island-flash/index.js +7 -0
- package/dist/components/island/island-tabs/index.d.ts +2 -0
- package/dist/components/island/island-tabs/index.js +9 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +151 -0
- package/dist/lib/clock.d.ts +2 -0
- package/dist/lib/clock.js +14 -0
- package/dist/lib/geometry.d.ts +2 -0
- package/dist/lib/geometry.js +24 -0
- package/dist/lib/island-context.d.ts +3 -0
- package/dist/lib/island-context.js +8 -0
- package/dist/lib/motion.d.ts +21 -0
- package/dist/lib/motion.js +16 -0
- package/dist/shared/chunk-152gpyq3.d.ts +13 -0
- package/dist/shared/chunk-2f7zxrbk.js +65 -0
- package/dist/shared/chunk-2qpcsv5h.d.ts +45 -0
- package/dist/shared/chunk-2s4q6mt0.js +27 -0
- package/dist/shared/chunk-45gytfr1.d.ts +84 -0
- package/dist/shared/chunk-502rmtap.js +54 -0
- package/dist/shared/chunk-50ffk4r7.d.ts +69 -0
- package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
- package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
- package/dist/shared/chunk-5w0yck07.d.ts +32 -0
- package/dist/shared/chunk-6c1jbefs.d.ts +36 -0
- package/dist/shared/chunk-78w7qwp0.js +58 -0
- package/dist/shared/chunk-7hr53mby.js +116 -0
- package/dist/shared/chunk-9nhpg9t8.d.ts +47 -0
- package/dist/shared/chunk-b8jb1w72.js +145 -0
- package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
- package/dist/shared/chunk-cpewy6yg.js +178 -0
- package/dist/shared/chunk-d5qm9cps.js +10 -0
- package/dist/shared/chunk-e3e4s4ds.d.ts +77 -0
- package/dist/shared/chunk-enm6td0p.js +280 -0
- package/dist/shared/chunk-fvedaas2.d.ts +33 -0
- package/dist/shared/chunk-gb56m10p.js +39 -0
- package/dist/shared/chunk-gex38j8x.d.ts +82 -0
- package/dist/shared/chunk-hpsabfsd.d.ts +75 -0
- package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
- package/dist/shared/chunk-hwtxpzg0.js +69 -0
- package/dist/shared/chunk-mp1nx0ez.js +101 -0
- package/dist/shared/chunk-phb53x1f.js +252 -0
- package/dist/shared/chunk-r8esmjfs.d.ts +42 -0
- package/dist/shared/chunk-rcp1g9ca.js +70 -0
- package/dist/shared/chunk-rpfwv3pz.js +209 -0
- package/dist/shared/chunk-rr5e0g15.d.ts +35 -0
- package/dist/shared/chunk-rx9sphz2.js +266 -0
- package/dist/shared/chunk-s33y1pcq.js +305 -0
- package/dist/shared/chunk-sbnrhy5m.js +331 -0
- package/dist/shared/chunk-w48eyvfr.d.ts +56 -0
- package/dist/shared/chunk-wwjxs75m.js +74 -0
- package/dist/shared/chunk-xdeek16r.d.ts +58 -0
- package/dist/shared/chunk-xkzjk1tq.js +206 -0
- package/dist/shared/chunk-yngkkxz2.d.ts +88 -0
- package/dist/shared/chunk-zvh0d3qb.js +63 -0
- package/dist/styles.css +222 -0
- package/index.ts +21 -0
- package/lib/clock.ts +53 -0
- package/lib/geometry.ts +130 -0
- package/lib/island-context.tsx +24 -0
- package/lib/motion.ts +42 -0
- package/mock/activities.tsx +100 -0
- package/mock/artwork.tsx +25 -0
- package/mock/data.ts +153 -0
- package/mock/desktop.tsx +83 -0
- package/mock/fit.ts +26 -0
- package/mock/island-content.tsx +217 -0
- package/mock/scene.tsx +52 -0
- package/mock/settings.tsx +210 -0
- package/package.json +117 -4
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: a notch app's Bluetooth devices and their batteries.
|
|
3
|
+
* Rebuilt from Just Notch's devices plugin (`Devices`, `Device`, `Connected`)
|
|
4
|
+
* as presentational parts: the devices come in as props.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use client'
|
|
8
|
+
|
|
9
|
+
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
10
|
+
import EmptyState from '@justanarthur/modo-ui/components/feedback/empty-state'
|
|
11
|
+
import StatusDot from '@justanarthur/modo-ui/components/feedback/status-dot'
|
|
12
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
13
|
+
import {
|
|
14
|
+
Bluetooth,
|
|
15
|
+
Gamepad2,
|
|
16
|
+
Headphones,
|
|
17
|
+
Keyboard,
|
|
18
|
+
type LucideIcon,
|
|
19
|
+
Mouse,
|
|
20
|
+
Smartphone,
|
|
21
|
+
Speaker,
|
|
22
|
+
Watch,
|
|
23
|
+
} from 'lucide-react'
|
|
24
|
+
import BatteryGlyph from '../../../components/indicators/battery-glyph'
|
|
25
|
+
import IslandFlash from '../../../components/island/island-flash'
|
|
26
|
+
|
|
27
|
+
type DeviceKind = 'headphones' | 'keyboard' | 'mouse' | 'speaker' | 'gamepad' | 'phone' | 'watch' | 'other'
|
|
28
|
+
|
|
29
|
+
interface DeviceInfo {
|
|
30
|
+
id: string
|
|
31
|
+
name: string
|
|
32
|
+
/** What it is, for its glyph. */
|
|
33
|
+
kind: DeviceKind
|
|
34
|
+
connected: boolean
|
|
35
|
+
/** Its charge in percent, when it reports one. */
|
|
36
|
+
battery?: number
|
|
37
|
+
charging?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface DevicesProps {
|
|
41
|
+
/** The paired devices; connected ones list first, then by name. */
|
|
42
|
+
devices: DeviceInfo[]
|
|
43
|
+
/** Called by the empty state's Open Bluetooth Settings; without it the button hides. */
|
|
44
|
+
onOpenSettings?: () => void
|
|
45
|
+
/** Classes for the root, which fills its container. */
|
|
46
|
+
className?: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const KIND: Record<DeviceKind, LucideIcon> = {
|
|
50
|
+
headphones: Headphones,
|
|
51
|
+
keyboard: Keyboard,
|
|
52
|
+
mouse: Mouse,
|
|
53
|
+
speaker: Speaker,
|
|
54
|
+
gamepad: Gamepad2,
|
|
55
|
+
phone: Smartphone,
|
|
56
|
+
watch: Watch,
|
|
57
|
+
other: Bluetooth,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function Charge({ device }: { device: DeviceInfo }) {
|
|
61
|
+
if (device.battery === undefined) return null
|
|
62
|
+
return (
|
|
63
|
+
<span className="flex shrink-0 items-center gap-2 text-caption tabular-nums text-muted-foreground">
|
|
64
|
+
{device.battery}%
|
|
65
|
+
<BatteryGlyph level={device.battery} charging={device.charging} fillIn={false} />
|
|
66
|
+
</span>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function Glyph({ device }: { device: DeviceInfo }) {
|
|
71
|
+
const Icon = KIND[device.kind]
|
|
72
|
+
return (
|
|
73
|
+
<span
|
|
74
|
+
className={cn(
|
|
75
|
+
'flex size-8 shrink-0 items-center justify-center rounded-full',
|
|
76
|
+
device.connected ? 'bg-surface-3 text-foreground' : 'bg-surface-2 text-muted-foreground',
|
|
77
|
+
)}
|
|
78
|
+
>
|
|
79
|
+
<Icon size={16} strokeWidth={1.5} />
|
|
80
|
+
</span>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function Device({ device }: { device: DeviceInfo }) {
|
|
85
|
+
return (
|
|
86
|
+
<li className="flex h-11 min-w-0 items-center gap-3">
|
|
87
|
+
<Glyph device={device} />
|
|
88
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
89
|
+
<span className={cn('truncate text-body', device.connected ? 'text-foreground' : 'text-muted-foreground')}>
|
|
90
|
+
{device.name}
|
|
91
|
+
</span>
|
|
92
|
+
<span className="flex items-center gap-1.5 text-caption text-muted-foreground">
|
|
93
|
+
<StatusDot status={device.connected ? 'success' : 'idle'} size="compact" />
|
|
94
|
+
{device.connected ? 'Connected' : 'Not connected'}
|
|
95
|
+
</span>
|
|
96
|
+
</div>
|
|
97
|
+
{device.connected && <Charge device={device} />}
|
|
98
|
+
</li>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The island's flash when a device connects: its glyph, name and battery. */
|
|
103
|
+
function DevicesConnected({ device }: { device: DeviceInfo }) {
|
|
104
|
+
const Icon = KIND[device.kind]
|
|
105
|
+
return (
|
|
106
|
+
<IslandFlash
|
|
107
|
+
icon={
|
|
108
|
+
<span className="flex size-8 items-center justify-center rounded-full bg-surface-3 text-foreground">
|
|
109
|
+
<Icon size={16} strokeWidth={1.5} />
|
|
110
|
+
</span>
|
|
111
|
+
}
|
|
112
|
+
title={device.name}
|
|
113
|
+
caption="Connected"
|
|
114
|
+
value={device.battery === undefined ? undefined : `${device.battery}%`}
|
|
115
|
+
trailing={
|
|
116
|
+
device.battery === undefined ? undefined : <BatteryGlyph level={device.battery} charging={device.charging} />
|
|
117
|
+
}
|
|
118
|
+
/>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A notch app's Bluetooth devices: what's paired, what's connected and how
|
|
124
|
+
* much charge each has left.
|
|
125
|
+
*
|
|
126
|
+
* Devices list in two columns, connected first: a glyph for the kind of
|
|
127
|
+
* device (raised while connected), the name, a StatusDot with Connected or
|
|
128
|
+
* Not connected, and for a connected device that reports one, its charge as
|
|
129
|
+
* a figure and a BatteryGlyph, which turns to the warning and error hues as
|
|
130
|
+
* it runs low. Without devices it says how to pair one, with a button to the
|
|
131
|
+
* system's Bluetooth settings when `onOpenSettings` is given.
|
|
132
|
+
*
|
|
133
|
+
* `Devices.Connected` is the island's flash when a device connects.
|
|
134
|
+
*
|
|
135
|
+
* @example {@include ./examples.mdx}
|
|
136
|
+
*/
|
|
137
|
+
function Devices({ devices, onOpenSettings, className }: DevicesProps) {
|
|
138
|
+
if (devices.length === 0)
|
|
139
|
+
return (
|
|
140
|
+
<div className={cn('flex size-full items-center justify-center', className)}>
|
|
141
|
+
<EmptyState
|
|
142
|
+
size="compact"
|
|
143
|
+
icon={Bluetooth}
|
|
144
|
+
title="No Bluetooth devices"
|
|
145
|
+
description="Pair headphones, a keyboard or a mouse to see them here."
|
|
146
|
+
actions={
|
|
147
|
+
onOpenSettings && (
|
|
148
|
+
<Button variant="secondary" size="compact" onClick={onOpenSettings}>
|
|
149
|
+
Open Bluetooth Settings
|
|
150
|
+
</Button>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
/>
|
|
154
|
+
</div>
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
const sorted = [...devices].sort((a, b) => Number(b.connected) - Number(a.connected) || a.name.localeCompare(b.name))
|
|
158
|
+
return (
|
|
159
|
+
<ul className={cn('m-0 grid list-none grid-cols-2 content-start gap-x-8 p-0', className)}>
|
|
160
|
+
{sorted.map(device => (
|
|
161
|
+
<Device key={device.id} device={device} />
|
|
162
|
+
))}
|
|
163
|
+
</ul>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
Devices.Connected = DevicesConnected
|
|
168
|
+
|
|
169
|
+
export default Devices
|
|
170
|
+
|
|
171
|
+
export type { DeviceInfo, DeviceKind, DevicesProps }
|
|
172
|
+
export { Devices, DevicesConnected }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import PowerAlert from './index'
|
|
2
|
+
import { FlashIsland } from '../../../mock/island-content'
|
|
3
|
+
|
|
4
|
+
# Charging
|
|
5
|
+
|
|
6
|
+
A charger plugs in: the figure and the battery in the success hue, and how long until full.
|
|
7
|
+
|
|
8
|
+
<FlashIsland>
|
|
9
|
+
<PowerAlert kind="charging" level={82} minutes={38} />
|
|
10
|
+
</FlashIsland>
|
|
11
|
+
|
|
12
|
+
# On battery
|
|
13
|
+
|
|
14
|
+
<FlashIsland>
|
|
15
|
+
<PowerAlert kind="unplugged" level={82} minutes={252} />
|
|
16
|
+
</FlashIsland>
|
|
17
|
+
|
|
18
|
+
# Low
|
|
19
|
+
|
|
20
|
+
Once on the way down through 20%.
|
|
21
|
+
|
|
22
|
+
<FlashIsland>
|
|
23
|
+
<PowerAlert kind="low" level={19} />
|
|
24
|
+
</FlashIsland>
|
|
25
|
+
|
|
26
|
+
# Critical
|
|
27
|
+
|
|
28
|
+
Once on the way down through 10%.
|
|
29
|
+
|
|
30
|
+
<FlashIsland>
|
|
31
|
+
<PowerAlert kind="critical" level={8} />
|
|
32
|
+
</FlashIsland>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: a notch app's power alerts. Rebuilt from Just Notch's
|
|
3
|
+
* power plugin (`Charging`, `Unplugged`, `Low`, `Critical`) as one
|
|
4
|
+
* presentational flash: the battery comes in as props.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use client'
|
|
8
|
+
|
|
9
|
+
import { BatteryLow, BatteryWarning, Unplug, Zap } from 'lucide-react'
|
|
10
|
+
import type { ReactNode } from 'react'
|
|
11
|
+
import BatteryGlyph, { type BatteryTone } from '../../../components/indicators/battery-glyph'
|
|
12
|
+
import IslandFlash, { type IslandFlashTone } from '../../../components/island/island-flash'
|
|
13
|
+
|
|
14
|
+
type PowerAlertKind = 'charging' | 'unplugged' | 'low' | 'critical'
|
|
15
|
+
|
|
16
|
+
interface PowerAlertProps {
|
|
17
|
+
/** What happened: a charger plugged in or out, or the battery crossing 20% or 10%. */
|
|
18
|
+
kind: PowerAlertKind
|
|
19
|
+
/** The charge, in percent (0 to 100). */
|
|
20
|
+
level: number
|
|
21
|
+
/** Minutes until full while charging, or of battery left on battery: the caption says it. */
|
|
22
|
+
minutes?: number
|
|
23
|
+
/** Replaces the caption the kind and `minutes` give. */
|
|
24
|
+
caption?: ReactNode
|
|
25
|
+
/** Classes for the row. */
|
|
26
|
+
className?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const ALERT: Record<
|
|
30
|
+
PowerAlertKind,
|
|
31
|
+
{ title: string; tone: IslandFlashTone & BatteryTone; icon: ReactNode; verb?: string; caption?: string }
|
|
32
|
+
> = {
|
|
33
|
+
charging: {
|
|
34
|
+
title: 'Charging',
|
|
35
|
+
tone: 'success',
|
|
36
|
+
icon: <Zap size={18} strokeWidth={1.5} fill="currentColor" />,
|
|
37
|
+
verb: 'until full',
|
|
38
|
+
},
|
|
39
|
+
unplugged: { title: 'On battery', tone: 'default', icon: <Unplug size={18} strokeWidth={1.5} />, verb: 'remaining' },
|
|
40
|
+
low: {
|
|
41
|
+
title: 'Low battery',
|
|
42
|
+
tone: 'warning',
|
|
43
|
+
icon: <BatteryLow size={18} strokeWidth={1.5} />,
|
|
44
|
+
caption: 'Plug in soon',
|
|
45
|
+
},
|
|
46
|
+
critical: {
|
|
47
|
+
title: 'Battery critically low',
|
|
48
|
+
tone: 'error',
|
|
49
|
+
icon: <BatteryWarning size={18} strokeWidth={1.5} />,
|
|
50
|
+
caption: 'Plug in now',
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Minutes as `38 min` or `4 h 12 min`. */
|
|
55
|
+
const span = (minutes: number) =>
|
|
56
|
+
minutes >= 60 ? `${Math.floor(minutes / 60)} h ${Math.round(minutes % 60)} min` : `${Math.round(minutes)} min`
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A notch app's power alert: a charger plugged in or out, or the battery
|
|
60
|
+
* running low, as the island's flash.
|
|
61
|
+
*
|
|
62
|
+
* Each kind brings its icon, title and status hue: charging in success,
|
|
63
|
+
* unplugged in the text color, low in warning (at 20%), critical in error
|
|
64
|
+
* (at 10%). The level shows as a figure in that hue and as a BatteryGlyph
|
|
65
|
+
* that fills up from empty as the flash opens. With `minutes`, the caption
|
|
66
|
+
* says how long until full or how much is left; low and critical say to plug
|
|
67
|
+
* in. Pass it as the Island's `flash`, keyed by kind, so one alert replacing
|
|
68
|
+
* another swaps instead of updating in place.
|
|
69
|
+
*
|
|
70
|
+
* @example {@include ./examples.mdx}
|
|
71
|
+
*/
|
|
72
|
+
export default function PowerAlert({ kind, level, minutes, caption, className }: PowerAlertProps) {
|
|
73
|
+
const alert = ALERT[kind]
|
|
74
|
+
const detail = minutes !== undefined && alert.verb ? `${span(minutes)} ${alert.verb}` : alert.caption
|
|
75
|
+
return (
|
|
76
|
+
<IslandFlash
|
|
77
|
+
className={className}
|
|
78
|
+
icon={alert.icon}
|
|
79
|
+
tone={alert.tone}
|
|
80
|
+
title={alert.title}
|
|
81
|
+
caption={caption ?? detail}
|
|
82
|
+
value={`${Math.round(level)}%`}
|
|
83
|
+
trailing={<BatteryGlyph level={level} charging={kind === 'charging'} tone={alert.tone} />}
|
|
84
|
+
/>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type { PowerAlertKind, PowerAlertProps }
|
|
89
|
+
export { PowerAlert }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import SystemStats from './index'
|
|
2
|
+
import { WidgetIsland, WingsIsland } from '../../../mock/island-content'
|
|
3
|
+
import { SAMPLES } from '../../../mock/data'
|
|
4
|
+
|
|
5
|
+
# System
|
|
6
|
+
|
|
7
|
+
The latest reading as the figure, every reading so far as the trend.
|
|
8
|
+
|
|
9
|
+
<WidgetIsland tab="stats">
|
|
10
|
+
<SystemStats samples={SAMPLES} />
|
|
11
|
+
</WidgetIsland>
|
|
12
|
+
|
|
13
|
+
# Measuring
|
|
14
|
+
|
|
15
|
+
Before the first reading.
|
|
16
|
+
|
|
17
|
+
<WidgetIsland tab="stats">
|
|
18
|
+
<SystemStats samples={[]} />
|
|
19
|
+
</WidgetIsland>
|
|
20
|
+
|
|
21
|
+
# Compact
|
|
22
|
+
|
|
23
|
+
<WingsIsland leading={<SystemStats.Leading />} trailing={<SystemStats.Trailing sample={SAMPLES[SAMPLES.length - 1]} />} />
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: a notch app's system load, CPU, memory and network as
|
|
3
|
+
* tiles with their trends. Rebuilt from Just Notch's stats plugin (`System`,
|
|
4
|
+
* `Tile`, `Measuring`, `CpuLoad`) on modo-ui's Sparkline: the samples come
|
|
5
|
+
* in as props.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use client'
|
|
9
|
+
|
|
10
|
+
import Sparkline from '@justanarthur/modo-ui/components/data-display/sparkline'
|
|
11
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
12
|
+
import { ArrowDown, ArrowUp, Cpu, type LucideIcon, MemoryStick, Network } from 'lucide-react'
|
|
13
|
+
import type { ReactNode } from 'react'
|
|
14
|
+
|
|
15
|
+
/** One reading of the system. */
|
|
16
|
+
interface StatsSample {
|
|
17
|
+
/** CPU load, from 0 to 1. */
|
|
18
|
+
cpu: number
|
|
19
|
+
/** Memory in use, in bytes. */
|
|
20
|
+
memoryUsed: number
|
|
21
|
+
/** All the memory, in bytes. */
|
|
22
|
+
memoryTotal: number
|
|
23
|
+
/** Network in, in bytes per second. */
|
|
24
|
+
netIn: number
|
|
25
|
+
/** Network out, in bytes per second. */
|
|
26
|
+
netOut: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SystemStatsProps {
|
|
30
|
+
/** The readings so far, oldest first; the latest is the figure, all of them the trend. Without any, it is still measuring. */
|
|
31
|
+
samples: StatsSample[]
|
|
32
|
+
/** Classes for the root, which fills its container. */
|
|
33
|
+
className?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const percent = (v: number) => `${Math.round(v * 100)}%`
|
|
37
|
+
const gigabytes = (bytes: number) => `${(bytes / 1e9).toFixed(1)} GB`
|
|
38
|
+
|
|
39
|
+
/** Bytes per second as `2.4 MB/s`, `512 KB/s` or `80 B/s`. */
|
|
40
|
+
function rate(bps: number) {
|
|
41
|
+
if (bps >= 1e6) return `${(bps / 1e6).toFixed(1)} MB/s`
|
|
42
|
+
if (bps >= 1e3) return `${Math.round(bps / 1e3)} KB/s`
|
|
43
|
+
return `${Math.round(bps)} B/s`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface TileProps {
|
|
47
|
+
icon: LucideIcon
|
|
48
|
+
label: string
|
|
49
|
+
value: ReactNode
|
|
50
|
+
children: ReactNode
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function Tile({ icon: Icon, label, value, children }: TileProps) {
|
|
54
|
+
return (
|
|
55
|
+
<div className="flex min-w-0 flex-col gap-2 rounded-xl bg-surface-2 p-3">
|
|
56
|
+
<span className="flex items-center gap-1.5 text-caption text-muted-foreground">
|
|
57
|
+
<Icon size={14} strokeWidth={1.5} />
|
|
58
|
+
{label}
|
|
59
|
+
</span>
|
|
60
|
+
<div className="flex min-w-0 items-baseline gap-2 text-subtitle weight-semibold tabular-nums text-foreground">
|
|
61
|
+
{value}
|
|
62
|
+
</div>
|
|
63
|
+
<div className="mt-auto">{children}</div>
|
|
64
|
+
</div>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** CPU and network are rates between two readings: the first lands about a second after opening. */
|
|
69
|
+
function Measuring({ className }: { className?: string }) {
|
|
70
|
+
const tiles = [
|
|
71
|
+
{ icon: Cpu, label: 'CPU' },
|
|
72
|
+
{ icon: MemoryStick, label: 'Memory' },
|
|
73
|
+
{ icon: Network, label: 'Network' },
|
|
74
|
+
]
|
|
75
|
+
return (
|
|
76
|
+
<div className={cn('grid size-full grid-cols-3 content-center gap-3', className)} aria-busy>
|
|
77
|
+
{tiles.map(({ icon, label }) => (
|
|
78
|
+
<Tile key={label} icon={icon} label={label} value={<span className="text-muted-foreground">–</span>}>
|
|
79
|
+
<Sparkline values={[]} label={`${label}, measuring`} className="h-10" />
|
|
80
|
+
</Tile>
|
|
81
|
+
))}
|
|
82
|
+
</div>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The compact island's left wing: the CPU glyph. */
|
|
87
|
+
function SystemStatsLeading() {
|
|
88
|
+
return <Cpu size={16} strokeWidth={1.5} className="text-muted-foreground" />
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The compact island's right wing: the CPU load, a dash until the first reading. */
|
|
92
|
+
function SystemStatsTrailing({ sample }: { sample?: StatsSample }) {
|
|
93
|
+
if (!sample) return <span className="text-caption weight-semibold text-muted-foreground">–</span>
|
|
94
|
+
return <span className="text-caption weight-semibold tabular-nums text-foreground">{percent(sample.cpu)}</span>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A notch app's system load: CPU, memory and network, each a tile with its
|
|
99
|
+
* figure and its trend.
|
|
100
|
+
*
|
|
101
|
+
* The latest reading is the figure: the CPU load, the memory in use of all
|
|
102
|
+
* of it, and the network's in and out rates. Every reading so far is the
|
|
103
|
+
* trend, a modo-ui Sparkline that spans the tile however many readings there
|
|
104
|
+
* are, since the island stays open for seconds, too short to fill a fixed
|
|
105
|
+
* window; network out runs muted under network in, on one scale. Before the
|
|
106
|
+
* first reading the tiles show a dash over the Sparkline's baseline.
|
|
107
|
+
*
|
|
108
|
+
* `SystemStats.Leading` and `SystemStats.Trailing` show the CPU load in the
|
|
109
|
+
* compact island's wings.
|
|
110
|
+
*
|
|
111
|
+
* @example {@include ./examples.mdx}
|
|
112
|
+
*/
|
|
113
|
+
function SystemStats({ samples, className }: SystemStatsProps) {
|
|
114
|
+
const last = samples.at(-1)
|
|
115
|
+
if (!last) return <Measuring className={className} />
|
|
116
|
+
|
|
117
|
+
const cpu = samples.map(s => s.cpu)
|
|
118
|
+
const memory = samples.map(s => s.memoryUsed)
|
|
119
|
+
const netIn = samples.map(s => s.netIn)
|
|
120
|
+
const netOut = samples.map(s => s.netOut)
|
|
121
|
+
return (
|
|
122
|
+
<div className={cn('grid size-full grid-cols-3 content-center gap-3', className)}>
|
|
123
|
+
<Tile icon={Cpu} label="CPU" value={percent(last.cpu)}>
|
|
124
|
+
<Sparkline values={cpu} max={1} label={`CPU, ${percent(last.cpu)}`} className="h-10" />
|
|
125
|
+
</Tile>
|
|
126
|
+
<Tile
|
|
127
|
+
icon={MemoryStick}
|
|
128
|
+
label="Memory"
|
|
129
|
+
value={
|
|
130
|
+
<>
|
|
131
|
+
{gigabytes(last.memoryUsed)}
|
|
132
|
+
<span className="truncate text-caption weight-normal text-muted-foreground">
|
|
133
|
+
of {gigabytes(last.memoryTotal)}
|
|
134
|
+
</span>
|
|
135
|
+
</>
|
|
136
|
+
}
|
|
137
|
+
>
|
|
138
|
+
<Sparkline
|
|
139
|
+
values={memory}
|
|
140
|
+
max={last.memoryTotal}
|
|
141
|
+
label={`Memory, ${gigabytes(last.memoryUsed)}`}
|
|
142
|
+
className="h-10"
|
|
143
|
+
/>
|
|
144
|
+
</Tile>
|
|
145
|
+
<Tile
|
|
146
|
+
icon={Network}
|
|
147
|
+
label="Network"
|
|
148
|
+
value={
|
|
149
|
+
<>
|
|
150
|
+
<span className="flex items-center gap-0.5">
|
|
151
|
+
<ArrowDown size={12} strokeWidth={2} aria-label="In" />
|
|
152
|
+
{rate(last.netIn)}
|
|
153
|
+
</span>
|
|
154
|
+
<span className="flex min-w-0 items-center gap-0.5 truncate text-caption weight-normal text-muted-foreground">
|
|
155
|
+
<ArrowUp size={12} strokeWidth={2} aria-label="Out" />
|
|
156
|
+
{rate(last.netOut)}
|
|
157
|
+
</span>
|
|
158
|
+
</>
|
|
159
|
+
}
|
|
160
|
+
>
|
|
161
|
+
<Sparkline
|
|
162
|
+
values={netIn}
|
|
163
|
+
secondary={netOut}
|
|
164
|
+
label={`Network, ${rate(last.netIn)} in, ${rate(last.netOut)} out`}
|
|
165
|
+
className="h-10"
|
|
166
|
+
/>
|
|
167
|
+
</Tile>
|
|
168
|
+
</div>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
SystemStats.Leading = SystemStatsLeading
|
|
173
|
+
SystemStats.Trailing = SystemStatsTrailing
|
|
174
|
+
|
|
175
|
+
export default SystemStats
|
|
176
|
+
|
|
177
|
+
export type { StatsSample, SystemStatsProps }
|
|
178
|
+
export { SystemStats, SystemStatsLeading, SystemStatsTrailing }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import BatteryGlyph from './index'
|
|
2
|
+
|
|
3
|
+
# Levels
|
|
4
|
+
|
|
5
|
+
The fill takes the warning hue from 20% down and the error hue from 10%.
|
|
6
|
+
|
|
7
|
+
<div className="flex items-center gap-6">
|
|
8
|
+
<BatteryGlyph level={82} />
|
|
9
|
+
<BatteryGlyph level={46} />
|
|
10
|
+
<BatteryGlyph level={18} />
|
|
11
|
+
<BatteryGlyph level={6} />
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
# Charging
|
|
15
|
+
|
|
16
|
+
A bolt, and the success hue.
|
|
17
|
+
|
|
18
|
+
<div className="dark flex items-center gap-6 rounded-box bg-ink px-5 py-3 text-foreground">
|
|
19
|
+
<BatteryGlyph level={82} charging />
|
|
20
|
+
<BatteryGlyph level={12} charging />
|
|
21
|
+
<BatteryGlyph level={100} tone="default" />
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: a battery that fills to its level, for a notch app's power
|
|
3
|
+
* alerts. Rebuilt from Just Notch's power plugin (`Battery`).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use client'
|
|
7
|
+
|
|
8
|
+
import { useReduceMotion } from '@justanarthur/modo-ui/lib/reduced-motion'
|
|
9
|
+
import { spring } from '@justanarthur/modo-ui/lib/springs'
|
|
10
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
11
|
+
import { motion } from 'motion/react'
|
|
12
|
+
|
|
13
|
+
type BatteryTone = 'default' | 'success' | 'warning' | 'error'
|
|
14
|
+
|
|
15
|
+
// Literal table: UnoCSS only generates the classes it can read whole.
|
|
16
|
+
const FILL: Record<BatteryTone, string> = {
|
|
17
|
+
default: 'bg-foreground',
|
|
18
|
+
success: 'bg-status-success',
|
|
19
|
+
warning: 'bg-status-warning',
|
|
20
|
+
error: 'bg-status-error',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface BatteryGlyphProps {
|
|
24
|
+
/** The charge, in percent (0 to 100). */
|
|
25
|
+
level: number
|
|
26
|
+
/** A charger is connected: the bolt shows and the tone turns to success. Defaults to `false`. */
|
|
27
|
+
charging?: boolean
|
|
28
|
+
/** The fill's hue. Defaults to success while charging, error at 10% and below, warning at 20% and below, else the text color. */
|
|
29
|
+
tone?: BatteryTone
|
|
30
|
+
/** Fill up from empty when it first shows, as a flash opens. Defaults to `true`. */
|
|
31
|
+
fillIn?: boolean
|
|
32
|
+
/** What screen readers hear. Defaults to the level, and "charging" while it charges. */
|
|
33
|
+
label?: string
|
|
34
|
+
/** Classes for the glyph. */
|
|
35
|
+
className?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The tone a battery at `level` takes on its own. */
|
|
39
|
+
function batteryTone(level: number, charging: boolean): BatteryTone {
|
|
40
|
+
if (charging) return 'success'
|
|
41
|
+
if (level <= 10) return 'error'
|
|
42
|
+
if (level <= 20) return 'warning'
|
|
43
|
+
return 'default'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A battery at a glance: a case that fills to the charge, a bolt while it
|
|
48
|
+
* charges.
|
|
49
|
+
*
|
|
50
|
+
* The fill turns to the success hue while charging and to the warning and
|
|
51
|
+
* error hues as the charge runs low, unless `tone` pins one. It fills up from
|
|
52
|
+
* empty when it first shows, on the slow spring, the way a power alert opens;
|
|
53
|
+
* a later change of level springs from where it was. A sliver always shows,
|
|
54
|
+
* so an empty battery still reads as one.
|
|
55
|
+
*
|
|
56
|
+
* @example {@include ./examples.mdx}
|
|
57
|
+
*/
|
|
58
|
+
export default function BatteryGlyph({
|
|
59
|
+
level,
|
|
60
|
+
charging = false,
|
|
61
|
+
tone,
|
|
62
|
+
fillIn = true,
|
|
63
|
+
label,
|
|
64
|
+
className,
|
|
65
|
+
}: BatteryGlyphProps) {
|
|
66
|
+
const reduced = useReduceMotion()
|
|
67
|
+
const share = Math.max(0.06, Math.min(1, level / 100))
|
|
68
|
+
const name = label ?? `${Math.round(level)}%${charging ? ', charging' : ''}`
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<span role="img" aria-label={name} className={cn('inline-flex shrink-0 items-center gap-px', className)}>
|
|
72
|
+
<span className="relative h-3.5 w-7 overflow-hidden rounded-box bg-active p-0.5">
|
|
73
|
+
<motion.span
|
|
74
|
+
className={cn('block h-full w-full origin-left rounded-glyph', FILL[tone ?? batteryTone(level, charging)])}
|
|
75
|
+
initial={fillIn && !reduced ? { scaleX: 0 } : false}
|
|
76
|
+
animate={{ scaleX: share }}
|
|
77
|
+
transition={reduced ? { duration: 0 } : spring.slow}
|
|
78
|
+
/>
|
|
79
|
+
{charging && (
|
|
80
|
+
<svg aria-hidden viewBox="0 0 24 24" className="absolute inset-0 m-auto size-3 fill-foreground">
|
|
81
|
+
<path d="M13 2 4.5 13.5H11L10 22l8.5-11.5H12z" />
|
|
82
|
+
</svg>
|
|
83
|
+
)}
|
|
84
|
+
</span>
|
|
85
|
+
<span className="h-1.5 w-0.5 rounded-r-full bg-active" />
|
|
86
|
+
</span>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type { BatteryGlyphProps, BatteryTone }
|
|
91
|
+
export { BatteryGlyph, batteryTone }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Countdown from './index'
|
|
2
|
+
|
|
3
|
+
# Clock
|
|
4
|
+
|
|
5
|
+
`4:05`, a digit at a time on the second's edge.
|
|
6
|
+
|
|
7
|
+
<div className="flex items-center gap-6 text-subtitle weight-semibold">
|
|
8
|
+
<Countdown duration={245000} />
|
|
9
|
+
<Countdown duration={3725000} />
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
# Short
|
|
13
|
+
|
|
14
|
+
The largest unit, for a compact wing: minutes, then seconds in the last minute.
|
|
15
|
+
|
|
16
|
+
<div className="dark flex items-center gap-6 rounded-box bg-ink px-5 py-3 text-caption weight-medium text-status-warning">
|
|
17
|
+
<Countdown duration={240000} format="short" />
|
|
18
|
+
<Countdown duration={45000} format="short" />
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
# Paused
|
|
22
|
+
|
|
23
|
+
It holds the time left.
|
|
24
|
+
|
|
25
|
+
<Countdown paused remaining={754000} className="text-subtitle weight-semibold text-muted-foreground" />
|