@instincthub/react-ui 0.1.21 → 0.1.23
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.
|
@@ -170,13 +170,63 @@
|
|
|
170
170
|
border-radius: 5px;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
/* Selected Options Styles */
|
|
174
|
+
.ihub-selected-options {
|
|
175
|
+
list-style: none;
|
|
176
|
+
padding: 0;
|
|
177
|
+
margin: 0;
|
|
178
|
+
border-top: 1px solid var(--borderDefault);
|
|
179
|
+
margin-top: 10px;
|
|
180
|
+
padding-top: 10px;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.ihub-selected-options h4 {
|
|
184
|
+
margin: 0 0 10px 0;
|
|
185
|
+
color: var(--Gunmetal);
|
|
186
|
+
font-weight: 600;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.ihub-selected-options li {
|
|
190
|
+
background-color: rgba(0, 131, 143, 0.1);
|
|
191
|
+
border: 1px solid var(--DarkCyan);
|
|
192
|
+
border-radius: 4px;
|
|
193
|
+
margin-bottom: 5px;
|
|
194
|
+
padding: 8px 12px;
|
|
195
|
+
display: flex;
|
|
196
|
+
align-items: center;
|
|
197
|
+
justify-content: space-between;
|
|
198
|
+
font-size: 14px;
|
|
199
|
+
color: var(--Gunmetal);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.ihub-selected-options .ihub-delete-icon {
|
|
203
|
+
color: var(--Danger);
|
|
204
|
+
cursor: pointer;
|
|
205
|
+
font-size: 18px !important;
|
|
206
|
+
margin-left: auto;
|
|
207
|
+
transition: color 0.2s ease, transform 0.1s ease;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.ihub-selected-options .ihub-delete-icon:hover {
|
|
211
|
+
color: var(--TurkishRose);
|
|
212
|
+
transform: scale(1.1);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.ihub-selected-options .ihub-delete-icon:active {
|
|
216
|
+
transform: scale(0.95);
|
|
217
|
+
}
|
|
218
|
+
|
|
173
219
|
/* Responsive adjustments */
|
|
174
220
|
@media (max-width: 576px) {
|
|
175
221
|
.ihub-react-search {
|
|
176
222
|
max-width: 100%;
|
|
177
223
|
}
|
|
178
|
-
|
|
224
|
+
|
|
179
225
|
.ihub-search-result-item {
|
|
180
226
|
padding: 14px 12px;
|
|
181
227
|
}
|
|
228
|
+
|
|
229
|
+
.ihub-selected-options li {
|
|
230
|
+
padding: 10px 12px;
|
|
231
|
+
}
|
|
182
232
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{slicedToArray as e,asyncToGenerator as
|
|
1
|
+
import{slicedToArray as e,asyncToGenerator as n,regeneratorRuntime as r,toConsumableArray as a,typeof as i,createForOfIteratorHelper as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as l,jsxs as c}from"react/jsx-runtime";import{memo as o,useState as s,useEffect as u,useCallback as d}from"react";import{reqOptions as h,API_HOST_URL as m}from"../lib/helpFunction.js";import"../lib/utils.js";import f from"@mui/icons-material/SearchOutlined";import p from"@mui/icons-material/Check";import v from"@mui/icons-material/CloseOutlined";var b=function(e){if(!e||!Array.isArray(e))return[];var n,r=[],l=t(e);try{for(l.s();!(n=l.n()).done;){var c=n.value;Array.isArray(c)?r.push.apply(r,a(b(c))):c&&"object"===i(c)&&c.id&&r.push(c)}}catch(e){l.e(e)}finally{l.f()}var o=r.filter((function(e,n,r){return r.findIndex((function(n){return n.id===e.id}))===n}));return o};function y(t){var o=t.label,y=t.token,g=t.handle,N=t.selected,k=t.setSelected,x=t.appLabel,S=t.modelName,j=t.filterChannel,C=void 0!==j&&j,O=t.limitQuery,_=void 0===O?5:O,D=t.limitSelect,w=void 0===D?0:D,F=t.options,T=t.keyName,A=void 0===T?"title":T,E=t.placeholder,B=void 0===E?"Search by Username or Email":E,I=t.searchUrl,q=t.err,H=void 0!==q&&q,P=t.required,U=void 0!==P&&P,G=s(""),J=e(G,2),K=J[0],L=J[1],R=s([]),Q=e(R,2),z=Q[0],M=Q[1],V=s(!1),W=e(V,2),X=W[0],Y=W[1],Z=s(null),$=e(Z,2),ee=$[0],ne=$[1];u((function(){N&&N.length>0&&0===z.length&&M(N)}),[N]),u((function(){M(F||[])}),[F]),u((function(){if(N&&N.length>0){var e=b(N);JSON.stringify(e)!==JSON.stringify(N)&&console.warn("SearchObjectsFromDB: Detected malformed selected array. Parent should provide flattened data:",{original:N,expectedFormat:e,keyName:A})}console.log("SearchObjectsFromDB Debug:",{keyName:A,selectedLength:(null==N?void 0:N.length)||0,selectedSample:null==N?void 0:N[0],label:o})}),[N,A,o]);var re,ae=d(n(r().mark((function e(){var n,i,t,l,c;return r().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y(!0),ne(null),n=h("GET",null,y),i=I?I.includes("/?")?"".concat(I,"&search=").concat(K):"".concat(I,"?search=").concat(K):x?"".concat(m,"channels/").concat(g,"/dynamic-search/?app_label=").concat(x,"&model_name=").concat(S,"&value=").concat(K,"&filter_channel=").concat(C):"".concat(m,"auth/").concat(g,"/search-user/").concat(K,"/?limit=").concat(_),e.prev=4,e.next=7,fetch(i,n);case 7:if((t=e.sent).ok){e.next=10;break}throw new Error("HTTP error ".concat(t.status));case 10:return e.next=12,t.json();case 12:l=e.sent,M([].concat(a(l.results||[]),a(F||[]))),e.next=22;break;case 16:e.prev=16,e.t0=e.catch(4),c=e.t0 instanceof Error?e.t0.message:"Unknown error occurred",console.error("Error fetching search results:",c),ne(c),M(a(F||[]));case 22:return e.prev=22,Y(!1),e.finish(22);case 25:case"end":return e.stop()}}),e,null,[[4,16,22,25]])}))),[K,y,I,x,S,g,C,_]),ie=d((function(e){"Enter"===e.key&&(e.preventDefault(),ae())}),[ae]),te=d((function(){L(""),M(a(F||[])),ne(null)}),[]),le=d((function(e){return!(!e||!N||0===N.length)&&b(N).some((function(n){if(!n)return!1;var r="object"===i(n)?null==n?void 0:n.id:n,a=(null==e?void 0:e.username)||(null==e?void 0:e.id);return r===a&&null!=r&&null!=a}))}),[N]),ce=d((function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e&&e.id&&N){var r=b(N),i=r.find((function(n){return(null==n?void 0:n.id)===e.id}));if(n){var t=r.filter((function(n){return(null==n?void 0:n.id)!==e.id}));k(t)}else!i&&(0===w||r.length<w)?k([].concat(a(r),[e])):1===w&&k([e])}}),[N,k,w]);return l("div",{className:"ihub-react-search-container",children:c("div",{className:"ihub-react-search card",children:[o&&c("h4",{className:"ihub-fs-sm ihub-mt-2 ihub-mb-2",children:[o," ",U&&l("span",{className:"ihub-required",children:"*"})]}),c("div",{className:"ihub-search-input",children:[l("input",{type:"text",placeholder:B,onKeyDown:ie,value:K,onChange:function(e){return L(e.target.value)},disabled:X,required:U&&!N.length}),c("div",{className:"ihub-search-icons",children:[K&&l(v,{onClick:te,className:"ihub-search-icon ihub-close-icon"}),l(f,{onClick:ae,className:"ihub-search-icon ihub-search-button ".concat(X?"ihub-disabled":"")})]})]}),X&&l("div",{className:"ihub-loading",children:"Searching..."}),ee&&l("div",{className:"ihub-search-error",children:ee}),c("ul",{className:"ihub-search-results",children:[null==z?void 0:z.map((function(e,n){return c("li",{className:"ihub-search-result-item ihub-valid",onClick:function(){return e&&ce(e)},children:[le(e)&&l(p,{className:"ihub-check-icon",style:{position:"relative",top:"5px",marginRight:"10px"}}),e[A]||(null==e?void 0:e.title)||"",le(e)?l(v,{className:"ihub-delete-icon ihub-ml-auto",onClick:function(){return e&&ce(e,!0)}}):""]},"".concat((null==e?void 0:e.id)||(null==e?void 0:e.username)||n))})),X||ee||z.length||N.length?"":l("li",{className:"ihub-no-results",children:"No available options"})]}),(re=b(N||[]),0===re.length?null:c("ul",{className:"ihub-selected-options",children:[l("h4",{className:"ihub-fs-md",children:"Selected Options:"}),re.map((function(e,n){if(!e||"object"!==i(e))return console.warn("SearchObjectsFromDB: Invalid item in selected array:",e),null;var r=e,a=r[A]||r.title||r.name||r.full_name||r.name_plus_username||r.display_name||r.username||"Item ".concat(n+1),t=e.id||r.username||"selected-".concat(n);return a&&a!=="Item ".concat(n+1)||console.log("SearchObjectsFromDB: Display text debug:",{item:e,keyName:A,itemKeyName:r[A],title:r.title,name:r.name,fullName:r.full_name,displayText:a}),c("li",{children:[l("span",{children:a}),l(v,{className:"ihub-delete-icon",onClick:function(){return ce(e,!0)}})]},t)}))]})),H&&l("p",{className:"ihub-error",children:"This field is required"})]})})}var g=o(y);export{g as default};
|
|
2
2
|
//# sourceMappingURL=SearchObjectsFromDB.js.map
|
|
@@ -47,6 +47,6 @@ interface SearchObjectsFromDBProps<T extends SearchObjectItemType = SearchObject
|
|
|
47
47
|
* @param {T[]} props.selected - The selected for the API request
|
|
48
48
|
* @param {boolean} props.err - The error for the API request
|
|
49
49
|
*/
|
|
50
|
-
declare function SearchObjectsFromDB<T extends SearchObjectItemType = SearchObjectItemType>({ label, token, handle, setSelected, appLabel, modelName, filterChannel, limitQuery, limitSelect, options, keyName, placeholder, searchUrl,
|
|
50
|
+
declare function SearchObjectsFromDB<T extends SearchObjectItemType = SearchObjectItemType>({ label, token, handle, selected, setSelected, appLabel, modelName, filterChannel, limitQuery, limitSelect, options, keyName, placeholder, searchUrl, err, required, }: SearchObjectsFromDBProps<T>): JSX.Element;
|
|
51
51
|
declare const _default: typeof SearchObjectsFromDB;
|
|
52
52
|
export default _default;
|