@moi952/decky-ui-kit 0.6.1 → 0.7.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 CHANGED
@@ -288,7 +288,7 @@ import { FiEyeOff } from "react-icons/fi";
288
288
  | `borderOnFocus` | `boolean` | `true` | A real border on focus/hover, via an inset box-shadow (not `outline` — outline doesn't respect border-radius). Independent of `highlightOnFocus` below — same convention as `ScreenshotCarousel`'s own `borderOnFocus`. |
289
289
  | `highlightColor` | `string` | `"#dcdedf"` | Border color on focus/hover (used when `borderOnFocus`). Same default across every focusable component in this library. |
290
290
  | `highlightOnFocus` | `boolean` | `true` | A background tint on focus/hover, independent of `borderOnFocus` above. |
291
- | `highlightBackground` | `string` | `"#2a3a4a"` | Background color on focus/hover (used when `highlightOnFocus`). |
291
+ | `highlightBackground` | `string` | The theme's button fill | Background color on focus/hover (used when `highlightOnFocus`). By default the fill the active theme gives a plain button (Float's glass, Steam's own gray without a theme) with the row's text kept white: a discreet tint, never a white card. It out-ranks a theme's own focus style. |
292
292
  | `spacing` | `number` | `0` | Gap below the row, for a list of spaced-apart cards. An alternative to `bottomSeparator`, not meant combined with it. |
293
293
  | `bottomSeparator` | `boolean` | `false` | A bottom divider line, for a continuous divided list — the alternative to `spacing`. Pair with `color="transparent"` so the row shows no card background of its own, just the divider and the focus highlight. |
294
294
  | `onSecondaryButton` | `(evt) => void` | — | Fires on gamepad X / Steam "Secondary" while the row has focus. |
@@ -376,6 +376,63 @@ import { StatusCard } from "@moi952/decky-ui-kit";
376
376
 
377
377
  </details>
378
378
 
379
+ ### `ThemedSurface`
380
+
381
+ A block whose background is the one the active theme gives to a plain Steam button (Float's glass, Steam's own bluish gray, whatever is installed), instead of a hard-coded translucent white. For placeholder icons, progress tracks and other surfaces that should read as part of the theme. The fill is read from a plain button already on screen; when there is none, `fallback` is used. `InfoTable` does the same for its card unless it is given a `bgColor`.
382
+
383
+ ```tsx
384
+ import { ThemedSurface } from "@moi952/decky-ui-kit";
385
+
386
+ <ThemedSurface style={{ width: 44, height: 44, borderRadius: 8 }}>
387
+ <AppGlyph />
388
+ </ThemedSurface>
389
+ ```
390
+
391
+ <details>
392
+ <summary>Props</summary>
393
+
394
+ | Prop | Type | Default | Description |
395
+ | --- | --- | --- | --- |
396
+ | `fallback` | `string` | `"rgba(255, 255, 255, 0.08)"` | Background used when no plain Steam button is on screen to read the theme from. |
397
+ | `className` | `string` | — | Class on the block. |
398
+ | `style` | `CSSProperties` | — | Style on the block; anything set here wins, including `background`. |
399
+ | `children` | `ReactNode` | — | The content of the block. |
400
+
401
+ </details>
402
+
403
+ ### `TabBar`
404
+
405
+ Icon tabs flanked by white bumper hints (LB / RB on Xbox, L1 / R1 on PlayStation and Steam, L / R on Switch — following the pad in use), controlled by the parent (`activeId` / `onSelect`). The icons are click/touch only — the gamepad never lands on them: L1 / R1 switch page from anywhere inside `children` (not only while the bar has focus), stopping at both ends. `children` is the page under the bar. After a page switch or on mount, focus is put back on the first control of the page (`restoreFocus`), because without focus inside the page the next bumper press would go to Steam instead of the bar.
406
+
407
+ ```tsx
408
+ import { TabBar } from "@moi952/decky-ui-kit";
409
+
410
+ <TabBar items={tabs} activeId={tab} onSelect={setTab}>
411
+ {page}
412
+ </TabBar>
413
+ ```
414
+
415
+ <details>
416
+ <summary>Props</summary>
417
+
418
+ | Prop | Type | Default | Description |
419
+ | --- | --- | --- | --- |
420
+ | `items` | `{ id: string; icon: ReactNode; label: string }[]` | — | The tabs, in order. `label` is the tooltip / accessible name. |
421
+ | `activeId` | `string` | — | Id of the selected tab. |
422
+ | `onSelect` | `(id: string) => void` | — | Called on icon click or L1 / R1. |
423
+ | `children` | `ReactNode` | — | The page under the bar; L1 / R1 work from anywhere inside it. |
424
+ | `activeColor` | `string` | `"#d0d5dc"` | Selected icon color. |
425
+ | `inactiveColor` | `string` | `"#4b515b"` | Other icons' color. |
426
+ | `showHints` | `boolean` | `true` | Show the bumper pills at both ends. |
427
+ | `controller` | `"auto" \| "xbox" \| "playstation" \| "switch" \| "steam"` | `"auto"` | Which pad's bumper names to show; `auto` follows the pad in use (read from Steam's internal state, falls back to L1 / R1). |
428
+ | `previousHint` | `string` | from `controller` | Overrides the left pill text. |
429
+ | `nextHint` | `string` | from `controller` | Overrides the right pill text. |
430
+ | `hintBackground` | `string` | `"#ffffff"` | Pills' background. |
431
+ | `hintColor` | `string` | `"#14181d"` | Pills' text color. |
432
+ | `restoreFocus` | `boolean` | `true` | Refocus the first control of the page after a switch / on mount. |
433
+
434
+ </details>
435
+
379
436
  ## Hooks
380
437
 
381
438
  ### `useRemoteJson`
@@ -26,49 +26,61 @@ export const ActionButton = ({ children, onClick, size = "small", variant = "nor
26
26
  // instead, since a border would resize the button whenever it
27
27
  // appears (no fixed width here, buttons size to their content).
28
28
  };
29
- const cls = [variant !== "normal" ? `dck-action-btn-${variant}` : null, isPressed ? `dck-action-btn-pressed-${variant}` : null]
29
+ const cls = ["dck-action-btn", variant !== "normal" ? `dck-action-btn-${variant}` : null, isPressed ? `dck-action-btn-pressed-${variant}` : null]
30
30
  .filter(Boolean)
31
31
  .join(" ") || undefined;
32
- // Compound selector so the pressed rule reliably outranks the plain
33
- // variant rule regardless of style-tag mount order.
34
- const pressedVariantCls = variant !== "normal" ? `.dck-action-btn-${variant}` : "";
35
- return (_jsxs(_Fragment, { children: [variant === "bordered" && (_jsx("style", { children: `
36
- .dck-action-btn-bordered {
32
+ // Own look, whatever the theme: a theme restyling every DialogButton (fill, ring,
33
+ // white focus) must not win, so each class is repeated to out-rank it. Compound
34
+ // selectors also keep the pressed rule above the plain variant one regardless of
35
+ // style-tag mount order.
36
+ const B = ".dck-action-btn-bordered";
37
+ const V = `.dck-action-btn-${variant}`;
38
+ const P = `.dck-action-btn-pressed-${variant}`;
39
+ const withVariant = variant !== "normal";
40
+ const variantPressed = withVariant ? `, ${V}${V}${P}${P}` : "";
41
+ const variantPressedFocus = withVariant
42
+ ? `, ${V}${V}${P}${P}:focus, ${V}${V}${P}${P}.gpfocus, ${V}${V}${P}${P}:hover`
43
+ : "";
44
+ return (_jsxs(_Fragment, { children: [_jsx("style", { children: `.dck-action-btn svg[fill="none"] { fill: none !important; }` }), variant === "bordered" && (_jsx("style", { children: `
45
+ ${B}${B} {
37
46
  background: rgba(255, 255, 255, 0.08) !important;
38
47
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18) !important;
39
48
  }
40
- .dck-action-btn-bordered:focus,
41
- .dck-action-btn-bordered:hover {
49
+ ${B}${B}${B}:focus,
50
+ ${B}${B}${B}.gpfocus,
51
+ ${B}${B}${B}:hover {
42
52
  background: #dcdedf !important;
43
53
  color: #000 !important;
44
54
  box-shadow: inset 0 0 0 1px #dcdedf !important;
45
55
  }
46
- .dck-action-btn-bordered:disabled,
47
- .dck-action-btn-bordered[disabled] {
56
+ ${B}${B}:disabled,
57
+ ${B}${B}[disabled] {
48
58
  opacity: 1 !important;
49
59
  background: #2a2e35 !important;
50
60
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15) !important;
51
61
  color: #6b7076 !important;
52
62
  }
53
63
  ` })), (variant === "danger" || variant === "primary") && (_jsx("style", { children: `
54
- .dck-action-btn-${variant} {
64
+ ${V}${V} {
55
65
  background-color: ${SOLID_VARIANT_COLOR[variant]} !important;
56
66
  color: #fff !important;
67
+ box-shadow: none !important;
57
68
  }
58
- .dck-action-btn-${variant}:focus,
59
- .dck-action-btn-${variant}:hover {
69
+ ${V}${V}${V}:focus,
70
+ ${V}${V}${V}.gpfocus,
71
+ ${V}${V}${V}:hover {
60
72
  background-color: #fff !important;
61
73
  color: ${SOLID_VARIANT_COLOR[variant]} !important;
62
74
  }
63
75
  ` })), isPressed && (_jsx("style", { children: `
64
- .dck-action-btn-pressed-${variant}${pressedVariantCls ? `, ${pressedVariantCls}.dck-action-btn-pressed-${variant}` : ""} {
76
+ ${P}${P}${variantPressed} {
65
77
  background-color: ${PRESSED_COLOR[variant]} !important;
66
78
  color: #fff !important;
79
+ box-shadow: none !important;
67
80
  }
68
- .dck-action-btn-pressed-${variant}:focus,
69
- .dck-action-btn-pressed-${variant}:hover${pressedVariantCls ? `,
70
- ${pressedVariantCls}.dck-action-btn-pressed-${variant}:focus,
71
- ${pressedVariantCls}.dck-action-btn-pressed-${variant}:hover` : ""} {
81
+ ${P}${P}${P}:focus,
82
+ ${P}${P}${P}.gpfocus,
83
+ ${P}${P}${P}:hover${variantPressedFocus} {
72
84
  background-color: #fff !important;
73
85
  color: #111 !important;
74
86
  }
@@ -7,6 +7,13 @@ const DEFAULT_BG = DEFAULT_PANEL_BACKGROUND;
7
7
  const DEFAULT_TEXT = "#bfbfbf";
8
8
  const DEFAULT_BORDER = "transparent";
9
9
  const FALLBACK_RADIUS = "6px";
10
+ // A theme can give the trigger a pill radius (999px): copying that onto the
11
+ // whole list would round its corners absurdly.
12
+ const MAX_LIST_RADIUS = 12;
13
+ const clampRadius = (radius) => {
14
+ const px = parseFloat(radius);
15
+ return Number.isFinite(px) && px > MAX_LIST_RADIUS ? `${MAX_LIST_RADIUS}px` : radius;
16
+ };
10
17
  // The trigger's own horizontal padding/vertical rhythm — fontSize and
11
18
  // minHeight (the actual height-determining values) come from the shared
12
19
  // SIZE_STYLE table instead (see internal/theme.ts), the same one
@@ -70,7 +77,7 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labe
70
77
  }, [variant, size]);
71
78
  useEffect(() => {
72
79
  if (variant === "boxed" && triggerRef.current) {
73
- const r = getComputedStyle(triggerRef.current).borderRadius;
80
+ const r = clampRadius(getComputedStyle(triggerRef.current).borderRadius);
74
81
  if (r) {
75
82
  sharedBoxedRadius = r;
76
83
  setListRadius(r);
@@ -186,13 +193,16 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labe
186
193
  const triggerLabelCls = `${uid}-trigger-label`;
187
194
  const countCls = `${uid}-count`;
188
195
  const wrapperCls = `${uid}-wrapper`;
196
+ // The options are a designed list: a theme restyling every DialogButton (pill,
197
+ // glass fill, white focus) must not win over it, so the classes are repeated.
198
+ const optSel = `.${wrapperCls}.${wrapperCls} .${optionCls}.${optionCls}`;
189
199
  const optionPadding = OPTION_PADDING[size];
190
200
  const optionFontSize = OPTION_FONT_SIZE[size];
191
201
  const triggerPadding = `${TRIGGER_PADDING_V[size]}px ${TRIGGER_PADDING_H[size]}px`;
192
202
  const { fontSize: sizeFontSize, minHeight: triggerMinHeight } = SIZE_STYLE[size];
193
203
  const triggerFontSize = valueFontSize ?? sizeFontSize;
194
204
  return (_jsxs("div", { ref: wrapperRef, className: wrapperCls, style: { position: "relative", width: "100%", maxWidth: "100%", boxSizing: "border-box" }, children: [_jsx("style", { children: `
195
- .${optionCls} {
205
+ ${optSel} {
196
206
  box-sizing: border-box !important;
197
207
  padding: ${optionPadding} !important;
198
208
  font-size: ${optionFontSize} !important;
@@ -205,6 +215,7 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labe
205
215
  background-image: none !important;
206
216
  box-shadow: none !important;
207
217
  border: 2px solid transparent !important;
218
+ border-radius: 2px !important;
208
219
  color: ${textColor} !important;
209
220
  }
210
221
  .${triggerCls} {
@@ -246,12 +257,12 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labe
246
257
  }
247
258
  ${focusStyle === "outline"
248
259
  ? `
249
- .${optionCls}.${selectedCls} {
260
+ ${optSel}.${selectedCls} {
250
261
  border-color: #dcdedf !important;
251
262
  color: #fff !important;
252
263
  }
253
- .${optionCls}:focus,
254
- .${optionCls}:hover {
264
+ ${optSel}:focus,
265
+ ${optSel}:hover {
255
266
  background: #555 !important;
256
267
  border-color: #fff !important;
257
268
  color: #fff !important;
@@ -264,11 +275,11 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labe
264
275
  }
265
276
  `
266
277
  : `
267
- .${optionCls}.${selectedCls} {
278
+ ${optSel}.${selectedCls} {
268
279
  color: #fff !important;
269
280
  }
270
- .${optionCls}:focus,
271
- .${optionCls}:hover {
281
+ ${optSel}:focus,
282
+ ${optSel}:hover {
272
283
  background: #fff !important;
273
284
  color: #111 !important;
274
285
  }
@@ -1,7 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useRef } from "react";
2
3
  import { DialogButton, Field } from "@decky/ui";
3
4
  import { FaChevronDown, FaChevronRight } from "react-icons/fa";
4
5
  import { FiChevronDown, FiChevronRight } from "react-icons/fi";
6
+ import { MAX_CARD_RADIUS } from "./internal/theme";
7
+ import { useRadiusCap } from "./internal/useRadiusCap";
8
+ import { useThemeFill } from "./internal/themeFill";
5
9
  const DIVIDER_COLOR = "rgba(255, 255, 255, 0.08)";
6
10
  // Scoped by module load, not per-instance — this variant's focus/hover
7
11
  // look never varies by caller (no color/size props), so one shared class
@@ -9,19 +13,52 @@ const DIVIDER_COLOR = "rgba(255, 255, 255, 0.08)";
9
13
  // per-instance useId() pattern, and it's already how the original
10
14
  // GameGroupHeader this variant reproduces did it.
11
15
  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;
16
+ // Same focus as a MediaRow: a light frame and a discreet tint (the fill the theme gives a
17
+ // plain button), text staying readable — with or without a theme. The tripled class keeps a
18
+ // theme's own focus (white fill, dark text, shadow) from taking over.
19
+ const FOCUS_TINT_FALLBACK = "rgba(255, 255, 255, 0.12)";
20
+ const FOCUS_FRAME = "#dcdedf";
21
+ const groupHeaderStyleTag = (tint) => `
22
+ .${GROUP_HEADER_CLASS}.${GROUP_HEADER_CLASS}:not(:focus):not(:focus-within):not(.gpfocus):not(:hover) {
23
+ background: transparent !important;
24
+ box-shadow: none !important;
25
+ }
26
+ .${GROUP_HEADER_CLASS}.${GROUP_HEADER_CLASS}.${GROUP_HEADER_CLASS}:focus,
27
+ .${GROUP_HEADER_CLASS}.${GROUP_HEADER_CLASS}.${GROUP_HEADER_CLASS}.gpfocus,
28
+ .${GROUP_HEADER_CLASS}.${GROUP_HEADER_CLASS}.${GROUP_HEADER_CLASS}:hover {
29
+ background: ${tint} !important;
30
+ box-shadow: inset 0 0 0 2px ${FOCUS_FRAME} !important;
31
+ }
32
+ /* The greys are fixed inline and too faint on the tint: white while focused. */
33
+ .${GROUP_HEADER_CLASS}:focus span,
34
+ .${GROUP_HEADER_CLASS}.gpfocus span,
35
+ .${GROUP_HEADER_CLASS}:hover span {
36
+ color: #fff !important;
37
+ }
38
+ /* Stroke icons stay strokes when a theme recolours a focused button's svg. */
39
+ .${GROUP_HEADER_CLASS} svg[fill="none"] {
40
+ fill: none !important;
41
+ }
42
+ .${GROUP_HEADER_CLASS}:not(:focus):not(.gpfocus):not(:hover) .${GROUP_HEADER_CLASS}-chevron {
43
+ color: #888 !important;
44
+ }
45
+ .${GROUP_HEADER_CLASS}:focus .${GROUP_HEADER_CLASS}-chevron,
46
+ .${GROUP_HEADER_CLASS}.gpfocus .${GROUP_HEADER_CLASS}-chevron,
47
+ .${GROUP_HEADER_CLASS}:hover .${GROUP_HEADER_CLASS}-chevron {
48
+ color: #fff !important;
17
49
  }
18
50
  `;
19
51
  // Field is the generic building block Decky's own ToggleField/SliderField
20
52
  // are built on — using it here gets native padding/separator for free,
21
53
  // instead of approximating them with a hand-styled button.
22
54
  export const CollapsibleSection = ({ label, expanded, onToggle, children, contentBottomSeparator = false, variant = "field", icon: Icon, iconColor = "#888", count, }) => {
55
+ // The tint is read from the window the header is rendered in, through its own <style>.
56
+ const probeRef = useRef(null);
57
+ const tint = useThemeFill(probeRef, FOCUS_TINT_FALLBACK);
58
+ // The radius is the theme's own; only a pill (999px) is capped.
59
+ const capTag = useRadiusCap(probeRef, GROUP_HEADER_CLASS, MAX_CARD_RADIUS);
23
60
  if (variant === "group-header") {
24
- return (_jsxs(_Fragment, { children: [_jsx("style", { children: groupHeaderStyleTag }), _jsxs(DialogButton, { className: GROUP_HEADER_CLASS, onClick: onToggle, style: {
61
+ return (_jsxs(_Fragment, { children: [_jsx("style", { ref: probeRef, children: `${groupHeaderStyleTag(tint)}${capTag}` }), _jsxs(DialogButton, { className: GROUP_HEADER_CLASS, onClick: onToggle, style: {
25
62
  width: "100%",
26
63
  boxSizing: "border-box",
27
64
  display: "flex",
@@ -37,7 +74,7 @@ export const CollapsibleSection = ({ label, expanded, onToggle, children, conten
37
74
  color: "#aaa",
38
75
  textTransform: "uppercase",
39
76
  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] }));
77
+ }, children: label }), count !== undefined && (_jsx("span", { style: { fontSize: 11, color: "#666" }, children: count }))] }), expanded ? (_jsx(FiChevronDown, { className: `${GROUP_HEADER_CLASS}-chevron`, size: 12, color: "#888" })) : (_jsx(FiChevronRight, { className: `${GROUP_HEADER_CLASS}-chevron`, size: 12, color: "#888" }))] }), expanded && children] }));
41
78
  }
42
79
  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
80
  };
package/dist/InfoTable.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef } from "react";
2
3
  import { DEFAULT_ROUNDNESS } from "./internal/theme";
4
+ import { useThemeFill } from "./internal/themeFill";
3
5
  const DEFAULT_LABEL_WIDTH = 90;
4
6
  const DEFAULT_LABEL_COLOR = "#9aa1a8";
5
7
  const DEFAULT_ICON_COLOR = "#6b7076";
@@ -26,9 +28,14 @@ const InfoTableRowView = ({ icon, label, value, accent, last, labelWidth, labelC
26
28
  // the caller. Built for a "detail" screen sitting below its header, but
27
29
  // nothing here assumes any particular kind of entity. Rows with an
28
30
  // `accent` (e.g. an available update in green) stand out against the rest.
29
- export const InfoTable = ({ rows, labelWidth = DEFAULT_LABEL_WIDTH, labelColor = DEFAULT_LABEL_COLOR, iconColor = DEFAULT_ICON_COLOR, valueColor = DEFAULT_VALUE_COLOR, bgColor = DEFAULT_BG, borderColor = DEFAULT_BORDER, }) => (_jsx("div", { style: {
30
- background: bgColor,
31
- border: `1px solid ${borderColor}`,
32
- borderRadius: DEFAULT_ROUNDNESS,
33
- overflow: "hidden",
34
- }, children: rows.map((row, i) => (_jsx(InfoTableRowView, { ...row, last: i === rows.length - 1, labelWidth: labelWidth, labelColor: labelColor, iconColor: iconColor, valueColor: valueColor }, i))) }));
31
+ export const InfoTable = ({ rows, labelWidth = DEFAULT_LABEL_WIDTH, labelColor = DEFAULT_LABEL_COLOR, iconColor = DEFAULT_ICON_COLOR, valueColor = DEFAULT_VALUE_COLOR, bgColor, borderColor = DEFAULT_BORDER, }) => {
32
+ const ref = useRef(null);
33
+ // Without a bgColor the card takes the fill the active theme gives a button.
34
+ const themeFill = useThemeFill(ref, DEFAULT_BG);
35
+ return (_jsx("div", { ref: ref, style: {
36
+ background: bgColor ?? themeFill,
37
+ border: `1px solid ${borderColor}`,
38
+ borderRadius: DEFAULT_ROUNDNESS,
39
+ overflow: "hidden",
40
+ }, children: rows.map((row, i) => (_jsx(InfoTableRowView, { ...row, last: i === rows.length - 1, labelWidth: labelWidth, labelColor: labelColor, iconColor: iconColor, valueColor: valueColor }, i))) }));
41
+ };
package/dist/MediaRow.js CHANGED
@@ -1,14 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useState } from "react";
2
+ import { useRef, useState } from "react";
3
3
  import { DialogButton, Focusable } from "@decky/ui";
4
4
  import { useFocusHighlightClass } from "./internal/focusHighlight";
5
5
  import { Separator } from "./internal/Separator";
6
- import { ACCENT_DANGER, ACCENT_INFO, ACCENT_SUCCESS, ACCENT_WARNING, DEFAULT_HIGHLIGHT_BACKGROUND, DEFAULT_HIGHLIGHT_COLOR, DEFAULT_PANEL_BACKGROUND, DEFAULT_ROUNDNESS, } from "./internal/theme";
6
+ import { useRadiusCap } from "./internal/useRadiusCap";
7
+ import { useThemeFill } from "./internal/themeFill";
8
+ import { ACCENT_DANGER, ACCENT_INFO, ACCENT_SUCCESS, ACCENT_WARNING, DEFAULT_HIGHLIGHT_COLOR, MAX_CARD_RADIUS, DEFAULT_PANEL_BACKGROUND, DEFAULT_ROUNDNESS, } from "./internal/theme";
7
9
  const MEDIA_ALIGN = {
8
10
  top: "flex-start",
9
11
  center: "center",
10
12
  bottom: "flex-end",
11
13
  };
14
+ // Used for the focus tint when no plain Steam button is on screen to read the theme's fill from.
15
+ const THEME_FILL_FALLBACK = "rgba(255, 255, 255, 0.12)";
12
16
  const COLOR_STYLES = {
13
17
  // The plain default look — reserves the same border width as every
14
18
  // accented color below (an invisible border, not an absent one) so a
@@ -40,7 +44,13 @@ export const MediaRow = ({ media, mediaWidth = 32, mediaLayout = "fixed", mediaH
40
44
  // changed every existing mediaLayout="stretch" caller's look (e.g.
41
45
  // decky-proton-launch's own GameRow cover art) the moment they upgraded
42
46
  // — 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, onOptionsButton, onOptionsActionDescription, onOKActionDescription, }) => {
47
+ 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: highlightBackgroundProp, spacing = 0, bottomSeparator = false, onSecondaryButton, onSecondaryActionDescription, onOptionsButton, onOptionsActionDescription, onOKActionDescription, }) => {
48
+ // The focus fill is the one the active theme gives a plain button (Float's glass, Steam's
49
+ // own gray without a theme) — a discreet tint, never a white card. Read from the window
50
+ // the row is rendered in, through this <style>.
51
+ const probeRef = useRef(null);
52
+ const themeFill = useThemeFill(probeRef, THEME_FILL_FALLBACK);
53
+ const highlightBackground = highlightBackgroundProp ?? themeFill;
44
54
  const { cls, styleTag } = useFocusHighlightClass("dck-media-row", {
45
55
  highlightOnFocus,
46
56
  borderOnFocus,
@@ -48,6 +58,8 @@ mediaAlign = mediaLayout === "stretch" ? "top" : "center", title, titleLines = 1
48
58
  highlightBackground,
49
59
  borderWidth: accentBorderWidth,
50
60
  hasBottomDivider: bottomSeparator,
61
+ // The row's text stays white on that tint, whatever colour a theme gives a focused button.
62
+ highlightForeground: highlightBackgroundProp === undefined ? "#fff" : undefined,
51
63
  });
52
64
  const hasActions = !!actions;
53
65
  // `collapsedByDefault` always governs the initial state, `onPress` or
@@ -85,10 +97,54 @@ mediaAlign = mediaLayout === "stretch" ? "top" : "center", title, titleLines = 1
85
97
  borderRadius: DEFAULT_ROUNDNESS,
86
98
  overflow: "hidden",
87
99
  background: resolvedBackground,
100
+ color: "#fff",
88
101
  border: `${bottomSeparator ? 0 : accentBorderWidth}px solid ${resolvedBorderColor}`,
89
102
  ...(spacing ? { marginBottom: spacing } : {}),
90
103
  };
91
- const highlightStyle = styleTag ? _jsx("style", { children: styleTag }) : null;
104
+ // A theme may round every button into a pill (999px), which swallows the cover
105
+ // and the title: cap the card's radius, but leave anything smaller to the theme.
106
+ const capTag = useRadiusCap(probeRef, cls, MAX_CARD_RADIUS, hasActions ? `.${cls}-header` : `.${cls}`);
107
+ // A flat row (color="transparent") is a designed list entry: no theme fill, pill or
108
+ // ring behind it at rest.
109
+ const rest = `.${cls}.${cls}`;
110
+ const flatTag = color === "transparent"
111
+ ? `
112
+ ${rest}:not(:focus):not(:focus-within):not(.gpfocus):not(:hover) {
113
+ background: transparent !important;
114
+ box-shadow: none !important;
115
+ }
116
+ ${rest} {
117
+ border-radius: ${DEFAULT_ROUNDNESS} !important;
118
+ }
119
+ `
120
+ : "";
121
+ // The header button sits inside the card (actions variant): it stays transparent, white
122
+ // text included, even while focused — the card behind it carries the focus frame and tint,
123
+ // and a theme's own focus (white fill, dark text) must not paint over it.
124
+ const headerSel = `.${cls}-header.${cls}-header.${cls}-header`;
125
+ const headerTag = hasActions
126
+ ? `
127
+ ${headerSel} {
128
+ background: transparent !important;
129
+ border-radius: 0 !important;
130
+ box-shadow: none !important;
131
+ color: #fff !important;
132
+ }
133
+ `
134
+ : "";
135
+ // A row that asked for a border only gets no fill from a theme either.
136
+ const focus3 = `.${cls}.${cls}.${cls}`;
137
+ const borderOnlyTag = !highlightOnFocus
138
+ ? `
139
+ ${focus3}:focus, ${focus3}.gpfocus, ${focus3}:hover {
140
+ background: transparent !important;
141
+ color: #fff !important;
142
+ }
143
+ `
144
+ : "";
145
+ // A theme recolouring a focused button's svg must not fill the stroke icons.
146
+ const iconTag = `.${cls} svg[fill="none"] { fill: none !important; }`;
147
+ const highlightStyle = (_jsx("style", { ref: probeRef, children: `${flatTag}${styleTag ?? ""}${borderOnlyTag}${headerTag}${iconTag}${capTag}` }));
92
148
  const titleNode = (_jsx("div", { style: {
93
149
  fontSize: 13,
94
150
  // Steam's own default line-height runs noticeably taller than this
@@ -98,7 +154,9 @@ mediaAlign = mediaLayout === "stretch" ? "top" : "center", title, titleLines = 1
98
154
  // happens; this cuts down how much leftover there is to manage).
99
155
  lineHeight: 1.2,
100
156
  fontWeight: 600,
101
- color: "#fff",
157
+ // Inherited from the button (white below), so a theme that recolours a
158
+ // focused button recolours this text with it.
159
+ color: "inherit",
102
160
  ...(titleLines > 1
103
161
  ? {
104
162
  overflow: "hidden",
@@ -156,7 +214,7 @@ mediaAlign = mediaLayout === "stretch" ? "top" : "center", title, titleLines = 1
156
214
  padding: stretch ? 0 : "4px 8px",
157
215
  }, children: [mediaBox, textBox] }), bottomSeparator && _jsx(Separator, { marginTop: 1 })] }));
158
216
  }
159
- return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cls, style: { width: "100%", boxSizing: "border-box", ...cardStyle }, children: [highlightStyle, _jsxs(DialogButton, { onClick: handleClick, onSecondaryButton: onSecondaryButton, onSecondaryActionDescription: onSecondaryActionDescription, onOptionsButton: onOptionsButton, onOptionsActionDescription: onOptionsActionDescription, onOKActionDescription: onOKActionDescription, style: {
217
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cls, style: { width: "100%", boxSizing: "border-box", ...cardStyle }, children: [highlightStyle, _jsxs(DialogButton, { className: `${cls}-header`, onClick: handleClick, onSecondaryButton: onSecondaryButton, onSecondaryActionDescription: onSecondaryActionDescription, onOptionsButton: onOptionsButton, onOptionsActionDescription: onOptionsActionDescription, onOKActionDescription: onOKActionDescription, style: {
160
218
  width: "100%",
161
219
  boxSizing: "border-box",
162
220
  display: "flex",
@@ -164,6 +222,7 @@ mediaAlign = mediaLayout === "stretch" ? "top" : "center", title, titleLines = 1
164
222
  gap: 10,
165
223
  padding: stretch ? 0 : "4px 8px",
166
224
  background: "transparent",
225
+ color: "#fff",
167
226
  border: "none",
168
227
  }, children: [mediaBox, textBox] }), expanded && (_jsx(Focusable, { style: {
169
228
  display: "flex",
@@ -4,6 +4,9 @@ import { DialogButton, Focusable, GamepadButton } from "@decky/ui";
4
4
  import { DEFAULT_HIGHLIGHT_BACKGROUND, useFocusHighlightClass } from "./internal/focusHighlight";
5
5
  import { Separator } from "./internal/Separator";
6
6
  import { DEFAULT_ROUNDNESS } from "./internal/theme";
7
+ import { useRadiusCap } from "./internal/useRadiusCap";
8
+ // A preview is a picture: a theme's pill radius would crop it, so keep it light.
9
+ const MAX_PREVIEW_RADIUS = 8;
7
10
  // A single screenshot "stage" (app store/catalog "photos", not the
8
11
  // small square icon MediaRow already covers) — reads as one pressable
9
12
  // card, exactly like a MediaRow instance (same rounded corners, same
@@ -52,6 +55,8 @@ export const ScreenshotCarousel = ({ screenshots, height = 120, bottomSeparator
52
55
  highlightBackground,
53
56
  hasBottomDivider: bottomSeparator,
54
57
  });
58
+ const probeRef = useRef(null);
59
+ const capTag = useRadiusCap(probeRef, cls, MAX_PREVIEW_RADIUS);
55
60
  useEffect(() => {
56
61
  if (zoomed)
57
62
  zoomRef.current?.focus();
@@ -79,7 +84,7 @@ export const ScreenshotCarousel = ({ screenshots, height = 120, bottomSeparator
79
84
  setZoomed(false);
80
85
  stageRef.current?.focus();
81
86
  };
82
- return (_jsxs(_Fragment, { children: [styleTag && _jsx("style", { children: styleTag }), _jsx(Focusable, { style: { width: "100%", boxSizing: "border-box" }, onButtonDown: handleButtonDown, actionDescriptionMap: visible.length > 1
87
+ return (_jsxs(_Fragment, { children: [_jsx("style", { ref: probeRef, children: `${styleTag ?? ""}${capTag}` }), _jsx(Focusable, { style: { width: "100%", boxSizing: "border-box" }, onButtonDown: handleButtonDown, actionDescriptionMap: visible.length > 1
83
88
  ? {
84
89
  [GamepadButton.BUMPER_LEFT]: prevActionDescription,
85
90
  [GamepadButton.BUMPER_RIGHT]: nextActionDescription,
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import { ControllerKind } from "./internal/controllerKind";
3
+ export interface TabBarItem {
4
+ id: string;
5
+ icon: React.ReactNode;
6
+ label: string;
7
+ }
8
+ export interface TabBarProps {
9
+ items: TabBarItem[];
10
+ activeId: string;
11
+ onSelect: (id: string) => void;
12
+ children?: React.ReactNode;
13
+ activeColor?: string;
14
+ inactiveColor?: string;
15
+ showHints?: boolean;
16
+ controller?: "auto" | ControllerKind;
17
+ previousHint?: string;
18
+ nextHint?: string;
19
+ hintBackground?: string;
20
+ hintColor?: string;
21
+ restoreFocus?: boolean;
22
+ }
23
+ export declare const TabBar: React.FC<TabBarProps>;
package/dist/TabBar.js ADDED
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { Focusable, GamepadButton } from "@decky/ui";
4
+ import { BUMPER_LABELS, useControllerKind } from "./internal/controllerKind";
5
+ const RESTORE_INTERVAL_MS = 100;
6
+ const RESTORE_MAX_TRIES = 15;
7
+ const Hint = ({ label, radius, background, color }) => (_jsx("span", { style: {
8
+ background,
9
+ color,
10
+ fontSize: 11,
11
+ fontWeight: 800,
12
+ lineHeight: 1,
13
+ padding: "8px 11px 6px",
14
+ borderRadius: radius,
15
+ flexShrink: 0,
16
+ }, children: label }));
17
+ // Icon tabs flanked by bumper hints (L1 / R1, LB / RB or L / R depending on
18
+ // the pad in use). The icons are pointer/touch only —
19
+ // the gamepad never lands on them, it switches page with the bumpers
20
+ // (stopping at both ends). Controlled: the parent owns `activeId`.
21
+ export const TabBar = ({ items, activeId, onSelect, children, activeColor = "#d0d5dc", inactiveColor = "#4b515b", showHints = true, controller = "auto", previousHint, nextHint, hintBackground = "#ffffff", hintColor = "#14181d", restoreFocus = true, }) => {
22
+ const detected = useControllerKind(controller === "auto");
23
+ const labels = BUMPER_LABELS[controller === "auto" ? detected : controller];
24
+ const rootRef = useRef(null);
25
+ const contentRef = useRef(null);
26
+ const handleButtonDown = (evt) => {
27
+ const index = items.findIndex((item) => item.id === activeId);
28
+ let delta = 0;
29
+ if (evt.detail.button === GamepadButton.BUMPER_LEFT)
30
+ delta = -1;
31
+ else if (evt.detail.button === GamepadButton.BUMPER_RIGHT)
32
+ delta = 1;
33
+ const next = delta ? items[index + delta] : undefined;
34
+ if (next)
35
+ onSelect(next.id);
36
+ };
37
+ useEffect(() => {
38
+ if (!restoreFocus)
39
+ return;
40
+ let tries = 0;
41
+ const timer = setInterval(() => {
42
+ const root = rootRef.current;
43
+ tries += 1;
44
+ if (!root ||
45
+ tries > RESTORE_MAX_TRIES ||
46
+ root.contains(root.ownerDocument.activeElement)) {
47
+ clearInterval(timer);
48
+ return;
49
+ }
50
+ const target = [
51
+ ...(contentRef.current?.querySelectorAll(".Focusable") ??
52
+ []),
53
+ ].find((el) => !el.querySelector(".Focusable"));
54
+ if (target) {
55
+ target.focus();
56
+ clearInterval(timer);
57
+ }
58
+ }, RESTORE_INTERVAL_MS);
59
+ return () => clearInterval(timer);
60
+ }, [activeId, restoreFocus]);
61
+ return (_jsx(Focusable, { onButtonDown: handleButtonDown, children: _jsxs("div", { ref: rootRef, children: [_jsxs("div", { style: { display: "flex", alignItems: "center", padding: "6px 16px" }, children: [showHints && (_jsx(Hint, { label: previousHint ?? labels.left, radius: "12px 4px 4px 4px", background: hintBackground, color: hintColor })), _jsx("div", { style: { flex: 1, display: "flex", justifyContent: "center", gap: 10 }, children: items.map((item) => (_jsx("div", { role: "button", tabIndex: -1, title: item.label, "aria-label": item.label, "aria-current": item.id === activeId, onClick: () => onSelect(item.id), onKeyDown: (evt) => {
62
+ if (evt.key === "Enter")
63
+ onSelect(item.id);
64
+ }, style: {
65
+ display: "flex",
66
+ alignItems: "center",
67
+ justifyContent: "center",
68
+ padding: "6px 8px",
69
+ cursor: "pointer",
70
+ color: item.id === activeId ? activeColor : inactiveColor,
71
+ }, children: item.icon }, item.id))) }), showHints && (_jsx(Hint, { label: nextHint ?? labels.right, radius: "4px 12px 4px 4px", background: hintBackground, color: hintColor }))] }), _jsx("div", { ref: contentRef, children: children })] }) }));
72
+ };
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ export interface ThemedSurfaceProps {
3
+ fallback?: string;
4
+ className?: string;
5
+ style?: React.CSSProperties;
6
+ children?: React.ReactNode;
7
+ }
8
+ export declare const ThemedSurface: React.FC<ThemedSurfaceProps>;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useRef } from "react";
3
+ import { useThemeFill } from "./internal/themeFill";
4
+ const DEFAULT_FALLBACK = "rgba(255, 255, 255, 0.08)";
5
+ // A block whose background is the one the active theme gives to a plain
6
+ // button — Float's glass, Steam's own bluish gray, whatever is installed —
7
+ // instead of a hard-coded translucent white. For placeholder icons, progress
8
+ // tracks and other surfaces that should read as part of the theme.
9
+ export const ThemedSurface = ({ fallback = DEFAULT_FALLBACK, className, style, children, }) => {
10
+ const ref = useRef(null);
11
+ const fill = useThemeFill(ref, fallback);
12
+ return (_jsx("div", { ref: ref, className: className, style: { background: fill, ...style }, children: children }));
13
+ };
package/dist/index.d.ts CHANGED
@@ -18,5 +18,9 @@ export { ScreenshotCarousel } from "./ScreenshotCarousel";
18
18
  export type { ScreenshotCarouselProps } from "./ScreenshotCarousel";
19
19
  export { StatusCard } from "./StatusCard";
20
20
  export type { StatusCardProps } from "./StatusCard";
21
+ export { ThemedSurface } from "./ThemedSurface";
22
+ export type { ThemedSurfaceProps } from "./ThemedSurface";
23
+ export { TabBar } from "./TabBar";
24
+ export type { TabBarProps, TabBarItem } from "./TabBar";
21
25
  export { useRemoteJson } from "./useRemoteJson";
22
26
  export type { UseRemoteJsonResult } from "./useRemoteJson";
package/dist/index.js CHANGED
@@ -8,4 +8,6 @@ export { MediaRow } from "./MediaRow";
8
8
  export { QrCodeButton } from "./QrCodeButton";
9
9
  export { ScreenshotCarousel } from "./ScreenshotCarousel";
10
10
  export { StatusCard } from "./StatusCard";
11
+ export { ThemedSurface } from "./ThemedSurface";
12
+ export { TabBar } from "./TabBar";
11
13
  export { useRemoteJson } from "./useRemoteJson";
@@ -0,0 +1,6 @@
1
+ export type ControllerKind = "xbox" | "playstation" | "switch" | "steam";
2
+ export declare const BUMPER_LABELS: Record<ControllerKind, {
3
+ left: string;
4
+ right: string;
5
+ }>;
6
+ export declare const useControllerKind: (enabled?: boolean) => ControllerKind;
@@ -0,0 +1,50 @@
1
+ import { useEffect, useState } from "react";
2
+ // What Steam itself would draw for the bumpers on each family of pad.
3
+ export const BUMPER_LABELS = {
4
+ xbox: { left: "LB", right: "RB" },
5
+ playstation: { left: "L1", right: "R1" },
6
+ switch: { left: "L", right: "R" },
7
+ steam: { left: "L1", right: "R1" },
8
+ };
9
+ const FAMILY_BY_STEAM_NAME = {
10
+ Xbox: "xbox",
11
+ PlayStation: "playstation",
12
+ NintendoSwitch: "switch",
13
+ // Third-party pads (GameSir, 8BitDo...) — Steam files them as "Generic" but
14
+ // they follow the Xbox layout, so LB / RB is what the player expects.
15
+ Generic: "xbox",
16
+ };
17
+ // Steam keeps the pad family of the last-used input in an observable on its
18
+ // own globals (FocusNavController / ControllerStore). Both are internal and
19
+ // undocumented, so every access is guarded: anything missing or renamed just
20
+ // falls back to "steam" (L1 / R1).
21
+ const read = (nextValue) => {
22
+ try {
23
+ const w = window;
24
+ const type = nextValue?.nControllerType ??
25
+ w.FocusNavController?.m_glyphInfo?.m_currentValue?.nControllerType;
26
+ const family = w.ControllerStore?.GetConsolidatedControllerType?.(type);
27
+ return FAMILY_BY_STEAM_NAME[family] ?? "steam";
28
+ }
29
+ catch {
30
+ return "steam";
31
+ }
32
+ };
33
+ // The pad family currently driving the UI, kept live as the player switches
34
+ // between pads (Xbox, PlayStation, Switch, Steam Deck...).
35
+ export const useControllerKind = (enabled = true) => {
36
+ const [kind, setKind] = useState(read);
37
+ useEffect(() => {
38
+ if (!enabled)
39
+ return;
40
+ setKind(read());
41
+ try {
42
+ const sub = window.FocusNavController?.m_glyphInfo?.Subscribe?.((value) => setKind(read(value)));
43
+ return () => sub?.Unsubscribe?.();
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ }, [enabled]);
49
+ return kind;
50
+ };
@@ -8,8 +8,9 @@ export interface FocusHighlightConfig {
8
8
  highlightBackground?: string;
9
9
  borderWidth?: number;
10
10
  hasBottomDivider?: boolean;
11
+ highlightForeground?: string;
11
12
  }
12
- export declare function useFocusHighlightClass(prefix: string, { highlightOnFocus, borderOnFocus, highlightColor, highlightBackground, borderWidth, hasBottomDivider, }: FocusHighlightConfig): {
13
+ export declare function useFocusHighlightClass(prefix: string, { highlightOnFocus, borderOnFocus, highlightColor, highlightBackground, borderWidth, hasBottomDivider, highlightForeground, }: FocusHighlightConfig): {
13
14
  cls: string;
14
15
  styleTag: string | null;
15
16
  reserveBorder: CSSProperties;
@@ -18,7 +18,7 @@ export { DEFAULT_HIGHLIGHT_COLOR, DEFAULT_HIGHLIGHT_BACKGROUND };
18
18
  // this into its base style instead. Always includes `boxSizing` (even
19
19
  // when borderOnFocus is off) so spreading it never leaves a component
20
20
  // without one.
21
- export function useFocusHighlightClass(prefix, { highlightOnFocus = true, borderOnFocus = true, highlightColor = DEFAULT_HIGHLIGHT_COLOR, highlightBackground, borderWidth = 2, hasBottomDivider = false, }) {
21
+ export function useFocusHighlightClass(prefix, { highlightOnFocus = true, borderOnFocus = true, highlightColor = DEFAULT_HIGHLIGHT_COLOR, highlightBackground, borderWidth = 2, hasBottomDivider = false, highlightForeground, }) {
22
22
  const cls = `${prefix}${useId().replace(/[^a-zA-Z0-9]/g, "")}`;
23
23
  const declarations = [
24
24
  // !important on both — the underlying native button/div this class
@@ -32,12 +32,16 @@ export function useFocusHighlightClass(prefix, { highlightOnFocus = true, border
32
32
  : `border-color: ${highlightColor} !important;`
33
33
  : "",
34
34
  highlightOnFocus && highlightBackground ? `background: ${highlightBackground} !important;` : "",
35
+ highlightOnFocus && highlightBackground && highlightForeground ? `color: ${highlightForeground} !important;` : "",
35
36
  ]
36
37
  .filter(Boolean)
37
38
  .join("\n ");
39
+ // Tripled class: a theme restyling every DialogButton on focus (its own shadow, a white
40
+ // fill) must not erase the frame or turn the row white.
41
+ const sel = `.${cls}.${cls}.${cls}`;
38
42
  const styleTag = declarations
39
43
  ? `
40
- .${cls}:focus, .${cls}:focus-within, .${cls}:hover {
44
+ ${sel}:focus, ${sel}.gpfocus, ${sel}:focus-within, ${sel}:hover {
41
45
  ${declarations}
42
46
  }
43
47
  `
@@ -21,3 +21,4 @@ export declare const SIZE_STYLE: {
21
21
  };
22
22
  };
23
23
  export type ComponentSize = keyof typeof SIZE_STYLE;
24
+ export declare const MAX_CARD_RADIUS = 14;
@@ -71,3 +71,6 @@ export const SIZE_STYLE = {
71
71
  medium: { fontSize: 14, minHeight: 37 },
72
72
  large: { fontSize: 16, minHeight: 41 },
73
73
  };
74
+ // Highest corner radius a row or header keeps when a theme rounds buttons further (e.g. into
75
+ // pills); a smaller radius is left to the theme.
76
+ export const MAX_CARD_RADIUS = 14;
@@ -0,0 +1,3 @@
1
+ import { RefObject } from "react";
2
+ export declare const sampleThemeFill: (doc: Document) => string | null;
3
+ export declare function useThemeFill(ref: RefObject<Element | null>, fallback: string): string;
@@ -0,0 +1,29 @@
1
+ import { useLayoutEffect, useState } from "react";
2
+ // The fill of a plain Steam button in the window the component is rendered in,
3
+ // i.e. whatever the active theme (or Steam's own look) gives a button at rest.
4
+ // A plugin's UI lives in another window than its code (the Quick Access menu),
5
+ // so this looks up from the component's own ownerDocument.
6
+ //
7
+ // Only a native-looking button counts: none of ours (their classes carry a
8
+ // hyphen, Steam's hashed ones don't), none with an inline background, no
9
+ // primary / destructive / focused / disabled one.
10
+ const SAMPLE_SELECTOR = 'button.DialogButton.Secondary:not([class*="-"]):not([style*="background"]):not(.Primary):not(.Destructive):not(.gpfocus):not([disabled])';
11
+ const TRANSPARENT = new Set(["transparent", "rgba(0, 0, 0, 0)"]);
12
+ export const sampleThemeFill = (doc) => {
13
+ const button = doc.querySelector(SAMPLE_SELECTOR);
14
+ if (!button)
15
+ return null;
16
+ const fill = getComputedStyle(button).backgroundColor;
17
+ return fill && !TRANSPARENT.has(fill) ? fill : null;
18
+ };
19
+ // Re-sampled after every render (cheap, and a theme can change at any time);
20
+ // state only moves when the value does.
21
+ export function useThemeFill(ref, fallback) {
22
+ const [fill, setFill] = useState(fallback);
23
+ useLayoutEffect(() => {
24
+ const doc = ref.current?.ownerDocument;
25
+ const next = (doc && sampleThemeFill(doc)) || fallback;
26
+ setFill((prev) => (prev === next ? prev : next));
27
+ });
28
+ return fill;
29
+ }
@@ -0,0 +1,2 @@
1
+ import { RefObject } from "react";
2
+ export declare function useRadiusCap(probeRef: RefObject<HTMLStyleElement | null>, cls: string, max: number, selector?: string): string;
@@ -0,0 +1,22 @@
1
+ import { useLayoutEffect, useState } from "react";
2
+ // A theme may round every button into a pill (999px), which swallows a cover,
3
+ // a screenshot or a title. Measures the element matching `selector` and, only
4
+ // when its radius exceeds `max`, returns a CSS rule capping it. A smaller
5
+ // radius is left to the theme.
6
+ //
7
+ // A plugin's UI lives in another window than the one its code runs in (the
8
+ // Quick Access menu), so a plain `document.querySelector` finds nothing: the
9
+ // caller attaches `probeRef` to its own <style> and the lookup starts from that
10
+ // element's ownerDocument.
11
+ export function useRadiusCap(probeRef, cls, max, selector = `.${cls}`) {
12
+ const [capped, setCapped] = useState(false);
13
+ // No deps: the element can mount after the first render.
14
+ useLayoutEffect(() => {
15
+ if (capped)
16
+ return;
17
+ const el = probeRef.current?.ownerDocument.querySelector(selector);
18
+ if (el && parseFloat(getComputedStyle(el).borderRadius) > max)
19
+ setCapped(true);
20
+ });
21
+ return capped ? `.${cls}.${cls}, .${cls}-header.${cls}-header { border-radius: ${max}px !important; }` : "";
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moi952/decky-ui-kit",
3
- "version": "0.6.1",
3
+ "version": "0.7.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",