UNPKG

@wordpress/widget-dashboard

Version:

Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.

31 lines (30 loc) • 1.3 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_compose = require("@wordpress/compose"); let _wordpress_element = require("@wordpress/element"); let ___widget_header_widget_header_fit_ts = require("../widget-header/widget-header-fit.cjs"); // 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 = (0, ___widget_header_widget_header_fit_ts.useWidgetHeaderAvailableSize)(); const [naturalSize, setNaturalSize] = (0, _wordpress_element.useState)(0); const measureRef = (0, _wordpress_compose.useResizeObserver)(([entry]) => setNaturalSize(entry.contentRect.width)); const computed = availableSize !== null && naturalSize > 0 && naturalSize > availableSize; const [held, setHeld] = (0, _wordpress_element.useState)(computed); if (!locked && held !== computed) setHeld(computed); return { measureRef, collapsed: locked ? held : computed }; } exports.useInlineFit = useInlineFit; //# sourceMappingURL=use-inline-fit.cjs.map