UNPKG

dgz-ui

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript

64 lines (63 loc) 1.6 kB
import * as e from "react"; import { u as a } from "./index-ljY4mZHt.js"; var S = e[" useId ".trim().toString()] || (() => { }), E = 0; function g(t) { const [n, o] = e.useState(S()); return a(() => { o((l) => l ?? String(E++)); }, [t]), t || (n ? `radix-${n}` : ""); } var I = e[" useInsertionEffect ".trim().toString()] || a; function y({ prop: t, defaultProp: n, onChange: o = () => { }, caller: l }) { const [f, r, s] = w({ defaultProp: n, onChange: o }), c = t !== void 0, v = c ? t : f; { const u = e.useRef(t !== void 0); e.useEffect(() => { const i = u.current; i !== c && console.warn( `${l} is changing from ${i ? "controlled" : "uncontrolled"} to ${c ? "controlled" : "uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.` ), u.current = c; }, [c, l]); } const m = e.useCallback( (u) => { var i; if (c) { const d = R(u) ? u(t) : u; d !== t && ((i = s.current) == null || i.call(s, d)); } else r(u); }, [c, t, r, s] ); return [v, m]; } function w({ defaultProp: t, onChange: n }) { const [o, l] = e.useState(t), f = e.useRef(o), r = e.useRef(n); return I(() => { r.current = n; }, [n]), e.useEffect(() => { var s; f.current !== o && ((s = r.current) == null || s.call(r, o), f.current = o); }, [o, f]), [o, l, r]; } function R(t) { return typeof t == "function"; } export { g as a, y as u };