@moi952/decky-ui-kit 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -2
- package/dist/AnchoredDropdown.d.ts +6 -0
- package/dist/AnchoredDropdown.js +50 -27
- package/dist/FieldTextInput.d.ts +12 -0
- package/dist/FieldTextInput.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,8 +62,14 @@ import { AnchoredDropdown } from "@moi952/decky-ui-kit";
|
|
|
62
62
|
| `borderColor` | `string` | `"transparent"` | Trigger and list border color. |
|
|
63
63
|
| `blurBackground` | `boolean` | `true` | Blurs the panel behind the list while it's open. |
|
|
64
64
|
| `multiple` | `boolean` | `false` | Multi-select mode (comma-joined value). |
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
65
|
+
| `selectedValuesLayout` | `"inline" \| "stacked"` | `"inline"` | Multi-select summary as one comma-joined line, or one value per line. |
|
|
66
|
+
| `selectedCountLabel` | `(count: number) => ReactNode` | — | Multi-select only: small caption above the trigger once ≥1 option is picked (e.g. `n => \`${n} selected\``). No i18n of its own — the caller formats the text. |
|
|
67
|
+
| `onSecondaryButton` | `() => void` | — | Fires on gamepad X / Steam "Secondary" while the trigger or open list has focus. |
|
|
68
|
+
| `onSecondaryActionDescription` | `ReactNode` | — | Shown in Steam's own bottom action-legend bar next to the X prompt (only while `onSecondaryButton` is set). Same names/shape as `@decky/ui`'s own `FooterLegendProps`. |
|
|
69
|
+
| `onOptionsButton` | `() => void` | — | Fires on gamepad Y / Steam "Options" while the trigger or open list has focus. |
|
|
70
|
+
| `onOptionsActionDescription` | `ReactNode` | — | Shown in Steam's own bottom action-legend bar next to the Y prompt (only while `onOptionsButton` is set). |
|
|
71
|
+
| `maxDisplayLines` | `number` | `1` | Lines the trigger's selected-value summary can wrap before clipping. `0` shows it in full, unclamped. |
|
|
72
|
+
| `maxVisibleOptions` | `number` | — | Rows visible before the list scrolls. `0` shows every option, no cap. Defaults to a fixed max height. |
|
|
67
73
|
| `highlightOnFocus` | `boolean` | `true` | Native Steam focus highlight band, themeable via CSS Loader. |
|
|
68
74
|
| `bottomSeparator` | `boolean` | `true` | Native Steam separator line below the trigger. |
|
|
69
75
|
|
|
@@ -94,3 +100,29 @@ import { CollapsibleSection } from "@moi952/decky-ui-kit";
|
|
|
94
100
|
| `children` | `ReactNode` | — | Rendered below the header while `expanded` is `true`. |
|
|
95
101
|
|
|
96
102
|
</details>
|
|
103
|
+
|
|
104
|
+
### `FieldTextInput`
|
|
105
|
+
|
|
106
|
+
A text input with the standard Field row look (bottom separator, focus highlight, size) — `@decky/ui`'s own `TextField` doesn't extend the same row contract `ToggleField`/`SliderField` do, so it renders bare by default.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { FieldTextInput } from "@moi952/decky-ui-kit";
|
|
110
|
+
|
|
111
|
+
<FieldTextInput label="Frame Rate Limit" mustBeNumeric value={value} onChange={setValue} />
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
<details>
|
|
115
|
+
<summary>Props</summary>
|
|
116
|
+
|
|
117
|
+
| Prop | Type | Default | Description |
|
|
118
|
+
| --- | --- | --- | --- |
|
|
119
|
+
| `value` | `string` | — | Current value. |
|
|
120
|
+
| `onChange` | `(value: string) => void` | — | Called with the new value on every keystroke. |
|
|
121
|
+
| `label` | `ReactNode` | — | Label text/content. |
|
|
122
|
+
| `size` | `"default" \| "small"` | `"default"` | Input font size and padding. |
|
|
123
|
+
| `labelPosition` | `"top" \| "left" \| "right"` | `"top"` | Where the label sits relative to the input. |
|
|
124
|
+
| `mustBeNumeric` | `boolean` | `false` | Restricts input to numeric characters. |
|
|
125
|
+
| `bottomSeparator` | `boolean` | `true` | Native Steam separator line below the row. |
|
|
126
|
+
| `highlightOnFocus` | `boolean` | `true` | Background highlight while the input has focus. |
|
|
127
|
+
|
|
128
|
+
</details>
|
|
@@ -15,6 +15,12 @@ export interface AnchoredDropdownProps {
|
|
|
15
15
|
borderColor?: string;
|
|
16
16
|
blurBackground?: boolean;
|
|
17
17
|
multiple?: boolean;
|
|
18
|
+
selectedValuesLayout?: "inline" | "stacked";
|
|
19
|
+
selectedCountLabel?: (count: number) => React.ReactNode;
|
|
20
|
+
onSecondaryButton?: () => void;
|
|
21
|
+
onSecondaryActionDescription?: React.ReactNode;
|
|
22
|
+
onOptionsButton?: () => void;
|
|
23
|
+
onOptionsActionDescription?: React.ReactNode;
|
|
18
24
|
maxDisplayLines?: number;
|
|
19
25
|
maxVisibleOptions?: number;
|
|
20
26
|
highlightOnFocus?: boolean;
|
package/dist/AnchoredDropdown.js
CHANGED
|
@@ -6,9 +6,7 @@ const DEFAULT_BG = "#35373c";
|
|
|
6
6
|
const DEFAULT_TEXT = "#bfbfbf";
|
|
7
7
|
const DEFAULT_BORDER = "transparent";
|
|
8
8
|
const FALLBACK_RADIUS = "6px";
|
|
9
|
-
// Shared across
|
|
10
|
-
// radius a "boxed" one already measured, instead of measuring its own
|
|
11
|
-
// differently-shaped native element (Field vs DialogButton).
|
|
9
|
+
// Shared across instances so "row" reuses a "boxed" one's measured radius.
|
|
12
10
|
let sharedBoxedRadius = null;
|
|
13
11
|
let uidCounter = 0;
|
|
14
12
|
const splitCsv = (value) => value.split(",").map((v) => v.trim()).filter(Boolean);
|
|
@@ -22,9 +20,8 @@ const toggleCsv = (csv, value, options) => {
|
|
|
22
20
|
.map((o) => o.value)
|
|
23
21
|
.join(",");
|
|
24
22
|
};
|
|
25
|
-
// Native Steam popups reset the
|
|
26
|
-
|
|
27
|
-
export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "boxed", focusStyle = "fill", size = "default", bgColor = DEFAULT_BG, textColor = DEFAULT_TEXT, borderColor = DEFAULT_BORDER, blurBackground = true, multiple = false, maxDisplayLines = 1, maxVisibleOptions, highlightOnFocus = true, bottomSeparator = true, }) => {
|
|
23
|
+
// Native Steam popups reset the panel on close — this is an inline overlay instead.
|
|
24
|
+
export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "boxed", focusStyle = "fill", size = "default", bgColor = DEFAULT_BG, textColor = DEFAULT_TEXT, borderColor = DEFAULT_BORDER, blurBackground = true, multiple = false, selectedValuesLayout = "inline", selectedCountLabel, onSecondaryButton, onSecondaryActionDescription, onOptionsButton, onOptionsActionDescription, maxDisplayLines = 1, maxVisibleOptions, highlightOnFocus = true, bottomSeparator = true, }) => {
|
|
28
25
|
// Scoped per instance so sibling dropdowns don't share class names.
|
|
29
26
|
const [uid] = useState(() => `dck-anchored-dd${uidCounter++}`);
|
|
30
27
|
const [expanded, setExpanded] = useState(false);
|
|
@@ -35,9 +32,7 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
35
32
|
const [openUp, setOpenUp] = useState(false);
|
|
36
33
|
// Mirrors the trigger's real computed radius instead of a guessed CSS var.
|
|
37
34
|
const [listRadius, setListRadius] = useState(FALLBACK_RADIUS);
|
|
38
|
-
//
|
|
39
|
-
// shrink, % width) proved unreliable through Field's own layout, so this
|
|
40
|
-
// measures the trigger's actual rendered width instead of guessing it.
|
|
35
|
+
// CSS-only truncation proved unreliable through Field's layout — measure instead.
|
|
41
36
|
const [labelMaxWidth, setLabelMaxWidth] = useState(undefined);
|
|
42
37
|
useLayoutEffect(() => {
|
|
43
38
|
if (variant !== "boxed" || !triggerRef.current)
|
|
@@ -47,9 +42,14 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
47
42
|
const overhead = horizontalPadding * 2 + 12 + 8;
|
|
48
43
|
const measure = () => setLabelMaxWidth(Math.max(0, el.clientWidth - overhead));
|
|
49
44
|
measure();
|
|
45
|
+
// One more pass next frame — a remount can measure before the panel settles.
|
|
46
|
+
const raf = requestAnimationFrame(measure);
|
|
50
47
|
const ro = new ResizeObserver(measure);
|
|
51
48
|
ro.observe(el);
|
|
52
|
-
return () =>
|
|
49
|
+
return () => {
|
|
50
|
+
cancelAnimationFrame(raf);
|
|
51
|
+
ro.disconnect();
|
|
52
|
+
};
|
|
53
53
|
}, [variant, size]);
|
|
54
54
|
useEffect(() => {
|
|
55
55
|
if (variant === "boxed" && triggerRef.current) {
|
|
@@ -68,7 +68,7 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
68
68
|
const displayLabel = multiple
|
|
69
69
|
? selectedValues
|
|
70
70
|
.map((v) => options.find((o) => o.value === v)?.label ?? v)
|
|
71
|
-
.join(", ") || selectedValue
|
|
71
|
+
.join(selectedValuesLayout === "stacked" ? "\n" : ", ") || selectedValue
|
|
72
72
|
: singleSelected?.label ?? selectedValue;
|
|
73
73
|
useEffect(() => {
|
|
74
74
|
if (!expanded)
|
|
@@ -95,8 +95,7 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
95
95
|
closeList();
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
-
// Steam's focus engine picks by
|
|
99
|
-
// ourselves to stay inside the list.
|
|
98
|
+
// Steam's focus engine picks by geometry — handle DIR_UP/DOWN ourselves.
|
|
100
99
|
const handleListButtonDown = (evt) => {
|
|
101
100
|
if (evt.detail.button === GamepadButton.DIR_DOWN) {
|
|
102
101
|
evt.stopPropagation();
|
|
@@ -110,13 +109,19 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
110
109
|
evt.stopPropagation();
|
|
111
110
|
closeList();
|
|
112
111
|
}
|
|
112
|
+
else if (evt.detail.button === GamepadButton.SECONDARY && onSecondaryButton) {
|
|
113
|
+
evt.stopPropagation();
|
|
114
|
+
onSecondaryButton();
|
|
115
|
+
}
|
|
116
|
+
else if (evt.detail.button === GamepadButton.OPTIONS && onOptionsButton) {
|
|
117
|
+
evt.stopPropagation();
|
|
118
|
+
onOptionsButton();
|
|
119
|
+
}
|
|
113
120
|
};
|
|
114
|
-
// Padding +
|
|
115
|
-
// (previously missing from this estimate, clipping the last visible row).
|
|
121
|
+
// Padding + line-height + the option's 2px border.
|
|
116
122
|
const rowHeight = size === "small" ? 26 : 42;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
: 220;
|
|
123
|
+
// 0 means "show every option, no scroll cap".
|
|
124
|
+
const listMaxHeight = maxVisibleOptions === 0 ? undefined : maxVisibleOptions ? maxVisibleOptions * (rowHeight + 2) : 220;
|
|
120
125
|
const toggle = () => {
|
|
121
126
|
setExpanded((prev) => {
|
|
122
127
|
const next = !prev;
|
|
@@ -124,7 +129,7 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
124
129
|
const r = wrapperRef.current.getBoundingClientRect();
|
|
125
130
|
const spaceBelow = window.innerHeight - r.bottom;
|
|
126
131
|
const spaceAbove = r.top;
|
|
127
|
-
setOpenUp(spaceBelow < listMaxHeight && spaceAbove > spaceBelow);
|
|
132
|
+
setOpenUp(spaceBelow < (listMaxHeight ?? Infinity) && spaceAbove > spaceBelow);
|
|
128
133
|
}
|
|
129
134
|
return next;
|
|
130
135
|
});
|
|
@@ -133,10 +138,12 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
133
138
|
const selectedCls = `${uid}-selected`;
|
|
134
139
|
const triggerCls = `${uid}-trigger`;
|
|
135
140
|
const triggerLabelCls = `${uid}-trigger-label`;
|
|
141
|
+
const countCls = `${uid}-count`;
|
|
136
142
|
const wrapperCls = `${uid}-wrapper`;
|
|
137
143
|
const optionPadding = size === "small" ? "4px 8px" : "10px 14px";
|
|
138
144
|
const optionFontSize = size === "small" ? "11px" : "14px";
|
|
139
|
-
const
|
|
145
|
+
const triggerPaddingH = size === "small" ? "10px" : "14px";
|
|
146
|
+
const triggerPadding = size === "small" ? `6px ${triggerPaddingH}` : `10px ${triggerPaddingH}`;
|
|
140
147
|
const triggerFontSize = size === "small" ? "12px" : "15px";
|
|
141
148
|
return (_jsxs("div", { ref: wrapperRef, className: wrapperCls, style: { position: "relative", width: "100%", maxWidth: "100%", boxSizing: "border-box" }, children: [_jsx("style", { children: `
|
|
142
149
|
.${optionCls} {
|
|
@@ -168,13 +175,25 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
168
175
|
background: ${bgColor} !important;
|
|
169
176
|
border: 1px solid ${borderColor} !important;
|
|
170
177
|
color: ${textColor} !important;
|
|
178
|
+
overflow: hidden !important;
|
|
179
|
+
}
|
|
180
|
+
.${countCls} {
|
|
181
|
+
font-size: 11px !important;
|
|
182
|
+
opacity: 0.75 !important;
|
|
183
|
+
text-align: left !important;
|
|
184
|
+
color: ${textColor} !important;
|
|
171
185
|
}
|
|
172
186
|
.${triggerLabelCls} {
|
|
187
|
+
${maxDisplayLines > 0
|
|
188
|
+
? `
|
|
173
189
|
display: -webkit-box !important;
|
|
174
190
|
-webkit-box-orient: vertical !important;
|
|
175
191
|
-webkit-line-clamp: ${maxDisplayLines} !important;
|
|
176
192
|
overflow: hidden !important;
|
|
177
193
|
text-overflow: ellipsis !important;
|
|
194
|
+
`
|
|
195
|
+
: ""}
|
|
196
|
+
${selectedValuesLayout === "stacked" ? "white-space: pre-line !important;" : ""}
|
|
178
197
|
text-align: left !important;
|
|
179
198
|
flex: 1 !important;
|
|
180
199
|
min-width: 0 !important;
|
|
@@ -213,11 +232,17 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
213
232
|
color: #111 !important;
|
|
214
233
|
}
|
|
215
234
|
`}
|
|
216
|
-
` }),
|
|
235
|
+
` }), (() => {
|
|
236
|
+
const countNode = multiple && selectedCountLabel && selectedValues.length > 0 ? (_jsx("div", { className: countCls, children: selectedCountLabel(selectedValues.length) })) : null;
|
|
237
|
+
if (variant === "boxed") {
|
|
238
|
+
return (_jsx(Field, { focusable: true, highlightOnFocus: highlightOnFocus, bottomSeparator: bottomSeparator ? "standard" : "none", childrenContainerWidth: "max", onActivate: toggle, onClick: toggle, onSecondaryButton: onSecondaryButton, onSecondaryActionDescription: onSecondaryButton ? onSecondaryActionDescription : undefined, onOptionsButton: onOptionsButton, onOptionsActionDescription: onOptionsButton ? onOptionsActionDescription : undefined, children: _jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 2, width: "100%" }, children: [countNode, _jsxs(DialogButton, { className: triggerCls, ref: (el) => {
|
|
239
|
+
triggerRef.current = el;
|
|
240
|
+
}, children: [_jsx("span", { className: triggerLabelCls, style: labelMaxWidth !== undefined ? { maxWidth: labelMaxWidth } : undefined, children: displayLabel }), _jsx(FaChevronDown, { size: 12, style: { flexShrink: 0 } })] })] }) }));
|
|
241
|
+
}
|
|
242
|
+
return (_jsx(Field, { focusable: true, highlightOnFocus: highlightOnFocus, bottomSeparator: bottomSeparator ? "standard" : "none", onActivate: toggle, onClick: toggle, onSecondaryButton: onSecondaryButton, onSecondaryActionDescription: onSecondaryButton ? onSecondaryActionDescription : undefined, onOptionsButton: onOptionsButton, onOptionsActionDescription: onOptionsButton ? onOptionsActionDescription : undefined, label: countNode ? (_jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 2, width: "100%" }, children: [countNode, displayLabel] })) : (displayLabel), childrenLayout: "inline", ref: (el) => {
|
|
217
243
|
triggerRef.current = el;
|
|
218
|
-
}, children:
|
|
219
|
-
|
|
220
|
-
}, children: expanded ? _jsx(FaChevronDown, { size: 12 }) : _jsx(FaChevronRight, { size: 12 }) })), expanded && blurBackground && (_jsx("div", { onClick: closeList, style: {
|
|
244
|
+
}, children: expanded ? _jsx(FaChevronDown, { size: 12 }) : _jsx(FaChevronRight, { size: 12 }) }));
|
|
245
|
+
})(), expanded && blurBackground && (_jsx("div", { onClick: closeList, style: {
|
|
221
246
|
position: "fixed",
|
|
222
247
|
inset: 0,
|
|
223
248
|
zIndex: 49,
|
|
@@ -225,9 +250,7 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, variant = "
|
|
|
225
250
|
backdropFilter: "blur(6px)",
|
|
226
251
|
WebkitBackdropFilter: "blur(6px)",
|
|
227
252
|
} })), expanded && (
|
|
228
|
-
// This div
|
|
229
|
-
// handles scrolling and gamepad focus (it's a native Steam module,
|
|
230
|
-
// its own classes can beat an inline style).
|
|
253
|
+
// This div clips/rounds; Focusable inside only handles scroll + gamepad focus.
|
|
231
254
|
_jsx("div", { style: {
|
|
232
255
|
boxSizing: "border-box",
|
|
233
256
|
position: "absolute",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface FieldTextInputProps {
|
|
3
|
+
label?: React.ReactNode;
|
|
4
|
+
value: string;
|
|
5
|
+
onChange: (value: string) => void;
|
|
6
|
+
size?: "default" | "small";
|
|
7
|
+
mustBeNumeric?: boolean;
|
|
8
|
+
bottomSeparator?: boolean;
|
|
9
|
+
highlightOnFocus?: boolean;
|
|
10
|
+
labelPosition?: "top" | "left" | "right";
|
|
11
|
+
}
|
|
12
|
+
export declare const FieldTextInput: React.FC<FieldTextInputProps>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Field, TextField } from "@decky/ui";
|
|
3
|
+
// TextField lacks bottomSeparator/highlightOnFocus/size, so this wraps it in Field.
|
|
4
|
+
export const FieldTextInput = ({ label, value, onChange, size = "default", mustBeNumeric, bottomSeparator = true, highlightOnFocus = true, labelPosition = "top", }) => {
|
|
5
|
+
const input = (_jsx(TextField, { mustBeNumeric: mustBeNumeric, value: value, onChange: (e) => onChange(e.target.value), style: {
|
|
6
|
+
fontSize: size === "small" ? 12 : 14,
|
|
7
|
+
padding: size === "small" ? "6px 8px" : "10px 12px",
|
|
8
|
+
} }));
|
|
9
|
+
return (_jsx(Field, { label: labelPosition === "right" ? undefined : label, bottomSeparator: bottomSeparator ? "standard" : "none", childrenLayout: labelPosition === "top" ? "below" : "inline", highlightOnFocus: highlightOnFocus, children: labelPosition === "right" ? (_jsxs("div", { style: {
|
|
10
|
+
display: "flex",
|
|
11
|
+
alignItems: "center",
|
|
12
|
+
justifyContent: "space-between",
|
|
13
|
+
gap: 12,
|
|
14
|
+
width: "100%",
|
|
15
|
+
}, children: [input, label] })) : (input) }));
|
|
16
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { AnchoredDropdown } from "./AnchoredDropdown";
|
|
|
2
2
|
export type { AnchoredDropdownProps } from "./AnchoredDropdown";
|
|
3
3
|
export { CollapsibleSection } from "./CollapsibleSection";
|
|
4
4
|
export type { CollapsibleSectionProps } from "./CollapsibleSection";
|
|
5
|
+
export { FieldTextInput } from "./FieldTextInput";
|
|
6
|
+
export type { FieldTextInputProps } from "./FieldTextInput";
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moi952/decky-ui-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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",
|