@moi952/decky-ui-kit 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -4
- package/dist/CollapsibleSection.d.ts +6 -1
- package/dist/CollapsibleSection.js +38 -3
- package/dist/MediaRow.d.ts +1 -0
- package/dist/MediaRow.js +23 -1
- package/dist/QrCodeButton.d.ts +12 -0
- package/dist/QrCodeButton.js +36 -0
- package/dist/StatusCard.d.ts +1 -1
- package/dist/StatusCard.js +23 -5
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/useRemoteJson.d.ts +6 -0
- package/dist/useRemoteJson.js +49 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ import { AnchoredDropdown } from "@moi952/decky-ui-kit";
|
|
|
56
56
|
| `onChange` | `(value: string) => void` | — | Called with the new value (or comma-joined list, in `multiple` mode). |
|
|
57
57
|
| `variant` | `"row" \| "boxed"` | `"boxed"` | `"row"`: flat, matches surrounding list rows. `"boxed"`: bordered box with an arrow. |
|
|
58
58
|
| `focusStyle` | `"fill" \| "outline"` | `"fill"` | `"fill"`: solid white background on focus. `"outline"`: transparent border that fills on focus. |
|
|
59
|
-
| `size` | `"
|
|
59
|
+
| `size` | `"small" \| "medium" \| "large"` | `"small"` | Row/trigger height and font size — same scale as `ActionButton`/`FieldTextInput`. |
|
|
60
60
|
| `bgColor` | `string` | Steam-like dark gray | Background color. |
|
|
61
61
|
| `textColor` | `string` | Steam-like light gray | Text color. |
|
|
62
62
|
| `borderColor` | `string` | `"transparent"` | Trigger and list border color. |
|
|
@@ -79,7 +79,7 @@ The list's corner radius is read at runtime from the trigger's own computed `bor
|
|
|
79
79
|
|
|
80
80
|
### `CollapsibleSection`
|
|
81
81
|
|
|
82
|
-
An expand/collapse row
|
|
82
|
+
An expand/collapse row, for tucking secondary content (settings, history, details) behind a single toggleable header. Two looks, picked with `variant`: `"field"` (default) is built on `Field` — native Steam padding/highlight/separator, right for a settings-page-style toggle. `"group-header"` is a flat, transparent, uppercase trigger with an optional icon+count instead — a collapsible category header for a list (e.g. a game list grouped by status), not a settings row.
|
|
83
83
|
|
|
84
84
|
```tsx
|
|
85
85
|
import { CollapsibleSection } from "@moi952/decky-ui-kit";
|
|
@@ -89,15 +89,36 @@ import { CollapsibleSection } from "@moi952/decky-ui-kit";
|
|
|
89
89
|
</CollapsibleSection>
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
```tsx
|
|
93
|
+
import { FiCheckCircle } from "react-icons/fi";
|
|
94
|
+
|
|
95
|
+
<CollapsibleSection
|
|
96
|
+
variant="group-header"
|
|
97
|
+
label="Ready"
|
|
98
|
+
icon={FiCheckCircle}
|
|
99
|
+
iconColor="#4caf50"
|
|
100
|
+
count={12}
|
|
101
|
+
expanded={expanded}
|
|
102
|
+
onToggle={() => setExpanded(!expanded)}
|
|
103
|
+
>
|
|
104
|
+
{games.map((g) => <GameRow key={g.id} game={g} />)}
|
|
105
|
+
</CollapsibleSection>
|
|
106
|
+
```
|
|
107
|
+
|
|
92
108
|
<details>
|
|
93
109
|
<summary>Props</summary>
|
|
94
110
|
|
|
95
111
|
| Prop | Type | Default | Description |
|
|
96
112
|
| --- | --- | --- | --- |
|
|
97
|
-
| `label` | `
|
|
113
|
+
| `label` | `ReactNode` | — | Header text. |
|
|
98
114
|
| `expanded` | `boolean` | — | Whether the children are shown. State is owned by the caller. |
|
|
99
115
|
| `onToggle` | `() => void` | — | Called on click/activate; flip `expanded` in response. |
|
|
100
116
|
| `children` | `ReactNode` | — | Rendered below the header while `expanded` is `true`. |
|
|
117
|
+
| `variant` | `"field" \| "group-header"` | `"field"` | `"field"`: native `Field`-based row. `"group-header"`: flat, transparent, uppercase trigger with an optional icon+count — a fixed look, no color/size props of its own. |
|
|
118
|
+
| `contentBottomSeparator` | `boolean` | `false` | `"field"` variant only. A second separator drawn after the expanded content, mirroring the one `Field`'s own `bottomSeparator` already draws before it. |
|
|
119
|
+
| `icon` | `IconType` | — | `"group-header"` variant only. An icon (from `react-icons`) shown before the label. |
|
|
120
|
+
| `iconColor` | `string` | `"#888"` | `"group-header"` variant only. Color for `icon`. |
|
|
121
|
+
| `count` | `number` | — | `"group-header"` variant only. A small counter shown after the label (e.g. how many items are in this group). Omitted entirely when not passed. |
|
|
101
122
|
|
|
102
123
|
</details>
|
|
103
124
|
|
|
@@ -119,7 +140,7 @@ import { FieldTextInput } from "@moi952/decky-ui-kit";
|
|
|
119
140
|
| `value` | `string` | — | Current value. |
|
|
120
141
|
| `onChange` | `(value: string) => void` | — | Called with the new value on every keystroke. |
|
|
121
142
|
| `label` | `ReactNode` | — | Label text/content. |
|
|
122
|
-
| `size` | `"
|
|
143
|
+
| `size` | `"small" \| "medium" \| "large"` | `"medium"` | Input font size and padding — same scale as `ActionButton`/`AnchoredDropdown`. |
|
|
123
144
|
| `labelPosition` | `"top" \| "left" \| "right"` | `"top"` | Where the label sits relative to the input. |
|
|
124
145
|
| `mustBeNumeric` | `boolean` | `false` | Restricts input to numeric characters. |
|
|
125
146
|
| `bottomSeparator` | `boolean` | `true` | Native Steam separator line below the row. |
|
|
@@ -253,6 +274,7 @@ import { FiEyeOff } from "react-icons/fi";
|
|
|
253
274
|
| `mediaWidth` | `number` | `32` | Media box width — only used by `mediaLayout="fixed"`. |
|
|
254
275
|
| `mediaHeight` | `number` | `32` | Media box height. |
|
|
255
276
|
| `mediaLayout` | `"fixed" \| "stretch"` | `"fixed"` | `"fixed"`: media centered in an exact `mediaWidth`×`mediaHeight` box (a small icon). `"stretch"`: exactly `mediaHeight` tall, but no fixed width at all — the media renders at whatever width its own aspect ratio calls for at that height (e.g. `<img style={{ height: "100%", width: "auto" }} />`), so a cover image always shows in full. |
|
|
277
|
+
| `mediaAlign` | `"top" \| "center" \| "bottom"` | `"center"` for `mediaLayout="fixed"`, `"top"` for `"stretch"` | Where the fixed-height media box sits once `titleLines > 1` makes the row taller than `mediaHeight`. The default matches each layout's own prior look exactly (before this prop existed), so it's opt-in, not a behavior change. |
|
|
256
278
|
| `title` | `ReactNode` | — | The row's title. |
|
|
257
279
|
| `titleLines` | `number` | `1` | `1`: ellipsis-truncated single line. `>1`: line-clamped over that many lines. |
|
|
258
280
|
| `details` | `ReactNode` | — | Extra content under the title — your own pre-colored status line(s). Omit for a title-only row. |
|
|
@@ -274,6 +296,36 @@ import { FiEyeOff } from "react-icons/fi";
|
|
|
274
296
|
|
|
275
297
|
</details>
|
|
276
298
|
|
|
299
|
+
### `QrCodeButton`
|
|
300
|
+
|
|
301
|
+
A collapsible section (built on `CollapsibleSection`) that reveals a QR code on expand — for handing a URL off to the user's phone (a feedback form, a release page, ...) instead of them typing it on a gamepad. The revealed code is itself a real gamepad-focusable button — pressing it opens the URL directly in Steam's own browser overlay, for anyone who'd rather not reach for their phone.
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
import { QrCodeButton } from "@moi952/decky-ui-kit";
|
|
305
|
+
|
|
306
|
+
<QrCodeButton
|
|
307
|
+
value="https://github.com/moi952/decky-proton-launch/issues"
|
|
308
|
+
label="Suggest a feature"
|
|
309
|
+
hint="Scan with your phone"
|
|
310
|
+
/>
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
<details>
|
|
314
|
+
<summary>Props</summary>
|
|
315
|
+
|
|
316
|
+
| Prop | Type | Default | Description |
|
|
317
|
+
| --- | --- | --- | --- |
|
|
318
|
+
| `value` | `string` | — | The URL (or any text) encoded into the QR code. |
|
|
319
|
+
| `label` | `ReactNode` | — | Collapsible section header text. |
|
|
320
|
+
| `hint` | `ReactNode` | — | Shown under the code once revealed. |
|
|
321
|
+
| `qrSize` | `number` | `160` | QR code size in pixels. |
|
|
322
|
+
| `borderOnFocus` | `boolean` | `true` | A real border on focus/hover — same convention as `MediaRow`'s own `borderOnFocus`. |
|
|
323
|
+
| `highlightColor` | `string` | `"#2a3a4a"` | Border color on focus/hover (used when `borderOnFocus`). Darker than `MediaRow`'s own default (`"#dcdedf"`, invisible against this component's white QR panel), but the same shared `DEFAULT_HIGHLIGHT_BACKGROUND` constant used elsewhere in this library — not an arbitrary one-off color. |
|
|
324
|
+
| `highlightOnFocus` | `boolean` | `false` | A background tint on focus/hover, independent of `borderOnFocus` above. Off by default here (unlike `MediaRow`'s own `true`): the panel is deliberately white to keep the QR code scannable, and the shared default tint would wash out over it. |
|
|
325
|
+
| `highlightBackground` | `string` | `"#2a3a4a"` | Background color on focus/hover (used when `highlightOnFocus`). |
|
|
326
|
+
|
|
327
|
+
</details>
|
|
328
|
+
|
|
277
329
|
### `ScreenshotCarousel`
|
|
278
330
|
|
|
279
331
|
A single screenshot "stage" — app store/catalog "photos", one shown at a time, reading as one pressable card (same rounded corners, same `bottomSeparator`/focus-border conventions as `MediaRow`). Moved with DIR_LEFT/DIR_RIGHT or LB/RB (advertised in Steam's own bottom action-legend bar) — no on-screen prev/next buttons on this inline view, those only live in the full-screen zoom pressing the photo opens (a real Steam modal, via `showModal`/`ModalRoot`). Renders nothing at all when `screenshots` is empty, so a caller never needs its own length check around it.
|
|
@@ -300,3 +352,45 @@ import { ScreenshotCarousel } from "@moi952/decky-ui-kit";
|
|
|
300
352
|
| `nextActionDescription` | `ReactNode` | `"Next"` | Shown next to the RB prompt. |
|
|
301
353
|
|
|
302
354
|
</details>
|
|
355
|
+
|
|
356
|
+
### `StatusCard`
|
|
357
|
+
|
|
358
|
+
A finished-state card — "done, here's what happened" — for after an update/install/check completes. `variant="info"` is the odd one out: not a finished-state verdict, a plain announcement/notice instead (e.g. "check out my other plugins"), same card look, neutral blue. Colors and layout match the hand-rolled success/error/notice cards several Decky plugins had already converged on independently. No first-class dismiss-button prop — the same `children` slot that already fits a "Reboot now"/"Try again" action fits a dismiss button just as well (render one, e.g. `ActionButton`, straight into `children`).
|
|
359
|
+
|
|
360
|
+
```tsx
|
|
361
|
+
import { StatusCard } from "@moi952/decky-ui-kit";
|
|
362
|
+
|
|
363
|
+
<StatusCard title="Everything is up to date" />
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
<details>
|
|
367
|
+
<summary>Props</summary>
|
|
368
|
+
|
|
369
|
+
| Prop | Type | Default | Description |
|
|
370
|
+
| --- | --- | --- | --- |
|
|
371
|
+
| `variant` | `"success" \| "error" \| "info"` | `"success"` | Icon/text/border color. |
|
|
372
|
+
| `title` | `ReactNode` | — | Bold headline. |
|
|
373
|
+
| `description` | `ReactNode` | — | Smaller text below the title. |
|
|
374
|
+
| `icon` | `ReactNode` | A check/X/info circle matching `variant` | Overrides the default icon. |
|
|
375
|
+
| `children` | `ReactNode` | — | Rendered below the description — e.g. a "Reboot now"/"Try again"/"Got it" action or dismiss button. |
|
|
376
|
+
|
|
377
|
+
</details>
|
|
378
|
+
|
|
379
|
+
## Hooks
|
|
380
|
+
|
|
381
|
+
### `useRemoteJson`
|
|
382
|
+
|
|
383
|
+
Fetches and JSON-parses a URL once, keeping the result in memory for a TTL (default 12h) so every component calling this with the same URL during that window reuses the same result instead of re-fetching. Never throws into the caller — a failed fetch (offline, CDN hiccup, ...) just leaves `data` null and `error` true.
|
|
384
|
+
|
|
385
|
+
```tsx
|
|
386
|
+
import { useRemoteJson } from "@moi952/decky-ui-kit";
|
|
387
|
+
|
|
388
|
+
const { data, loading, error } = useRemoteJson<MyType>("https://cdn.jsdelivr.net/gh/user/repo@main/data.json");
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
| Param | Type | Default | Description |
|
|
392
|
+
| --- | --- | --- | --- |
|
|
393
|
+
| `url` | `string` | — | Fetched with a plain `fetch(url).then(r => r.json())` — same-origin/CORS rules apply like any other `fetch` call. |
|
|
394
|
+
| `ttlMs` | `number` | `43200000` (12h) | How long a successful result is reused before the next mount re-fetches. |
|
|
395
|
+
|
|
396
|
+
Returns `{ data: T \| null, loading: boolean, error: boolean }`.
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { IconType } from "react-icons";
|
|
2
3
|
export interface CollapsibleSectionProps {
|
|
3
|
-
label:
|
|
4
|
+
label: React.ReactNode;
|
|
4
5
|
expanded: boolean;
|
|
5
6
|
onToggle: () => void;
|
|
6
7
|
children: React.ReactNode;
|
|
7
8
|
contentBottomSeparator?: boolean;
|
|
9
|
+
variant?: "field" | "group-header";
|
|
10
|
+
icon?: IconType;
|
|
11
|
+
iconColor?: string;
|
|
12
|
+
count?: number;
|
|
8
13
|
}
|
|
9
14
|
export declare const CollapsibleSection: React.FC<CollapsibleSectionProps>;
|
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import { Field } from "@decky/ui";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { DialogButton, Field } from "@decky/ui";
|
|
3
3
|
import { FaChevronDown, FaChevronRight } from "react-icons/fa";
|
|
4
|
+
import { FiChevronDown, FiChevronRight } from "react-icons/fi";
|
|
4
5
|
const DIVIDER_COLOR = "rgba(255, 255, 255, 0.08)";
|
|
6
|
+
// Scoped by module load, not per-instance — this variant's focus/hover
|
|
7
|
+
// look never varies by caller (no color/size props), so one shared class
|
|
8
|
+
// for every instance is simpler than InlineConfirm/QrCodeButton's own
|
|
9
|
+
// per-instance useId() pattern, and it's already how the original
|
|
10
|
+
// GameGroupHeader this variant reproduces did it.
|
|
11
|
+
const GROUP_HEADER_CLASS = "dck-collapsible-group-header";
|
|
12
|
+
const groupHeaderStyleTag = `
|
|
13
|
+
.${GROUP_HEADER_CLASS}:focus {
|
|
14
|
+
outline: 2px solid #dcdedf !important;
|
|
15
|
+
outline-offset: 0px !important;
|
|
16
|
+
background: #2a3a4a !important;
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
5
19
|
// Field is the generic building block Decky's own ToggleField/SliderField
|
|
6
20
|
// are built on — using it here gets native padding/separator for free,
|
|
7
21
|
// instead of approximating them with a hand-styled button.
|
|
8
|
-
export const CollapsibleSection = ({ label, expanded, onToggle, children, contentBottomSeparator = false,
|
|
22
|
+
export const CollapsibleSection = ({ label, expanded, onToggle, children, contentBottomSeparator = false, variant = "field", icon: Icon, iconColor = "#888", count, }) => {
|
|
23
|
+
if (variant === "group-header") {
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsx("style", { children: groupHeaderStyleTag }), _jsxs(DialogButton, { className: GROUP_HEADER_CLASS, onClick: onToggle, style: {
|
|
25
|
+
width: "100%",
|
|
26
|
+
boxSizing: "border-box",
|
|
27
|
+
display: "flex",
|
|
28
|
+
alignItems: "center",
|
|
29
|
+
justifyContent: "space-between",
|
|
30
|
+
padding: "6px 10px",
|
|
31
|
+
marginBottom: "4px",
|
|
32
|
+
background: "transparent",
|
|
33
|
+
border: "none",
|
|
34
|
+
}, children: [_jsxs("span", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [Icon && _jsx(Icon, { size: 9, color: iconColor }), _jsx("span", { style: {
|
|
35
|
+
fontSize: 11,
|
|
36
|
+
fontWeight: 600,
|
|
37
|
+
color: "#aaa",
|
|
38
|
+
textTransform: "uppercase",
|
|
39
|
+
letterSpacing: "0.04em",
|
|
40
|
+
}, children: label }), count !== undefined && _jsx("span", { style: { fontSize: 11, color: "#666" }, children: count })] }), expanded ? _jsx(FiChevronDown, { size: 12, color: "#888" }) : _jsx(FiChevronRight, { size: 12, color: "#888" })] }), expanded && children] }));
|
|
41
|
+
}
|
|
42
|
+
return (_jsxs(_Fragment, { children: [_jsx(Field, { label: label, onActivate: onToggle, onClick: onToggle, focusable: true, bottomSeparator: "standard", childrenLayout: "inline", children: expanded ? _jsx(FaChevronDown, { size: 12 }) : _jsx(FaChevronRight, { size: 12 }) }), expanded && children, expanded && contentBottomSeparator && (_jsx("div", { style: { marginTop: 8, borderBottom: `1px solid ${DIVIDER_COLOR}` } }))] }));
|
|
43
|
+
};
|
package/dist/MediaRow.d.ts
CHANGED
package/dist/MediaRow.js
CHANGED
|
@@ -4,6 +4,11 @@ import { DialogButton, Focusable } from "@decky/ui";
|
|
|
4
4
|
import { useFocusHighlightClass } from "./internal/focusHighlight";
|
|
5
5
|
import { Separator } from "./internal/Separator";
|
|
6
6
|
import { ACCENT_DANGER, ACCENT_INFO, ACCENT_SUCCESS, ACCENT_WARNING, DEFAULT_HIGHLIGHT_BACKGROUND, DEFAULT_HIGHLIGHT_COLOR, DEFAULT_PANEL_BACKGROUND, DEFAULT_ROUNDNESS, } from "./internal/theme";
|
|
7
|
+
const MEDIA_ALIGN = {
|
|
8
|
+
top: "flex-start",
|
|
9
|
+
center: "center",
|
|
10
|
+
bottom: "flex-end",
|
|
11
|
+
};
|
|
7
12
|
const COLOR_STYLES = {
|
|
8
13
|
// The plain default look — reserves the same border width as every
|
|
9
14
|
// accented color below (an invisible border, not an absent one) so a
|
|
@@ -26,7 +31,16 @@ const COLOR_STYLES = {
|
|
|
26
31
|
// split (with its own show/hide), `mediaLayout="stretch"` opts into a
|
|
27
32
|
// cover-image box instead of a centered icon. Neither look is "the
|
|
28
33
|
// special case" — both are just points on the same prop surface.
|
|
29
|
-
export const MediaRow = ({ media, mediaWidth = 32, mediaLayout = "fixed", mediaHeight = 32,
|
|
34
|
+
export const MediaRow = ({ media, mediaWidth = 32, mediaLayout = "fixed", mediaHeight = 32,
|
|
35
|
+
// Layout-dependent default, not a flat "center" for both — a flex item
|
|
36
|
+
// with a definite cross-size (mediaBox always has one: mediaHeight)
|
|
37
|
+
// renders at the container's cross-axis start when align-items can't
|
|
38
|
+
// actually stretch it, which is what "stretch" always used before this
|
|
39
|
+
// prop existed. Defaulting it to "center" for both would have silently
|
|
40
|
+
// changed every existing mediaLayout="stretch" caller's look (e.g.
|
|
41
|
+
// decky-proton-launch's own GameRow cover art) the moment they upgraded
|
|
42
|
+
// — this keeps that exact prior look until a caller opts in.
|
|
43
|
+
mediaAlign = mediaLayout === "stretch" ? "top" : "center", title, titleLines = 1, details, onPress, actions, collapsedByDefault = false, color, accentBorderColor, accentBorderWidth = 2, accentBackground, highlightOnFocus = true, borderOnFocus = true, highlightColor = DEFAULT_HIGHLIGHT_COLOR, highlightBackground = DEFAULT_HIGHLIGHT_BACKGROUND, spacing = 0, bottomSeparator = false, onSecondaryButton, onSecondaryActionDescription, }) => {
|
|
30
44
|
const { cls, styleTag } = useFocusHighlightClass("dck-media-row", {
|
|
31
45
|
highlightOnFocus,
|
|
32
46
|
borderOnFocus,
|
|
@@ -77,6 +91,12 @@ export const MediaRow = ({ media, mediaWidth = 32, mediaLayout = "fixed", mediaH
|
|
|
77
91
|
const highlightStyle = styleTag ? _jsx("style", { children: styleTag }) : null;
|
|
78
92
|
const titleNode = (_jsx("div", { style: {
|
|
79
93
|
fontSize: 13,
|
|
94
|
+
// Steam's own default line-height runs noticeably taller than this
|
|
95
|
+
// font actually needs — harmless for a single line, but it's what
|
|
96
|
+
// pushes a 2+ line title past mediaHeight in the first place
|
|
97
|
+
// (mediaAlign, above, only ever manages the leftover once that
|
|
98
|
+
// happens; this cuts down how much leftover there is to manage).
|
|
99
|
+
lineHeight: 1.2,
|
|
80
100
|
fontWeight: 600,
|
|
81
101
|
color: "#fff",
|
|
82
102
|
...(titleLines > 1
|
|
@@ -98,6 +118,7 @@ export const MediaRow = ({ media, mediaWidth = 32, mediaLayout = "fixed", mediaH
|
|
|
98
118
|
height: mediaHeight,
|
|
99
119
|
flexShrink: 0,
|
|
100
120
|
overflow: "hidden",
|
|
121
|
+
alignSelf: MEDIA_ALIGN[mediaAlign],
|
|
101
122
|
}
|
|
102
123
|
: {
|
|
103
124
|
width: mediaWidth,
|
|
@@ -106,6 +127,7 @@ export const MediaRow = ({ media, mediaWidth = 32, mediaLayout = "fixed", mediaH
|
|
|
106
127
|
display: "flex",
|
|
107
128
|
alignItems: "center",
|
|
108
129
|
justifyContent: "center",
|
|
130
|
+
alignSelf: MEDIA_ALIGN[mediaAlign],
|
|
109
131
|
}, children: media }));
|
|
110
132
|
const textBox = (_jsxs("div", { style: {
|
|
111
133
|
flex: 1,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface QrCodeButtonProps {
|
|
3
|
+
value: string;
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
hint?: React.ReactNode;
|
|
6
|
+
qrSize?: number;
|
|
7
|
+
borderOnFocus?: boolean;
|
|
8
|
+
highlightColor?: string;
|
|
9
|
+
highlightOnFocus?: boolean;
|
|
10
|
+
highlightBackground?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const QrCodeButton: React.FC<QrCodeButtonProps>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { QRCodeSVG } from "qrcode.react";
|
|
4
|
+
import { DialogButton, Navigation } from "@decky/ui";
|
|
5
|
+
import { CollapsibleSection } from "./CollapsibleSection";
|
|
6
|
+
import { useFocusHighlightClass } from "./internal/focusHighlight";
|
|
7
|
+
import { DEFAULT_HIGHLIGHT_BACKGROUND } from "./internal/theme";
|
|
8
|
+
// A collapsible section that reveals a QR code on expand — for handing off
|
|
9
|
+
// a URL to the user's phone (a plugin's own feedback form, a release page,
|
|
10
|
+
// ...) without them having to type it on a gamepad. The revealed code is
|
|
11
|
+
// itself a real focusable button — pressing it (gamepad A / click) opens
|
|
12
|
+
// `value` directly in Steam's own browser overlay via
|
|
13
|
+
// Navigation.NavigateToExternalWeb, for anyone who'd rather not reach for
|
|
14
|
+
// their phone at all.
|
|
15
|
+
export const QrCodeButton = ({ value, label, hint, qrSize = 160, borderOnFocus = true, highlightColor = DEFAULT_HIGHLIGHT_BACKGROUND, highlightOnFocus = false, highlightBackground, }) => {
|
|
16
|
+
const [expanded, setExpanded] = useState(false);
|
|
17
|
+
const { cls, styleTag, reserveBorder } = useFocusHighlightClass("dck-qr-btn", {
|
|
18
|
+
borderOnFocus,
|
|
19
|
+
highlightColor,
|
|
20
|
+
highlightOnFocus,
|
|
21
|
+
highlightBackground,
|
|
22
|
+
});
|
|
23
|
+
return (_jsxs(CollapsibleSection, { label: label, expanded: expanded, onToggle: () => setExpanded((v) => !v), children: [styleTag && _jsx("style", { children: styleTag }), _jsxs(DialogButton, { className: cls, onClick: () => Navigation.NavigateToExternalWeb(value), style: {
|
|
24
|
+
display: "flex",
|
|
25
|
+
flexDirection: "column",
|
|
26
|
+
alignItems: "center",
|
|
27
|
+
width: "100%",
|
|
28
|
+
boxSizing: "border-box",
|
|
29
|
+
marginTop: 10,
|
|
30
|
+
marginBottom: 10,
|
|
31
|
+
padding: 12,
|
|
32
|
+
background: "#fff",
|
|
33
|
+
borderRadius: 8,
|
|
34
|
+
...reserveBorder,
|
|
35
|
+
}, children: [_jsx(QRCodeSVG, { value: value, size: qrSize }), hint && (_jsx("div", { style: { marginTop: 8, fontSize: 11, color: "#333", textAlign: "center" }, children: hint }))] })] }));
|
|
36
|
+
};
|
package/dist/StatusCard.d.ts
CHANGED
package/dist/StatusCard.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { FaCheckCircle, FaTimesCircle } from "react-icons/fa";
|
|
3
|
+
import { FiInfo } from "react-icons/fi";
|
|
3
4
|
import { DEFAULT_ROUNDNESS } from "./internal/theme";
|
|
4
5
|
const VARIANT_COLORS = {
|
|
5
6
|
success: {
|
|
@@ -12,12 +13,29 @@ const VARIANT_COLORS = {
|
|
|
12
13
|
bg: "rgba(255, 107, 107, 0.12)",
|
|
13
14
|
border: "rgba(255, 107, 107, 0.35)",
|
|
14
15
|
},
|
|
16
|
+
// Not a finished-state ("done, here's what happened") like the other
|
|
17
|
+
// two — for a plain announcement/notice instead (e.g. "check out my
|
|
18
|
+
// other plugins"), same card look, neutral blue instead of a verdict.
|
|
19
|
+
info: {
|
|
20
|
+
fg: "#4b9cf7",
|
|
21
|
+
bg: "rgba(75, 156, 247, 0.12)",
|
|
22
|
+
border: "rgba(75, 156, 247, 0.35)",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const DEFAULT_ICON = {
|
|
26
|
+
success: _jsx(FaCheckCircle, {}),
|
|
27
|
+
error: _jsx(FaTimesCircle, {}),
|
|
28
|
+
info: _jsx(FiInfo, {}),
|
|
15
29
|
};
|
|
16
30
|
// A finished-state card — "done, here's what happened" — for after an
|
|
17
|
-
// update/install/check completes
|
|
18
|
-
//
|
|
19
|
-
// decky-nvidia-update)
|
|
20
|
-
//
|
|
31
|
+
// update/install/check completes (or, with variant="info", a plain
|
|
32
|
+
// announcement/notice instead). Colors and layout match the hand-rolled
|
|
33
|
+
// success/error cards several Decky plugins (e.g. decky-nvidia-update)
|
|
34
|
+
// already converged on independently; this gives that same look as one
|
|
35
|
+
// reusable component instead of copy-pasted CSS. There's no first-class
|
|
36
|
+
// dismiss-button prop — the same `children` slot that already fits a
|
|
37
|
+
// "Reboot now"/"Try again" action fits a dismiss button just as well
|
|
38
|
+
// (render one, e.g. `ActionButton`, straight into `children`).
|
|
21
39
|
export const StatusCard = ({ variant = "success", title, description, icon, children, }) => {
|
|
22
40
|
const colors = VARIANT_COLORS[variant];
|
|
23
41
|
return (_jsxs("div", { style: {
|
|
@@ -29,7 +47,7 @@ export const StatusCard = ({ variant = "success", title, description, icon, chil
|
|
|
29
47
|
borderRadius: DEFAULT_ROUNDNESS,
|
|
30
48
|
background: colors.bg,
|
|
31
49
|
border: `1px solid ${colors.border}`,
|
|
32
|
-
}, children: [_jsx("div", { style: { fontSize: 42, color: colors.fg, marginBottom: 8 }, children: icon ??
|
|
50
|
+
}, children: [_jsx("div", { style: { fontSize: 42, color: colors.fg, marginBottom: 8 }, children: icon ?? DEFAULT_ICON[variant] }), _jsx("div", { style: {
|
|
33
51
|
fontSize: 15,
|
|
34
52
|
fontWeight: 700,
|
|
35
53
|
// No description: the title sits directly above `children`, so it
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,11 @@ export { InlineConfirm } from "./InlineConfirm";
|
|
|
12
12
|
export type { InlineConfirmProps } from "./InlineConfirm";
|
|
13
13
|
export { MediaRow } from "./MediaRow";
|
|
14
14
|
export type { MediaRowProps } from "./MediaRow";
|
|
15
|
+
export { QrCodeButton } from "./QrCodeButton";
|
|
16
|
+
export type { QrCodeButtonProps } from "./QrCodeButton";
|
|
15
17
|
export { ScreenshotCarousel } from "./ScreenshotCarousel";
|
|
16
18
|
export type { ScreenshotCarouselProps } from "./ScreenshotCarousel";
|
|
17
19
|
export { StatusCard } from "./StatusCard";
|
|
18
20
|
export type { StatusCardProps } from "./StatusCard";
|
|
21
|
+
export { useRemoteJson } from "./useRemoteJson";
|
|
22
|
+
export type { UseRemoteJsonResult } from "./useRemoteJson";
|
package/dist/index.js
CHANGED
|
@@ -5,5 +5,7 @@ export { FieldTextInput } from "./FieldTextInput";
|
|
|
5
5
|
export { InfoTable } from "./InfoTable";
|
|
6
6
|
export { InlineConfirm } from "./InlineConfirm";
|
|
7
7
|
export { MediaRow } from "./MediaRow";
|
|
8
|
+
export { QrCodeButton } from "./QrCodeButton";
|
|
8
9
|
export { ScreenshotCarousel } from "./ScreenshotCarousel";
|
|
9
10
|
export { StatusCard } from "./StatusCard";
|
|
11
|
+
export { useRemoteJson } from "./useRemoteJson";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
// Module-level — shared by every component calling this hook with the
|
|
3
|
+
// same `url` in the same session, so only the first one actually fetches.
|
|
4
|
+
const cache = new Map();
|
|
5
|
+
// Fetches and JSON-parses `url` once, keeping the result in memory for
|
|
6
|
+
// `ttlMs` (default 12h) so every consumer mounting during that window
|
|
7
|
+
// reuses the same result instead of re-fetching. Never throws into the
|
|
8
|
+
// caller — a failed fetch (offline, CDN hiccup, ...) just leaves `data`
|
|
9
|
+
// null and `error` true, so a banner/list built on this can simply render
|
|
10
|
+
// nothing rather than break the page it's on.
|
|
11
|
+
export function useRemoteJson(url, ttlMs = 12 * 60 * 60 * 1000) {
|
|
12
|
+
const cached = cache.get(url);
|
|
13
|
+
const isFresh = !!cached && Date.now() - cached.fetchedAt < ttlMs;
|
|
14
|
+
const [data, setData] = useState(isFresh ? cached.data : null);
|
|
15
|
+
const [loading, setLoading] = useState(!isFresh);
|
|
16
|
+
const [error, setError] = useState(false);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (isFresh)
|
|
19
|
+
return;
|
|
20
|
+
let cancelled = false;
|
|
21
|
+
setLoading(true);
|
|
22
|
+
setError(false);
|
|
23
|
+
fetch(url)
|
|
24
|
+
.then((res) => {
|
|
25
|
+
if (!res.ok)
|
|
26
|
+
throw new Error(`HTTP ${res.status}`);
|
|
27
|
+
return res.json();
|
|
28
|
+
})
|
|
29
|
+
.then((json) => {
|
|
30
|
+
if (cancelled)
|
|
31
|
+
return;
|
|
32
|
+
cache.set(url, { data: json, fetchedAt: Date.now() });
|
|
33
|
+
setData(json);
|
|
34
|
+
})
|
|
35
|
+
.catch(() => {
|
|
36
|
+
if (!cancelled)
|
|
37
|
+
setError(true);
|
|
38
|
+
})
|
|
39
|
+
.finally(() => {
|
|
40
|
+
if (!cancelled)
|
|
41
|
+
setLoading(false);
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
cancelled = true;
|
|
45
|
+
};
|
|
46
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
|
+
}, [url]);
|
|
48
|
+
return { data, loading, error };
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moi952/decky-ui-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Reusable UI components for Decky Loader plugins that need popups/dropdowns without triggering the native panel-remount bug",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -43,5 +43,8 @@
|
|
|
43
43
|
"steam-deck",
|
|
44
44
|
"ui",
|
|
45
45
|
"dropdown"
|
|
46
|
-
]
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"qrcode.react": "^4.2.0"
|
|
49
|
+
}
|
|
47
50
|
}
|