UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

77 lines (76 loc) 1.95 kB
import { jsx as O } from "react/jsx-runtime"; import { Autocomplete as j, TextField as A } from "@mui/material"; import { createFilterOptions as I } from "@mui/material/Autocomplete"; import { isObject as b } from "lodash-es"; const q = I(); function H(t, r) { if (t == null) return null; const n = r.filter((l) => l.value === t); return n.length > 0 ? n[0] : { value: t, label: t }; } const $ = (t) => { const { id: r, options: n, value: l, required: g, disabled: F, readonly: h, multiple: v, autofocus: y, onChange: i, onBlur: u, onFocus: c, placeholder: C, isClearable: _ = !0, rawErrors: a, registry: x } = t, { enumOptions: f } = n, p = ["__oneof_select", "__anyof_select"].some( (o) => r.includes(o) ), d = !p && !!x.formContext.allowFreeSoloEnum, S = _ && !p; return /* @__PURE__ */ O( j, { id: r, value: H(l, f), freeSolo: d, forcePopupIcon: !0, selectOnFocus: !0, clearOnBlur: !0, handleHomeEndKeys: !0, options: f, readOnly: h, disabled: F, multiple: v, disableClearable: !S, onChange: (o, e) => { b(e) && "inputValue" in e ? i(e.inputValue) : b(e) && "value" in e ? i(e.value) : i(e); }, renderInput: (o) => /* @__PURE__ */ O( A, { ...o, required: g, placeholder: C, error: a && a.length > 0, autoFocus: y, onFocus: c && (() => c(r, l?.value)), onBlur: u && (() => u(r, l?.value)) } ), filterOptions: (o, e) => { const m = q(o, e), { inputValue: s } = e, B = o.some((E) => s === E.label); return d && s !== "" && !B && m.push({ value: s, label: `Set to custom value "${s}"` }), m; } } ); }; export { $ as SelectWidget, H as findValueOption }; //# sourceMappingURL=SelectWidget.js.map