@moi952/decky-ui-kit 0.6.1 → 0.6.2

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
@@ -376,6 +376,39 @@ import { StatusCard } from "@moi952/decky-ui-kit";
376
376
 
377
377
  </details>
378
378
 
379
+ ### `TabBar`
380
+
381
+ 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.
382
+
383
+ ```tsx
384
+ import { TabBar } from "@moi952/decky-ui-kit";
385
+
386
+ <TabBar items={tabs} activeId={tab} onSelect={setTab}>
387
+ {page}
388
+ </TabBar>
389
+ ```
390
+
391
+ <details>
392
+ <summary>Props</summary>
393
+
394
+ | Prop | Type | Default | Description |
395
+ | --- | --- | --- | --- |
396
+ | `items` | `{ id: string; icon: ReactNode; label: string }[]` | — | The tabs, in order. `label` is the tooltip / accessible name. |
397
+ | `activeId` | `string` | — | Id of the selected tab. |
398
+ | `onSelect` | `(id: string) => void` | — | Called on icon click or L1 / R1. |
399
+ | `children` | `ReactNode` | — | The page under the bar; L1 / R1 work from anywhere inside it. |
400
+ | `activeColor` | `string` | `"#d0d5dc"` | Selected icon color. |
401
+ | `inactiveColor` | `string` | `"#4b515b"` | Other icons' color. |
402
+ | `showHints` | `boolean` | `true` | Show the bumper pills at both ends. |
403
+ | `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). |
404
+ | `previousHint` | `string` | from `controller` | Overrides the left pill text. |
405
+ | `nextHint` | `string` | from `controller` | Overrides the right pill text. |
406
+ | `hintBackground` | `string` | `"#ffffff"` | Pills' background. |
407
+ | `hintColor` | `string` | `"#14181d"` | Pills' text color. |
408
+ | `restoreFocus` | `boolean` | `true` | Refocus the first control of the page after a switch / on mount. |
409
+
410
+ </details>
411
+
379
412
  ## Hooks
380
413
 
381
414
  ### `useRemoteJson`
@@ -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
+ };
package/dist/index.d.ts CHANGED
@@ -18,5 +18,7 @@ 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 { TabBar } from "./TabBar";
22
+ export type { TabBarProps, TabBarItem } from "./TabBar";
21
23
  export { useRemoteJson } from "./useRemoteJson";
22
24
  export type { UseRemoteJsonResult } from "./useRemoteJson";
package/dist/index.js CHANGED
@@ -8,4 +8,5 @@ export { MediaRow } from "./MediaRow";
8
8
  export { QrCodeButton } from "./QrCodeButton";
9
9
  export { ScreenshotCarousel } from "./ScreenshotCarousel";
10
10
  export { StatusCard } from "./StatusCard";
11
+ export { TabBar } from "./TabBar";
11
12
  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
+ };
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.6.2",
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",