UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

143 lines (142 loc) 4.42 kB
"use client"; import { clsx as T } from "../../../clsx/dist/clsx.js"; import * as z from "react"; import { forwardRef as M, useRef as C, useImperativeHandle as N, useState as K, useCallback as B, useEffect as I, useMemo as $, cloneElement as q } from "react"; import A from "../../../../_virtual/throttle.js"; import { isPercent as f } from "../util/DataUtils.js"; import { warn as w } from "../util/LogUtils.js"; function x(t, r) { var e = Object.keys(t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(t); r && (n = n.filter(function(a) { return Object.getOwnPropertyDescriptor(t, a).enumerable; })), e.push.apply(e, n); } return e; } function O(t) { for (var r = 1; r < arguments.length; r++) { var e = arguments[r] != null ? arguments[r] : {}; r % 2 ? x(Object(e), !0).forEach(function(n) { F(t, n, e[n]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(e)) : x(Object(e)).forEach(function(n) { Object.defineProperty(t, n, Object.getOwnPropertyDescriptor(e, n)); }); } return t; } function F(t, r, e) { return (r = G(r)) in t ? Object.defineProperty(t, r, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : t[r] = e, t; } function G(t) { var r = J(t, "string"); return typeof r == "symbol" ? r : r + ""; } function J(t, r) { if (typeof t != "object" || !t) return t; var e = t[Symbol.toPrimitive]; if (e !== void 0) { var n = e.call(t, r); if (typeof n != "object") return n; throw new TypeError("@@toPrimitive must return a primitive value."); } return (r === "string" ? String : Number)(t); } var Y = /* @__PURE__ */ M((t, r) => { var { aspect: e, initialDimension: n = { width: -1, height: -1 }, width: a = "100%", height: s = "100%", /* * default min-width to 0 if not specified - 'auto' causes issues with flexbox * https://github.com/recharts/recharts/issues/172 */ minWidth: m = 0, minHeight: g, maxHeight: d, children: j, debounce: p = 0, id: P, className: E, onResize: S, style: D = {} } = t, l = C(null), v = C(); v.current = S, N(r, () => l.current); var [R, _] = K({ containerWidth: n.width, containerHeight: n.height }), b = B((c, h) => { _((o) => { var i = Math.round(c), u = Math.round(h); return o.containerWidth === i && o.containerHeight === u ? o : { containerWidth: i, containerHeight: u }; }); }, []); I(() => { var c = (u) => { var y, { width: H, height: W } = u[0].contentRect; b(H, W), (y = v.current) === null || y === void 0 || y.call(v, H, W); }; p > 0 && (c = A(c, p, { trailing: !0, leading: !1 })); var h = new ResizeObserver(c), { width: o, height: i } = l.current.getBoundingClientRect(); return b(o, i), h.observe(l.current), () => { h.disconnect(); }; }, [b, p]); var k = $(() => { var { containerWidth: c, containerHeight: h } = R; if (c < 0 || h < 0) return null; w(f(a) || f(s), `The width(%s) and height(%s) are both fixed numbers, maybe you don't need to use a ResponsiveContainer.`, a, s), w(!e || e > 0, "The aspect(%s) must be greater than zero.", e); var o = f(a) ? c : a, i = f(s) ? h : s; return e && e > 0 && (o ? i = o / e : i && (o = i * e), d && i > d && (i = d)), w(o > 0 || i > 0, `The width(%s) and height(%s) of chart should be greater than 0, please check the style of container, or the props width(%s) and height(%s), or add a minWidth(%s) or minHeight(%s) or use aspect(%s) to control the height and width.`, o, i, a, s, m, g, e), z.Children.map(j, (u) => /* @__PURE__ */ q(u, { width: o, height: i, // calculate the actual size and override it. style: O({ height: "100%", width: "100%", maxHeight: i, maxWidth: o }, u.props.style) })); }, [e, j, s, d, g, m, R, a]); return /* @__PURE__ */ z.createElement("div", { id: P ? "".concat(P) : void 0, className: T("recharts-responsive-container", E), style: O(O({}, D), {}, { width: a, height: s, minWidth: m, minHeight: g, maxHeight: d }), ref: l }, k); }); export { Y as ResponsiveContainer };