@hashsome/ui 0.7.0 → 0.9.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/dist/.tsbuildinfo +1 -1
- package/dist/entities/attention-dot.d.ts +4 -0
- package/dist/entities/attention-dot.js +12 -0
- package/dist/entities/media-browser.js +35 -9
- package/dist/entities/media-controls.d.ts +22 -4
- package/dist/entities/media-controls.js +45 -10
- package/dist/entities/media-loading-line.d.ts +9 -0
- package/dist/entities/media-loading-line.js +14 -0
- package/dist/entities/media-pending.d.ts +24 -0
- package/dist/entities/media-pending.js +121 -0
- package/dist/entities/media-player-bar.js +10 -6
- package/dist/entities/media-progress.d.ts +4 -0
- package/dist/entities/media-progress.js +41 -0
- package/dist/entities/nav-dock.js +2 -1
- package/dist/entities/nav-rail.d.ts +2 -0
- package/dist/entities/nav-rail.js +4 -2
- package/dist/entities/now-playing.js +9 -6
- package/dist/entities/top-bar.d.ts +1 -1
- package/dist/entities/top-bar.js +24 -11
- package/dist/gallery/gallery.js +27 -1
- package/dist/gallery/props-data.js +106 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/layout/check-mark.d.ts +5 -0
- package/dist/layout/check-mark.js +9 -0
- package/dist/layout/confirm-dialog.d.ts +28 -0
- package/dist/layout/confirm-dialog.js +62 -0
- package/dist/layout/debug-menu.js +10 -5
- package/dist/layout/drawer-controls.js +46 -3
- package/dist/layout/fade-scroll.d.ts +2 -0
- package/dist/layout/fade-scroll.js +1 -1
- package/dist/layout/icon-button-styles.js +3 -1
- package/dist/layout/spinner.d.ts +16 -0
- package/dist/layout/spinner.js +23 -0
- package/dist/layout/task-tile.d.ts +28 -0
- package/dist/layout/task-tile.js +78 -0
- package/dist/layout/tile.d.ts +1 -1
- package/dist/layout/tile.js +3 -1
- package/dist/layout/use-timed.d.ts +7 -0
- package/dist/layout/use-timed.js +22 -0
- package/dist/theme/grid.d.ts +3 -0
- package/dist/theme/grid.js +3 -0
- package/dist/theme/index.js +3 -0
- package/dist/theme/tokens.d.ts +4 -0
- package/dist/use-media-queue.js +5 -2
- package/package.json +2 -2
|
@@ -7,10 +7,11 @@ import { ValueBar } from '../layout/drawer-controls.js';
|
|
|
7
7
|
import { PlainButton } from '../layout/plain-button.js';
|
|
8
8
|
import { IconButton } from '../layout/tile.js';
|
|
9
9
|
import { statusLabels } from '../status.js';
|
|
10
|
-
import { usePressFeedback, useVolumeControl } from './media-controls.js';
|
|
11
|
-
import { formatDuration, useMediaPosition } from './media-progress.js';
|
|
10
|
+
import { usePressFeedback, useTransportAvailability, useVolumeControl } from './media-controls.js';
|
|
11
|
+
import { formatDuration, useMediaPosition, useSteadyPlaying } from './media-progress.js';
|
|
12
12
|
import { useSeekHold } from './media-seek.js';
|
|
13
13
|
import { ArtworkRing } from './artwork-ring.js';
|
|
14
|
+
import { LoadingLine, useLoadingLabel } from './media-loading-line.js';
|
|
14
15
|
/** The upright "now playing" panel the media column and page share: the artwork on a record, what is playing, how
|
|
15
16
|
* far along it is, the transport buttons and a volume bar that is always there. Not exported from
|
|
16
17
|
* the package; `MediaPlayerColumn` and `MediaPlayerFull` are its public forms. */
|
|
@@ -19,12 +20,14 @@ export function NowPlaying({ handle, fallback, name, extra, leading, onOpenArtwo
|
|
|
19
20
|
const { iconCircle, space } = useTheme().density;
|
|
20
21
|
const transportWidth = 5 * iconCircle + 4 * space;
|
|
21
22
|
const { status } = handle;
|
|
23
|
+
const loading = useLoadingLabel(player?.ref);
|
|
22
24
|
const ready = status === 'ready';
|
|
23
25
|
const caps = player?.capabilities;
|
|
24
|
-
const playing = player
|
|
25
|
-
const { feedbackFor, press } = usePressFeedback();
|
|
26
|
+
const playing = useSteadyPlaying(player);
|
|
27
|
+
const { feedbackFor, press } = usePressFeedback(player?.ref);
|
|
26
28
|
const volume = useVolumeControl(handle);
|
|
27
29
|
const position = useMediaPosition(player);
|
|
30
|
+
const can = useTransportAvailability(player, position);
|
|
28
31
|
const duration = ready ? player?.duration : undefined;
|
|
29
32
|
// The ring and the time under the title share one position, so dragging the ring moves both.
|
|
30
33
|
const seek = useSeekHold(ready ? position : undefined, caps?.seek ? (next) => void handle.command('seek', { position: next }) : undefined);
|
|
@@ -32,8 +35,8 @@ export function NowPlaying({ handle, fallback, name, extra, leading, onOpenArtwo
|
|
|
32
35
|
// No wider than the row of five buttons under it (268px: five circles and the gaps between them).
|
|
33
36
|
maxSize: transportWidth }), _jsxs(Flex, { direction: "column", align: "center", gap: 0.5, color: ready ? 'text' : 'textMuted', children: [_jsxs(Flex, { align: "center", justify: "center", gap: 2, maxWidth: "100%", children: [_jsx(Typography, { as: "h2", variant: "title", noWrap: true, textOverflow: "ellipsis", overflow: "hidden", m: 0, minWidth: 0, children: ready
|
|
34
37
|
? (player?.media?.title ?? 'Nothing playing')
|
|
35
|
-
: statusLabels[status] }), caps?.shuffle && shufflePlacement === 'title' ? (_jsx(IconButton, { icon: "lu:shuffle", label: "Shuffle", size: 14, active: player?.shuffle === true, pressed: player?.shuffle === true, disabled: !ready, onClick: () =>
|
|
38
|
+
: statusLabels[status] }), caps?.shuffle && shufflePlacement === 'title' ? (_jsx(IconButton, { icon: "lu:shuffle", label: "Shuffle", size: 14, active: player?.shuffle === true, pressed: player?.shuffle === true, disabled: !ready, feedback: feedbackFor('setShuffle'), onClick: () => press('setShuffle', () => handle.command('setShuffle', { shuffle: player?.shuffle !== true })) })) : null] }), loading ? (_jsx(LoadingLine, { label: loading, variant: "body" })) : ready && player?.media?.artist ? (_jsx(Typography, { as: "span", variant: "body", color: "textMuted", noWrap: true, textOverflow: "ellipsis", overflow: "hidden", children: [player.media.artist, player.media.album].filter(Boolean).join(' · ') })) : (_jsx(Typography, { as: "span", variant: "body", color: "textMuted", noWrap: true, textOverflow: "ellipsis", overflow: "hidden", children: name ?? player?.name ?? fallback }))] }), seek.shown !== undefined && duration ? (_jsxs(Typography, { as: "span", variant: "secondary", color: "textMuted", align: "center", css: { fontVariantNumeric: 'tabular-nums' }, children: [formatDuration(seek.shown), " / ", formatDuration(duration)] })) : null, _jsxs(Grid, { gap: 3, css: ({ density }) => ({
|
|
36
39
|
gridTemplateColumns: `repeat(5, ${density.iconCircle}px)`,
|
|
37
40
|
justifyContent: 'center',
|
|
38
|
-
}), children: [caps?.shuffle && shufflePlacement === 'transport' ? (_jsx(IconButton, { icon: "lu:shuffle", label: "Shuffle", glyph: 18, active: player?.shuffle === true, pressed: player?.shuffle === true, disabled: !ready, onClick: () =>
|
|
41
|
+
}), children: [caps?.shuffle && shufflePlacement === 'transport' ? (_jsx(IconButton, { icon: "lu:shuffle", label: "Shuffle", glyph: 18, active: player?.shuffle === true, pressed: player?.shuffle === true, disabled: !ready, feedback: feedbackFor('setShuffle'), onClick: () => press('setShuffle', () => handle.command('setShuffle', { shuffle: player?.shuffle !== true })) })) : shufflePlacement === 'title' ? ((leading ?? _jsx("span", {}))) : (_jsx("span", {})), _jsx(IconButton, { icon: "lu:skip-back", label: "Previous", glyph: 18, disabled: !ready || caps?.previous === false || !can.previous, feedback: feedbackFor('previous'), onClick: () => press('previous', () => handle.command('previous')) }), _jsx(IconButton, { icon: playing ? 'lu:pause' : 'lu:play', label: playing ? 'Pause' : 'Play', glyph: 18, disabled: !ready || !can.play, primary: true, feedback: feedbackFor('togglePlay'), onClick: () => press('togglePlay', () => handle.command('togglePlay')) }), _jsx(IconButton, { icon: "lu:skip-forward", label: "Next", glyph: 18, disabled: !ready || caps?.next === false || !can.next, feedback: feedbackFor('next'), onClick: () => press('next', () => handle.command('next')) }), extra ?? _jsx("span", {})] }), caps?.volume !== false || caps.mute ? (_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(PlainButton, { "aria-label": volume.muted ? 'Unmute' : 'Mute', "aria-pressed": volume.muted, title: volume.muted ? 'Unmute' : 'Mute', disabled: !ready || caps?.mute === false, onClick: volume.toggleMute, center: true, color: volume.muted ? 'accent' : 'textMuted', css: { flex: 'none' }, children: _jsx(Icon, { name: volume.muted ? 'lu:volume-x' : 'lu:volume-2', size: 16 }) }), _jsx(ValueBar, { label: "Volume level", value: volume.shown, min: 0, max: 100, keyStep: 5, height: 10, onDrag: volume.drag, onCommit: volume.commit }), _jsxs(Typography, { as: "span", variant: "secondary", color: "textMuted", minWidth: 32, align: "right", css: { flex: 'none', fontVariantNumeric: 'tabular-nums' }, children: [volume.shown, "%"] })] })) : null] }));
|
|
39
42
|
}
|
|
@@ -12,7 +12,7 @@ export interface DashboardOption {
|
|
|
12
12
|
export interface TopBarScene {
|
|
13
13
|
entity: EntityRef;
|
|
14
14
|
icon?: IconName;
|
|
15
|
-
/** A literal CSS color for this scene's dot (e.g. `#8B5CF6`) — scenes are meant to read as distinct at a glance, which the palette doesn't have enough colors for, so each app picks its own. Defaults to the theme's accent. */
|
|
15
|
+
/** A literal CSS color for this scene's dot (the one place a color is not from the theme: scenes are meant to be told apart by their own) (e.g. `#8B5CF6`) — scenes are meant to read as distinct at a glance, which the palette doesn't have enough colors for, so each app picks its own. Defaults to the theme's accent. */
|
|
16
16
|
color?: string;
|
|
17
17
|
}
|
|
18
18
|
export interface TopBarProps {
|
package/dist/entities/top-bar.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { Box, Flex, Typography } from 'e-prim';
|
|
3
|
+
import { motion } from 'motion/react';
|
|
3
4
|
import { PlainButton } from '../layout/plain-button.js';
|
|
4
5
|
import { useEffect, useRef, useState } from 'react';
|
|
5
6
|
import { useLocation, useNavigate } from 'react-router';
|
|
@@ -8,7 +9,9 @@ import { useConnectionStatus, useEntity, useEntityHandle, useIntegrationStatuses
|
|
|
8
9
|
import { Icon } from '../icon.js';
|
|
9
10
|
import { statusLabels } from '../status.js';
|
|
10
11
|
import { TOP_ROW } from '../theme/grid.js';
|
|
12
|
+
import { CheckMark } from '../layout/check-mark.js';
|
|
11
13
|
import { DrawerTrigger } from '../layout/use-drawer.js';
|
|
14
|
+
import { useTimed } from '../layout/use-timed.js';
|
|
12
15
|
import { useWeatherForecast } from '../use-weather-forecast.js';
|
|
13
16
|
import { SensorReadout } from './sensor-readout.js';
|
|
14
17
|
import { WeatherForecast } from './weather-forecast.js';
|
|
@@ -86,11 +89,8 @@ function DashboardSwitcher({ title, dashboards, }) {
|
|
|
86
89
|
height: SWITCHER_HEIGHT, radius: "small", px: 3, color: "text", background: active ? 'surface' : 'transparent', cursor: active ? 'default' : 'pointer', css: { textAlign: 'left' }, children: [d.icon ? _jsx(Icon, { name: d.icon, size: 16 }) : null, _jsx(Typography, { as: "span", variant: "body", grow: 1, children: d.title }), active ? _jsx(Icon, { name: "lu:check", size: 16 }) : null] }) }, d.id));
|
|
87
90
|
}) })) : null] }));
|
|
88
91
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
pending: '#FBBF24',
|
|
92
|
-
down: '#F2554A',
|
|
93
|
-
};
|
|
92
|
+
/** The palette color each health reads as. */
|
|
93
|
+
const HEALTH_COLORS = { ok: 'success', pending: 'warm', down: 'danger' };
|
|
94
94
|
function linkHealth(link) {
|
|
95
95
|
return link === 'open' ? 'ok' : link === 'connecting' ? 'pending' : 'down';
|
|
96
96
|
}
|
|
@@ -133,10 +133,10 @@ export function SystemStatus({ link: linkOverride, statuses: statusesOverride, d
|
|
|
133
133
|
: overall === 'pending'
|
|
134
134
|
? 'Connecting…'
|
|
135
135
|
: `${rows.filter((row) => row.health === 'down').length} system(s) down`;
|
|
136
|
-
return (_jsxs(Flex, { ref: ref, position: "relative", children: [_jsx(PlainButton, { "aria-label": summary, "aria-expanded": open, title: summary, onClick: () => setOpen((o) => !o), align: "center", justify: "center", width: 32, height: 32, radius: "full", children: _jsx(Flex, { as: "span", width: 12, height: 12, radius: "full", css: {
|
|
137
|
-
background: HEALTH_COLORS[overall],
|
|
138
|
-
boxShadow: `0 0 0 4px ${HEALTH_COLORS[overall]}
|
|
139
|
-
} }) }), open ? (_jsxs(Flex, { direction: "column", gap: 2, background: "surfaceRaised", radius: "row", shadow: "drawer", p: 3.5, role: "status", position: "absolute", zIndex: "dropdown", mt: 2, minWidth: 220, css: { top: '100%', right: 0, whiteSpace: 'nowrap' }, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Flex, { as: "span", width: 8, height: 8, radius: "full", css: { background: HEALTH_COLORS[overall] } }), _jsx(Typography, { as: "span", variant: "bodyStrong", children: summary })] }), rows.map((row) => (_jsxs(Flex, { align: "center", justify: "space-between", gap: 6, children: [_jsx(Typography, { as: "span", variant: "body", children: row.name }), _jsx(Typography, { as: "span", variant: "label", css: { color: HEALTH_COLORS[row.health] }, children: row.label })] }, row.name)))] })) : null] }));
|
|
136
|
+
return (_jsxs(Flex, { ref: ref, position: "relative", children: [_jsx(PlainButton, { "aria-label": summary, "aria-expanded": open, title: summary, onClick: () => setOpen((o) => !o), align: "center", justify: "center", width: 32, height: 32, radius: "full", children: _jsx(Flex, { as: "span", width: 12, height: 12, radius: "full", css: ({ palette }) => ({
|
|
137
|
+
background: palette[HEALTH_COLORS[overall]],
|
|
138
|
+
boxShadow: `0 0 0 4px color-mix(in srgb, ${palette[HEALTH_COLORS[overall]]} 20%, transparent)`,
|
|
139
|
+
}) }) }), open ? (_jsxs(Flex, { direction: "column", gap: 2, background: "surfaceRaised", radius: "row", shadow: "drawer", p: 3.5, role: "status", position: "absolute", zIndex: "dropdown", mt: 2, minWidth: 220, css: { top: '100%', right: 0, whiteSpace: 'nowrap' }, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Flex, { as: "span", width: 8, height: 8, radius: "full", css: ({ palette }) => ({ background: palette[HEALTH_COLORS[overall]] }) }), _jsx(Typography, { as: "span", variant: "bodyStrong", children: summary })] }), rows.map((row) => (_jsxs(Flex, { align: "center", justify: "space-between", gap: 6, children: [_jsx(Typography, { as: "span", variant: "body", children: row.name }), _jsx(Typography, { as: "span", variant: "label", css: ({ palette }) => ({ color: palette[HEALTH_COLORS[row.health]] }), children: row.label })] }, row.name)))] })) : null] }));
|
|
140
140
|
}
|
|
141
141
|
function StatusChip({ children }) {
|
|
142
142
|
return (_jsx(Flex, { align: "center", gap: 2, background: "surface", border: true, radius: "full", px: 3.5, py: 2.5, children: children }));
|
|
@@ -181,14 +181,27 @@ function SensorWeather({ entity }) {
|
|
|
181
181
|
const handle = useEntityHandle('sensor', entity);
|
|
182
182
|
const { status } = handle;
|
|
183
183
|
const sensor = handle.entity;
|
|
184
|
-
return (_jsxs(StatusChip, { children: [_jsx(Flex, { as: "span", css: { color:
|
|
184
|
+
return (_jsxs(StatusChip, { children: [_jsx(Flex, { as: "span", css: ({ palette }) => ({ color: palette.warm }), children: _jsx(Icon, { name: "lu:sun", size: 14 }) }), _jsx(Typography, { as: "span", variant: "label", children: status === 'ready' && sensor?.numeric !== undefined
|
|
185
185
|
? `${Math.round(sensor.numeric)}°`
|
|
186
186
|
: statusLabels[status] })] }));
|
|
187
187
|
}
|
|
188
|
+
/** How long a scene's dot shows it has been pressed, from the press. */
|
|
189
|
+
const SCENE_DONE_MS = 1500;
|
|
188
190
|
function SceneDot({ entity, icon, color }) {
|
|
189
191
|
const handle = useEntityHandle('action', entity);
|
|
190
192
|
const label = handle.entity?.name ?? '';
|
|
191
|
-
|
|
193
|
+
// A press is answered at once, for a fixed time and whatever the scene does: the dot pops, turns green and
|
|
194
|
+
// draws a check in place of its icon. It cannot be pressed again until that is over.
|
|
195
|
+
const { active: done, start } = useTimed(SCENE_DONE_MS);
|
|
196
|
+
return (_jsxs(Flex, { as: motion.button, type: "button", "aria-label": label, title: label, disabled: done, onClick: () => {
|
|
197
|
+
if (start()) {
|
|
198
|
+
void handle.command('trigger');
|
|
199
|
+
}
|
|
200
|
+
}, align: "center", justify: "center", width: 40, height: 40, radius: "full", position: "relative", cursor: done ? 'default' : 'pointer', animate: { scale: done ? [1, 1.18, 1] : 1 }, transition: { duration: 0.4 }, css: ({ palette }) => ({
|
|
201
|
+
background: done ? palette.success : (color ?? palette.accent),
|
|
202
|
+
color: palette.accentText,
|
|
203
|
+
transition: 'background-color 0.25s ease',
|
|
204
|
+
}), children: [_jsx(Box, { as: motion.span, css: { display: 'grid' }, animate: { opacity: done ? 0 : 1, scale: done ? 0.5 : 1 }, transition: { duration: 0.18 }, children: _jsx(Icon, { name: icon ?? 'lu:palette', size: 18 }) }), done ? (_jsx(Flex, { align: "center", justify: "center", position: "absolute", css: { inset: 0 }, children: _jsx(CheckMark, {}) })) : null] }));
|
|
192
205
|
}
|
|
193
206
|
function initials(name) {
|
|
194
207
|
const words = name.trim().split(/\s+/).filter(Boolean);
|
package/dist/gallery/gallery.js
CHANGED
|
@@ -27,6 +27,8 @@ import { Board, Cell } from '../layout/board.js';
|
|
|
27
27
|
import { Grid } from '../layout/grid.js';
|
|
28
28
|
import { HistorySection } from '../layout/history-section.js';
|
|
29
29
|
import { RoomHeader } from '../layout/room-header.js';
|
|
30
|
+
import { ConfirmDialog } from '../layout/confirm-dialog.js';
|
|
31
|
+
import { TaskTile } from '../layout/task-tile.js';
|
|
30
32
|
import { Tile } from '../layout/tile.js';
|
|
31
33
|
import { TopRow } from '../layout/top-row.js';
|
|
32
34
|
import { HashsomeProvider } from '../provider.js';
|
|
@@ -42,6 +44,12 @@ const NAV_ITEMS = [
|
|
|
42
44
|
{ to: 'climate', label: 'Climate', icon: 'lu:thermometer' },
|
|
43
45
|
{ to: 'music', label: 'Music', icon: 'lu:music' },
|
|
44
46
|
];
|
|
47
|
+
/** The same pages with something to look at on two of them: a warm dot (`notice`) and a red one (`urgent`). */
|
|
48
|
+
const ATTENTION_ITEMS = NAV_ITEMS.map((item) => item.to === 'lights'
|
|
49
|
+
? { ...item, attention: 'notice' }
|
|
50
|
+
: item.to === 'climate'
|
|
51
|
+
? { ...item, attention: 'urgent' }
|
|
52
|
+
: item);
|
|
45
53
|
const codeStyles = {
|
|
46
54
|
fontFamily: "ui-monospace, 'SF Mono', Menlo, monospace",
|
|
47
55
|
overflowWrap: 'anywhere',
|
|
@@ -75,6 +83,24 @@ function PropsTable({ name }) {
|
|
|
75
83
|
function ComponentDoc({ title, description, components, children, }) {
|
|
76
84
|
return (_jsxs("section", { css: { marginBottom: 40 }, children: [_jsxs(Flex, { direction: "column", gap: 1, maxWidth: "60ch", mb: 4, children: [_jsx(Typography, { as: "h2", variant: "heading", children: title }), _jsx(Typography, { as: "p", variant: "body", color: "textMuted", children: description })] }), _jsx(Stage, { children: children }), components.map((name) => (_jsx(PropsTable, { name: name }, name)))] }));
|
|
77
85
|
}
|
|
86
|
+
/** A day `n` days from today, at the start of it. */
|
|
87
|
+
const inDays = (n) => {
|
|
88
|
+
const now = new Date();
|
|
89
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate() + n);
|
|
90
|
+
};
|
|
91
|
+
/** What marking something done takes in a demo: a moment, and nothing else. */
|
|
92
|
+
const pause = () => new Promise((resolve) => setTimeout(resolve, 600));
|
|
93
|
+
function ConfirmDialogDemo() {
|
|
94
|
+
const [open, setOpen] = useState(false);
|
|
95
|
+
const [answer, setAnswer] = useState();
|
|
96
|
+
return (_jsxs(Flex, { align: "center", gap: 4, children: [_jsx(ActionButton, { label: "Empty the trash?", icon: "lu:trash-2", onPress: async () => setOpen(true) }), _jsx(Typography, { as: "span", variant: "body", color: "textMuted", children: answer ?? 'Not asked yet' }), _jsx(ConfirmDialog, { open: open, title: "Empty the trash?", description: "Nothing in it can be brought back.", confirmLabel: "Empty it", onConfirm: () => {
|
|
97
|
+
setAnswer('Emptied');
|
|
98
|
+
setOpen(false);
|
|
99
|
+
}, onCancel: () => {
|
|
100
|
+
setAnswer('Left alone');
|
|
101
|
+
setOpen(false);
|
|
102
|
+
} })] }));
|
|
103
|
+
}
|
|
78
104
|
/** A reading that changes every time the button is pressed, to see it move. */
|
|
79
105
|
function AnimatedNumberDemo() {
|
|
80
106
|
const [watts, setWatts] = useState(40.1);
|
|
@@ -374,7 +400,7 @@ export function Gallery({ density = 'comfortable' }) {
|
|
|
374
400
|
boxShadow: '0 1px 3px rgba(0, 0, 0, 0.25)',
|
|
375
401
|
transform: mode === 'dark' ? 'translate(28px, -50%)' : 'translateY(-50%)',
|
|
376
402
|
transition: 'transform 0.2s ease',
|
|
377
|
-
}) }), _jsx(Icon, { name: "lu:sun", size: 14 }), _jsx(Icon, { name: "lu:moon", size: 14 })] })] }), _jsx(ComponentDoc, { title: "Board & Cell", components: ['Board', 'Cell'], description: "A page for one known device, laid out on a grid. Each cell says only how big it is (`cols` wide, `rows` tall); the board places them in order, in the first spot they fit. Rows are as tall as their content, so a cell of `rows={2}` ends where the second row does, and `rows='fill'` runs from where the cell is placed down to the bottom of the page, whatever rows are beside it. Every card is a whole number of grid modules tall, the gap between columns and inside a cell is three modules and between rows six, so the result stays on the grid (turn on the debug menu's Show grid to see it).", children: _jsxs(Flex, { direction: "column", gap: 5, children: [_jsxs(Board, { children: [_jsxs(Cell, { cols: 8, children: [_jsx(RoomHeader, { title: "Kitchen", icon: "lu:utensils-crossed" }), _jsxs(Grid, { columns: 2, children: [_jsx(Tile, { label: "Lamp", icon: "lu:lightbulb" }), _jsx(Tile, { label: "Ceiling", icon: "lu:lightbulb" })] })] }), _jsx(Cell, { cols: 4, rows: 2, children: _jsx(MediaPlayerColumn, { entity: "ha:media_player.off" }) }), _jsxs(Cell, { cols: 8, children: [_jsx(RoomHeader, { title: "Stairs", icon: "lu:footprints" }), _jsxs(Grid, { columns: 2, children: [_jsx(Tile, { label: "Lamp", icon: "lu:lightbulb" }), _jsx(Tile, { label: "Spotlights", icon: "lu:lightbulb" })] })] })] }), _jsx(Flex, { direction: "column", height: 460, css: { outline: '1px dashed currentColor' }, children: _jsxs(Board, { children: [_jsx(Cell, { children: _jsxs(TopRow, { children: [_jsx(DateChip, {}), _jsx(Clock, { format: "24h" })] }) }), _jsxs(Cell, { cols: 8, children: [_jsx(RoomHeader, { title: "Kitchen", icon: "lu:utensils-crossed" }), _jsxs(Grid, { columns: 2, children: [_jsx(Tile, { label: "Lamp", icon: "lu:lightbulb" }), _jsx(Tile, { label: "Ceiling", icon: "lu:lightbulb" })] })] }), _jsx(Cell, { cols: 4, rows: "fill", children: _jsx(MediaPlayerColumn, { entity: "ha:media_player.off" }) })] }) })] }) }), _jsx(ComponentDoc, { title: "Top Row", components: ['TopRow'], description: "The row along the top of a page you build yourself instead of with `TopBar`: the date, the weather, the clock and the status in a line at the right, in the height the grid gives the top row (40px), with no padding of its own.", children: _jsxs(TopRow, { children: [_jsx(DateChip, {}), _jsx(Clock, { format: "24h" })] }) }), _jsx(ComponentDoc, { title: "Grid", components: ['Grid'], description: "Lays tiles out in equal-width columns (`columns`, default 2). Cells share the width and never overflow it.", children: _jsxs(Flex, { direction: "column", gap: 5, children: [_jsxs(Grid, { columns: 2, children: [_jsx(Tile, { label: "Two", icon: "lu:layout-grid", secondary: "columns={2}" }), _jsx(Tile, { label: "Columns", icon: "lu:layout-grid", secondary: "equal width" })] }), _jsxs(Grid, { columns: 3, children: [_jsx(Tile, { label: "Three", icon: "lu:layout-grid", secondary: "columns={3}" }), _jsx(Tile, { label: "Columns", icon: "lu:layout-grid", secondary: "equal width" }), _jsx(Tile, { label: "Wide", icon: "lu:layout-grid", secondary: "fits the row" })] })] }) }), _jsx(ComponentDoc, { title: "Room Header", components: ['RoomHeader'], description: "The header that starts a room: a muted icon and title, a hairline and readouts on the right, placed above a Grid (or any tiles). It adds its own space above, so consecutive rooms read as groups.", children: _jsxs(Flex, { direction: "column", gap: 4, children: [_jsx(RoomHeader, { title: "Kitchen", icon: "lu:utensils-crossed" }), _jsx(RoomHeader, { title: "Porch", icon: "lu:house", readouts: _jsxs(_Fragment, { children: [_jsx(SensorReadout, { entity: "ha:sensor.temperature" }), _jsx(SensorReadout, { entity: "ha:sensor.humidity" })] }) })] }) }), _jsx(ComponentDoc, { title: "Tile", components: ['Tile'], description: "The base card every entity tile is built from: icon, label, status line, optional fill bar (drag to change it), trailing controls, a hold-to-open drawer and pending / done / error feedback. Use it directly for something that isn't an entity.", children: _jsxs(Grid, { children: [_jsx(Tile, { label: "Plain", icon: "lu:lamp", secondary: "Off" }), _jsx(Tile, { label: "Active", icon: "lu:lamp", active: true }), _jsx(TileFillDemo, {}), _jsx(Tile, { label: "With controls", icon: "lu:fan", trailing: _jsx(Typography, { as: "span", variant: "secondary", color: "textMuted", children: "trailing" }) }), _jsx(Tile, { label: "Pending", icon: "lu:lamp", feedback: "pending" }), _jsx(Tile, { label: "Error", icon: "lu:lamp", feedback: "error" }), _jsx(Tile, { label: "Unavailable", icon: "lu:lamp", status: "unavailable" }), _jsx(Tile, { label: "Not found", icon: "lu:lamp", status: "missing" })] }) }), _jsx(ComponentDoc, { title: "Icon", components: ['Icon'], description: "A plain prefixed string, no import: `lu:` is Lucide, `tb:` is Tabler outline. It takes the surrounding text color and scales with `size` (default 24px).", children: _jsxs(Flex, { direction: "column", gap: 4, children: [_jsxs(Flex, { align: "center", gap: 4, children: [_jsx(Icon, { name: "lu:lightbulb" }), _jsx(Icon, { name: "lu:thermometer", size: 16 }), _jsx(Icon, { name: "lu:sofa", size: 32 }), _jsx(Icon, { name: "tb:vacuum-cleaner" }), _jsx(Icon, { name: "tb:car-fan", size: 16 })] }), _jsxs(Flex, { align: "center", gap: 4, css: { flexWrap: 'wrap' }, children: [_jsx(Typography, { as: "span", variant: "body", color: "textMuted", children: "Find an icon:" }), ICON_PACKS.map((pack) => (_jsx(Typography, { as: "span", variant: "body", children: _jsxs("a", { css: ({ palette }) => ({ color: palette.accent, textUnderlineOffset: 3 }), href: pack.href, target: "_blank", rel: "noreferrer", children: ["Search ", pack.name, " icons (", _jsxs("span", { css: codeStyles, children: [pack.prefix, ":"] }), ")"] }) }, pack.prefix)))] })] }) }), _jsx(ComponentDoc, { title: "Energy Chart", components: ['EnergyChart'], description: "A power section for a drawer, which tiles pass through `energy`: a live power reading, usage tiles and a sparkline. Expanded in a drawer it becomes the full chart with a range switcher.", children: _jsx(EnergyChart, { power: "ha:sensor.heater_power", energy: "ha:sensor.heater_energy", usage: heaterUsage, seriesByRange: heaterSeries }) }), _jsx(ComponentDoc, { title: "History Section", components: ['HistorySection'], description: "Recent activity for a drawer, which tiles pass through `history`: who or what changed the entity, and when. An empty list renders nothing.", children: _jsx(HistorySection, { entries: lampHistory }) }), _jsx(ComponentDoc, { title: "Light Tile", components: ['LightTile'], description: "Tap to toggle, hold to open its detail drawer. Dimmable lights drag to set brightness; color-capable lights add a palette button that opens swatches in the card (white temperatures by default, overridable with `colors`), and the card's icon shows the light's current color. The drawer has the full temperature and hue bars.", children: _jsxs(Grid, { children: [_jsx(LightTile, { entity: "ha:light.plain_on", energy: lampEnergy, history: lampHistory }), _jsx(LightTile, { entity: "ha:light.plain_off", history: stairsHistory }), _jsx(LightTile, { entity: "ha:light.dimmable", icon: "lu:sparkles", energy: ledEnergy, history: ledHistory }), _jsx(LightTile, { entity: "ha:light.color", icon: "lu:lamp-desk", history: nightLampHistory }), _jsx(LightTile, { entity: "ha:light.cct", icon: "lu:lamp-desk" }), _jsx(LightTile, { entity: "ha:light.unavailable" }), _jsx(LightTile, { entity: "ha:light.missing" })] }) }), _jsx(ComponentDoc, { title: "Climate Tile", components: ['ClimateTile'], description: "A heater/thermostat tile: a mode button that opens mode swatches in the card (like light colors), plus a target-temperature stepper. Hold for the drawer: modes, a target bar with fine +/- (hold to repeat), presets, energy and history.", children: _jsxs(Grid, { columns: 1, children: [_jsx(ClimateTile, { entity: "ha:climate.heater", energy: heaterEnergy, history: heaterHistory }), _jsx(ClimateTile, { entity: "ha:climate.off", energy: thermostatEnergy, history: heaterHistory }), _jsx(ClimateTile, { entity: "ha:climate.unavailable" })] }) }), _jsx(ComponentDoc, { title: "Animated Number", components: ['AnimatedNumber'], description: "A number that moves to its new value instead of jumping: a power reading, a temperature. The first value is shown at once; a new one is moved to from what is shown now, even if the last move has not finished. The text is changed directly, with no render for each step, so many of them cost little, and nothing moves when the app is set to reduced motion. `format` writes a number with its unit and should round, as it is called for each step. The drawer's power reading, the sensor readouts and a thermostat's current temperature use it.", children: _jsx(AnimatedNumberDemo, {}) }), _jsx(ComponentDoc, { title: "Sensor Readout", components: ['SensorReadout'], description: "An inline value with icon and unit, defaulting its icon by device class. Readings outside a safe range get a warning (humidity defaults to 30\u201360 %; override with `safeRange`). Pass `history` to make it tappable: the drawer charts it with min/max for today, this week and this month, and a custom date and time range when expanded.", children: _jsxs(Grid, { columns: 3, children: [_jsx(SensorReadout, { entity: "ha:sensor.temperature", history: temperatureHistory }), _jsx(SensorReadout, { entity: "ha:sensor.humidity", history: humidityHistory }), _jsx(SensorReadout, { entity: "ha:sensor.bedroom_humidity", history: bedroomHumidityHistory }), _jsx(SensorReadout, { entity: "ha:sensor.office_humidity", history: officeHumidityHistory }), _jsx(SensorReadout, { entity: "ha:sensor.unavailable" }), _jsx(SensorReadout, { entity: "ha:sensor.unknown" })] }) }), _jsx(ComponentDoc, { title: "Scene Button & Action Button", components: ['SceneButton', 'ActionButton'], description: "A scene is just an action entity. An action button triggers an action (or flips a switch) and shows pending / done / error feedback after a press; `onPress` runs your own logic instead.", children: _jsxs(Grid, { columns: 3, children: [_jsx(SceneButton, { entity: "ha:scene.tv_time" }), _jsx(ActionButton, { label: "Shower", icon: "tb:bath", entity: "ha:script.shower" }), _jsx(ActionButton, { label: "Always Fails", onPress: () => Promise.reject(new Error('That went wrong')) })] }) }), _jsx(ComponentDoc, { title: "Media Player Bar", components: ['MediaPlayerBar'], description: "Track info (with a small shuffle toggle by the title) and the time beside it, then volume, browse, previous, play/pause and next (the artwork opens the browser too), with a thin progress line along the bottom while something plays. The browse button opens the player's own library in the drawer; pass `browse` content to replace it, or `false` for no button. The volume button opens a volume slider in the bar (with a mute swatch, like the light colors and climate modes). Shows album art, or a note glyph when there is none. In a space narrower than 560px, or with `rows={2}`, the controls move to a second row under the track.", children: _jsxs(Flex, { direction: "column", gap: 3, children: [_jsx(MediaPlayerBar, { entity: "ha:media_player.living_room" }), _jsx(MediaPlayerBar, { entity: "ha:media_player.off" }), _jsx(Flex, { width: 380, children: _jsx(MediaPlayerBar, { entity: "ha:media_player.living_room", rows: 2 }) })] }) }), _jsx(ComponentDoc, { title: "Media Player Column", components: ['MediaPlayerColumn'], description: "The player as an upright card for a narrow column beside a dashboard: the artwork in a ring that shows how far along playback is (drag around it to seek), title, transport, and a volume bar that is always visible. The browse button opens the library in the drawer.", children: _jsx(Flex, { width: 320, children: _jsx(MediaPlayerColumn, { entity: "ha:media_player.living_room" }) }) }), _jsx(ComponentDoc, { title: "Media Player Full", components: ['MediaPlayerFull', 'MediaQueue'], description: "The big player: the player centered with its queue beside it (`MediaQueue`: tap a track to jump to it, the cross takes it out, Clear empties it), and its library below, where every track can be played, played next or added to the queue, and an open album or playlist can be played, shuffled or added whole. The media cards' drawers show the player and library too. Where the queue has no room beside the player (a narrow column, the side drawer), Library and Queue are tabs above the list; `tabs={false}` leaves only the library, `defaultTab` and `tab` / `onTabChange` choose which is open. A dashboard puts it in a page of its own, around it whatever it likes.", children: _jsx(Flex, { direction: "column", children: _jsx(MediaPlayerFull, { entity: "ha:media_player.living_room", wide: true, queue: _jsx(MediaQueue, { entity: "ha:media_player.living_room" }), browser: _jsx(MediaBrowser, { entity: "ha:media_player.living_room", layout: "theater" }) }) }) }), _jsx(ComponentDoc, { title: "Weather Forecast", components: ['WeatherForecast'], description: "A weather entity's forecast: the weather now, the next 24 hours as a chart (hover it for everything about an hour) and the days ahead. The top bar's weather chip shows it in a drawer; a dashboard can put it in a page of its own. Narrow, then with `expanded` (readings tiles, a card for each hour).", children: _jsxs(Flex, { direction: "column", gap: 6, children: [_jsx(Flex, { direction: "column", width: 380, children: _jsx(WeatherForecast, { entity: "ha:weather.home", expanded: false }) }), _jsx(WeatherForecast, { entity: "ha:weather.home", expanded: true })] }) }), _jsx(ComponentDoc, { title: "Media Browser", components: ['MediaBrowser'], description: "A player's own library in the app's style: tap a folder to open it, a track or station to play it, or the play button on an album, playlist or artist for all of it. The search box appears when the library can be searched; with `search='icon'` (the second demo) it is an icon at the end of the row of tabs, after a thin line, and pressing it turns that row into the field, so it takes no room of its own. The `theater` layout (third demo) is one row of large cards that scrolls sideways, for a wide space; `list` is the compact default. While a shelf loads, placeholders take the room the cards will (fourth demo, a shelf that never arrives), so nothing moves.", children: _jsxs(Flex, { direction: "column", gap: 6, children: [_jsx(Flex, { direction: "column", maxHeight: 420, overflow: "auto", children: _jsx(MediaBrowser, { entity: "ha:media_player.living_room" }) }), _jsx(Flex, { direction: "column", maxHeight: 420, overflow: "auto", children: _jsx(MediaBrowser, { entity: "ha:media_player.living_room", search: "icon" }) }), _jsx(MediaBrowser, { entity: "ha:media_player.living_room", layout: "theater" }), _jsx(MediaBrowser, { entity: "ha:media_player.loading", layout: "theater" })] }) }), _jsx(ComponentDoc, { title: "Navigation", components: ['NavRail', 'NavDock', 'Page'], description: "Routes within one dashboard. A dashboard includes one itself, usually in its layout route: NavRail is fixed to the left and NavDock floats at the bottom, and both reserve the space they take in the Page around them, which pads so content never sits under them.", children: _jsxs(Flex, { direction: "column", gap: 5, children: [_jsx(SubPreview, { label: "NavRail, in a Page", height: 240, children: _jsxs(Page, { height: "100%", children: [_jsx(NavRail, { base: "/gallery", items: NAV_ITEMS }), _jsx(Typography, { as: "p", variant: "body", color: "textMuted", children: "Page content, padded clear of the rail." })] }) }), _jsx(SubPreview, { label: "NavDock", height: 140, children: _jsx(NavDock, { base: "/gallery", items: NAV_ITEMS }) })] }) }), _jsx(ComponentDoc, { title: "Animated Outlet", components: ['AnimatedOutlet'], description: "A dashboard layout's `Outlet` with a transition between its pages: the page that was showing fades out, then the new one fades in, sliding from the side it sits on in the nav (a later page from the right, an earlier one from the left) when you give it the nav's `items`. Without them the pages only fade. It does nothing for a visitor who prefers reduced motion. Try the links.", children: _jsx(AnimatedOutletDemo, {}) }), _jsx(ComponentDoc, { title: "Top Bar", components: ['TopBar'], description: "Page chrome above a dashboard's content: a title (a dropdown to switch dashboards, once there's more than one to switch to), scene shortcuts, weather (tap it for the forecast), presence, and a clock.", children: _jsx(TopBar, { title: "Living Room", dashboards: [
|
|
403
|
+
}) }), _jsx(Icon, { name: "lu:sun", size: 14 }), _jsx(Icon, { name: "lu:moon", size: 14 })] })] }), _jsx(ComponentDoc, { title: "Board & Cell", components: ['Board', 'Cell'], description: "A page for one known device, laid out on a grid. Each cell says only how big it is (`cols` wide, `rows` tall); the board places them in order, in the first spot they fit. Rows are as tall as their content, so a cell of `rows={2}` ends where the second row does, and `rows='fill'` runs from where the cell is placed down to the bottom of the page, whatever rows are beside it. Every card is a whole number of grid modules tall, the gap between columns and inside a cell is three modules and between rows six, so the result stays on the grid (turn on the debug menu's Show grid to see it).", children: _jsxs(Flex, { direction: "column", gap: 5, children: [_jsxs(Board, { children: [_jsxs(Cell, { cols: 8, children: [_jsx(RoomHeader, { title: "Kitchen", icon: "lu:utensils-crossed" }), _jsxs(Grid, { columns: 2, children: [_jsx(Tile, { label: "Lamp", icon: "lu:lightbulb" }), _jsx(Tile, { label: "Ceiling", icon: "lu:lightbulb" })] })] }), _jsx(Cell, { cols: 4, rows: 2, children: _jsx(MediaPlayerColumn, { entity: "ha:media_player.off" }) }), _jsxs(Cell, { cols: 8, children: [_jsx(RoomHeader, { title: "Stairs", icon: "lu:footprints" }), _jsxs(Grid, { columns: 2, children: [_jsx(Tile, { label: "Lamp", icon: "lu:lightbulb" }), _jsx(Tile, { label: "Spotlights", icon: "lu:lightbulb" })] })] })] }), _jsx(Flex, { direction: "column", height: 460, css: { outline: '1px dashed currentColor' }, children: _jsxs(Board, { children: [_jsx(Cell, { children: _jsxs(TopRow, { children: [_jsx(DateChip, {}), _jsx(Clock, { format: "24h" })] }) }), _jsxs(Cell, { cols: 8, children: [_jsx(RoomHeader, { title: "Kitchen", icon: "lu:utensils-crossed" }), _jsxs(Grid, { columns: 2, children: [_jsx(Tile, { label: "Lamp", icon: "lu:lightbulb" }), _jsx(Tile, { label: "Ceiling", icon: "lu:lightbulb" })] })] }), _jsx(Cell, { cols: 4, rows: "fill", children: _jsx(MediaPlayerColumn, { entity: "ha:media_player.off" }) })] }) })] }) }), _jsx(ComponentDoc, { title: "Top Row", components: ['TopRow'], description: "The row along the top of a page you build yourself instead of with `TopBar`: the date, the weather, the clock and the status in a line at the right, in the height the grid gives the top row (40px), with no padding of its own.", children: _jsxs(TopRow, { children: [_jsx(DateChip, {}), _jsx(Clock, { format: "24h" })] }) }), _jsx(ComponentDoc, { title: "Grid", components: ['Grid'], description: "Lays tiles out in equal-width columns (`columns`, default 2). Cells share the width and never overflow it.", children: _jsxs(Flex, { direction: "column", gap: 5, children: [_jsxs(Grid, { columns: 2, children: [_jsx(Tile, { label: "Two", icon: "lu:layout-grid", secondary: "columns={2}" }), _jsx(Tile, { label: "Columns", icon: "lu:layout-grid", secondary: "equal width" })] }), _jsxs(Grid, { columns: 3, children: [_jsx(Tile, { label: "Three", icon: "lu:layout-grid", secondary: "columns={3}" }), _jsx(Tile, { label: "Columns", icon: "lu:layout-grid", secondary: "equal width" }), _jsx(Tile, { label: "Wide", icon: "lu:layout-grid", secondary: "fits the row" })] })] }) }), _jsx(ComponentDoc, { title: "Room Header", components: ['RoomHeader'], description: "The header that starts a room: a muted icon and title, a hairline and readouts on the right, placed above a Grid (or any tiles). It adds its own space above, so consecutive rooms read as groups.", children: _jsxs(Flex, { direction: "column", gap: 4, children: [_jsx(RoomHeader, { title: "Kitchen", icon: "lu:utensils-crossed" }), _jsx(RoomHeader, { title: "Porch", icon: "lu:house", readouts: _jsxs(_Fragment, { children: [_jsx(SensorReadout, { entity: "ha:sensor.temperature" }), _jsx(SensorReadout, { entity: "ha:sensor.humidity" })] }) })] }) }), _jsx(ComponentDoc, { title: "Tile", components: ['Tile'], description: "The base card every entity tile is built from: icon, label, status line, optional fill bar (drag to change it), trailing controls, a hold-to-open drawer and pending / done / error feedback. Use it directly for something that isn't an entity.", children: _jsxs(Grid, { children: [_jsx(Tile, { label: "Plain", icon: "lu:lamp", secondary: "Off" }), _jsx(Tile, { label: "Active", icon: "lu:lamp", active: true }), _jsx(TileFillDemo, {}), _jsx(Tile, { label: "With controls", icon: "lu:fan", trailing: _jsx(Typography, { as: "span", variant: "secondary", color: "textMuted", children: "trailing" }) }), _jsx(Tile, { label: "Pending", icon: "lu:lamp", feedback: "pending" }), _jsx(Tile, { label: "Error", icon: "lu:lamp", feedback: "error" }), _jsx(Tile, { label: "Unavailable", icon: "lu:lamp", status: "unavailable" }), _jsx(Tile, { label: "Not found", icon: "lu:lamp", status: "missing" })] }) }), _jsx(ComponentDoc, { title: "Task Tile", components: ['TaskTile'], description: "A recurring task (a filter to change, an additive to add) as a tile: its name, where it stands (up to date, due soon, overdue) and when it is due. Whoever has the task decides the state, since how soon is 'soon' differs between a weekly task and a yearly one. Tap one: it asks whether it is done, and for the day it was done on (today, or an earlier one if it was forgotten), and only a confirmation calls `onComplete`. Marking one done here only waits a moment.", children: _jsxs(Grid, { children: [_jsx(TaskTile, { label: "Filter", icon: "lu:wrench", state: "ok", dueAt: inDays(20), lastDoneAt: inDays(-10), onComplete: pause }), _jsx(TaskTile, { label: "Additive", icon: "lu:pipette", state: "dueSoon", dueAt: inDays(2), lastDoneAt: inDays(-5), onComplete: pause }), _jsx(TaskTile, { label: "Salt", icon: "lu:shaker", state: "overdue", dueAt: inDays(-3), lastDoneAt: inDays(-10), onComplete: pause }), _jsx(TaskTile, { label: "Not found", icon: "lu:wrench", state: "ok", status: "missing", onComplete: pause })] }) }), _jsx(ComponentDoc, { title: "Confirm Dialog", components: ['ConfirmDialog'], description: "A question that has to be answered before something is done, so a stray tap cannot do it. It is drawn over the whole page, with a way to back out (Cancel, a tap outside, Escape) and a button to go ahead; more to ask for (a date, say) goes inside it.", children: _jsx(ConfirmDialogDemo, {}) }), _jsx(ComponentDoc, { title: "Icon", components: ['Icon'], description: "A plain prefixed string, no import: `lu:` is Lucide, `tb:` is Tabler outline. It takes the surrounding text color and scales with `size` (default 24px).", children: _jsxs(Flex, { direction: "column", gap: 4, children: [_jsxs(Flex, { align: "center", gap: 4, children: [_jsx(Icon, { name: "lu:lightbulb" }), _jsx(Icon, { name: "lu:thermometer", size: 16 }), _jsx(Icon, { name: "lu:sofa", size: 32 }), _jsx(Icon, { name: "tb:vacuum-cleaner" }), _jsx(Icon, { name: "tb:car-fan", size: 16 })] }), _jsxs(Flex, { align: "center", gap: 4, css: { flexWrap: 'wrap' }, children: [_jsx(Typography, { as: "span", variant: "body", color: "textMuted", children: "Find an icon:" }), ICON_PACKS.map((pack) => (_jsx(Typography, { as: "span", variant: "body", children: _jsxs("a", { css: ({ palette }) => ({ color: palette.accent, textUnderlineOffset: 3 }), href: pack.href, target: "_blank", rel: "noreferrer", children: ["Search ", pack.name, " icons (", _jsxs("span", { css: codeStyles, children: [pack.prefix, ":"] }), ")"] }) }, pack.prefix)))] })] }) }), _jsx(ComponentDoc, { title: "Energy Chart", components: ['EnergyChart'], description: "A power section for a drawer, which tiles pass through `energy`: a live power reading, usage tiles and a sparkline. Expanded in a drawer it becomes the full chart with a range switcher.", children: _jsx(EnergyChart, { power: "ha:sensor.heater_power", energy: "ha:sensor.heater_energy", usage: heaterUsage, seriesByRange: heaterSeries }) }), _jsx(ComponentDoc, { title: "History Section", components: ['HistorySection'], description: "Recent activity for a drawer, which tiles pass through `history`: who or what changed the entity, and when. An empty list renders nothing.", children: _jsx(HistorySection, { entries: lampHistory }) }), _jsx(ComponentDoc, { title: "Light Tile", components: ['LightTile'], description: "Tap to toggle, hold to open its detail drawer. Dimmable lights drag to set brightness; color-capable lights add a palette button that opens swatches in the card (white temperatures by default, overridable with `colors`), and the card's icon shows the light's current color. The drawer has the full temperature and hue bars.", children: _jsxs(Grid, { children: [_jsx(LightTile, { entity: "ha:light.plain_on", energy: lampEnergy, history: lampHistory }), _jsx(LightTile, { entity: "ha:light.plain_off", history: stairsHistory }), _jsx(LightTile, { entity: "ha:light.dimmable", icon: "lu:sparkles", energy: ledEnergy, history: ledHistory }), _jsx(LightTile, { entity: "ha:light.color", icon: "lu:lamp-desk", history: nightLampHistory }), _jsx(LightTile, { entity: "ha:light.cct", icon: "lu:lamp-desk" }), _jsx(LightTile, { entity: "ha:light.unavailable" }), _jsx(LightTile, { entity: "ha:light.missing" })] }) }), _jsx(ComponentDoc, { title: "Climate Tile", components: ['ClimateTile'], description: "A heater/thermostat tile: a mode button that opens mode swatches in the card (like light colors), plus a target-temperature stepper. Hold for the drawer: modes, a target bar with fine +/- (hold to repeat), presets, energy and history.", children: _jsxs(Grid, { columns: 1, children: [_jsx(ClimateTile, { entity: "ha:climate.heater", energy: heaterEnergy, history: heaterHistory }), _jsx(ClimateTile, { entity: "ha:climate.off", energy: thermostatEnergy, history: heaterHistory }), _jsx(ClimateTile, { entity: "ha:climate.unavailable" })] }) }), _jsx(ComponentDoc, { title: "Animated Number", components: ['AnimatedNumber'], description: "A number that moves to its new value instead of jumping: a power reading, a temperature. The first value is shown at once; a new one is moved to from what is shown now, even if the last move has not finished. The text is changed directly, with no render for each step, so many of them cost little, and nothing moves when the app is set to reduced motion. `format` writes a number with its unit and should round, as it is called for each step. The drawer's power reading, the sensor readouts and a thermostat's current temperature use it.", children: _jsx(AnimatedNumberDemo, {}) }), _jsx(ComponentDoc, { title: "Sensor Readout", components: ['SensorReadout'], description: "An inline value with icon and unit, defaulting its icon by device class. Readings outside a safe range get a warning (humidity defaults to 30\u201360 %; override with `safeRange`). Pass `history` to make it tappable: the drawer charts it with min/max for today, this week and this month, and a custom date and time range when expanded.", children: _jsxs(Grid, { columns: 3, children: [_jsx(SensorReadout, { entity: "ha:sensor.temperature", history: temperatureHistory }), _jsx(SensorReadout, { entity: "ha:sensor.humidity", history: humidityHistory }), _jsx(SensorReadout, { entity: "ha:sensor.bedroom_humidity", history: bedroomHumidityHistory }), _jsx(SensorReadout, { entity: "ha:sensor.office_humidity", history: officeHumidityHistory }), _jsx(SensorReadout, { entity: "ha:sensor.unavailable" }), _jsx(SensorReadout, { entity: "ha:sensor.unknown" })] }) }), _jsx(ComponentDoc, { title: "Scene Button & Action Button", components: ['SceneButton', 'ActionButton'], description: "A scene is just an action entity. An action button triggers an action (or flips a switch) and shows pending / done / error feedback after a press; `onPress` runs your own logic instead.", children: _jsxs(Grid, { columns: 3, children: [_jsx(SceneButton, { entity: "ha:scene.tv_time" }), _jsx(ActionButton, { label: "Shower", icon: "tb:bath", entity: "ha:script.shower" }), _jsx(ActionButton, { label: "Always Fails", onPress: () => Promise.reject(new Error('That went wrong')) })] }) }), _jsx(ComponentDoc, { title: "Media Player Bar", components: ['MediaPlayerBar'], description: "Track info (with a small shuffle toggle by the title) and the time beside it, then volume, browse, previous, play/pause and next (the artwork opens the browser too), with a thin progress line along the bottom while something plays. The browse button opens the player's own library in the drawer; pass `browse` content to replace it, or `false` for no button. The volume button opens a volume slider in the bar (with a mute swatch, like the light colors and climate modes). Shows album art, or a note glyph when there is none. In a space narrower than 560px, or with `rows={2}`, the controls move to a second row under the track.", children: _jsxs(Flex, { direction: "column", gap: 3, children: [_jsx(MediaPlayerBar, { entity: "ha:media_player.living_room" }), _jsx(MediaPlayerBar, { entity: "ha:media_player.off" }), _jsx(Flex, { width: 380, children: _jsx(MediaPlayerBar, { entity: "ha:media_player.living_room", rows: 2 }) })] }) }), _jsx(ComponentDoc, { title: "Media Player Column", components: ['MediaPlayerColumn'], description: "The player as an upright card for a narrow column beside a dashboard: the artwork in a ring that shows how far along playback is (drag around it to seek), title, transport, and a volume bar that is always visible. The browse button opens the library in the drawer.", children: _jsx(Flex, { width: 320, children: _jsx(MediaPlayerColumn, { entity: "ha:media_player.living_room" }) }) }), _jsx(ComponentDoc, { title: "Media Player Full", components: ['MediaPlayerFull', 'MediaQueue'], description: "The big player: the player centered with its queue beside it (`MediaQueue`: tap a track to jump to it, the cross takes it out, Clear empties it), and its library below, where every track can be played, played next or added to the queue, and an open album or playlist can be played, shuffled or added whole. The media cards' drawers show the player and library too. Where the queue has no room beside the player (a narrow column, the side drawer), Library and Queue are tabs above the list; `tabs={false}` leaves only the library, `defaultTab` and `tab` / `onTabChange` choose which is open. A dashboard puts it in a page of its own, around it whatever it likes.", children: _jsx(Flex, { direction: "column", children: _jsx(MediaPlayerFull, { entity: "ha:media_player.living_room", wide: true, queue: _jsx(MediaQueue, { entity: "ha:media_player.living_room" }), browser: _jsx(MediaBrowser, { entity: "ha:media_player.living_room", layout: "theater" }) }) }) }), _jsx(ComponentDoc, { title: "Weather Forecast", components: ['WeatherForecast'], description: "A weather entity's forecast: the weather now, the next 24 hours as a chart (hover it for everything about an hour) and the days ahead. The top bar's weather chip shows it in a drawer; a dashboard can put it in a page of its own. Narrow, then with `expanded` (readings tiles, a card for each hour).", children: _jsxs(Flex, { direction: "column", gap: 6, children: [_jsx(Flex, { direction: "column", width: 380, children: _jsx(WeatherForecast, { entity: "ha:weather.home", expanded: false }) }), _jsx(WeatherForecast, { entity: "ha:weather.home", expanded: true })] }) }), _jsx(ComponentDoc, { title: "Media Browser", components: ['MediaBrowser'], description: "A player's own library in the app's style: tap a folder to open it, a track or station to play it, or the play button on an album, playlist or artist for all of it. The search box appears when the library can be searched; with `search='icon'` (the second demo) it is an icon at the end of the row of tabs, after a thin line, and pressing it turns that row into the field, so it takes no room of its own. The `theater` layout (third demo) is one row of large cards that scrolls sideways, for a wide space; `list` is the compact default. While a shelf loads, placeholders take the room the cards will (fourth demo, a shelf that never arrives), so nothing moves.", children: _jsxs(Flex, { direction: "column", gap: 6, children: [_jsx(Flex, { direction: "column", maxHeight: 420, overflow: "auto", children: _jsx(MediaBrowser, { entity: "ha:media_player.living_room" }) }), _jsx(Flex, { direction: "column", maxHeight: 420, overflow: "auto", children: _jsx(MediaBrowser, { entity: "ha:media_player.living_room", search: "icon" }) }), _jsx(MediaBrowser, { entity: "ha:media_player.living_room", layout: "theater" }), _jsx(MediaBrowser, { entity: "ha:media_player.loading", layout: "theater" })] }) }), _jsx(ComponentDoc, { title: "Navigation", components: ['NavRail', 'NavDock', 'Page'], description: "Routes within one dashboard. A dashboard includes one itself, usually in its layout route: NavRail is fixed to the left and NavDock floats at the bottom, and both reserve the space they take in the Page around them, which pads so content never sits under them. An item can carry a dot (`attention`: `notice` or `urgent`) when something on its page needs a look, so it is seen without opening the page.", children: _jsxs(Flex, { direction: "column", gap: 5, children: [_jsx(SubPreview, { label: "NavRail, in a Page", height: 240, children: _jsxs(Page, { height: "100%", children: [_jsx(NavRail, { base: "/gallery", items: NAV_ITEMS }), _jsx(Typography, { as: "p", variant: "body", color: "textMuted", children: "Page content, padded clear of the rail." })] }) }), _jsx(SubPreview, { label: "NavDock", height: 140, children: _jsx(NavDock, { base: "/gallery", items: NAV_ITEMS }) }), _jsx(SubPreview, { label: "NavRail, with something to look at on two pages", height: 240, children: _jsxs(Page, { height: "100%", children: [_jsx(NavRail, { base: "/gallery", items: ATTENTION_ITEMS }), _jsx(Typography, { as: "p", variant: "body", color: "textMuted", children: "A warm dot says something is coming up, a red one that it needs doing now." })] }) }), _jsx(SubPreview, { label: "NavDock, with something to look at on two pages", height: 140, children: _jsx(NavDock, { base: "/gallery", items: ATTENTION_ITEMS }) })] }) }), _jsx(ComponentDoc, { title: "Animated Outlet", components: ['AnimatedOutlet'], description: "A dashboard layout's `Outlet` with a transition between its pages: the page that was showing fades out, then the new one fades in, sliding from the side it sits on in the nav (a later page from the right, an earlier one from the left) when you give it the nav's `items`. Without them the pages only fade. It does nothing for a visitor who prefers reduced motion. Try the links.", children: _jsx(AnimatedOutletDemo, {}) }), _jsx(ComponentDoc, { title: "Top Bar", components: ['TopBar'], description: "Page chrome above a dashboard's content: a title (a dropdown to switch dashboards, once there's more than one to switch to), scene shortcuts, weather (tap it for the forecast), presence, and a clock.", children: _jsx(TopBar, { title: "Living Room", dashboards: [
|
|
378
404
|
{ id: 'living-room', title: 'Living Room', icon: 'lu:sofa' },
|
|
379
405
|
{ id: 'bedroom', title: 'Bedroom', icon: 'lu:bed' },
|
|
380
406
|
{ id: 'bathroom', title: 'Bathroom', icon: 'tb:bath' },
|
|
@@ -260,6 +260,112 @@ export const COMPONENT_PROPS = {
|
|
|
260
260
|
doc: '',
|
|
261
261
|
props: [],
|
|
262
262
|
},
|
|
263
|
+
TaskTile: {
|
|
264
|
+
doc: 'A recurring task as a tile: its name, where it stands (up to date, due soon, overdue) and when it is due. Tapping it asks whether it is done, with the day it was done on (today, or an earlier one if it was forgotten), and only a confirmation calls `onComplete`, so a stray tap does nothing.',
|
|
265
|
+
props: [
|
|
266
|
+
{
|
|
267
|
+
doc: 'What is to be done, e.g. `Septic additive`.',
|
|
268
|
+
name: 'label',
|
|
269
|
+
optional: false,
|
|
270
|
+
type: 'string',
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
doc: 'Icon id, e.g. `lu:wrench`.',
|
|
274
|
+
name: 'icon',
|
|
275
|
+
optional: true,
|
|
276
|
+
type: 'IconName',
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
doc: 'Where the task stands. Whoever has the task decides it: how soon is "soon" is different for a weekly task and a yearly one.',
|
|
280
|
+
name: 'state',
|
|
281
|
+
optional: false,
|
|
282
|
+
type: 'TaskState',
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
doc: 'When it is next due. Shown as "Due in 2 days" or "Overdue by 3 days".',
|
|
286
|
+
name: 'dueAt',
|
|
287
|
+
optional: true,
|
|
288
|
+
type: 'Date | undefined',
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
doc: 'When it was last done, shown in the question that marks it done again.',
|
|
292
|
+
name: 'lastDoneAt',
|
|
293
|
+
optional: true,
|
|
294
|
+
type: 'Date | undefined',
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
doc: 'Status of the thing behind it, as for `Tile`: anything but `ready` shows why instead and disables the tile.',
|
|
298
|
+
name: 'status',
|
|
299
|
+
optional: true,
|
|
300
|
+
type: 'EntityStatus',
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
doc: 'The person confirmed it is done, on this day (today unless they chose another, in case it was forgotten at the time). Rejecting shows the error in the dialog and leaves it open.',
|
|
304
|
+
name: 'onComplete',
|
|
305
|
+
optional: false,
|
|
306
|
+
type: '(doneOn: Date) => void | Promise<void>',
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
},
|
|
310
|
+
ConfirmDialog: {
|
|
311
|
+
doc: 'A question that has to be answered before something is done, so a stray tap cannot do it: a card in the middle of the page over a dimmed scrim, with a way to back out (Cancel, a tap outside, Escape) and a button to go ahead. It is drawn over the whole page, whatever it is opened from. Focus moves into it while it is open and returns to what had it after, and Tab stays inside.',
|
|
312
|
+
props: [
|
|
313
|
+
{
|
|
314
|
+
doc: 'Whether the dialog is showing.',
|
|
315
|
+
name: 'open',
|
|
316
|
+
optional: false,
|
|
317
|
+
type: 'boolean',
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
doc: 'What is being asked, as a short question: "Mark the septic additive as done?".',
|
|
321
|
+
name: 'title',
|
|
322
|
+
optional: false,
|
|
323
|
+
type: 'string',
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
doc: 'A line under the title.',
|
|
327
|
+
name: 'description',
|
|
328
|
+
optional: true,
|
|
329
|
+
type: 'ReactNode',
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
doc: 'Label of the button that goes ahead. Default `Confirm`.',
|
|
333
|
+
name: 'confirmLabel',
|
|
334
|
+
optional: true,
|
|
335
|
+
type: 'string',
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
doc: 'Label of the button that backs out. Default `Cancel`.',
|
|
339
|
+
name: 'cancelLabel',
|
|
340
|
+
optional: true,
|
|
341
|
+
type: 'string',
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
doc: 'The person went ahead.',
|
|
345
|
+
name: 'onConfirm',
|
|
346
|
+
optional: false,
|
|
347
|
+
type: '() => void',
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
doc: 'The person backed out: the Cancel button, a tap outside, or Escape.',
|
|
351
|
+
name: 'onCancel',
|
|
352
|
+
optional: false,
|
|
353
|
+
type: '() => void',
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
doc: 'Something is being done with the answer: both buttons wait.',
|
|
357
|
+
name: 'busy',
|
|
358
|
+
optional: true,
|
|
359
|
+
type: 'boolean',
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
doc: 'More to ask for before going ahead, e.g. a date.',
|
|
363
|
+
name: 'children',
|
|
364
|
+
optional: true,
|
|
365
|
+
type: 'ReactNode',
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
},
|
|
263
369
|
EnergyChart: {
|
|
264
370
|
doc: "A power-draw chart for an entity's detail drawer, e.g. from a Shelly's energy monitoring. Generic — any entity type can supply it. Deliberately two-tier: a bare sparkline while the drawer is at its normal (side) width, and the full interactive chart — axes, tooltip, a selectable time range — only once it's expanded to fullscreen, where there's room for it.",
|
|
265
371
|
props: [
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export * from './layout/page.tsx';
|
|
|
15
15
|
export * from './layout/animated-outlet.tsx';
|
|
16
16
|
export * from './layout/room-header.tsx';
|
|
17
17
|
export { Tile, type TileProps } from './layout/tile.tsx';
|
|
18
|
+
export { TaskTile, taskLine, type TaskState, type TaskTileProps } from './layout/task-tile.tsx';
|
|
19
|
+
export { ConfirmDialog, type ConfirmDialogProps } from './layout/confirm-dialog.tsx';
|
|
18
20
|
export * from './layout/energy-chart.tsx';
|
|
19
21
|
export * from './layout/history-section.tsx';
|
|
20
22
|
export type { SensorSample } from './layout/sensor-history.tsx';
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,8 @@ export * from './layout/page.js';
|
|
|
11
11
|
export * from './layout/animated-outlet.js';
|
|
12
12
|
export * from './layout/room-header.js';
|
|
13
13
|
export { Tile } from './layout/tile.js';
|
|
14
|
+
export { TaskTile, taskLine } from './layout/task-tile.js';
|
|
15
|
+
export { ConfirmDialog } from './layout/confirm-dialog.js';
|
|
14
16
|
export * from './layout/energy-chart.js';
|
|
15
17
|
export * from './layout/history-section.js';
|
|
16
18
|
export * from './entities/light-tile.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** A check that draws itself, in the text color of what it is in. It plays once, as it appears; with
|
|
2
|
+
* reduced motion it appears drawn. Announced as "Done". */
|
|
3
|
+
export declare function CheckMark({ size }: {
|
|
4
|
+
size?: number;
|
|
5
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
/** @jsxImportSource @emotion/react */
|
|
3
|
+
import { Box } from 'e-prim';
|
|
4
|
+
import { motion } from 'motion/react';
|
|
5
|
+
/** A check that draws itself, in the text color of what it is in. It plays once, as it appears; with
|
|
6
|
+
* reduced motion it appears drawn. Announced as "Done". */
|
|
7
|
+
export function CheckMark({ size = 22 }) {
|
|
8
|
+
return (_jsx(Box, { as: "span", role: "status", "aria-label": "Done", css: { display: 'grid', color: 'inherit' }, children: _jsx("svg", { viewBox: "0 0 24 24", width: size, height: size, "aria-hidden": "true", children: _jsx(motion.path, { d: "M6 12.5 L10.5 17 L18 8", fill: "none", stroke: "currentColor", strokeWidth: "2.6", strokeLinecap: "round", strokeLinejoin: "round", initial: { pathLength: 0 }, animate: { pathLength: 1 }, transition: { duration: 0.3, delay: 0.05, ease: 'easeOut' } }) }) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface ConfirmDialogProps {
|
|
3
|
+
/** Whether the dialog is showing. */
|
|
4
|
+
open: boolean;
|
|
5
|
+
/** What is being asked, as a short question: "Mark the septic additive as done?". */
|
|
6
|
+
title: string;
|
|
7
|
+
/** A line under the title. */
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
/** Label of the button that goes ahead. Default `Confirm`. */
|
|
10
|
+
confirmLabel?: string;
|
|
11
|
+
/** Label of the button that backs out. Default `Cancel`. */
|
|
12
|
+
cancelLabel?: string;
|
|
13
|
+
/** The person went ahead. */
|
|
14
|
+
onConfirm: () => void;
|
|
15
|
+
/** The person backed out: the Cancel button, a tap outside, or Escape. */
|
|
16
|
+
onCancel: () => void;
|
|
17
|
+
/** Something is being done with the answer: both buttons wait. */
|
|
18
|
+
busy?: boolean;
|
|
19
|
+
/** More to ask for before going ahead, e.g. a date. */
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A question that has to be answered before something is done, so a stray tap cannot do it: a card in the
|
|
24
|
+
* middle of the page over a dimmed scrim, with a way to back out (Cancel, a tap outside, Escape) and a button
|
|
25
|
+
* to go ahead. It is drawn over the whole page, whatever it is opened from. Focus moves into it while it is
|
|
26
|
+
* open and returns to what had it after, and Tab stays inside.
|
|
27
|
+
*/
|
|
28
|
+
export declare function ConfirmDialog({ open, title, description, confirmLabel, cancelLabel, onConfirm, onCancel, busy, children, }: ConfirmDialogProps): import("react").ReactPortal;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
/** @jsxImportSource @emotion/react */
|
|
3
|
+
import { Box, Flex, Typography } from 'e-prim';
|
|
4
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
5
|
+
import { useEffect, useId, useRef } from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
const FOCUSABLE = 'button:not(:disabled), [href], input:not(:disabled), [tabindex]:not([tabindex="-1"])';
|
|
8
|
+
/**
|
|
9
|
+
* A question that has to be answered before something is done, so a stray tap cannot do it: a card in the
|
|
10
|
+
* middle of the page over a dimmed scrim, with a way to back out (Cancel, a tap outside, Escape) and a button
|
|
11
|
+
* to go ahead. It is drawn over the whole page, whatever it is opened from. Focus moves into it while it is
|
|
12
|
+
* open and returns to what had it after, and Tab stays inside.
|
|
13
|
+
*/
|
|
14
|
+
export function ConfirmDialog({ open, title, description, confirmLabel = 'Confirm', cancelLabel = 'Cancel', onConfirm, onCancel, busy = false, children, }) {
|
|
15
|
+
const heading = useId();
|
|
16
|
+
const about = useId();
|
|
17
|
+
const card = useRef(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!open) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const before = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
23
|
+
card.current?.focus();
|
|
24
|
+
return () => before?.focus();
|
|
25
|
+
}, [open]);
|
|
26
|
+
const onKeyDown = (event) => {
|
|
27
|
+
if (event.key === 'Escape') {
|
|
28
|
+
event.stopPropagation();
|
|
29
|
+
onCancel();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (event.key === 'Tab' && card.current) {
|
|
33
|
+
const inside = [...card.current.querySelectorAll(FOCUSABLE)];
|
|
34
|
+
const first = inside[0];
|
|
35
|
+
const last = inside.at(-1);
|
|
36
|
+
if (event.shiftKey &&
|
|
37
|
+
(document.activeElement === first || document.activeElement === card.current)) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
last?.focus();
|
|
40
|
+
}
|
|
41
|
+
else if (!event.shiftKey && document.activeElement === last) {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
first?.focus();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return createPortal(_jsx(AnimatePresence, { children: open ? (_jsx(Flex, { as: motion.div, align: "center", justify: "center", position: "fixed", zIndex: "modal", p: 4, onClick: onCancel, initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.16 }, css: ({ palette }) => ({
|
|
48
|
+
inset: 0,
|
|
49
|
+
// The page's own color, so the dimming follows the theme.
|
|
50
|
+
background: `color-mix(in srgb, ${palette.bg} 72%, transparent)`,
|
|
51
|
+
}), children: _jsxs(Flex, { as: motion.div, ref: card, role: "dialog", "aria-modal": "true", "aria-labelledby": heading, ...(description ? { 'aria-describedby': about } : {}), tabIndex: -1, direction: "column", gap: 4, background: "surfaceRaised", radius: "card", shadow: "drawer", p: 5, onClick: (event) => event.stopPropagation(), onKeyDown: onKeyDown, initial: { opacity: 0, scale: 0.96, y: 8 }, animate: { opacity: 1, scale: 1, y: 0 }, exit: { opacity: 0, scale: 0.98 }, transition: { duration: 0.18, ease: 'easeOut' },
|
|
52
|
+
// Scrolls when what is in it does not fit the screen, rather than running off it.
|
|
53
|
+
css: {
|
|
54
|
+
width: 'min(420px, 100%)',
|
|
55
|
+
maxHeight: '100%',
|
|
56
|
+
overflowY: 'auto',
|
|
57
|
+
outline: 'none',
|
|
58
|
+
}, children: [_jsxs(Flex, { direction: "column", gap: 1.5, children: [_jsx(Typography, { as: "h2", variant: "heading", id: heading, children: title }), description ? (_jsx(Typography, { as: "p", variant: "body", color: "textMuted", id: about, children: description })) : null] }), children ? _jsx(Box, { children: children }) : null, _jsxs(Flex, { justify: "flex-end", gap: 2, children: [_jsx(DialogButton, { label: cancelLabel, disabled: busy, onClick: onCancel }), _jsx(DialogButton, { label: confirmLabel, primary: true, disabled: busy, onClick: onConfirm })] })] }) }, "scrim")) : null }), document.body);
|
|
59
|
+
}
|
|
60
|
+
function DialogButton({ label, primary = false, disabled, onClick, }) {
|
|
61
|
+
return (_jsx(Flex, { as: "button", type: "button", onClick: onClick, disabled: disabled, align: "center", justify: "center", radius: "full", cursor: disabled ? 'default' : 'pointer', height: 40, px: 5, background: primary ? 'accent' : 'surface', color: primary ? 'accentText' : 'text', css: { opacity: disabled ? 0.5 : 1 }, children: _jsx(Typography, { as: "span", variant: "label", children: label }) }));
|
|
62
|
+
}
|
|
@@ -5,6 +5,11 @@ import { THEME_CHOICES, useDebug } from '../debug.js';
|
|
|
5
5
|
import { Icon } from '../icon.js';
|
|
6
6
|
import { ChipRow } from './drawer-controls.js';
|
|
7
7
|
import { PlainButton } from './plain-button.js';
|
|
8
|
+
import { NAV_RAIL } from '../theme/grid.js';
|
|
9
|
+
/** The button's size, in px. */
|
|
10
|
+
const BUTTON = 40;
|
|
11
|
+
/** How far it is from the left and the bottom edge: on the line the navigation rail's icons are centered on, so it sits under them, and the same from the bottom. */
|
|
12
|
+
const INSET = (NAV_RAIL - BUTTON) / 2;
|
|
8
13
|
const THEME_LABELS = {
|
|
9
14
|
light: 'Light',
|
|
10
15
|
dark: 'Dark',
|
|
@@ -85,15 +90,15 @@ export function DebugMenu({ configured, sun, }) {
|
|
|
85
90
|
// which this is, and the button would sit at the top of it.
|
|
86
91
|
css: {
|
|
87
92
|
position: 'fixed',
|
|
88
|
-
left:
|
|
89
|
-
bottom:
|
|
93
|
+
left: INSET,
|
|
94
|
+
bottom: INSET,
|
|
90
95
|
zIndex: 30,
|
|
91
|
-
width:
|
|
92
|
-
height:
|
|
96
|
+
width: BUTTON,
|
|
97
|
+
height: BUTTON,
|
|
93
98
|
minHeight: 0,
|
|
94
99
|
}, children: [open ? (_jsxs(Flex, { role: "dialog", "aria-label": "Debug", direction: "column", gap: 4, background: "surface", radius: "row", shadow: "drawer", p: 4, width: 288, css: { position: 'absolute', left: 0, bottom: 52, boxSizing: 'border-box' }, children: [_jsx(Row, { label: "Show grid", children: _jsx(ChipRow, { options: ON_OFF, value: debug.grid ? 'on' : 'off', onChange: (value) => debug.setGrid(value === 'on') }) }), _jsx(Row, { label: "Fullscreen", children: canFullscreen ? (_jsx(ChipRow, { options: ON_OFF, value: isFull ? 'on' : 'off', onChange: (value) => toggleFullscreen(value === 'on') })) : (_jsx(Typography, { as: "span", variant: "secondary", color: "textMuted", children: "Not available in this browser." })) }), _jsx(Row, { label: "Theme", children: _jsx(ChipRow
|
|
95
100
|
// The sun only if the project has one to follow.
|
|
96
101
|
, {
|
|
97
102
|
// The sun only if the project has one to follow.
|
|
98
|
-
options: THEME_CHOICES.filter((choice) => choice !== 'sun' || sun !== undefined).map((choice) => ({ value: choice, label: THEME_LABELS[choice] })), value: theme, onChange: (value) => debug.setThemeChoice(value) }) })] })) : null, _jsx(PlainButton, { "aria-label": "Debug menu", title: "Debug menu", "aria-expanded": open, onClick: () => setOpen((current) => !current), center: true, radius: "full", background: "surface", color: "textMuted", shadow: "dock", width:
|
|
103
|
+
options: THEME_CHOICES.filter((choice) => choice !== 'sun' || sun !== undefined).map((choice) => ({ value: choice, label: THEME_LABELS[choice] })), value: theme, onChange: (value) => debug.setThemeChoice(value) }) })] })) : null, _jsx(PlainButton, { "aria-label": "Debug menu", title: "Debug menu", "aria-expanded": open, onClick: () => setOpen((current) => !current), center: true, radius: "full", background: "surface", color: "textMuted", shadow: "dock", width: BUTTON, height: BUTTON, css: { flex: 'none' }, children: _jsx(Icon, { name: "lu:bug", size: 18 }) })] }));
|
|
99
104
|
}
|