laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
23 lines (22 loc) • 618 B
JavaScript
"use client";
import { useRef as f, useLayoutEffect as a } from "react";
const d = typeof window < "u" ? a : () => {
};
function m({
ref: t,
maxHeight: o = Number.MAX_SAFE_INTEGER,
borderWidth: u = 0,
dependencies: c
}) {
const n = f(null);
d(() => {
if (typeof window > "u" || !t.current) return;
const e = t.current, r = u * 2;
n.current === null && (n.current = e.scrollHeight - r), e.style.removeProperty("height");
const s = e.scrollHeight, i = Math.min(s, o), l = Math.max(i, n.current);
e.style.height = `${l + r}px`;
}, [o, t, ...c]);
}
export {
m as useAutosizeTextArea
};