UNPKG

@wordpress/widget-dashboard

Version:

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

48 lines (46 loc) • 2.02 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/widget-dashboard/src/components/widget-attributes/use-inline-fit.ts var use_inline_fit_exports = {}; __export(use_inline_fit_exports, { useInlineFit: () => useInlineFit }); module.exports = __toCommonJS(use_inline_fit_exports); var import_compose = require("@wordpress/compose"); var import_element = require("@wordpress/element"); var import_widget_header_fit = require("../widget-header/widget-header-fit.cjs"); function useInlineFit(options = {}) { const { locked = false } = options; const availableSize = (0, import_widget_header_fit.useWidgetHeaderAvailableSize)(); const [naturalSize, setNaturalSize] = (0, import_element.useState)(0); const measureRef = (0, import_compose.useResizeObserver)( ([entry]) => setNaturalSize(entry.contentRect.width) ); const computed = availableSize !== null && naturalSize > 0 && naturalSize > availableSize; const [held, setHeld] = (0, import_element.useState)(computed); if (!locked && held !== computed) { setHeld(computed); } return { measureRef, collapsed: locked ? held : computed }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { useInlineFit }); //# sourceMappingURL=use-inline-fit.cjs.map