UNPKG

@sheerid/jslib-nightly

Version:

SheerID JavaScript Library

216 lines (214 loc) • 5.83 kB
/** * VERSION: 2.230.0-alpha.0 * BUILD_TIMESTAMP: 1778694684677 * BUILD_DATE: Wed May 13 2026 17:51:24 GMT+0000 (Coordinated Universal Time) * BUILD_COMMIT: 7af1c105d5485ac4ed1190c56d492bb4590667a9 */ import { j as o, F as A, G as P, i as R, b as h, s as E, l as H } from "../sheerid.js"; import { u as K } from "./downshift.esm-huKBwB2d.js"; const D = ({ getItemProps: t, getMenuProps: s, highlightedIndex: i, options: n, itemToString: a, ariaLabel: e, isOpen: c, isLoading: p = !1 }) => { const u = (r, l) => /* @__PURE__ */ o.jsx( "div", { className: `sid-input-select-list__item ${i === l ? "sid-input-select-list__item--highlighted" : ""}`, ...t({ item: r, index: l, key: r.value }), children: a(n[l]) } ), f = n.length > 0 ? n.map((r, l) => u(r, l)) : /* @__PURE__ */ o.jsx("div", { className: "sid-input-select-list__message", children: /* @__PURE__ */ o.jsx(A, { id: "noOptions", defaultMessage: "No Options" }) }); return /* @__PURE__ */ o.jsx("div", { ...s({ "aria-label": e }), children: c ? /* @__PURE__ */ o.jsx("div", { className: "sid-input-select-list__menu", children: p ? /* @__PURE__ */ o.jsx("div", { className: "sid-input-select-list__loading-spinner", children: /* @__PURE__ */ o.jsx(P, {}) }) : f }) : null }); }, J = D, U = ({ clearSelection: t, disabled: s, getToggleButtonProps: i, isOpen: n, isClearable: a, intl: e }) => { const { onClick: c, "aria-haspopup": p, "data-toggle": u, onKeyUp: f, onKeyDown: r, onBlur: l } = i(), g = a ? e.formatMessage({ id: "clearAndOpenMenu", defaultMessage: "Clear selection and open menu" }) : e.formatMessage({ id: "openMenu", defaultMessage: "Open menu" }); return /* @__PURE__ */ o.jsx( "button", { "aria-label": g, "aria-haspopup": p, "data-toggle": u, onKeyUp: f, onKeyDown: r, onBlur: l, className: "sid-input-select-button", disabled: s, type: "button", onClick: (m) => { typeof t == "function" && t(), typeof c == "function" && c(m); }, children: /* @__PURE__ */ o.jsx( "svg", { viewBox: "0 0 20 20", preserveAspectRatio: "none", width: 16, fill: "transparent", stroke: "#5A5A5A", strokeWidth: "1.1px", transform: n ? "rotate(180)" : void 0, children: /* @__PURE__ */ o.jsx("path", { d: "M1,6 L10,15 L19,6" }) } ) } ); }, q = R(U), y = (t) => t ? t.label : "", G = (t, s) => t.filter( (n) => !s || n.label.toLowerCase().includes(s.toLowerCase()) || n.value.toString().toLowerCase().includes(s.toLowerCase()) ), I = ({ className: t, inputId: s, disabled: i, fieldId: n, fieldLabelId: a, isErrored: e, options: c, onKeyDown: p, onChange: u, placeholder: f, // Most invokers want placeholder hidden by css, so it can be easily shown when // customizing the implementation. Birth date is an example of an exception. suppressPlaceholder: r = !0, value: l, autoFocus: g, ariaLabel: m, ariaDescribedBy: j, isRequired: O, isLoading: L = !1, role: M = "combobox", autoComplete: N }) => { const [b, w] = h.useState(""), x = b ? G(c, b) : c, { getInputProps: _, getItemProps: $, getMenuProps: v, getToggleButtonProps: B, highlightedIndex: F, isOpen: C, selectItem: k } = K({ id: s, items: x, onInputValueChange({ inputValue: d }) { w(d); }, onSelectedItemChange: ({ selectedItem: d }) => u(d), itemToString: y, selectedItem: l && l.value && l.label ? l : null, defaultHighlightedIndex: 0 }), T = (d) => { typeof p == "function" && p(d); }, S = h.useRef(null); return h.useEffect(() => { E(n, S.current); }), /* @__PURE__ */ o.jsxs("div", { className: `sid-input-select-list ${t || ""}`, children: [ /* @__PURE__ */ o.jsx( "input", { ..._({ ref: S, onKeyDown: (d) => T(d), "aria-labelledby": a }), autoFocus: g, id: s, className: `sid-l-full-width sid-text-input ${r ? "sid-hidden-placeholder" : ""} ${e ? "sid-text-input--error" : ""}`, disabled: i, placeholder: f, "aria-required": O, "aria-describedby": j, "aria-invalid": e, role: M, autoComplete: N } ), /* @__PURE__ */ o.jsx( q, { disabled: i, getToggleButtonProps: B, isOpen: C, isClearable: !!l?.value, clearSelection: () => k(void 0) } ), /* @__PURE__ */ o.jsx( J, { highlightedIndex: F, itemToString: y, options: x, getItemProps: $, getMenuProps: v, ariaLabel: m, isOpen: C, isLoading: L } ) ] }); }; I.defaultProps = { className: void 0, disabled: !1, inputId: void 0, isErrored: !1, onKeyDown: void 0, placeholder: "", value: void 0, autoComplete: void 0 }; const V = I, W = (t, s) => { let i; try { i = t.label.toUpperCase() > s.label.toUpperCase() ? 1 : -1; } catch { i = 1; } return i; }, X = (t) => t.sort(W), Y = (t, s = [], i) => { const n = [], a = []; return s.forEach((e) => { if (typeof e > "u") return a.push("undefined"); if (!e || typeof e == "number" || typeof e == "string" && !e.trim()) return a.push(JSON.stringify(e)); n.push({ value: e, label: i.formatHTMLMessage({ id: `${t}.${e}`, defaultMessage: `{${t}.${e}}` }) }); }), a.length > 0 && H.warn( `FormSelectChoice.getFormFieldSelectOptions contains unexpected values (${a.length}): ${a.join(", ")}` ), n; }; export { V as I, X as S, Y as g };