@cainiaofe/cn-ui-layout
Version:
- 安装 cone-cli | [Cone-CLI 使用指引](https://alidocs.dingtalk.com/i/nodes/xdqZp24KneBJzvGM6XezJvyb7RA0Nr1E) - `tnpm i -g @alife/cone-cli@latest` - 安装依赖包 - `cone install` - 启动研发 - `cone start`
38 lines • 2.6 kB
JavaScript
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
import { useEffect } from 'react';
import debounce from 'lodash/debounce';
export function useFooterAutoWidth(props) {
var _ref = props || {},
footerId = _ref.footerId,
containerId = _ref.containerId,
hidden = _ref.hidden;
var setFooterWidth = function setFooterWidth() {
var _containerDom$getBoun, _containerDom$getBoun2;
var footerDom = document.getElementById(footerId);
var containerDom = document.getElementById(containerId);
var formWidth = containerDom === null || containerDom === void 0 ? void 0 : (_containerDom$getBoun = containerDom.getBoundingClientRect) === null || _containerDom$getBoun === void 0 ? void 0 : (_containerDom$getBoun2 = _containerDom$getBoun.call(containerDom)) === null || _containerDom$getBoun2 === void 0 ? void 0 : _containerDom$getBoun2.width;
if (footerDom && typeof formWidth === 'number') {
footerDom.style.width = formWidth + "px";
}
};
var debounceSetFooterWidth = debounce(function () {
setFooterWidth();
}, 500, {
leading: true
});
useEffect(function () {
var containerDom = document.getElementById(containerId);
setFooterWidth();
if (ResizeObserver && containerDom) {
var resizeObserver = new ResizeObserver(function (entries) {
for (var _iterator = _createForOfIteratorHelperLoose(entries), _step; !(_step = _iterator()).done;) {
var entry = _step.value;
debounceSetFooterWidth();
}
});
resizeObserver.observe(containerDom);
}
}, [hidden]);
}