UNPKG

laif-ds

Version:

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

22 lines (21 loc) 596 B
"use client"; import { useRef as l, useLayoutEffect as f } from "react"; const a = typeof window < "u" ? f : () => { }; function h({ ref: t, maxHeight: o = Number.MAX_SAFE_INTEGER, borderWidth: r = 0 }) { const n = l(null); a(() => { if (typeof window > "u" || !t.current) return; const e = t.current, u = r * 2; n.current === null && (n.current = e.scrollHeight - u), e.style.removeProperty("height"); const c = e.scrollHeight, s = Math.min(c, o), i = Math.max(s, n.current); e.style.height = `${i + u}px`; }, [o, t, r]); } export { h as useAutosizeTextArea };