UNPKG

@lanaco/lnc-react-ui

Version:

React component library

326 lines (325 loc) 9.61 kB
import { jsx as de } from "react/jsx-runtime"; import { P as e } from "./index-S5Cd7WrG.js"; import * as Oe from "react"; import { useRef as G, useState as a, useEffect as W, useCallback as j, forwardRef as J } from "react"; import { _ as me, u as be } from "./emotion-element-f0de968e.browser.esm-CkCiQliQ.js"; import { _ as ge, b as s, h as Se, d as C, u as he, S as ve, a as ye } from "./CustomStyles-BwnfUVvi.js"; import { _ as _e } from "./defineProperty-DF3p0mVo.js"; import "./index-64mXPFBC.js"; import { d as Ie } from "./index-CkWvbrVT.js"; var Ce = ["defaultOptions", "cacheOptions", "loadOptions", "options", "isLoading", "onInputChange", "filterOption"]; function Le(o) { var r = o.defaultOptions, t = r === void 0 ? !1 : r, i = o.cacheOptions, l = i === void 0 ? !1 : i, d = o.loadOptions; o.options; var p = o.isLoading, L = p === void 0 ? !1 : p, h = o.onInputChange, v = o.filterOption, M = v === void 0 ? null : v, y = ge(o, Ce), _ = y.inputValue, u = G(void 0), O = G(!1), m = a(Array.isArray(t) ? t : void 0), f = s(m, 2), K = f[0], R = f[1], Q = a(typeof _ < "u" ? _ : ""), $ = s(Q, 2), w = $[0], P = $[1], U = a(t === !0), E = s(U, 2), X = E[0], b = E[1], Y = a(void 0), F = s(Y, 2), V = F[0], A = F[1], Z = a([]), z = s(Z, 2), ee = z[0], T = z[1], te = a(!1), B = s(te, 2), ne = B[0], I = B[1], oe = a({}), H = s(oe, 2), g = H[0], N = H[1], ae = a(void 0), k = s(ae, 2), se = k[0], ue = k[1], re = a(void 0), q = s(re, 2), ie = q[0], le = q[1]; l !== ie && (N({}), le(l)), t !== se && (R(Array.isArray(t) ? t : void 0), ue(t)), W(function() { return O.current = !0, function() { O.current = !1; }; }, []); var x = j(function(S, c) { if (!d) return c(); var n = d(S, c); n && typeof n.then == "function" && n.then(c, function() { return c(); }); }, [d]); W(function() { t === !0 && x(w, function(S) { O.current && (R(S || []), b(!!u.current)); }); }, []); var pe = j(function(S, c) { var n = Se(S, c, h); if (!n) { u.current = void 0, P(""), A(""), T([]), b(!1), I(!1); return; } if (l && g[n]) P(n), A(n), T(g[n]), b(!1), I(!1); else { var ce = u.current = {}; P(n), b(!0), I(!V), x(n, function(D) { O && ce === u.current && (u.current = void 0, b(!1), A(n), T(D || []), I(!1), N(D ? C(C({}, g), {}, _e({}, n, D)) : g)); }); } }, [l, x, V, g, h]), fe = ne ? [] : w && V ? ee : K || []; return C(C({}, y), {}, { options: fe, isLoading: X || L, onInputChange: pe, filterOption: M }); } var Me = /* @__PURE__ */ J(function(o, r) { var t = Le(o), i = he(t); return /* @__PURE__ */ Oe.createElement(ve, me({ ref: r }, i)); }), Pe = Me; const Ve = J((o, r) => { const { // defaultOptions, // cacheOptions, // loadOptions, styles: t, debounceTime: i = 0, // name, // hideSelectedOptions, // id, // inputId, // value, // readOnly, // tabIndex, isSearchable: l = !0, isClearable: d = !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: v = "", style: M = {}, // children, ...y } = o, _ = be(), u = j( Ie((m, f) => { p == null || p(m, f); }, i) ); return /* @__PURE__ */ de( Pe, { ref: r, styles: t || ye, size: L, color: h, theme: _, isSearchable: l, isClearable: d, onInputChange: (m, f) => { u(m, f); }, className: v, style: M, ...y } ); }); Ve.propTypes = { /** * The default set of options to show before the user starts searching. When set to true, the results for loadOptions('') will be autoloaded. */ defaultOptions: e.oneOfType([e.bool, e.array]), /** * If cacheOptions is truthy, then the loaded data will be cached. The cache will remain until cacheOptions changes value. */ cacheOptions: e.any, /** * Function that returns a promise, which is the set of options to be used once the promise resolves. */ loadOptions: e.func, styles: e.object, debounceTime: e.number, name: e.string, value: e.any, /** * Sets the tabIndex attribute on the input */ tabIndex: e.number, /** * Whether to enable search functionality */ isSearchable: e.bool, isClearable: e.bool, /** * Is the select in a state of loading (async) */ isLoading: e.bool, /** * Is the select direction right-to-left */ isRtl: e.bool, isDisabled: e.bool, readOnly: e.bool, /** * Close the select menu when the user selects an option */ closeMenuOnSelect: e.bool, /** * If true, close the select menu when the user scrolls the document/body. * If a function, takes a standard javascript ScrollEvent you return a boolean: * true => The menu closes * false => The menu stays open * This is useful when you have a scrollable modal and want to portal the menu out, but want to avoid graphical issues. */ closeMenuOnScroll: e.oneOfType([e.bool, e.func]), /** * Clear all values when the user presses escape AND the menu is closed */ escapeClearsValue: e.bool, /** * Custom method to filter whether an option should be displayed in the menu. Type: `null` or `() => boolean` */ filterOption: e.func, /** * Formats group labels in the menu as React components */ formatGroupLabel: e.func, /** * Formats option labels in the menu and control as React components */ formatOptionLabel: e.func, /** * Resolves option data to a string to be displayed as the label by components * Note: Failure to resolve to a string type can interfere with filtering and screen reader support. */ getOptionLabel: e.func, /** * Resolves option data to a string to compare options and specify value attributes */ getOptionValue: e.func, /** * Hide the selected option from the menu */ hideSelectedOptions: e.bool, /** * The id to set on the SelectContainer component */ id: e.string, /** * The id of the search input */ inputId: e.string, /** * Override the built-in logic to detect whether an option is disabled. `(...) => boolean` */ isOptionDisabled: e.func, /** * Override the built-in logic to detect whether an option is selected. `(...) => boolean` */ isOptionSelected: e.func, /** * Async: Text to display when loading options `(...) => ...` */ loadingMessage: e.func, /** * Minimum height of the menu before flipping */ minMenuHeight: e.number, /** * Maximum height of the menu before flipping */ maxMenuHeight: e.number, /** * Default placement of the menu in relation to the control. 'auto' will flip when there isn't enough space below the control. */ menuPlacement: e.oneOf(["bottom", "auto", "top"]), /** *The CSS position value of the menu, when "fixed" extra layout management is required. */ menuPosition: e.oneOf(["absolute", "fixed"]), /** * Whether to block scroll events when the menu is open */ menuShouldBlockScroll: e.bool, /** * Whether the menu should be scrolled into view when it opens */ menuShouldScrollIntoView: e.bool, /** * Allows control of whether the menu is opened when the Select is focused */ openMenuOnFocus: e.bool, /** * Allows control of whether the menu is opened when the Select is clicked */ openMenuOnClick: e.bool, //---- autoFocus: e.bool, placeholder: e.any, noOptionsMessage: e.string, menuIsOpen: e.bool, /** * This complex object includes all the compositional components that are used in react-select. If you wish to overwrite a component, pass in an object with the appropriate namespace. * If you only wish to restyle a component, we recommend using the styles prop instead. */ components: e.object, /** * initial value of the control */ defaultValue: e.string, /** * initial value of the search input */ defaultInputValue: e.string, /** * initial open value of the menu */ defaultMenuIsOpen: e.bool, /** * Delimiter used to join multiple values into a single HTML Input value */ delimiter: e.string, //--------------------------------------------------------------- onChange: e.func, /** * control the value of the search input (changing this will update the available options) */ onInputChange: e.func, onMenuOpen: e.func, onMenuClose: e.func, onFocus: e.func, onBlur: e.func, //--------------------------------------------------------------- className: e.string, style: e.object, color: e.oneOf([ "primary", "secondary", "success", "warning", "danger", "information", "neutral", "gray" ]), size: e.oneOf(["small", "medium", "large"]) }; export { Ve as default };