@kamleshchandel/react-select-kc 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/react-select-kc.cjs.js +6 -0
- package/dist/react-select-kc.es.js +464 -0
- package/package.json +39 -0
- package/types/index.d.ts +28 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Hello
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";const f=require("react");var Z={exports:{}},W={};var te;function le(){if(te)return W;te=1;var E=Symbol.for("react.transitional.element"),p=Symbol.for("react.fragment");function h(k,d,a){var R=null;if(a!==void 0&&(R=""+a),d.key!==void 0&&(R=""+d.key),"key"in d){a={};for(var O in d)O!=="key"&&(a[O]=d[O])}else a=d;return d=a.ref,{$$typeof:E,type:k,key:R,ref:d!==void 0?d:null,props:a}}return W.Fragment=p,W.jsx=h,W.jsxs=h,W}var q={};var ne;function ce(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&(function(){function E(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===l?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case S:return"Fragment";case M:return"Profiler";case x:return"StrictMode";case N:return"Suspense";case b:return"SuspenseList";case $: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 K:return"Portal";case A:return e.displayName||"Context";case Q:return(e._context.displayName||"Context")+".Consumer";case G:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case F:return t=e.displayName||null,t!==null?t:E(e.type)||"Memo";case C:t=e._payload,e=e._init;try{return E(e(t))}catch{}}return null}function p(e){return""+e}function h(e){try{p(e);var t=!1}catch{t=!0}if(t){t=console;var s=t.error,c=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return s.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",c),p(e)}}function k(e){if(e===S)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===C)return"<...>";try{var t=E(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function d(){var e=m.A;return e===null?null:e.getOwner()}function a(){return Error("react-stack-top-frame")}function R(e){if(D.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function O(e,t){function s(){H||(H=!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)",t))}s.isReactWarning=!0,Object.defineProperty(e,"key",{get:s,configurable:!0})}function J(){var e=E(this.type);return P[e]||(P[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 g(e,t,s,c,I,U){var i=s.ref;return e={$$typeof:z,type:e,key:t,props:s,_owner:c},(i!==void 0?i:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:J}):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:I}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function v(e,t,s,c,I,U){var i=t.children;if(i!==void 0)if(c)if(V(i)){for(c=0;c<i.length;c++)L(i[c]);Object.freeze&&Object.freeze(i)}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 L(i);if(D.call(t,"key")){i=E(e);var j=Object.keys(t).filter(function(n){return n!=="key"});c=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",B[i+c]||(j=0<j.length?"{"+j.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,c,i,j,i),B[i+c]=!0)}if(i=null,s!==void 0&&(h(s),i=""+s),R(t)&&(h(t.key),i=""+t.key),"key"in t){s={};for(var r in t)r!=="key"&&(s[r]=t[r])}else s=t;return i&&O(s,typeof e=="function"?e.displayName||e.name||"Unknown":e),g(e,i,s,d(),I,U)}function L(e){Y(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===C&&(e._payload.status==="fulfilled"?Y(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function Y(e){return typeof e=="object"&&e!==null&&e.$$typeof===z}var T=f,z=Symbol.for("react.transitional.element"),K=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),M=Symbol.for("react.profiler"),Q=Symbol.for("react.consumer"),A=Symbol.for("react.context"),G=Symbol.for("react.forward_ref"),N=Symbol.for("react.suspense"),b=Symbol.for("react.suspense_list"),F=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),$=Symbol.for("react.activity"),l=Symbol.for("react.client.reference"),m=T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=Object.prototype.hasOwnProperty,V=Array.isArray,y=console.createTask?console.createTask:function(){return null};T={react_stack_bottom_frame:function(e){return e()}};var H,P={},w=T.react_stack_bottom_frame.bind(T,a)(),X=y(k(a)),B={};q.Fragment=S,q.jsx=function(e,t,s){var c=1e4>m.recentlyCreatedOwnerStacks++;return v(e,t,s,!1,c?Error("react-stack-top-frame"):w,c?y(k(e)):X)},q.jsxs=function(e,t,s){var c=1e4>m.recentlyCreatedOwnerStacks++;return v(e,t,s,!0,c?Error("react-stack-top-frame"):w,c?y(k(e)):X)}})()),q}var se;function ie(){return se||(se=1,process.env.NODE_ENV==="production"?Z.exports=le():Z.exports=ce()),Z.exports}var o=ie();const re="UNIVERSAL_SELECT_VALUE";function ue({options:E=[],loadAsyncOptions:p,value:h,onChange:k,label:d,isMultiSelectAllow:a=!1,closeOnOutsideClick:R=!0,isClearOptionAllow:O=!0,isSearchAllow:J=!0,selectStyle:g={},renderOption:v,renderSelectedOptionChip:L}){const[Y,T]=f.useState(!1),[z,K]=f.useState(()=>{const r=localStorage.getItem(re);return r?JSON.parse(r):a?[]:null}),[S,x]=f.useState(-1),[M,Q]=f.useState([]),[A,G]=f.useState(!1),[N,b]=f.useState(""),F=h!==void 0?h:z,C=f.useRef(null),$=f.useRef(null),l=a?Array.isArray(F)?F:[]:F,m=p?M:E;f.useEffect(()=>{localStorage.setItem(re,JSON.stringify(l))},[l]),f.useEffect(()=>{!a&&l?.label&&b(l.label)},[l,a]);const D=async(r=!1)=>{if(!p)return;G(!0);const n=await p(N);G(!1),n&&Q(u=>r?n:[...u,...n])};f.useEffect(()=>{const r=setTimeout(()=>{D(!0)},400);return()=>clearTimeout(r)},[N]),f.useEffect(()=>{if(R)return document.addEventListener("click",P),()=>{document.removeEventListener("click",P)}},[R]),f.useLayoutEffect(()=>{C?.current?.scrollIntoView({top:0})},[S]);const V=f.useMemo(()=>p||!J?m:m.filter(r=>r.label.toLowerCase().includes(N.toLowerCase())),[m,N,p]),y=r=>{h===void 0&&K(r),k?.(r)},H=r=>a?l.some(n=>n.id===r.id):l?.id===r.id,P=()=>{if(a)b("");else try{const r=localStorage.getItem(re),n=r?JSON.parse(r):null;b(n?.label||"")}catch{b("")}x(-1),T(!1)},w=r=>{if(!a){y(r),b(r.label),P();return}const u=l.some(_=>_.id===r.id)?l.filter(_=>_.id!==r.id):[...l,r];y(u),b(""),requestAnimationFrame(()=>{$.current?.focus()})},X=r=>{if(m.length)if(r.key==="ArrowDown")x(n=>(n+1)%m.length);else if(r.key==="ArrowUp")x(n=>n<=0?m.length-1:n-1);else if(r.key==="Enter"){r.preventDefault();const n=m[S];if(!n||n.disabled)return;w(n),requestAnimationFrame(()=>{$.current?.focus()})}else r.key==="Escape"&&P()},B=r=>{A||r.target.scrollTop+r.target.clientHeight>=r.target.scrollHeight-5&&D()},e=r=>{r.stopPropagation(),x(-1),T(n=>!n)},t=r=>{b(r.target.value),x(-1)},s=(r,n,u)=>({...r&&g?.disabledOption,...n&&g?.highlightOption,...u&&g?.selectedOption}),c=(r,n,u)=>["custom-select-option",r&&"disabled",u&&"selected",n&&"highlight"].join(" "),I=()=>V.map((r,n)=>{const u=r.disabled,_=n===S,ee=H(r),ae=()=>a?o.jsxs("div",{className:`option-label ${u&&"disabled"}`,children:[o.jsx("input",{type:"checkbox",checked:ee,disabled:r.disabled,readOnly:!0}),v?v(r):r.label]}):o.jsx("span",{className:"option-label",children:v?v(r):r.label});return o.jsx("li",{ref:_?C:null,style:s(u,_,ee),className:c(u,_,ee),onClick:oe=>{oe.stopPropagation(),w(r)},children:ae()},r.id)}),U=r=>{r.stopPropagation(),y(a?[]:null),b(""),x(-1)},i=()=>{const r=l&&typeof l=="object"&&"id"in l,n=a?l.length>0:r;return A?o.jsx("span",{children:"Loading..."}):O&&n?o.jsx("span",{onClick:U,children:"Clear"}):o.jsx("span",{children:Y?"↑":"↓"})},j=()=>{const r=()=>l.map(u=>o.jsxs("div",{className:"multiple-options",children:[L?L(u):u.label,o.jsx("span",{onClick:_=>{_.stopPropagation(),w(u)},children:"⤬"})]},u.id)),n=()=>o.jsx("input",{onChange:t,onClick:u=>{u.stopPropagation(),T(!0)},placeholder:"Search Here",value:N});return J?a?o.jsxs("div",{className:"multiple-options-container",children:[r(),n()]}):n():a?l.length<=0?o.jsx("p",{children:"Please Select Options"}):o.jsx("div",{className:"multiple-options-container",children:r()}):o.jsx("p",{children:l?v?v(l):l.label:"Please Select Option"})};return o.jsxs("div",{className:"custom-select",style:g.selectWrapper&&g.selectWrapper,children:[o.jsx("label",{className:"custom-select-label",children:d}),o.jsxs("div",{type:"button",ref:$,className:"custom-select-trigger",tabIndex:0,onClick:e,onKeyDown:X,children:[j(),i()]}),Y&&o.jsxs(o.Fragment,{children:[V.length>0&&o.jsxs("ul",{className:"custom-select-options",style:g.optionsList&&g.optionsList,onScroll:B,children:[I(),A&&o.jsx("li",{className:"search-view",children:"Loading..."})]}),!A&&V.length===0&&o.jsx("div",{className:"no-custom-select-options",children:o.jsx("p",{className:"no-custom-select-option",children:"No Option Available"})})]})]})}module.exports=ue;
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import ie, { useState as I, useRef as ne, useEffect as Z, useLayoutEffect as ue, useMemo as fe } from "react";
|
|
2
|
+
var K = { exports: {} }, W = {};
|
|
3
|
+
var ae;
|
|
4
|
+
function de() {
|
|
5
|
+
if (ae) return W;
|
|
6
|
+
ae = 1;
|
|
7
|
+
var b = /* @__PURE__ */ Symbol.for("react.transitional.element"), m = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
8
|
+
function h(j, f, s) {
|
|
9
|
+
var _ = null;
|
|
10
|
+
if (s !== void 0 && (_ = "" + s), f.key !== void 0 && (_ = "" + f.key), "key" in f) {
|
|
11
|
+
s = {};
|
|
12
|
+
for (var k in f)
|
|
13
|
+
k !== "key" && (s[k] = f[k]);
|
|
14
|
+
} else s = f;
|
|
15
|
+
return f = s.ref, {
|
|
16
|
+
$$typeof: b,
|
|
17
|
+
type: j,
|
|
18
|
+
key: _,
|
|
19
|
+
ref: f !== void 0 ? f : null,
|
|
20
|
+
props: s
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return W.Fragment = m, W.jsx = h, W.jsxs = h, W;
|
|
24
|
+
}
|
|
25
|
+
var J = {};
|
|
26
|
+
var se;
|
|
27
|
+
function me() {
|
|
28
|
+
return se || (se = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
29
|
+
function b(e) {
|
|
30
|
+
if (e == null) return null;
|
|
31
|
+
if (typeof e == "function")
|
|
32
|
+
return e.$$typeof === l ? null : e.displayName || e.name || null;
|
|
33
|
+
if (typeof e == "string") return e;
|
|
34
|
+
switch (e) {
|
|
35
|
+
case O:
|
|
36
|
+
return "Fragment";
|
|
37
|
+
case Q:
|
|
38
|
+
return "Profiler";
|
|
39
|
+
case T:
|
|
40
|
+
return "StrictMode";
|
|
41
|
+
case N:
|
|
42
|
+
return "Suspense";
|
|
43
|
+
case p:
|
|
44
|
+
return "SuspenseList";
|
|
45
|
+
case $:
|
|
46
|
+
return "Activity";
|
|
47
|
+
}
|
|
48
|
+
if (typeof e == "object")
|
|
49
|
+
switch (typeof e.tag == "number" && console.error(
|
|
50
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
51
|
+
), e.$$typeof) {
|
|
52
|
+
case M:
|
|
53
|
+
return "Portal";
|
|
54
|
+
case P:
|
|
55
|
+
return e.displayName || "Context";
|
|
56
|
+
case ee:
|
|
57
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
58
|
+
case G:
|
|
59
|
+
var t = e.render;
|
|
60
|
+
return e = e.displayName, e || (e = t.displayName || t.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
61
|
+
case F:
|
|
62
|
+
return t = e.displayName || null, t !== null ? t : b(e.type) || "Memo";
|
|
63
|
+
case A:
|
|
64
|
+
t = e._payload, e = e._init;
|
|
65
|
+
try {
|
|
66
|
+
return b(e(t));
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function m(e) {
|
|
73
|
+
return "" + e;
|
|
74
|
+
}
|
|
75
|
+
function h(e) {
|
|
76
|
+
try {
|
|
77
|
+
m(e);
|
|
78
|
+
var t = !1;
|
|
79
|
+
} catch {
|
|
80
|
+
t = !0;
|
|
81
|
+
}
|
|
82
|
+
if (t) {
|
|
83
|
+
t = console;
|
|
84
|
+
var a = t.error, c = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
85
|
+
return a.call(
|
|
86
|
+
t,
|
|
87
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
|
+
c
|
|
89
|
+
), m(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function j(e) {
|
|
93
|
+
if (e === O) return "<>";
|
|
94
|
+
if (typeof e == "object" && e !== null && e.$$typeof === A)
|
|
95
|
+
return "<...>";
|
|
96
|
+
try {
|
|
97
|
+
var t = b(e);
|
|
98
|
+
return t ? "<" + t + ">" : "<...>";
|
|
99
|
+
} catch {
|
|
100
|
+
return "<...>";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function f() {
|
|
104
|
+
var e = d.A;
|
|
105
|
+
return e === null ? null : e.getOwner();
|
|
106
|
+
}
|
|
107
|
+
function s() {
|
|
108
|
+
return Error("react-stack-top-frame");
|
|
109
|
+
}
|
|
110
|
+
function _(e) {
|
|
111
|
+
if (D.call(e, "key")) {
|
|
112
|
+
var t = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
113
|
+
if (t && t.isReactWarning) return !1;
|
|
114
|
+
}
|
|
115
|
+
return e.key !== void 0;
|
|
116
|
+
}
|
|
117
|
+
function k(e, t) {
|
|
118
|
+
function a() {
|
|
119
|
+
H || (H = !0, console.error(
|
|
120
|
+
"%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)",
|
|
121
|
+
t
|
|
122
|
+
));
|
|
123
|
+
}
|
|
124
|
+
a.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
125
|
+
get: a,
|
|
126
|
+
configurable: !0
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function q() {
|
|
130
|
+
var e = b(this.type);
|
|
131
|
+
return S[e] || (S[e] = !0, console.error(
|
|
132
|
+
"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."
|
|
133
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
134
|
+
}
|
|
135
|
+
function E(e, t, a, c, w, U) {
|
|
136
|
+
var i = a.ref;
|
|
137
|
+
return e = {
|
|
138
|
+
$$typeof: z,
|
|
139
|
+
type: e,
|
|
140
|
+
key: t,
|
|
141
|
+
props: a,
|
|
142
|
+
_owner: c
|
|
143
|
+
}, (i !== void 0 ? i : null) !== null ? Object.defineProperty(e, "ref", {
|
|
144
|
+
enumerable: !1,
|
|
145
|
+
get: q
|
|
146
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
147
|
+
configurable: !1,
|
|
148
|
+
enumerable: !1,
|
|
149
|
+
writable: !0,
|
|
150
|
+
value: 0
|
|
151
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
152
|
+
configurable: !1,
|
|
153
|
+
enumerable: !1,
|
|
154
|
+
writable: !0,
|
|
155
|
+
value: null
|
|
156
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
157
|
+
configurable: !1,
|
|
158
|
+
enumerable: !1,
|
|
159
|
+
writable: !0,
|
|
160
|
+
value: w
|
|
161
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
162
|
+
configurable: !1,
|
|
163
|
+
enumerable: !1,
|
|
164
|
+
writable: !0,
|
|
165
|
+
value: U
|
|
166
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
167
|
+
}
|
|
168
|
+
function g(e, t, a, c, w, U) {
|
|
169
|
+
var i = t.children;
|
|
170
|
+
if (i !== void 0)
|
|
171
|
+
if (c)
|
|
172
|
+
if (V(i)) {
|
|
173
|
+
for (c = 0; c < i.length; c++)
|
|
174
|
+
L(i[c]);
|
|
175
|
+
Object.freeze && Object.freeze(i);
|
|
176
|
+
} else
|
|
177
|
+
console.error(
|
|
178
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
179
|
+
);
|
|
180
|
+
else L(i);
|
|
181
|
+
if (D.call(t, "key")) {
|
|
182
|
+
i = b(e);
|
|
183
|
+
var x = Object.keys(t).filter(function(n) {
|
|
184
|
+
return n !== "key";
|
|
185
|
+
});
|
|
186
|
+
c = 0 < x.length ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}", B[i + c] || (x = 0 < x.length ? "{" + x.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
188
|
+
let props = %s;
|
|
189
|
+
<%s {...props} />
|
|
190
|
+
React keys must be passed directly to JSX without using spread:
|
|
191
|
+
let props = %s;
|
|
192
|
+
<%s key={someKey} {...props} />`,
|
|
193
|
+
c,
|
|
194
|
+
i,
|
|
195
|
+
x,
|
|
196
|
+
i
|
|
197
|
+
), B[i + c] = !0);
|
|
198
|
+
}
|
|
199
|
+
if (i = null, a !== void 0 && (h(a), i = "" + a), _(t) && (h(t.key), i = "" + t.key), "key" in t) {
|
|
200
|
+
a = {};
|
|
201
|
+
for (var r in t)
|
|
202
|
+
r !== "key" && (a[r] = t[r]);
|
|
203
|
+
} else a = t;
|
|
204
|
+
return i && k(
|
|
205
|
+
a,
|
|
206
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
207
|
+
), E(
|
|
208
|
+
e,
|
|
209
|
+
i,
|
|
210
|
+
a,
|
|
211
|
+
f(),
|
|
212
|
+
w,
|
|
213
|
+
U
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function L(e) {
|
|
217
|
+
Y(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === A && (e._payload.status === "fulfilled" ? Y(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
218
|
+
}
|
|
219
|
+
function Y(e) {
|
|
220
|
+
return typeof e == "object" && e !== null && e.$$typeof === z;
|
|
221
|
+
}
|
|
222
|
+
var R = ie, z = /* @__PURE__ */ Symbol.for("react.transitional.element"), M = /* @__PURE__ */ Symbol.for("react.portal"), O = /* @__PURE__ */ Symbol.for("react.fragment"), T = /* @__PURE__ */ Symbol.for("react.strict_mode"), Q = /* @__PURE__ */ Symbol.for("react.profiler"), ee = /* @__PURE__ */ Symbol.for("react.consumer"), P = /* @__PURE__ */ Symbol.for("react.context"), G = /* @__PURE__ */ Symbol.for("react.forward_ref"), N = /* @__PURE__ */ Symbol.for("react.suspense"), p = /* @__PURE__ */ Symbol.for("react.suspense_list"), F = /* @__PURE__ */ Symbol.for("react.memo"), A = /* @__PURE__ */ Symbol.for("react.lazy"), $ = /* @__PURE__ */ Symbol.for("react.activity"), l = /* @__PURE__ */ Symbol.for("react.client.reference"), d = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, D = Object.prototype.hasOwnProperty, V = Array.isArray, y = console.createTask ? console.createTask : function() {
|
|
223
|
+
return null;
|
|
224
|
+
};
|
|
225
|
+
R = {
|
|
226
|
+
react_stack_bottom_frame: function(e) {
|
|
227
|
+
return e();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var H, S = {}, C = R.react_stack_bottom_frame.bind(
|
|
231
|
+
R,
|
|
232
|
+
s
|
|
233
|
+
)(), X = y(j(s)), B = {};
|
|
234
|
+
J.Fragment = O, J.jsx = function(e, t, a) {
|
|
235
|
+
var c = 1e4 > d.recentlyCreatedOwnerStacks++;
|
|
236
|
+
return g(
|
|
237
|
+
e,
|
|
238
|
+
t,
|
|
239
|
+
a,
|
|
240
|
+
!1,
|
|
241
|
+
c ? Error("react-stack-top-frame") : C,
|
|
242
|
+
c ? y(j(e)) : X
|
|
243
|
+
);
|
|
244
|
+
}, J.jsxs = function(e, t, a) {
|
|
245
|
+
var c = 1e4 > d.recentlyCreatedOwnerStacks++;
|
|
246
|
+
return g(
|
|
247
|
+
e,
|
|
248
|
+
t,
|
|
249
|
+
a,
|
|
250
|
+
!0,
|
|
251
|
+
c ? Error("react-stack-top-frame") : C,
|
|
252
|
+
c ? y(j(e)) : X
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
})()), J;
|
|
256
|
+
}
|
|
257
|
+
var oe;
|
|
258
|
+
function pe() {
|
|
259
|
+
return oe || (oe = 1, process.env.NODE_ENV === "production" ? K.exports = de() : K.exports = me()), K.exports;
|
|
260
|
+
}
|
|
261
|
+
var o = pe();
|
|
262
|
+
const te = "UNIVERSAL_SELECT_VALUE";
|
|
263
|
+
function he({
|
|
264
|
+
options: b = [],
|
|
265
|
+
loadAsyncOptions: m,
|
|
266
|
+
value: h,
|
|
267
|
+
onChange: j,
|
|
268
|
+
label: f,
|
|
269
|
+
isMultiSelectAllow: s = !1,
|
|
270
|
+
closeOnOutsideClick: _ = !0,
|
|
271
|
+
isClearOptionAllow: k = !0,
|
|
272
|
+
isSearchAllow: q = !0,
|
|
273
|
+
selectStyle: E = {},
|
|
274
|
+
renderOption: g,
|
|
275
|
+
renderSelectedOptionChip: L
|
|
276
|
+
}) {
|
|
277
|
+
const [Y, R] = I(!1), [z, M] = I(() => {
|
|
278
|
+
const r = localStorage.getItem(te);
|
|
279
|
+
return r ? JSON.parse(r) : s ? [] : null;
|
|
280
|
+
}), [O, T] = I(-1), [Q, ee] = I([]), [P, G] = I(!1), [N, p] = I(""), F = h !== void 0 ? h : z, A = ne(null), $ = ne(null), l = s ? Array.isArray(F) ? F : [] : F, d = m ? Q : b;
|
|
281
|
+
Z(() => {
|
|
282
|
+
localStorage.setItem(te, JSON.stringify(l));
|
|
283
|
+
}, [l]), Z(() => {
|
|
284
|
+
!s && l?.label && p(l.label);
|
|
285
|
+
}, [l, s]);
|
|
286
|
+
const D = async (r = !1) => {
|
|
287
|
+
if (!m) return;
|
|
288
|
+
G(!0);
|
|
289
|
+
const n = await m(N);
|
|
290
|
+
G(!1), n && ee(
|
|
291
|
+
(u) => r ? n : [...u, ...n]
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
Z(() => {
|
|
295
|
+
const r = setTimeout(() => {
|
|
296
|
+
D(!0);
|
|
297
|
+
}, 400);
|
|
298
|
+
return () => clearTimeout(r);
|
|
299
|
+
}, [N]), Z(() => {
|
|
300
|
+
if (_)
|
|
301
|
+
return document.addEventListener("click", S), () => {
|
|
302
|
+
document.removeEventListener("click", S);
|
|
303
|
+
};
|
|
304
|
+
}, [_]), ue(() => {
|
|
305
|
+
A?.current?.scrollIntoView({ top: 0 });
|
|
306
|
+
}, [O]);
|
|
307
|
+
const V = fe(() => m || !q ? d : d.filter(
|
|
308
|
+
(r) => r.label.toLowerCase().includes(N.toLowerCase())
|
|
309
|
+
), [d, N, m]), y = (r) => {
|
|
310
|
+
h === void 0 && M(r), j?.(r);
|
|
311
|
+
}, H = (r) => s ? l.some((n) => n.id === r.id) : l?.id === r.id, S = () => {
|
|
312
|
+
if (s)
|
|
313
|
+
p("");
|
|
314
|
+
else
|
|
315
|
+
try {
|
|
316
|
+
const r = localStorage.getItem(te), n = r ? JSON.parse(r) : null;
|
|
317
|
+
p(n?.label || "");
|
|
318
|
+
} catch {
|
|
319
|
+
p("");
|
|
320
|
+
}
|
|
321
|
+
T(-1), R(!1);
|
|
322
|
+
}, C = (r) => {
|
|
323
|
+
if (!s) {
|
|
324
|
+
y(r), p(r.label), S();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const u = l.some((v) => v.id === r.id) ? l.filter((v) => v.id !== r.id) : [...l, r];
|
|
328
|
+
y(u), p(""), requestAnimationFrame(() => {
|
|
329
|
+
$.current?.focus();
|
|
330
|
+
});
|
|
331
|
+
}, X = (r) => {
|
|
332
|
+
if (d.length)
|
|
333
|
+
if (r.key === "ArrowDown")
|
|
334
|
+
T((n) => (n + 1) % d.length);
|
|
335
|
+
else if (r.key === "ArrowUp")
|
|
336
|
+
T(
|
|
337
|
+
(n) => n <= 0 ? d.length - 1 : n - 1
|
|
338
|
+
);
|
|
339
|
+
else if (r.key === "Enter") {
|
|
340
|
+
r.preventDefault();
|
|
341
|
+
const n = d[O];
|
|
342
|
+
if (!n || n.disabled) return;
|
|
343
|
+
C(n), requestAnimationFrame(() => {
|
|
344
|
+
$.current?.focus();
|
|
345
|
+
});
|
|
346
|
+
} else r.key === "Escape" && S();
|
|
347
|
+
}, B = (r) => {
|
|
348
|
+
P || r.target.scrollTop + r.target.clientHeight >= r.target.scrollHeight - 5 && D();
|
|
349
|
+
}, e = (r) => {
|
|
350
|
+
r.stopPropagation(), T(-1), R((n) => !n);
|
|
351
|
+
}, t = (r) => {
|
|
352
|
+
p(r.target.value), T(-1);
|
|
353
|
+
}, a = (r, n, u) => ({
|
|
354
|
+
...r && E?.disabledOption,
|
|
355
|
+
...n && E?.highlightOption,
|
|
356
|
+
...u && E?.selectedOption
|
|
357
|
+
}), c = (r, n, u) => [
|
|
358
|
+
"custom-select-option",
|
|
359
|
+
r && "disabled",
|
|
360
|
+
u && "selected",
|
|
361
|
+
n && "highlight"
|
|
362
|
+
].join(" "), w = () => V.map((r, n) => {
|
|
363
|
+
const u = r.disabled, v = n === O, re = H(r), le = () => s ? /* @__PURE__ */ o.jsxs("div", { className: `option-label ${u && "disabled"}`, children: [
|
|
364
|
+
/* @__PURE__ */ o.jsx(
|
|
365
|
+
"input",
|
|
366
|
+
{
|
|
367
|
+
type: "checkbox",
|
|
368
|
+
checked: re,
|
|
369
|
+
disabled: r.disabled,
|
|
370
|
+
readOnly: !0
|
|
371
|
+
}
|
|
372
|
+
),
|
|
373
|
+
g ? g(r) : r.label
|
|
374
|
+
] }) : /* @__PURE__ */ o.jsx("span", { className: "option-label", children: g ? g(r) : r.label });
|
|
375
|
+
return /* @__PURE__ */ o.jsx(
|
|
376
|
+
"li",
|
|
377
|
+
{
|
|
378
|
+
ref: v ? A : null,
|
|
379
|
+
style: a(u, v, re),
|
|
380
|
+
className: c(u, v, re),
|
|
381
|
+
onClick: (ce) => {
|
|
382
|
+
ce.stopPropagation(), C(r);
|
|
383
|
+
},
|
|
384
|
+
children: le()
|
|
385
|
+
},
|
|
386
|
+
r.id
|
|
387
|
+
);
|
|
388
|
+
}), U = (r) => {
|
|
389
|
+
r.stopPropagation(), y(s ? [] : null), p(""), T(-1);
|
|
390
|
+
}, i = () => {
|
|
391
|
+
const r = l && typeof l == "object" && "id" in l, n = s ? l.length > 0 : r;
|
|
392
|
+
return P ? /* @__PURE__ */ o.jsx("span", { children: "Loading..." }) : k && n ? /* @__PURE__ */ o.jsx("span", { onClick: U, children: "Clear" }) : /* @__PURE__ */ o.jsx("span", { children: Y ? "↑" : "↓" });
|
|
393
|
+
}, x = () => {
|
|
394
|
+
const r = () => l.map((u) => /* @__PURE__ */ o.jsxs("div", { className: "multiple-options", children: [
|
|
395
|
+
L ? L(u) : u.label,
|
|
396
|
+
/* @__PURE__ */ o.jsx(
|
|
397
|
+
"span",
|
|
398
|
+
{
|
|
399
|
+
onClick: (v) => {
|
|
400
|
+
v.stopPropagation(), C(u);
|
|
401
|
+
},
|
|
402
|
+
children: "⤬"
|
|
403
|
+
}
|
|
404
|
+
)
|
|
405
|
+
] }, u.id)), n = () => /* @__PURE__ */ o.jsx(
|
|
406
|
+
"input",
|
|
407
|
+
{
|
|
408
|
+
onChange: t,
|
|
409
|
+
onClick: (u) => {
|
|
410
|
+
u.stopPropagation(), R(!0);
|
|
411
|
+
},
|
|
412
|
+
placeholder: "Search Here",
|
|
413
|
+
value: N
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
return q ? s ? /* @__PURE__ */ o.jsxs("div", { className: "multiple-options-container", children: [
|
|
417
|
+
r(),
|
|
418
|
+
n()
|
|
419
|
+
] }) : n() : s ? l.length <= 0 ? /* @__PURE__ */ o.jsx("p", { children: "Please Select Options" }) : /* @__PURE__ */ o.jsx("div", { className: "multiple-options-container", children: r() }) : /* @__PURE__ */ o.jsx("p", { children: l ? g ? g(l) : l.label : "Please Select Option" });
|
|
420
|
+
};
|
|
421
|
+
return /* @__PURE__ */ o.jsxs(
|
|
422
|
+
"div",
|
|
423
|
+
{
|
|
424
|
+
className: "custom-select",
|
|
425
|
+
style: E.selectWrapper && E.selectWrapper,
|
|
426
|
+
children: [
|
|
427
|
+
/* @__PURE__ */ o.jsx("label", { className: "custom-select-label", children: f }),
|
|
428
|
+
/* @__PURE__ */ o.jsxs(
|
|
429
|
+
"div",
|
|
430
|
+
{
|
|
431
|
+
type: "button",
|
|
432
|
+
ref: $,
|
|
433
|
+
className: "custom-select-trigger",
|
|
434
|
+
tabIndex: 0,
|
|
435
|
+
onClick: e,
|
|
436
|
+
onKeyDown: X,
|
|
437
|
+
children: [
|
|
438
|
+
x(),
|
|
439
|
+
i()
|
|
440
|
+
]
|
|
441
|
+
}
|
|
442
|
+
),
|
|
443
|
+
Y && /* @__PURE__ */ o.jsxs(o.Fragment, { children: [
|
|
444
|
+
V.length > 0 && /* @__PURE__ */ o.jsxs(
|
|
445
|
+
"ul",
|
|
446
|
+
{
|
|
447
|
+
className: "custom-select-options",
|
|
448
|
+
style: E.optionsList && E.optionsList,
|
|
449
|
+
onScroll: B,
|
|
450
|
+
children: [
|
|
451
|
+
w(),
|
|
452
|
+
P && /* @__PURE__ */ o.jsx("li", { className: "search-view", children: "Loading..." })
|
|
453
|
+
]
|
|
454
|
+
}
|
|
455
|
+
),
|
|
456
|
+
!P && V.length === 0 && /* @__PURE__ */ o.jsx("div", { className: "no-custom-select-options", children: /* @__PURE__ */ o.jsx("p", { className: "no-custom-select-option", children: "No Option Available" }) })
|
|
457
|
+
] })
|
|
458
|
+
]
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
export {
|
|
463
|
+
he as default
|
|
464
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kamleshchandel/react-select-kc",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Universal controlled and uncontrolled select component for React",
|
|
5
|
+
"main": "dist/react-select-kc.cjs.js",
|
|
6
|
+
"module": "dist/react-select-kc.es.js",
|
|
7
|
+
"types": "types/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"types"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/react-select-kc.es.js",
|
|
15
|
+
"require": "./dist/react-select-kc.cjs.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": ">=17",
|
|
20
|
+
"react-dom": ">=17"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "vite build",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"react",
|
|
28
|
+
"select",
|
|
29
|
+
"dropdown",
|
|
30
|
+
"universal-select",
|
|
31
|
+
"react-component"
|
|
32
|
+
],
|
|
33
|
+
"author": "Kamlesh Chandel",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
37
|
+
"vite": "^7.3.1"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export interface UniversalSelectOption {
|
|
4
|
+
id: string | number;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface UniversalSelectProps {
|
|
10
|
+
options?: UniversalSelectOption[];
|
|
11
|
+
loadAsyncOptions?: (query: string) => Promise<UniversalSelectOption[]>;
|
|
12
|
+
value?: UniversalSelectOption | UniversalSelectOption[] | null;
|
|
13
|
+
onChange?: (
|
|
14
|
+
value: UniversalSelectOption | UniversalSelectOption[] | null,
|
|
15
|
+
) => void;
|
|
16
|
+
label?: string;
|
|
17
|
+
isMultiSelectAllow?: boolean;
|
|
18
|
+
closeOnOutsideClick?: boolean;
|
|
19
|
+
isClearOptionAllow?: boolean;
|
|
20
|
+
isSearchAllow?: boolean;
|
|
21
|
+
selectStyle?: Record<string, React.CSSProperties>;
|
|
22
|
+
renderOption?: (option: UniversalSelectOption) => React.ReactNode;
|
|
23
|
+
renderSelectedOptionChip?: (option: UniversalSelectOption) => React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare const UniversalSelect: React.FC<UniversalSelectProps>;
|
|
27
|
+
|
|
28
|
+
export default UniversalSelect;
|