UNPKG

@konstructio/ui

Version:

A set of reusable and customizable React components built for konstruct.io

49 lines (48 loc) 1.43 kB
import { useToggle as L } from "../../../hooks/useToggle.js"; import { SelectContext as N } from "./select.context.js"; import { useCallback as f, useEffect as T, useRef as p, useState as e } from "react"; import { jsx as O } from "react/jsx-runtime"; var c = 1, R = 300, V = ({ children: v, value: C, name: i, highlightSearch: E = !1, options: n, onChange: a, onBlur: u }) => { const [S, l] = e(n), d = p(E), [F, g] = L(!1), [P, I] = e(""), [b, x] = e(!0), [A, o] = e(!0), [_, s] = e(c), [y, h] = e(!1), t = p(void 0), D = f((r, m) => { m?.current && (m.current.value = r), t.current && clearTimeout(t.current), h(!0), o(!0), s(c), a?.({ target: { value: r, name: i ?? "" } }), u?.(), t.current = setTimeout(() => { h(!1); }, R); }, [ a, i, u ]), G = f((r) => { g(r), o(!0), s(c); }, [g]); return T(() => { l(n); }, [n.length]), T(() => () => { t.current && clearTimeout(t.current); }, []), /* @__PURE__ */ O(N.Provider, { value: { highlightSearchEnabled: d.current, isOpen: F, searchTerm: P, value: C, canFilter: b, canContinueFetching: A, page: _, options: S, isTyping: y, setOptions: l, setPage: s, setCanContinueFetching: o, setCanFilter: x, setSearchTerm: I, setValue: D, toggleOpen: G }, children: v }); }; export { V as SelectProvider };