mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 04:16:24 -05:00
Expanding FileBrowser button widths when page is wide enough.
This commit is contained in:
parent
7005cd0681
commit
2acdc2e16d
4 changed files with 51 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue