@lanaco/lnc-react-ui
Version:
React component library
145 lines (144 loc) • 4.33 kB
JavaScript
import { jsx as le } from "react/jsx-runtime";
import * as ce from "react";
import { useRef as G, useState as a, useEffect as H, useCallback as E, forwardRef as J } from "react";
import { _ as ve, u as Oe } from "./emotion-element-f0de968e.browser.esm-CkCiQliQ.js";
import { _ as Se, b as s, h as me, d as C, u as he, S as _e, a as ye } from "./CustomStyles-YyM49BGx.js";
import { _ as ge } from "./defineProperty-DF3p0mVo.js";
import "./index-B2yaYXE2.js";
import { d as Ie } from "./index-Dt62UGku.js";
var Ce = ["defaultOptions", "cacheOptions", "loadOptions", "options", "isLoading", "onInputChange", "filterOption"];
function Le(n) {
var o = n.defaultOptions, e = o === void 0 ? !1 : o, u = n.cacheOptions, i = u === void 0 ? !1 : u, l = n.loadOptions;
n.options;
var p = n.isLoading, L = p === void 0 ? !1 : p, h = n.onInputChange, _ = n.filterOption, A = _ === void 0 ? null : _, y = Se(n, Ce), g = y.inputValue, r = G(void 0), c = G(!1), v = a(Array.isArray(e) ? e : void 0), f = s(v, 2), K = f[0], R = f[1], Q = a(typeof g < "u" ? g : ""), j = s(Q, 2), T = j[0], P = j[1], U = a(e === !0), w = s(U, 2), X = w[0], O = w[1], Y = a(void 0), M = s(Y, 2), V = M[0], b = M[1], Z = a([]), q = s(Z, 2), k = q[0], D = q[1], ee = a(!1), z = s(ee, 2), te = z[0], I = z[1], ne = a({}), N = s(ne, 2), S = N[0], W = N[1], ae = a(void 0), B = s(ae, 2), se = B[0], re = B[1], oe = a(void 0), F = s(oe, 2), ue = F[0], ie = F[1];
i !== ue && (W({}), ie(i)), e !== se && (R(Array.isArray(e) ? e : void 0), re(e)), H(function() {
return c.current = !0, function() {
c.current = !1;
};
}, []);
var $ = E(function(m, d) {
if (!l) return d();
var t = l(m, d);
t && typeof t.then == "function" && t.then(d, function() {
return d();
});
}, [l]);
H(function() {
e === !0 && $(T, function(m) {
c.current && (R(m || []), O(!!r.current));
});
}, []);
var pe = E(function(m, d) {
var t = me(m, d, h);
if (!t) {
r.current = void 0, P(""), b(""), D([]), O(!1), I(!1);
return;
}
if (i && S[t])
P(t), b(t), D(S[t]), O(!1), I(!1);
else {
var de = r.current = {};
P(t), O(!0), I(!V), $(t, function(x) {
c && de === r.current && (r.current = void 0, O(!1), b(t), D(x || []), I(!1), W(x ? C(C({}, S), {}, ge({}, t, x)) : S));
});
}
}, [i, $, V, S, h]), fe = te ? [] : T && V ? k : K || [];
return C(C({}, y), {}, {
options: fe,
isLoading: X || L,
onInputChange: pe,
filterOption: A
});
}
var Ae = /* @__PURE__ */ J(function(n, o) {
var e = Le(n), u = he(e);
return /* @__PURE__ */ ce.createElement(_e, ve({
ref: o
}, u));
}), Pe = Ae;
const je = J((n, o) => {
const {
// defaultOptions,
// cacheOptions,
// loadOptions,
styles: e,
debounceTime: u = 0,
// name,
// hideSelectedOptions,
// id,
// inputId,
// value,
// readOnly,
// tabIndex,
isSearchable: i = !0,
isClearable: l = !0,
// isLoading,
// isRtl,
// isDisabled,
// closeMenuOnSelect,
// closeMenuOnScroll,
// escapeClearsValue,
// filterOption,
// formatGroupLabel,
// formatOptionLabel,
// getOptionLabel,
// getOptionValue,
// isOptionDisabled,
// isOptionSelected,
// loadingMessage,
// minMenuHeight,
// maxMenuHeight,
// menuPlacement,
// menuPosition,
// menuShouldBlockScroll,
// menuShouldScrollIntoView,
// openMenuOnFocus,
// openMenuOnClick,
// autoFocus,
// placeholder,
// noOptionsMessage,
// menuIsOpen,
// components,
// defaultValue,
// defaultInputValue,
// defaultMenuIsOpen,
// delimiter,
// onChange,
onInputChange: p,
// onMenuOpen,
// onMenuClose,
// onBlur,
// onFocus,
size: L = "small",
color: h = "primary",
className: _ = "",
style: A = {},
// children,
...y
} = n, g = Oe(), r = E(
Ie((v, f) => {
p == null || p(v, f);
}, u)
);
return /* @__PURE__ */ le(
Pe,
{
ref: o,
styles: e || ye,
size: L,
color: h,
theme: g,
isSearchable: i,
isClearable: l,
onInputChange: (v, f) => {
r(v, f);
},
className: _,
style: A,
...y
}
);
});
export {
je as default
};