Expanding FileBrowser button widths when page is wide enough.
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

This commit is contained in:
Roland 2026-07-01 19:52:15 -06:00
parent 7005cd0681
commit 2acdc2e16d
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 51 additions and 7 deletions

View file

@ -1,4 +1,4 @@
import React, {useContext, useEffect, useRef, useState} from "react";
import React, {useCallback, useContext, useEffect, useRef, useState} from "react";
import {
ApiDownError,
createChannel,
@ -83,6 +83,28 @@ export const useIsTouchDevice = () => {
return isTouchDevice;
};
export const useElementWidth = () => {
// Tracks the rendered width (in pixels) of an element. Returns a callback ref to attach to the element
// and its current width. Uses a callback ref (not a plain ref) so it re-attaches if the element mounts
// later (e.g. after data loads), and a ResizeObserver so the width updates as the container/viewport changes.
const [width, setWidth] = useState(0);
const observer = useRef(null);
const ref = useCallback((node) => {
if (observer.current) {
observer.current.disconnect();
observer.current = null;
}
if (node && typeof ResizeObserver === 'function') {
setWidth(node.offsetWidth);
observer.current = new ResizeObserver(() => setWidth(node.offsetWidth));
observer.current.observe(node);
}
}, []);
return [ref, width];
};
export const usePlatformModifier = () => {
// Detects if the user is on macOS to display the correct keyboard shortcut modifier.
const [isMac, setIsMac] = useState(false);