@instincthub/react-ui 0.0.7 → 0.0.9

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.
@@ -1,6 +1,5 @@
1
1
  /* Submit Button Styles */
2
2
  .ihub-submit-btn-wrapper {
3
- margin-bottom: 20px;
4
3
  position: relative;
5
4
  display: inline-block;
6
5
  }
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,objectSpread2 as r,asyncToGenerator as a,regeneratorRuntime as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as n,jsxs as c}from"react/jsx-runtime";import{reqOptions as s,API_HOST_URL as o}from"../lib/helpFunction.js";import i from"@mui/icons-material/SearchRounded";import{useRouter as u}from"next/navigation";import{useState as l,useEffect as h}from"react";var p=function(p){var m=u(),f=p.params.channel,d=p.searchParams.search,v=l(),b=e(v,2),x=b[0],y=b[1],g=l(d),k=e(g,2),N=k[0],w=k[1],j=function(e){var a=m.query,t=r(r({},a),{},{search:e});m.replace({query:t})},C=function(){var e=a(t().mark((function e(r){var a,n,c=arguments;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=c.length>1&&void 0!==c[1]&&c[1],(13===r.keyCode||a)&&(n=r.currentTarget.value,j(n));case 2:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),P=function(){var e=a(t().mark((function e(){var r,a,n,c;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return y(0),r=s("GET",null,p.token,!1,f),a="".concat(o).concat(p.urlPath,"search=").concat(d||""),e.prev=3,e.next=6,fetch(a,r);case 6:if(200!==(n=e.sent).status){e.next=14;break}return e.next=10,n.json();case 10:c=e.sent,p.setData(c.results),p.setNext(c.next),p.setPrevious(c.previous);case 14:y(n.status),e.next=21;break;case 17:e.prev=17,e.t0=e.catch(3),console.error("Search error:",e.t0),y(500);case 21:case"end":return e.stop()}}),e,null,[[3,17]])})));return function(){return e.apply(this,arguments)}}();return h((function(){void 0!==d&&(P(),w(d))}),[d]),n("div",{className:"ihub-search-field",children:c("div",{className:"ihub-search-courses",children:[n("input",{type:"search",placeholder:"Search ".concat(p.labels?p.labels:"Items"," ..."),onChange:function(e){w(e.target.value)},value:N||"",onKeyDown:C}),N?n("svg",{className:"ihub-search-cancel",focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24","data-testid":"CloseIcon",onClick:function(){w(""),j("")},children:n("path",{d:"M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})}):null,n("div",{className:"ihub-search-btn",children:0===x?n("div",{className:"ihub-loader"}):n(i,{className:"ihub-material-symbols-outlined",onClick:function(){return j(N)}})})]})})};export{p as default};
1
+ import{slicedToArray as e,asyncToGenerator as r,regeneratorRuntime as a}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as t,jsxs as n}from"react/jsx-runtime";import{reqOptions as c,API_HOST_URL as s}from"../lib/helpFunction.js";import o from"@mui/icons-material/SearchRounded";import{useRouter as i}from"next/navigation";import{useState as l,useEffect as u}from"react";import"../lib/utils.js";import{urlQueryHelper as h}from"../lib/queryParameters/index.js";var m=function(m){var p=i(),v=m.params.channel,d=m.searchParams.search,f=l(),b=e(f,2),x=b[0],y=b[1],k=l(d),g=e(k,2),N=g[0],j=g[1],w=function(e){var r=h({key:"search",value:e,action:"add"});p.replace(r)},C=function(){var e=r(a().mark((function e(r){var t,n,c=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=c.length>1&&void 0!==c[1]&&c[1],(13===r.keyCode||t)&&(n=r.currentTarget.value,w(n));case 2:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),P=function(){var e=r(a().mark((function e(){var r,t,n,o,i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return y(0),r=c("GET",null,m.token,!1,v),t="".concat(s).concat(m.urlPath,"search=").concat(d||""),e.prev=3,e.next=6,fetch(t,r);case 6:if(200!==(n=e.sent).status){e.next=14;break}return e.next=10,n.json();case 10:i=e.sent,m.setData(i.results),m.setNext(i.next),null===(o=m.setPrevious)||void 0===o||o.call(m,i.previous);case 14:y(n.status),e.next=21;break;case 17:e.prev=17,e.t0=e.catch(3),console.error("Search error:",e.t0),y(500);case 21:case"end":return e.stop()}}),e,null,[[3,17]])})));return function(){return e.apply(this,arguments)}}();return u((function(){void 0!==d&&(P(),j(d))}),[d]),t("div",{className:"ihub-search-field",children:n("div",{className:"ihub-search-courses",children:[t("input",{type:"search",placeholder:"Search ".concat(m.labels?m.labels:"Items"," ..."),onChange:function(e){j(e.target.value)},value:N||"",onKeyDown:C}),N?t("svg",{className:"ihub-search-cancel",focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24","data-testid":"CloseIcon",onClick:function(){var e=h({key:"search",value:"",action:"remove"});p.replace(e)},children:t("path",{d:"M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})}):null,t("div",{className:"ihub-search-btn",children:0===x?t("div",{className:"ihub-loader"}):t(o,{className:"ihub-material-symbols-outlined",onClick:function(){return w(N)}})})]})})};export{m as default};
2
2
  //# sourceMappingURL=SearchFieldDB.js.map
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,asyncToGenerator as n,regeneratorRuntime as r,toConsumableArray as i,typeof as a}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as c,jsxs as t}from"react/jsx-runtime";import{memo as o,useState as l,useEffect as s,useCallback as u}from"react";import{reqOptions as h,API_HOST_URL as m}from"../lib/helpFunction.js";import"../lib/utils.js";import d from"@mui/icons-material/SearchOutlined";import b from"@mui/icons-material/Check";import f from"@mui/icons-material/CloseOutlined";function p(o){var p=o.label,v=o.token,N=o.handle,g=o.setSelected,k=o.appLabel,y=o.modelName,x=o.filterChannel,C=void 0!==x&&x,_=o.limit_query,j=void 0===_?5:_,w=o.limit_select,E=void 0===w?0:w,T=o.options,S=o.key_name,U=void 0===S?"title":S,q=o.placeholder,A=void 0===q?"Search by Username or Email":q,D=o.searchUrl,G=o.selected,H=o.err,O=void 0!==H&&H,P=l(""),R=e(P,2),B=R[0],F=R[1],K=l([]),L=e(K,2),z=L[0],I=L[1],J=l(!1),M=e(J,2),Q=M[0],V=M[1],W=l(null),X=e(W,2),Y=X[0],Z=X[1];s((function(){G&&G.length>0&&0===z.length&&I(G)}),[G]),s((function(){I(T||[])}),[T]);var $=u(n(r().mark((function e(){var n,a,c,t,o;return r().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return V(!0),Z(null),n=h("GET",null,v),a=D?D.includes("/?")?"".concat(D,"&search=").concat(B):"".concat(D,"?search=").concat(B):k?"".concat(m,"channels/").concat(N,"/dynamic-search/?app_label=").concat(k,"&model_name=").concat(y,"&value=").concat(B,"&filter_channel=").concat(C):"".concat(m,"auth/").concat(N,"/search-user/").concat(B,"/?limit=").concat(j),e.prev=4,e.next=7,fetch(a,n);case 7:if((c=e.sent).ok){e.next=10;break}throw new Error("HTTP error ".concat(c.status));case 10:return e.next=12,c.json();case 12:t=e.sent,I([].concat(i(t.results||[]),i(T||[]))),e.next=22;break;case 16:e.prev=16,e.t0=e.catch(4),o=e.t0 instanceof Error?e.t0.message:"Unknown error occurred",console.error("Error fetching search results:",o),Z(o),I(i(T||[]));case 22:return e.prev=22,V(!1),e.finish(22);case 25:case"end":return e.stop()}}),e,null,[[4,16,22,25]])}))),[B,v,D,k,y,N,C,j]),ee=u((function(e){"Enter"===e.key&&(e.preventDefault(),$())}),[$]),ne=u((function(){F(""),I(i(T||[])),Z(null)}),[]),re=u((function(e){return G.some((function(n){return("object"===a(n)?null==n?void 0:n.id:n)===((null==e?void 0:e.username)||(null==e?void 0:e.id))}))}),[G]),ie=u((function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=G.find((function(n){return n.id===e.id}));n?g(G.filter((function(n){return n.id!==e.id}))):!r&&(0===E||G.length<E)?g([].concat(i(G),[e])):1===E&&g([e])}),[G,g,E]);return c("div",{className:"ihub-react-search-container",children:t("div",{className:"ihub-react-search card",children:[p&&c("h4",{className:"ihub-fs-sm ihub-mt-2 ihub-mb-2",children:p}),t("div",{className:"ihub-search-input",children:[c("input",{type:"text",placeholder:A,onKeyDown:ee,value:B,onChange:function(e){return F(e.target.value)},disabled:Q}),t("div",{className:"ihub-search-icons",children:[B&&c(f,{onClick:ne,className:"ihub-search-icon ihub-close-icon"}),c(d,{onClick:$,className:"ihub-search-icon ihub-search-button ".concat(Q?"ihub-disabled":"")})]})]}),Q&&c("div",{className:"ihub-loading",children:"Searching..."}),Y&&c("div",{className:"ihub-search-error",children:Y}),t("ul",{className:"ihub-search-results",children:[null==z?void 0:z.map((function(e,n){return t("li",{className:"ihub-search-result-item ihub-valid",onClick:function(){return ie(e)},children:[re(e)&&c(b,{className:"ihub-check-icon",style:{position:"relative",top:"5px",marginRight:"10px"}}),e[U]||e.title,re(e)?c(f,{className:"ihub-delete-icon ihub-ml-auto",onClick:function(){return ie(e,!0)}}):""]},"".concat(e.id||e.username||n))})),Q||Y||z.length||G.length?"":c("li",{className:"ihub-no-results",children:"No available options"})]}),O&&c("p",{className:"ihub-error",children:"This field is required"})]})})}var v=o(p);export{v as default};
1
+ import{slicedToArray as e,asyncToGenerator as i,regeneratorRuntime as n,toConsumableArray as r,typeof as c}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as t,jsxs as a}from"react/jsx-runtime";import{memo as l,useState as o,useEffect as s,useCallback as u}from"react";import{reqOptions as h,API_HOST_URL as d}from"../lib/helpFunction.js";import"../lib/utils.js";import m from"@mui/icons-material/SearchOutlined";import b from"@mui/icons-material/Check";import f from"@mui/icons-material/CloseOutlined";function p(l){var p=l.label,v=l.token,N=l.handle,g=l.setSelected,k=l.appLabel,y=l.modelName,x=l.filterChannel,C=void 0!==x&&x,_=l.limit_query,j=void 0===_?5:_,w=l.limit_select,E=void 0===w?0:w,T=l.options,S=l.key_name,O=void 0===S?"title":S,U=l.placeholder,q=void 0===U?"Search by Username or Email":U,A=l.searchUrl,D=l.selected,G=l.err,H=void 0!==G&&G,P=o(""),R=e(P,2),B=R[0],F=R[1],K=o([]),L=e(K,2),z=L[0],I=L[1],J=o(!1),M=e(J,2),Q=M[0],V=M[1],W=o(null),X=e(W,2),Y=X[0],Z=X[1];s((function(){D&&D.length>0&&0===z.length&&I(D)}),[D]),s((function(){I(T||[])}),[T]);var $=u(i(n().mark((function e(){var i,c,t,a,l;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return V(!0),Z(null),i=h("GET",null,v),c=A?A.includes("/?")?"".concat(A,"&search=").concat(B):"".concat(A,"?search=").concat(B):k?"".concat(d,"channels/").concat(N,"/dynamic-search/?app_label=").concat(k,"&model_name=").concat(y,"&value=").concat(B,"&filter_channel=").concat(C):"".concat(d,"auth/").concat(N,"/search-user/").concat(B,"/?limit=").concat(j),e.prev=4,e.next=7,fetch(c,i);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:a=e.sent,I([].concat(r(a.results||[]),r(T||[]))),e.next=22;break;case 16:e.prev=16,e.t0=e.catch(4),l=e.t0 instanceof Error?e.t0.message:"Unknown error occurred",console.error("Error fetching search results:",l),Z(l),I(r(T||[]));case 22:return e.prev=22,V(!1),e.finish(22);case 25:case"end":return e.stop()}}),e,null,[[4,16,22,25]])}))),[B,v,A,k,y,N,C,j]),ee=u((function(e){"Enter"===e.key&&(e.preventDefault(),$())}),[$]),ie=u((function(){F(""),I(r(T||[])),Z(null)}),[]),ne=u((function(e){return D.some((function(i){return("object"===c(i)?null==i?void 0:i.id:i)===((null==e?void 0:e.username)||(null==e?void 0:e.id))}))}),[D]),re=u((function(e){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e&&e.id){var n=D.find((function(i){return i.id===e.id}));i?g(D.filter((function(i){return i.id!==e.id}))):!n&&(0===E||D.length<E)?g([].concat(r(D),[e])):1===E&&g([e])}}),[D,g,E]);return t("div",{className:"ihub-react-search-container",children:a("div",{className:"ihub-react-search card",children:[p&&t("h4",{className:"ihub-fs-sm ihub-mt-2 ihub-mb-2",children:p}),a("div",{className:"ihub-search-input",children:[t("input",{type:"text",placeholder:q,onKeyDown:ee,value:B,onChange:function(e){return F(e.target.value)},disabled:Q}),a("div",{className:"ihub-search-icons",children:[B&&t(f,{onClick:ie,className:"ihub-search-icon ihub-close-icon"}),t(m,{onClick:$,className:"ihub-search-icon ihub-search-button ".concat(Q?"ihub-disabled":"")})]})]}),Q&&t("div",{className:"ihub-loading",children:"Searching..."}),Y&&t("div",{className:"ihub-search-error",children:Y}),a("ul",{className:"ihub-search-results",children:[null==z?void 0:z.map((function(e,i){return a("li",{className:"ihub-search-result-item ihub-valid",onClick:function(){return e&&re(e)},children:[ne(e)&&t(b,{className:"ihub-check-icon",style:{position:"relative",top:"5px",marginRight:"10px"}}),(null==e?void 0:e[O])||(null==e?void 0:e.title)||"",ne(e)?t(f,{className:"ihub-delete-icon ihub-ml-auto",onClick:function(){return e&&re(e,!0)}}):""]},"".concat((null==e?void 0:e.id)||(null==e?void 0:e.username)||i))})),Q||Y||z.length||D.length?"":t("li",{className:"ihub-no-results",children:"No available options"})]}),a("ul",{className:"ihub-selected-options ihub-mt-2 ihub-",children:[t("h4",{className:"ihub-fs-sm ihub-mt-2 ihub-mb-2",children:"Selected Options:"}),D.map((function(e){return a("li",{className:"ihub-fs-sm ihub-border-bottom ihub-pb-2 ihub-flex ihub-items-center",children:[e[O]||e.title,t(f,{className:"ihub-delete-icon ihub-ml-auto",onClick:function(){return re(e,!0)}})]},null==e?void 0:e.id)}))]}),H&&t("p",{className:"ihub-error",children:"This field is required"})]})})}var v=l(p);export{v as default};
2
2
  //# sourceMappingURL=SearchObjectsFromDB.js.map
@@ -7,7 +7,7 @@ interface SearchFieldDBProps {
7
7
  /** Function to set next page URL */
8
8
  setNext: React.Dispatch<React.SetStateAction<string | null>>;
9
9
  /** Function to set previous page URL */
10
- setPrevious: React.Dispatch<React.SetStateAction<string | null>>;
10
+ setPrevious?: React.Dispatch<React.SetStateAction<string | null>>;
11
11
  /** Auth token for API requests */
12
12
  token?: string | null;
13
13
  /** Search parameters from URL */
@@ -36,7 +36,7 @@ interface SearchObjectsFromDBProps<T extends SearchObjectItemType = SearchObject
36
36
  * @param {string} props.appLabel - The app label for the API request
37
37
  * @param {string} props.modelName - The model name for the API request
38
38
  * @param {boolean} props.filterChannel - The filter channel for the API request
39
- * @param {number} props.limit_query - The limit for the API request
39
+ * @param {number} props.limit_query - 0 means unlimited, 1 means only one result
40
40
  * @param {number} props.limit_select - The limit user can select (0 means unlimited)
41
41
  * @param {T[]} props.options - The options for the API request
42
42
  * @param {keyof T | "name_plus_username"} props.key_name - The key_name to display search results (option[key_name])
@@ -19,6 +19,15 @@ interface BreadcrumbProps {
19
19
  /**
20
20
  * Modern breadcrumb component for InstinctHub NextJS application
21
21
  * Automatically generates breadcrumb from current path
22
+ * @example
23
+ * ```tsx
24
+ * <Breadcrumb homeLabel="Home" pathMapping={{ "/courses": "Courses" }} excludePaths={["/courses/1"]} />
25
+ * ```
26
+ * @param {string} props.homeLabel - The label for the home page
27
+ * @param {Record<string, string>} props.pathMapping - The mapping of path segments to display names
28
+ * @param {string[]} props.excludePaths - The paths to exclude from the breadcrumb
29
+ * @param {string} props.className - The class name for the breadcrumb container
30
+ *
22
31
  */
23
32
  declare const Breadcrumb: ({ homeLabel, pathMapping, excludePaths, className, }: BreadcrumbProps) => import("react/jsx-runtime").JSX.Element | null;
24
33
  export default Breadcrumb;
@@ -88,8 +88,8 @@ export type SearchParamsType = {
88
88
  [key: string]: string;
89
89
  };
90
90
  export interface SearchParamsPageProps {
91
- params: SearchParamsType;
92
- searchParams: SearchParamsType;
91
+ params: Promise<SearchParamsType>;
92
+ searchParams: Promise<SearchParamsType>;
93
93
  }
94
94
  /**
95
95
  * Response interface for S3 uploads