@moi952/decky-ui-kit 0.6.0 → 0.6.1

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.
@@ -29,6 +29,7 @@ export interface AnchoredDropdownProps {
29
29
  highlightOnFocus?: boolean;
30
30
  bottomSeparator?: boolean;
31
31
  valueFontSize?: number;
32
+ renderOptionLabel?: (option: DropdownOption) => React.ReactNode;
32
33
  }
33
34
  export declare const AnchoredDropdown: React.FC<AnchoredDropdownProps>;
34
35
  export {};
@@ -37,7 +37,7 @@ const toggleCsv = (csv, value, options) => {
37
37
  .join(",");
38
38
  };
39
39
  // Native Steam popups reset the panel on close — this is an inline overlay instead.
40
- export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labelFontSize, variant = "boxed", focusStyle = "fill", size = "medium", 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, valueFontSize, }) => {
40
+ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labelFontSize, variant = "boxed", focusStyle = "fill", size = "medium", 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, valueFontSize, renderOptionLabel, }) => {
41
41
  // Scoped per instance so sibling dropdowns don't share class names.
42
42
  const [uid] = useState(() => `dck-anchored-dd${uidCounter++}`);
43
43
  const [expanded, setExpanded] = useState(false);
@@ -46,6 +46,7 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labe
46
46
  const wrapperRef = useRef(null);
47
47
  const triggerRef = useRef(null);
48
48
  const [openUp, setOpenUp] = useState(false);
49
+ const [listMaxHeight, setListMaxHeight] = useState(220);
49
50
  // Mirrors the trigger's real computed radius instead of a guessed CSS var.
50
51
  const [listRadius, setListRadius] = useState(FALLBACK_RADIUS);
51
52
  // CSS-only truncation proved unreliable through Field's layout — measure instead.
@@ -137,19 +138,48 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labe
137
138
  // Padding + line-height + the option's 2px border.
138
139
  const rowHeight = OPTION_ROW_HEIGHT[size];
139
140
  // 0 means "show every option, no scroll cap".
140
- const listMaxHeight = maxVisibleOptions === 0 ? undefined : maxVisibleOptions ? maxVisibleOptions * (rowHeight + 2) : 220;
141
- const toggle = () => {
142
- setExpanded((prev) => {
143
- const next = !prev;
144
- if (next && wrapperRef.current) {
145
- const r = wrapperRef.current.getBoundingClientRect();
146
- const spaceBelow = window.innerHeight - r.bottom;
147
- const spaceAbove = r.top;
148
- setOpenUp(spaceBelow < (listMaxHeight ?? Infinity) && spaceAbove > spaceBelow);
141
+ const requestedHeight = maxVisibleOptions === 0 ? Infinity : maxVisibleOptions ? maxVisibleOptions * (rowHeight + 2) : 220;
142
+ useLayoutEffect(() => {
143
+ if (!expanded || !wrapperRef.current)
144
+ return;
145
+ const wrapper = wrapperRef.current;
146
+ const view = wrapper.ownerDocument.defaultView;
147
+ if (!view)
148
+ return;
149
+ const measure = () => {
150
+ const r = wrapper.getBoundingClientRect();
151
+ const scale = (wrapper.offsetHeight ? r.height / wrapper.offsetHeight : 1) || 1;
152
+ let top = 8;
153
+ let bottom = view.innerHeight - 8;
154
+ for (let p = wrapper.parentElement; p; p = p.parentElement) {
155
+ if (p === wrapper.ownerDocument.body || p === wrapper.ownerDocument.documentElement)
156
+ continue;
157
+ if (/^(auto|scroll|hidden|clip)$/.test(view.getComputedStyle(p).overflowY)) {
158
+ const b = p.getBoundingClientRect();
159
+ top = Math.max(top, b.top + 8);
160
+ bottom = Math.min(bottom, b.bottom - 8);
161
+ }
149
162
  }
150
- return next;
151
- });
152
- };
163
+ const below = Math.max(0, (bottom - r.bottom) / scale - 2);
164
+ const above = Math.max(0, (r.top - top) / scale - 2);
165
+ const visible = maxVisibleOptions ?? 0;
166
+ const rows = visible > 0 ? itemRefs.current.slice(0, visible).filter(Boolean) : [];
167
+ const wanted = rows.length
168
+ ? rows.reduce((sum, row) => sum + (row?.offsetHeight ?? 0), 0) + (rows.length - 1) * 2 + 2
169
+ : requestedHeight;
170
+ const up = below < wanted && above > below;
171
+ setOpenUp(up);
172
+ setListMaxHeight(Math.min(wanted, up ? above : below));
173
+ };
174
+ measure();
175
+ view.addEventListener("resize", measure);
176
+ view.addEventListener("scroll", measure, true);
177
+ return () => {
178
+ view.removeEventListener("resize", measure);
179
+ view.removeEventListener("scroll", measure, true);
180
+ };
181
+ }, [expanded, requestedHeight, options.length]);
182
+ const toggle = () => setExpanded((prev) => !prev);
153
183
  const optionCls = `${uid}-option`;
154
184
  const selectedCls = `${uid}-selected`;
155
185
  const triggerCls = `${uid}-trigger`;
@@ -300,6 +330,6 @@ export const AnchoredDropdown = ({ options, selectedValue, onChange, label, labe
300
330
  : opt.value === selectedValue;
301
331
  return (_jsxs(DialogButton, { ref: (el) => {
302
332
  itemRefs.current[i] = el;
303
- }, className: `${optionCls}${isSelected ? ` ${selectedCls}` : ""}`, onClick: () => pick(opt.value), children: [_jsx("span", { children: opt.label }), isSelected && _jsx(FaCheck, { size: 10 })] }, opt.value));
333
+ }, className: `${optionCls}${isSelected ? ` ${selectedCls}` : ""}`, onClick: () => pick(opt.value), children: [renderOptionLabel ? (_jsx("span", { style: { flex: 1, minWidth: 0, textAlign: "left" }, children: renderOptionLabel(opt) })) : (_jsx("span", { children: opt.label })), isSelected && _jsx(FaCheck, { size: 10 })] }, opt.value));
304
334
  }) }) }))] }));
305
335
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moi952/decky-ui-kit",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
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",