UNPKG

laif-ds

Version:

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

31 lines (30 loc) 789 B
"use client"; import { useState as s, useCallback as u } from "react"; var i = 1; function f() { var n = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], [t, g] = s({ height: 0, left: 0, top: 0, width: 0 }), l = u((a) => { if (a != null) { var h = a.getBoundingClientRect(), e = { height: h.height, left: h.left, top: h.top, width: h.width }; (Math.abs(e.height - t.height) > i || Math.abs(e.left - t.left) > i || Math.abs(e.top - t.top) > i || Math.abs(e.width - t.width) > i) && g({ height: e.height, left: e.left, top: e.top, width: e.width }); } }, [t.width, t.height, t.top, t.left, ...n]); return [t, l]; } export { f as useElementOffset };