koko-react-select
Version:
한국어 초성, 부분 검색을 지원하는 커스텀 React Select 컴포넌트입니다. 멀티 선택, 검색, 초기화 기능을 포함합니다.
517 lines (516 loc) • 18.9 kB
JavaScript
import * as _ from "react";
import ce, { useEffect as fe, useState as K, useRef as ee, useMemo as H } from "react";
var U = { exports: {} }, $ = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var re;
function de() {
if (re) return $;
re = 1;
var r = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
function l(t, i, d) {
var c = null;
if (d !== void 0 && (c = "" + d), i.key !== void 0 && (c = "" + i.key), "key" in i) {
d = {};
for (var m in i)
m !== "key" && (d[m] = i[m]);
} else d = i;
return i = d.ref, {
$$typeof: r,
type: t,
key: c,
ref: i !== void 0 ? i : null,
props: d
};
}
return $.Fragment = n, $.jsx = l, $.jsxs = l, $;
}
var F = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var te;
function pe() {
return te || (te = 1, process.env.NODE_ENV !== "production" && function() {
function r(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === G ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case E:
return "Fragment";
case Y:
return "Profiler";
case L:
return "StrictMode";
case Q:
return "Suspense";
case z:
return "SuspenseList";
case q:
return "Activity";
}
if (typeof e == "object")
switch (typeof e.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), e.$$typeof) {
case y:
return "Portal";
case w:
return (e.displayName || "Context") + ".Provider";
case N:
return (e._context.displayName || "Context") + ".Consumer";
case D:
var a = e.render;
return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case J:
return a = e.displayName || null, a !== null ? a : r(e.type) || "Memo";
case M:
a = e._payload, e = e._init;
try {
return r(e(a));
} catch {
}
}
return null;
}
function n(e) {
return "" + e;
}
function l(e) {
try {
n(e);
var a = !1;
} catch {
a = !0;
}
if (a) {
a = console;
var u = a.error, p = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return u.call(
a,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
p
), n(e);
}
}
function t(e) {
if (e === E) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === M)
return "<...>";
try {
var a = r(e);
return a ? "<" + a + ">" : "<...>";
} catch {
return "<...>";
}
}
function i() {
var e = I.A;
return e === null ? null : e.getOwner();
}
function d() {
return Error("react-stack-top-frame");
}
function c(e) {
if (V.call(e, "key")) {
var a = Object.getOwnPropertyDescriptor(e, "key").get;
if (a && a.isReactWarning) return !1;
}
return e.key !== void 0;
}
function m(e, a) {
function u() {
s || (s = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
a
));
}
u.isReactWarning = !0, Object.defineProperty(e, "key", {
get: u,
configurable: !0
});
}
function g() {
var e = r(this.type);
return b[e] || (b[e] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), e = this.props.ref, e !== void 0 ? e : null;
}
function h(e, a, u, p, O, x, B, X) {
return u = x.ref, e = {
$$typeof: k,
type: e,
key: a,
props: x,
_owner: O
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: g
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(e, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(e, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: B
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: X
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function j(e, a, u, p, O, x, B, X) {
var v = a.children;
if (v !== void 0)
if (p)
if (W(v)) {
for (p = 0; p < v.length; p++)
o(v[p]);
Object.freeze && Object.freeze(v);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else o(v);
if (V.call(a, "key")) {
v = r(e);
var A = Object.keys(a).filter(function(ue) {
return ue !== "key";
});
p = 0 < A.length ? "{key: someKey, " + A.join(": ..., ") + ": ...}" : "{key: someKey}", C[v + p] || (A = 0 < A.length ? "{" + A.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
p,
v,
A,
v
), C[v + p] = !0);
}
if (v = null, u !== void 0 && (l(u), v = "" + u), c(a) && (l(a.key), v = "" + a.key), "key" in a) {
u = {};
for (var Z in a)
Z !== "key" && (u[Z] = a[Z]);
} else u = a;
return v && m(
u,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), h(
e,
v,
x,
O,
i(),
u,
B,
X
);
}
function o(e) {
typeof e == "object" && e !== null && e.$$typeof === k && e._store && (e._store.validated = 1);
}
var R = ce, k = Symbol.for("react.transitional.element"), y = Symbol.for("react.portal"), E = Symbol.for("react.fragment"), L = Symbol.for("react.strict_mode"), Y = Symbol.for("react.profiler"), N = Symbol.for("react.consumer"), w = Symbol.for("react.context"), D = Symbol.for("react.forward_ref"), Q = Symbol.for("react.suspense"), z = Symbol.for("react.suspense_list"), J = Symbol.for("react.memo"), M = Symbol.for("react.lazy"), q = Symbol.for("react.activity"), G = Symbol.for("react.client.reference"), I = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, V = Object.prototype.hasOwnProperty, W = Array.isArray, T = console.createTask ? console.createTask : function() {
return null;
};
R = {
"react-stack-bottom-frame": function(e) {
return e();
}
};
var s, b = {}, S = R["react-stack-bottom-frame"].bind(
R,
d
)(), P = T(t(d)), C = {};
F.Fragment = E, F.jsx = function(e, a, u, p, O) {
var x = 1e4 > I.recentlyCreatedOwnerStacks++;
return j(
e,
a,
u,
!1,
p,
O,
x ? Error("react-stack-top-frame") : S,
x ? T(t(e)) : P
);
}, F.jsxs = function(e, a, u, p, O) {
var x = 1e4 > I.recentlyCreatedOwnerStacks++;
return j(
e,
a,
u,
!0,
p,
O,
x ? Error("react-stack-top-frame") : S,
x ? T(t(e)) : P
);
};
}()), F;
}
var ne;
function ve() {
return ne || (ne = 1, process.env.NODE_ENV === "production" ? U.exports = de() : U.exports = pe()), U.exports;
}
var f = ve();
const me = (r) => /* @__PURE__ */ _.createElement("svg", { width: "1em", height: "1em", viewBox: "0 0 18 19", stroke: "none", xmlns: "http://www.w3.org/2000/svg", ...r }, /* @__PURE__ */ _.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M4.04547 6.79547C4.29652 6.54441 4.70355 6.54441 4.9546 6.79547L9.00003 10.8409L13.0455 6.79547C13.2965 6.54441 13.7036 6.54441 13.9546 6.79547C14.2057 7.04652 14.2057 7.45355 13.9546 7.7046L9.4546 12.2046C9.20355 12.4557 8.79652 12.4557 8.54547 12.2046L4.04547 7.7046C3.79441 7.45355 3.79441 7.04652 4.04547 6.79547Z", strokeOpacity: 0 })), be = (r) => /* @__PURE__ */ _.createElement("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...r }, /* @__PURE__ */ _.createElement("path", { d: "M17 7L7 17M7 7L17 17", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" })), he = (r) => /* @__PURE__ */ _.createElement("svg", { width: "1em", height: "1em", viewBox: "0 0 14 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...r }, /* @__PURE__ */ _.createElement("g", { id: "icon" }, /* @__PURE__ */ _.createElement("path", { id: "Icon", d: "M12.25 12.75L9.7125 10.2125M11.0833 6.91667C11.0833 9.494 8.994 11.5833 6.41667 11.5833C3.83934 11.5833 1.75 9.494 1.75 6.91667C1.75 4.33934 3.83934 2.25 6.41667 2.25C8.994 2.25 11.0833 4.33934 11.0833 6.91667Z", strokeLinecap: "round", strokeLinejoin: "round", fillOpacity: 0 }))), xe = (r) => {
const { ref: n, callback: l } = r;
fe(() => {
const t = (i) => {
i.target instanceof Node && n.current && !n.current.contains(i.target) && l();
};
return document.addEventListener("mousedown", t), () => {
document.removeEventListener("mousedown", t);
};
}, []);
};
function Ee(r, n) {
if (typeof r != "object" || !r) return r;
var l = r[Symbol.toPrimitive];
if (l !== void 0) {
var t = l.call(r, n);
if (typeof t != "object") return t;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (n === "string" ? String : Number)(r);
}
function ge(r) {
var n = Ee(r, "string");
return typeof n == "symbol" ? n : String(n);
}
function Re(r, n, l) {
return n = ge(n), n in r ? Object.defineProperty(r, n, {
value: l,
enumerable: !0,
configurable: !0,
writable: !0
}) : r[n] = l, r;
}
function ae(r, n) {
var l = Object.keys(r);
if (Object.getOwnPropertySymbols) {
var t = Object.getOwnPropertySymbols(r);
n && (t = t.filter(function(i) {
return Object.getOwnPropertyDescriptor(r, i).enumerable;
})), l.push.apply(l, t);
}
return l;
}
function le(r) {
for (var n = 1; n < arguments.length; n++) {
var l = arguments[n] != null ? arguments[n] : {};
n % 2 ? ae(Object(l), !0).forEach(function(t) {
Re(r, t, l[t]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(l)) : ae(Object(l)).forEach(function(t) {
Object.defineProperty(r, t, Object.getOwnPropertyDescriptor(l, t));
});
}
return r;
}
function oe(r, n) {
var l = {};
for (var t in r)
l[t] = n(r[t], t);
return l;
}
var ke = (r, n, l) => {
for (var t of Object.keys(r)) {
var i;
if (r[t] !== ((i = n[t]) !== null && i !== void 0 ? i : l[t]))
return !1;
}
return !0;
}, ie = (r) => {
var n = (l) => {
var t = r.defaultClassName, i = le(le({}, r.defaultVariants), l);
for (var d in i) {
var c, m = (c = i[d]) !== null && c !== void 0 ? c : r.defaultVariants[d];
if (m != null) {
var g = m;
typeof g == "boolean" && (g = g === !0 ? "true" : "false");
var h = (
// @ts-expect-error
r.variantClassNames[d][g]
);
h && (t += " " + h);
}
}
for (var [j, o] of r.compoundVariants)
ke(j, i, r.defaultVariants) && (t += " " + o);
return t;
};
return n.variants = () => Object.keys(r.variantClassNames), n.classNames = {
get base() {
return r.defaultClassName.split(" ")[0];
},
get variants() {
return oe(r.variantClassNames, (l) => oe(l, (t) => t.split(" ")[0]));
}
}, n;
}, Oe = ie({ defaultClassName: "_1knulxi0", variantClassNames: { isOpen: { true: "_1knulxi1", false: "_1knulxi2" }, disabled: { true: "_1knulxi3", false: "_1knulxi4" }, invalid: { true: "_1knulxi5", false: "_1knulxi6" } }, defaultVariants: { isOpen: !1, disabled: !1 }, compoundVariants: [] }), we = "_1knulxi7", _e = "_1knulxi8", je = "_1knulxi9", ye = ie({ defaultClassName: "_1knulxia", variantClassNames: { isLabel: { true: "_1knulxib", false: "_1knulxic" } }, defaultVariants: {}, compoundVariants: [] }), Te = "_1knulxid", se = "_1knulxie";
const Se = (r, n) => r.filter((l) => l.label.toLowerCase().includes(n.toLowerCase())), Ce = (r) => {
var W, T;
const {
isSearchable: n = !1,
isClearable: l = !0,
isMulti: t = !1,
disabled: i = !1,
invalid: d = !1,
value: c,
optionList: m = [],
placeholder: g,
onChange: h,
maxHeight: j = "200px",
customClassName: o
} = r, [R, k] = K(!1), [y, E] = K(""), L = ee(null), Y = ee(null), N = H(() => t ? c ?? [] : c != null ? [c] : [], [c, t]), w = H(() => m.filter((s) => N.includes(s.value)), [N, m]), D = H(() => Se(m, y), [m, y]);
xe({
ref: L,
callback: () => {
k(!1), E("");
}
});
const z = () => k(!0), J = (s) => {
s.stopPropagation(), E("");
}, M = (s) => {
E(s);
}, q = (s) => {
if (t) {
const b = c, P = b.includes(s.value) ? b.filter((C) => C !== s.value) : [...b, s.value];
h(P);
} else
h(s.value), k(!1);
E("");
}, G = (s, b) => {
if (b.stopPropagation(), !t) return;
const P = c.filter((C) => C !== s.value);
h(P);
}, I = (s) => {
s.stopPropagation(), h(t ? [] : null), E(""), k(!1);
}, V = () => {
var s;
i || (R ? k(!1) : (s = Y.current) == null || s.focus());
};
return /* @__PURE__ */ f.jsxs("div", { style: { position: "relative" }, ref: L, children: [
/* @__PURE__ */ f.jsxs(
"div",
{
className: `${Oe({ isOpen: R, disabled: i, invalid: d })} ${(o == null ? void 0 : o.container) || ""}`,
onClick: V,
style: { width: "300px" },
children: [
/* @__PURE__ */ f.jsxs("div", { className: `${we} ${(o == null ? void 0 : o.inputContainer) || ""}`, children: [
/* @__PURE__ */ f.jsx("div", { className: `${je} ${(o == null ? void 0 : o.placeholderContainer) || ""}`, children: /* @__PURE__ */ f.jsx(
"div",
{
className: `${ye({ isLabel: w.length > 0 })} ${(o == null ? void 0 : o.placeholder) || ""}`,
children: !y && (w.length === 0 ? g || "Select..." : t ? "" : (W = w[0]) == null ? void 0 : W.label)
}
) }),
/* @__PURE__ */ f.jsxs("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px", alignItems: "center" }, children: [
t && w.map((s) => /* @__PURE__ */ f.jsxs(
"div",
{
className: (o == null ? void 0 : o.selectedTag) || "",
style: {
padding: "2px 8px",
background: "#EEF0F4",
borderRadius: "4px",
fontSize: "12px",
display: "flex",
alignItems: "center",
gap: "4px"
},
children: [
s.label,
/* @__PURE__ */ f.jsx("span", { style: { cursor: "pointer" }, onClick: (b) => G(s, b), children: "×" })
]
},
s.value
)),
/* @__PURE__ */ f.jsx(
"input",
{
className: `${_e} ${(o == null ? void 0 : o.input) || ""}`,
ref: Y,
value: y,
onFocus: z,
onChange: (s) => M(s.target.value),
onClick: J,
disabled: i,
readOnly: !n,
style: { flex: 1, minWidth: "40px" }
}
)
] })
] }),
/* @__PURE__ */ f.jsxs(
"div",
{
style: { display: "flex", alignItems: "center", gap: "8px" },
className: (o == null ? void 0 : o.iconWrapper) || "",
children: [
l && w.length > 0 && !i && /* @__PURE__ */ f.jsx(be, { width: 20, height: 20, stroke: "#5C7099", style: { cursor: "pointer" }, onClick: I }),
n ? /* @__PURE__ */ f.jsx(he, { width: 20, height: 20, style: { cursor: "pointer", stroke: "#5C7099" } }) : /* @__PURE__ */ f.jsx(me, { width: 20, height: 20, style: { cursor: "pointer", stroke: "#5C7099", fill: "#5C7099" } })
]
}
)
]
}
),
R && /* @__PURE__ */ f.jsx(
"div",
{
className: `${Te} ${(o == null ? void 0 : o.optionContainer) || ""}`,
style: {
minWidth: (T = L.current) == null ? void 0 : T.offsetWidth,
maxHeight: j
},
children: D.length === 0 ? /* @__PURE__ */ f.jsx("div", { className: `${se} ${(o == null ? void 0 : o.option) || ""}`, children: "No Data" }) : D.map((s) => {
const b = N.some((S) => S === s.value);
return /* @__PURE__ */ f.jsxs(
"div",
{
className: `${se} ${(o == null ? void 0 : o.option) || ""}`,
onClick: () => q(s),
children: [
t && /* @__PURE__ */ f.jsx("input", { type: "checkbox", readOnly: !0, checked: b, style: { marginRight: "8px" } }),
s.label
]
},
s.value
);
})
}
)
] });
};
export {
Ce as default
};