@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
26 lines (25 loc) • 1.03 kB
JavaScript
import { useResizeObserver } from "@wordpress/compose";
import { useState } from "@wordpress/element";
import { useWidgetHeaderAvailableSize } from "../widget-header/widget-header-fit.mjs";
// packages/widget-dashboard/src/components/widget-attributes/use-inline-fit.ts
/**
* Decides whether the inline attribute controls fit the space the header
* row can grant its toolbar.
*
* @param {InlineFitOptions} [options] Fit options.
*/
function useInlineFit(options = {}) {
const { locked = false } = options;
const availableSize = useWidgetHeaderAvailableSize();
const [naturalSize, setNaturalSize] = useState(0);
const measureRef = useResizeObserver(([entry]) => setNaturalSize(entry.contentRect.width));
const computed = availableSize !== null && naturalSize > 0 && naturalSize > availableSize;
const [held, setHeld] = useState(computed);
if (!locked && held !== computed) setHeld(computed);
return {
measureRef,
collapsed: locked ? held : computed
};
}
export { useInlineFit };
//# sourceMappingURL=use-inline-fit.mjs.map