naria-ui 0.1.38 → 0.1.39
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/dist/naria-ui.cjs.js +8 -8
- package/dist/naria-ui.es.js +55 -55
- package/package.json +4 -2
- package/lib/components/Button/Button.tsx +0 -16
- package/lib/components/Button/index.ts +0 -1
- package/lib/components/Input/Input.tsx +0 -59
- package/lib/components/Input/index.ts +0 -1
- package/lib/components/Select/Select.tsx +0 -380
- package/lib/components/Select/index.ts +0 -1
- package/lib/components/Select/select.scss +0 -132
- package/lib/components/index.ts +0 -3
- package/lib/index.ts +0 -2
- package/lib/utils/capitalize.ts +0 -4
- package/lib/utils/index.ts +0 -2
- package/lib/utils/navigator.ts +0 -29
package/dist/naria-ui.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react");function oe(t){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react");function oe(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const d=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(a,o,d.get?d:{enumerable:!0,get:()=>t[o]})}}return a.default=t,Object.freeze(a)}const z=oe(i);var V={exports:{}},U={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var K;function ce(){if(K)return U;K=1;var t=Symbol.for("react.transitional.element"),
|
|
9
|
+
*/var K;function ce(){if(K)return U;K=1;var t=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function o(d,c,f){var p=null;if(f!==void 0&&(p=""+f),c.key!==void 0&&(p=""+c.key),"key"in c){f={};for(var g in c)g!=="key"&&(f[g]=c[g])}else f=c;return c=f.ref,{$$typeof:t,type:d,key:p,ref:c!==void 0?c:null,props:f}}return U.Fragment=a,U.jsx=o,U.jsxs=o,U}var H={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var ee;function ie(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===b?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case
|
|
17
|
+
*/var ee;function ie(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===b?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case O:return"Fragment";case A:return"Profiler";case S:return"StrictMode";case M:return"Suspense";case _:return"SuspenseList";case C: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 G:return(e._context.displayName||"Context")+".Consumer";case u:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case T:return n=e.displayName||null,n!==null?n:t(e.type)||"Memo";case Y:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function a(e){return""+e}function o(e){try{a(e);var n=!1}catch{n=!0}if(n){n=console;var r=n.error,l=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return r.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",l),a(e)}}function d(e){if(e===O)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===Y)return"<...>";try{var n=t(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function c(){var e=P.A;return e===null?null:e.getOwner()}function f(){return Error("react-stack-top-frame")}function p(e){if(x.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function g(e,n){function r(){D||(D=!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)",n))}r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}function E(){var e=t(this.type);return $[e]||($[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,n,r,l,w,j,X,Z){return r=j.ref,e={$$typeof:L,type:e,key:n,props:j,_owner:w},(r!==void 0?r:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:E}):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:X}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Z}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function N(e,n,r,l,w,j,X,Z){var m=n.children;if(m!==void 0)if(l)if(q(m)){for(l=0;l<m.length;l++)v(m[l]);Object.freeze&&Object.freeze(m)}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 v(m);if(x.call(n,"key")){m=t(e);var I=Object.keys(n).filter(function(ae){return ae!=="key"});l=0<I.length?"{key: someKey, "+I.join(": ..., ")+": ...}":"{key: someKey}",J[m+l]||(I=0<I.length?"{"+I.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,l,m
|
|
23
|
-
${o&&"!text-danger-100"}`,children:[
|
|
24
|
-
${o&&"!border-danger-100 focus:border-danger-100 outline-danger-100"}`,value:Y,disabled:E,type:"text",onClick
|
|
25
|
-
${o&&"!border-danger-100 focus:border-danger-100 outline-danger-100"}`,onClick
|
|
26
|
-
${o&&"!border-danger-100 focus:border-danger-100 outline-danger-100"}`,value:Y,disabled:E,type:"text",onChange:n}),
|
|
22
|
+
<%s key={someKey} {...props} />`,l,m,I,m),J[m+l]=!0)}if(m=null,r!==void 0&&(o(r),m=""+r),p(n)&&(o(n.key),m=""+n.key),"key"in n){r={};for(var Q in n)Q!=="key"&&(r[Q]=n[Q])}else r=n;return m&&g(r,typeof e=="function"?e.displayName||e.name||"Unknown":e),h(e,m,j,w,c(),r,X,Z)}function v(e){typeof e=="object"&&e!==null&&e.$$typeof===L&&e._store&&(e._store.validated=1)}var R=i,L=Symbol.for("react.transitional.element"),y=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),A=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),W=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),M=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),T=Symbol.for("react.memo"),Y=Symbol.for("react.lazy"),C=Symbol.for("react.activity"),b=Symbol.for("react.client.reference"),P=R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,x=Object.prototype.hasOwnProperty,q=Array.isArray,k=console.createTask?console.createTask:function(){return null};R={"react-stack-bottom-frame":function(e){return e()}};var D,$={},F=R["react-stack-bottom-frame"].bind(R,f)(),B=k(d(f)),J={};H.Fragment=O,H.jsx=function(e,n,r,l,w){var j=1e4>P.recentlyCreatedOwnerStacks++;return N(e,n,r,!1,l,w,j?Error("react-stack-top-frame"):F,j?k(d(e)):B)},H.jsxs=function(e,n,r,l,w){var j=1e4>P.recentlyCreatedOwnerStacks++;return N(e,n,r,!0,l,w,j?Error("react-stack-top-frame"):F,j?k(d(e)):B)}}()),H}var re;function le(){return re||(re=1,process.env.NODE_ENV==="production"?V.exports=ce():V.exports=ie()),V.exports}var s=le();const ue=({type:t="button",value:a})=>s.jsx("button",{type:t,children:a}),fe=({type:t="text",placeholder:a,wrapperClass:o="",labelClass:d="",inputClass:c="",errorClass:f="",label:p,hasError:g,register:E,name:h,isDisabled:N=!1,autocomplete:v=!1,...R})=>s.jsxs("div",{className:o,children:[s.jsxs("label",{htmlFor:h,className:`${d} ${g&&"error"}`,children:[p,s.jsx("input",{disabled:N,autoComplete:v?"on":"off",id:h,...E,...R,type:t,name:h,className:`${c} ${g&&"error"} ${f}`,placeholder:a})]}),g&&s.jsx("p",{className:f,children:g})]}),te=t=>z.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor",...t},z.createElement("path",{fill:"currentColor",d:"M209.5 369c-9.4 9.4-24.6 9.4-33.9 0L15.5 209c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l143 143 143-143c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-160 160z"})),de=t=>z.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor",...t},z.createElement("path",{fill:"currentColor",d:"M7.5 105c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l151 151 151-151c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-151 151 151 151c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-151-151-151 151c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l151-151-151-151z"})),ne=t=>z.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",fill:"currentColor",...t},z.createElement("path",{fill:"currentColor",d:"M368 208a160 160 0 1 0 -320 0 160 160 0 1 0 320 0zM337.1 371.1C301.7 399.2 256.8 416 208 416 93.1 416 0 322.9 0 208S93.1 0 208 0 416 93.1 416 208c0 48.8-16.8 93.7-44.9 129.1L505 471c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0L337.1 371.1z"})),ge=()=>{const[t,a]=i.useState(typeof window<"u"?window.innerWidth:0),o=()=>a(typeof window<"u"?window.innerWidth:0);return i.useEffect(()=>(window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)),[t]),t},se=({classNames:t={wrapper:"",color:""}})=>s.jsxs("svg",{className:`nariaLoading ${t.wrapper}`,viewBox:"0 0 64 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[s.jsx("path",{d:"M32 3C35.8083 3 39.5794 3.75011 43.0978 5.20749C46.6163 6.66488 49.8132 8.80101 52.5061 11.4939C55.199 14.1868 57.3351 17.3837 58.7925 20.9022C60.2499 24.4206 61 28.1917 61 32C61 35.8083 60.2499 39.5794 58.7925 43.0978C57.3351 46.6163 55.199 49.8132 52.5061 52.5061C49.8132 55.199 46.6163 57.3351 43.0978 58.7925C39.5794 60.2499 35.8083 61 32 61C28.1917 61 24.4206 60.2499 20.9022 58.7925C17.3837 57.3351 14.1868 55.199 11.4939 52.5061C8.801 49.8132 6.66487 46.6163 5.20749 43.0978C3.7501 39.5794 3 35.8083 3 32C3 28.1917 3.75011 24.4206 5.2075 20.9022C6.66489 17.3837 8.80101 14.1868 11.4939 11.4939C14.1868 8.80099 17.3838 6.66487 20.9022 5.20749C24.4206 3.7501 28.1917 3 32 3L32 3Z",stroke:"currentColor",strokeWidth:"6",strokeLinecap:"round",strokeLinejoin:"round"}),s.jsx("path",{d:"M32 3C36.5778 3 41.0906 4.08374 45.1692 6.16256C49.2477 8.24138 52.7762 11.2562 55.466 14.9605C58.1558 18.6647 59.9304 22.9531 60.6448 27.4748C61.3591 31.9965 60.9928 36.6232 59.5759 40.9762",stroke:"currentColor",strokeWidth:"6",strokeLinecap:"round",strokeLinejoin:"round",className:t.color})]}),me=()=>{const t=`${window.location.pathname}${window.location.search}`;window.history.replaceState(null,"",t)},he=t=>{window.location.hash=t},pe=t=>{const[a,o]=i.useState(!1);return i.useEffect(()=>{const d=c=>{window.location.hash!==t?o(!0):o(!1)};return window.addEventListener("hashchange",d),()=>{window.removeEventListener("hashchange",d)}},[]),a},we=(t,a,o)=>{i.useEffect(()=>{function d(c){a.current&&!a.current.contains(c.target)&&t?.current&&!t?.current.contains(c.target)&&o()}return document.addEventListener("mousedown",d),()=>{document.removeEventListener("mousedown",d)}},[t,o])},ve=({options:t,label:a,hasError:o,title:d,value:c,api:f,selected:p,placeholder:g,disabled:E=!1,pagination:h,optionFilterLabel:N,hasSearch:v=!1,onSelectChange:R})=>{let L=!0;const y=ge(),O=pe("#select"),[S,A]=i.useState(!1),[G,W]=i.useState(!0),[u,M]=i.useState(null),[_,T]=i.useState(null),[Y,C]=i.useState(""),[b,P]=i.useState({page:1,pageLabel:"page",size:20,sizeLabel:"size",isLoading:!1}),x=i.useRef(void 0),q=i.useRef(void 0),k=i.useRef(void 0),D=async()=>{if(x?.current)try{const r=await fetch(x?.current);if(!r.ok)throw new Error(`Response status: ${r.status}`);return await r.json()}catch(r){console.error(r.message)}};i.useEffect(()=>()=>{L=!1},[]),i.useEffect(()=>{if(f?.length){if(x.current=f,x.current.includes(h?.pageLabel||"page")){const r=new URL(f);r.searchParams.set(h?.pageLabel||"page",(h?.page||b.page).toString()),r.searchParams.set(h?.sizeLabel||"size",(h?.size||b.size).toString()),x.current=r.href}W(!0),D().then(r=>{L&&(W(!1),T(r))})}},[f,h]),i.useEffect(()=>{if(b.isLoading){if(x.current.includes(h?.pageLabel||"page")){const r=new URL(x.current);r.searchParams.set(h?.pageLabel||"page",b.page.toString()),x.current=r.href}D().then(r=>{L&&(W(!1),P({...b,isLoading:!1}),T([..._,...r]))})}},[b]),i.useEffect(()=>{y<768&&(S?(he("select"),document.body.style.overflow="hidden",k.current?.focus()):(window.location.hash&&!document.referrer.includes("#")&&me(),document.body.style.overflow="auto"))},[S]),i.useEffect(()=>{p&&t?.length&&(t?.find(r=>r[a]===p)?M(t?.find(r=>r[a]===p)):M(p))},[p]),i.useEffect(()=>{u&&v&&(c?.length&&_?.find(r=>r[a]===u[a])?C(_?.find(r=>r[a]===u[a])[c]||""):C(u))},[u]),i.useEffect(()=>{O&&A(!1)},[O]),i.useEffect(()=>{t?.length&&T(t)},[t]);const $=()=>{v&&T(t),A(r=>!r)},F=()=>{v&&(T(t),C(typeof u=="string"?u:u?u[c]:"")),A(!1)},B=r=>{v&&(c?.length?C(r[c]):C(r)),M(r),$(),R&&R(r)},J=r=>{if(!u)return"";if(a?.length&&r[a]===u[a]||r===u)return"bg-grey-100"},e=r=>{_?.length&&!b.isLoading&&r.target.offsetHeight+r.target.scrollTop>=r.target.scrollHeight-100&&P({page:b.page+1,isLoading:!0})},n=r=>{const l=r?.target?.value?.length?t.filter(w=>typeof w=="object"?w[N?.length?N:c].includes(r?.target?.value):w.includes(r?.target?.value)):t;T(l),C(r?.target?.value),S||A(!0)};return we(q,k,F),s.jsxs("div",{className:`nariaSelect ${E?"nariaSelect-disabled":""}`,children:[s.jsxs("label",{className:`cursor-pointer
|
|
23
|
+
${o&&"!text-danger-100"}`,children:[s.jsx("span",{className:"",children:d}),v?s.jsxs("div",{className:"nariaSearchInput",children:[s.jsx("input",{ref:k,placeholder:g?.length?g:"Select",className:`${u?"text-dark-100":"text-grey-300"}
|
|
24
|
+
${o&&"!border-danger-100 focus:border-danger-100 outline-danger-100"}`,value:Y,disabled:E,type:"text",onClick:$,onChange:n}),S?s.jsx(ne,{className:"nariaSearchIcon"}):s.jsx(te,{className:`nariaArrowIcon ${S?"nariaArrowIcon-rotate-180":""}`})]}):s.jsxs("button",{type:"button",ref:k,disabled:E,className:`nariaHandler ${u?"text-dark-100":"text-grey-300"}
|
|
25
|
+
${o&&"!border-danger-100 focus:border-danger-100 outline-danger-100"}`,onClick:$,children:[u?c?.length?u[c]:u:g?.length?g:"Select"," ",s.jsx(te,{className:`nariaArrowIcon ${S?"nariaArrowIcon-rotate-180":""}`})]})]}),S?s.jsxs("div",{className:`nariaListWrapper ${y<768?"nariaListWrapper-mobile":""}`,ref:q,children:[v&&y<768?s.jsxs("div",{className:"nariaSearchInput",children:[s.jsx("input",{ref:k,placeholder:g?.length?g:"Select",className:`${u?"text-dark-100":"text-grey-300"}
|
|
26
|
+
${o&&"!border-danger-100 focus:border-danger-100 outline-danger-100"}`,value:Y,disabled:E,type:"text",onChange:n}),s.jsx(ne,{className:"nariaSearchIcon"})]}):void 0,s.jsx("div",{className:`nariaList ${y<768?"nariaList-mobile":"nariaList-desktop"}`,onScroll:e,children:f&&G?s.jsx("div",{className:"nariaLoadingWrapper",children:s.jsx(se,{})}):s.jsxs(s.Fragment,{children:[y<768?s.jsx("div",{className:"sticky top-0 text-left",children:s.jsx("button",{className:"p-3",onClick:F,disabled:E,children:s.jsx(de,{className:"w-6"})})}):void 0,_?.length?s.jsx(s.Fragment,{children:_?.map((r,l)=>s.jsx("button",{type:"button",onClick:()=>B(r),disabled:E,className:`text-right py-2.5 px-4 text-base hover:bg-grey-100 rounded-lg ${J(r)}`,children:c?.length?r[c]:r},l.toString()))}):s.jsx("div",{children:"No Data"}),b.isLoading?s.jsx("div",{className:"nariaLoadingMoreWrapper",children:s.jsx(se,{})}):void 0]})})]}):void 0,o&&s.jsx("p",{className:"text-xs mt-1 text-danger-100",children:o})]})};function be(t){return t.charAt(0).toUpperCase()+t.slice(1)}exports.Button=ue;exports.Input=fe;exports.Select=ve;exports.capitalize=be;
|
package/dist/naria-ui.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as W from "react";
|
|
2
2
|
import ie, { useState as N, useEffect as b, useRef as ee } from "react";
|
|
3
3
|
var G = { exports: {} }, H = {};
|
|
4
4
|
/**
|
|
@@ -51,13 +51,13 @@ function ue() {
|
|
|
51
51
|
return e.$$typeof === v ? null : e.displayName || e.name || null;
|
|
52
52
|
if (typeof e == "string") return e;
|
|
53
53
|
switch (e) {
|
|
54
|
-
case A:
|
|
55
|
-
return "Fragment";
|
|
56
54
|
case O:
|
|
55
|
+
return "Fragment";
|
|
56
|
+
case P:
|
|
57
57
|
return "Profiler";
|
|
58
58
|
case C:
|
|
59
59
|
return "StrictMode";
|
|
60
|
-
case
|
|
60
|
+
case M:
|
|
61
61
|
return "Suspense";
|
|
62
62
|
case S:
|
|
63
63
|
return "SuspenseList";
|
|
@@ -68,7 +68,7 @@ function ue() {
|
|
|
68
68
|
switch (typeof e.tag == "number" && console.error(
|
|
69
69
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
70
70
|
), e.$$typeof) {
|
|
71
|
-
case
|
|
71
|
+
case y:
|
|
72
72
|
return "Portal";
|
|
73
73
|
case Y:
|
|
74
74
|
return (e.displayName || "Context") + ".Provider";
|
|
@@ -79,7 +79,7 @@ function ue() {
|
|
|
79
79
|
return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
80
80
|
case T:
|
|
81
81
|
return n = e.displayName || null, n !== null ? n : t(e.type) || "Memo";
|
|
82
|
-
case
|
|
82
|
+
case D:
|
|
83
83
|
n = e._payload, e = e._init;
|
|
84
84
|
try {
|
|
85
85
|
return t(e(n));
|
|
@@ -109,8 +109,8 @@ function ue() {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
function g(e) {
|
|
112
|
-
if (e ===
|
|
113
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
112
|
+
if (e === O) return "<>";
|
|
113
|
+
if (typeof e == "object" && e !== null && e.$$typeof === D)
|
|
114
114
|
return "<...>";
|
|
115
115
|
try {
|
|
116
116
|
var n = t(e);
|
|
@@ -120,7 +120,7 @@ function ue() {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
function o() {
|
|
123
|
-
var e =
|
|
123
|
+
var e = $.A;
|
|
124
124
|
return e === null ? null : e.getOwner();
|
|
125
125
|
}
|
|
126
126
|
function u() {
|
|
@@ -135,7 +135,7 @@ function ue() {
|
|
|
135
135
|
}
|
|
136
136
|
function d(e, n) {
|
|
137
137
|
function r() {
|
|
138
|
-
|
|
138
|
+
F || (F = !0, console.error(
|
|
139
139
|
"%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)",
|
|
140
140
|
n
|
|
141
141
|
));
|
|
@@ -147,13 +147,13 @@ function ue() {
|
|
|
147
147
|
}
|
|
148
148
|
function E() {
|
|
149
149
|
var e = t(this.type);
|
|
150
|
-
return
|
|
150
|
+
return I[e] || (I[e] = !0, console.error(
|
|
151
151
|
"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."
|
|
152
152
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
153
153
|
}
|
|
154
154
|
function m(e, n, r, i, p, R, Z, Q) {
|
|
155
155
|
return r = R.ref, e = {
|
|
156
|
-
$$typeof:
|
|
156
|
+
$$typeof: A,
|
|
157
157
|
type: e,
|
|
158
158
|
key: n,
|
|
159
159
|
props: R,
|
|
@@ -183,7 +183,7 @@ function ue() {
|
|
|
183
183
|
value: Q
|
|
184
184
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function L(e, n, r, i, p, R, Z, Q) {
|
|
187
187
|
var f = n.children;
|
|
188
188
|
if (f !== void 0)
|
|
189
189
|
if (i)
|
|
@@ -198,10 +198,10 @@ function ue() {
|
|
|
198
198
|
else w(f);
|
|
199
199
|
if (x.call(n, "key")) {
|
|
200
200
|
f = t(e);
|
|
201
|
-
var
|
|
201
|
+
var z = Object.keys(n).filter(function(ce) {
|
|
202
202
|
return ce !== "key";
|
|
203
203
|
});
|
|
204
|
-
i = 0 <
|
|
204
|
+
i = 0 < z.length ? "{key: someKey, " + z.join(": ..., ") + ": ...}" : "{key: someKey}", V[f + i] || (z = 0 < z.length ? "{" + z.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
205
205
|
`A props object containing a "key" prop is being spread into JSX:
|
|
206
206
|
let props = %s;
|
|
207
207
|
<%s {...props} />
|
|
@@ -210,7 +210,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
210
210
|
<%s key={someKey} {...props} />`,
|
|
211
211
|
i,
|
|
212
212
|
f,
|
|
213
|
-
|
|
213
|
+
z,
|
|
214
214
|
f
|
|
215
215
|
), V[f + i] = !0);
|
|
216
216
|
}
|
|
@@ -234,9 +234,9 @@ React keys must be passed directly to JSX without using spread:
|
|
|
234
234
|
);
|
|
235
235
|
}
|
|
236
236
|
function w(e) {
|
|
237
|
-
typeof e == "object" && e !== null && e.$$typeof ===
|
|
237
|
+
typeof e == "object" && e !== null && e.$$typeof === A && e._store && (e._store.validated = 1);
|
|
238
238
|
}
|
|
239
|
-
var j = ie,
|
|
239
|
+
var j = ie, A = Symbol.for("react.transitional.element"), y = Symbol.for("react.portal"), O = Symbol.for("react.fragment"), C = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), X = Symbol.for("react.consumer"), Y = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), M = Symbol.for("react.suspense"), S = Symbol.for("react.suspense_list"), T = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), k = Symbol.for("react.activity"), v = Symbol.for("react.client.reference"), $ = j.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, x = Object.prototype.hasOwnProperty, q = Array.isArray, _ = console.createTask ? console.createTask : function() {
|
|
240
240
|
return null;
|
|
241
241
|
};
|
|
242
242
|
j = {
|
|
@@ -244,13 +244,13 @@ React keys must be passed directly to JSX without using spread:
|
|
|
244
244
|
return e();
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
|
-
var
|
|
247
|
+
var F, I = {}, U = j["react-stack-bottom-frame"].bind(
|
|
248
248
|
j,
|
|
249
249
|
u
|
|
250
250
|
)(), B = _(g(u)), V = {};
|
|
251
|
-
J.Fragment =
|
|
252
|
-
var R = 1e4 >
|
|
253
|
-
return
|
|
251
|
+
J.Fragment = O, J.jsx = function(e, n, r, i, p) {
|
|
252
|
+
var R = 1e4 > $.recentlyCreatedOwnerStacks++;
|
|
253
|
+
return L(
|
|
254
254
|
e,
|
|
255
255
|
n,
|
|
256
256
|
r,
|
|
@@ -261,8 +261,8 @@ React keys must be passed directly to JSX without using spread:
|
|
|
261
261
|
R ? _(g(e)) : B
|
|
262
262
|
);
|
|
263
263
|
}, J.jsxs = function(e, n, r, i, p) {
|
|
264
|
-
var R = 1e4 >
|
|
265
|
-
return
|
|
264
|
+
var R = 1e4 > $.recentlyCreatedOwnerStacks++;
|
|
265
|
+
return L(
|
|
266
266
|
e,
|
|
267
267
|
n,
|
|
268
268
|
r,
|
|
@@ -291,7 +291,7 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
291
291
|
hasError: d,
|
|
292
292
|
register: E,
|
|
293
293
|
name: m,
|
|
294
|
-
isDisabled:
|
|
294
|
+
isDisabled: L = !1,
|
|
295
295
|
autocomplete: w = !1,
|
|
296
296
|
...j
|
|
297
297
|
}) => /* @__PURE__ */ a.jsxs("div", { className: c, children: [
|
|
@@ -305,7 +305,7 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
305
305
|
/* @__PURE__ */ a.jsx(
|
|
306
306
|
"input",
|
|
307
307
|
{
|
|
308
|
-
disabled:
|
|
308
|
+
disabled: L,
|
|
309
309
|
autoComplete: w ? "on" : "off",
|
|
310
310
|
id: m,
|
|
311
311
|
...E,
|
|
@@ -320,7 +320,7 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
320
320
|
}
|
|
321
321
|
),
|
|
322
322
|
d && /* @__PURE__ */ a.jsx("p", { className: u, children: d })
|
|
323
|
-
] }), ae = (t) => /* @__PURE__ */
|
|
323
|
+
] }), ae = (t) => /* @__PURE__ */ W.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 384 512", fill: "currentColor", ...t }, /* @__PURE__ */ W.createElement("path", { fill: "currentColor", d: "M209.5 369c-9.4 9.4-24.6 9.4-33.9 0L15.5 209c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l143 143 143-143c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-160 160z" })), fe = (t) => /* @__PURE__ */ W.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 384 512", fill: "currentColor", ...t }, /* @__PURE__ */ W.createElement("path", { fill: "currentColor", d: "M7.5 105c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l151 151 151-151c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-151 151 151 151c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-151-151-151 151c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l151-151-151-151z" })), oe = (t) => /* @__PURE__ */ W.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 512 512", fill: "currentColor", ...t }, /* @__PURE__ */ W.createElement("path", { fill: "currentColor", d: "M368 208a160 160 0 1 0 -320 0 160 160 0 1 0 320 0zM337.1 371.1C301.7 399.2 256.8 416 208 416 93.1 416 0 322.9 0 208S93.1 0 208 0 416 93.1 416 208c0 48.8-16.8 93.7-44.9 129.1L505 471c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0L337.1 371.1z" })), ge = () => {
|
|
324
324
|
const [t, s] = N(typeof window < "u" ? window.innerWidth : 0), c = () => s(typeof window < "u" ? window.innerWidth : 0);
|
|
325
325
|
return b(() => (window.addEventListener("resize", c), () => window.removeEventListener("resize", c)), [t]), t;
|
|
326
326
|
}, se = ({
|
|
@@ -394,18 +394,18 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
394
394
|
placeholder: d,
|
|
395
395
|
disabled: E = !1,
|
|
396
396
|
pagination: m,
|
|
397
|
-
optionFilterLabel:
|
|
397
|
+
optionFilterLabel: L,
|
|
398
398
|
hasSearch: w = !1,
|
|
399
399
|
onSelectChange: j
|
|
400
400
|
}) => {
|
|
401
|
-
let
|
|
402
|
-
const
|
|
401
|
+
let A = !0;
|
|
402
|
+
const y = ge(), O = pe("#select"), [C, P] = N(!1), [X, Y] = N(!0), [l, M] = N(null), [S, T] = N(null), [D, k] = N(""), [v, $] = N({
|
|
403
403
|
page: 1,
|
|
404
404
|
pageLabel: "page",
|
|
405
405
|
size: 20,
|
|
406
406
|
sizeLabel: "size",
|
|
407
407
|
isLoading: !1
|
|
408
|
-
}), x = ee(void 0), q = ee(void 0), _ = ee(void 0),
|
|
408
|
+
}), x = ee(void 0), q = ee(void 0), _ = ee(void 0), F = async () => {
|
|
409
409
|
if (x?.current)
|
|
410
410
|
try {
|
|
411
411
|
const r = await fetch(x?.current);
|
|
@@ -417,15 +417,15 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
417
417
|
}
|
|
418
418
|
};
|
|
419
419
|
b(() => () => {
|
|
420
|
-
|
|
420
|
+
A = !1;
|
|
421
421
|
}, []), b(() => {
|
|
422
422
|
if (u?.length) {
|
|
423
423
|
if (x.current = u, x.current.includes(m?.pageLabel || "page")) {
|
|
424
424
|
const r = new URL(u);
|
|
425
425
|
r.searchParams.set(m?.pageLabel || "page", (m?.page || v.page).toString()), r.searchParams.set(m?.sizeLabel || "size", (m?.size || v.size).toString()), x.current = r.href;
|
|
426
426
|
}
|
|
427
|
-
Y(!0),
|
|
428
|
-
|
|
427
|
+
Y(!0), F().then((r) => {
|
|
428
|
+
A && (Y(!1), T(r));
|
|
429
429
|
});
|
|
430
430
|
}
|
|
431
431
|
}, [u, m]), b(() => {
|
|
@@ -434,8 +434,8 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
434
434
|
const r = new URL(x.current);
|
|
435
435
|
r.searchParams.set(m?.pageLabel || "page", v.page.toString()), x.current = r.href;
|
|
436
436
|
}
|
|
437
|
-
|
|
438
|
-
|
|
437
|
+
F().then((r) => {
|
|
438
|
+
A && (Y(!1), $({
|
|
439
439
|
...v,
|
|
440
440
|
isLoading: !1
|
|
441
441
|
}), T([
|
|
@@ -445,35 +445,35 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
445
445
|
});
|
|
446
446
|
}
|
|
447
447
|
}, [v]), b(() => {
|
|
448
|
-
|
|
448
|
+
y < 768 && (C ? (he("select"), document.body.style.overflow = "hidden", _.current?.focus()) : (window.location.hash && !document.referrer.includes("#") && me(), document.body.style.overflow = "auto"));
|
|
449
449
|
}, [C]), b(() => {
|
|
450
|
-
h && t?.length && (t?.find((r) => r[s] === h) ?
|
|
450
|
+
h && t?.length && (t?.find((r) => r[s] === h) ? M(t?.find((r) => r[s] === h)) : M(h));
|
|
451
451
|
}, [h]), b(() => {
|
|
452
452
|
l && w && (o?.length && S?.find((r) => r[s] === l[s]) ? k(S?.find((r) => r[s] === l[s])[o] || "") : k(l));
|
|
453
453
|
}, [l]), b(() => {
|
|
454
|
-
|
|
455
|
-
}, [
|
|
454
|
+
O && P(!1);
|
|
455
|
+
}, [O]), b(() => {
|
|
456
456
|
t?.length && T(t);
|
|
457
457
|
}, [t]);
|
|
458
|
-
const
|
|
459
|
-
w && T(t),
|
|
458
|
+
const I = () => {
|
|
459
|
+
w && T(t), P((r) => !r);
|
|
460
460
|
}, U = () => {
|
|
461
|
-
w && (T(t), k(typeof l == "string" ? l : l ? l[o] : "")),
|
|
461
|
+
w && (T(t), k(typeof l == "string" ? l : l ? l[o] : "")), P(!1);
|
|
462
462
|
}, B = (r) => {
|
|
463
|
-
w && (o?.length ? k(r[o]) : k(r)),
|
|
463
|
+
w && (o?.length ? k(r[o]) : k(r)), M(r), I(), j && j(r);
|
|
464
464
|
}, V = (r) => {
|
|
465
465
|
if (!l)
|
|
466
466
|
return "";
|
|
467
467
|
if (s?.length && r[s] === l[s] || r === l)
|
|
468
468
|
return "bg-grey-100";
|
|
469
469
|
}, e = (r) => {
|
|
470
|
-
S?.length && !v.isLoading && r.target.offsetHeight + r.target.scrollTop >= r.target.scrollHeight - 100 &&
|
|
470
|
+
S?.length && !v.isLoading && r.target.offsetHeight + r.target.scrollTop >= r.target.scrollHeight - 100 && $({
|
|
471
471
|
page: v.page + 1,
|
|
472
472
|
isLoading: !0
|
|
473
473
|
});
|
|
474
474
|
}, n = (r) => {
|
|
475
|
-
const i = r?.target?.value?.length ? t.filter((p) => typeof p == "object" ? p[o].includes(r?.target?.value) : p.includes(r?.target?.value)) : t;
|
|
476
|
-
T(i), k(r?.target?.value), C ||
|
|
475
|
+
const i = r?.target?.value?.length ? t.filter((p) => typeof p == "object" ? p[L?.length ? L : o].includes(r?.target?.value) : p.includes(r?.target?.value)) : t;
|
|
476
|
+
T(i), k(r?.target?.value), C || P(!0);
|
|
477
477
|
};
|
|
478
478
|
return we(q, _, U), /* @__PURE__ */ a.jsxs("div", { className: `nariaSelect ${E ? "nariaSelect-disabled" : ""}`, children: [
|
|
479
479
|
/* @__PURE__ */ a.jsxs(
|
|
@@ -491,10 +491,10 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
491
491
|
placeholder: d?.length ? d : "Select",
|
|
492
492
|
className: `${l ? "text-dark-100" : "text-grey-300"}
|
|
493
493
|
${c && "!border-danger-100 focus:border-danger-100 outline-danger-100"}`,
|
|
494
|
-
value:
|
|
494
|
+
value: D,
|
|
495
495
|
disabled: E,
|
|
496
496
|
type: "text",
|
|
497
|
-
onClick:
|
|
497
|
+
onClick: I,
|
|
498
498
|
onChange: n
|
|
499
499
|
}
|
|
500
500
|
),
|
|
@@ -517,7 +517,7 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
517
517
|
disabled: E,
|
|
518
518
|
className: `nariaHandler ${l ? "text-dark-100" : "text-grey-300"}
|
|
519
519
|
${c && "!border-danger-100 focus:border-danger-100 outline-danger-100"}`,
|
|
520
|
-
onClick:
|
|
520
|
+
onClick: I,
|
|
521
521
|
children: [
|
|
522
522
|
l ? o?.length ? l[o] : l : d?.length ? d : "Select",
|
|
523
523
|
" ",
|
|
@@ -536,10 +536,10 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
536
536
|
C ? /* @__PURE__ */ a.jsxs(
|
|
537
537
|
"div",
|
|
538
538
|
{
|
|
539
|
-
className: `nariaListWrapper ${
|
|
539
|
+
className: `nariaListWrapper ${y < 768 ? "nariaListWrapper-mobile" : ""}`,
|
|
540
540
|
ref: q,
|
|
541
541
|
children: [
|
|
542
|
-
w &&
|
|
542
|
+
w && y < 768 ? /* @__PURE__ */ a.jsxs("div", { className: "nariaSearchInput", children: [
|
|
543
543
|
/* @__PURE__ */ a.jsx(
|
|
544
544
|
"input",
|
|
545
545
|
{
|
|
@@ -547,7 +547,7 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
547
547
|
placeholder: d?.length ? d : "Select",
|
|
548
548
|
className: `${l ? "text-dark-100" : "text-grey-300"}
|
|
549
549
|
${c && "!border-danger-100 focus:border-danger-100 outline-danger-100"}`,
|
|
550
|
-
value:
|
|
550
|
+
value: D,
|
|
551
551
|
disabled: E,
|
|
552
552
|
type: "text",
|
|
553
553
|
onChange: n
|
|
@@ -563,10 +563,10 @@ const xe = ({ type: t = "button", value: s }) => /* @__PURE__ */ a.jsx("button",
|
|
|
563
563
|
/* @__PURE__ */ a.jsx(
|
|
564
564
|
"div",
|
|
565
565
|
{
|
|
566
|
-
className: `nariaList ${
|
|
566
|
+
className: `nariaList ${y < 768 ? "nariaList-mobile" : "nariaList-desktop"}`,
|
|
567
567
|
onScroll: e,
|
|
568
568
|
children: u && X ? /* @__PURE__ */ a.jsx("div", { className: "nariaLoadingWrapper", children: /* @__PURE__ */ a.jsx(se, {}) }) : /* @__PURE__ */ a.jsxs(a.Fragment, { children: [
|
|
569
|
-
|
|
569
|
+
y < 768 ? /* @__PURE__ */ a.jsx("div", { className: "sticky top-0 text-left", children: /* @__PURE__ */ a.jsx("button", { className: "p-3", onClick: U, disabled: E, children: /* @__PURE__ */ a.jsx(fe, { className: "w-6" }) }) }) : void 0,
|
|
570
570
|
S?.length ? /* @__PURE__ */ a.jsx(a.Fragment, { children: S?.map((r, i) => /* @__PURE__ */ a.jsx(
|
|
571
571
|
"button",
|
|
572
572
|
{
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"name": "Mohammad Mehdi Mohammadi",
|
|
6
6
|
"url": ""
|
|
7
7
|
},
|
|
8
|
-
"version": "0.1.
|
|
8
|
+
"version": "0.1.39",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/naria-ui.cjs.js",
|
|
11
11
|
"module": "dist/naria-ui.es.js",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"./dist/*.css": "./dist/*.css",
|
|
20
20
|
"./assets/*.css": "./assets/*.css"
|
|
21
21
|
},
|
|
22
|
-
"files": [
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
23
25
|
"publishConfig": {
|
|
24
26
|
"access": "public"
|
|
25
27
|
},
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React, {FC} from "react";
|
|
2
|
-
|
|
3
|
-
export interface props extends React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
|
|
4
|
-
type?: "button" | "submit";
|
|
5
|
-
value: string;
|
|
6
|
-
}
|
|
7
|
-
export const Button: FC<props> = ({type = "button", value}) => {
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
<button type={type}>
|
|
11
|
-
{value}
|
|
12
|
-
</button>
|
|
13
|
-
);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Button } from './Button';
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {FC} from "react";
|
|
2
|
-
|
|
3
|
-
export interface props {
|
|
4
|
-
type?: "password" | "text";
|
|
5
|
-
wrapperClass?: string;
|
|
6
|
-
labelClass?: string;
|
|
7
|
-
inputClass?: string;
|
|
8
|
-
errorClass?: string;
|
|
9
|
-
placeholder: string;
|
|
10
|
-
label: string;
|
|
11
|
-
hasError?: string | null;
|
|
12
|
-
register?: any;
|
|
13
|
-
name?: string;
|
|
14
|
-
isDisabled?: boolean;
|
|
15
|
-
autocomplete?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const Input: FC<props> = ({
|
|
19
|
-
type = "text",
|
|
20
|
-
placeholder,
|
|
21
|
-
wrapperClass = "",
|
|
22
|
-
labelClass = "",
|
|
23
|
-
inputClass = "",
|
|
24
|
-
errorClass = "",
|
|
25
|
-
label,
|
|
26
|
-
hasError,
|
|
27
|
-
register, name,
|
|
28
|
-
isDisabled = false,
|
|
29
|
-
autocomplete = false,
|
|
30
|
-
...otherProps
|
|
31
|
-
}) => {
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<div className={wrapperClass}>
|
|
35
|
-
<label
|
|
36
|
-
htmlFor={name}
|
|
37
|
-
className={`${labelClass} ${hasError && "error"}`}>
|
|
38
|
-
{label}
|
|
39
|
-
<input
|
|
40
|
-
disabled={isDisabled}
|
|
41
|
-
autoComplete={autocomplete ? "on" : "off"}
|
|
42
|
-
id={name}
|
|
43
|
-
{...register}
|
|
44
|
-
{...otherProps}
|
|
45
|
-
type={type}
|
|
46
|
-
name={name}
|
|
47
|
-
className={`${inputClass} ${hasError && "error"} ${errorClass}`}
|
|
48
|
-
placeholder={placeholder}
|
|
49
|
-
/>
|
|
50
|
-
</label>
|
|
51
|
-
{
|
|
52
|
-
hasError &&
|
|
53
|
-
<p className={errorClass}>{hasError}</p>
|
|
54
|
-
}
|
|
55
|
-
</div>
|
|
56
|
-
);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Input } from './Input';
|
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
import {FC, useEffect, useRef, useState} from "react";
|
|
2
|
-
import AngleDown from "../../../assets/icons/angle-down.svg?react";
|
|
3
|
-
import Close from '../../../assets/icons/close.svg?react';
|
|
4
|
-
import Search from '../../../assets/icons/search.svg?react';
|
|
5
|
-
import {useWidth} from "../../../hooks/use-width";
|
|
6
|
-
import Loading from "../../../shared/loading/Loading";
|
|
7
|
-
import './select.scss';
|
|
8
|
-
import {addNavigation, onHashChanges, removeNavigation} from "../../utils/navigator";
|
|
9
|
-
import useClickOutside from "../../../hooks/click-outside";
|
|
10
|
-
|
|
11
|
-
interface Pagination {
|
|
12
|
-
page?: number;
|
|
13
|
-
pageLabel?: string;
|
|
14
|
-
size?: number;
|
|
15
|
-
sizeLabel?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface SDS extends Pagination {
|
|
19
|
-
isLoading?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface props {
|
|
23
|
-
options?: any[];
|
|
24
|
-
label?: string;
|
|
25
|
-
title: string;
|
|
26
|
-
value?: string;
|
|
27
|
-
api?: string;
|
|
28
|
-
hasError?: string | null;
|
|
29
|
-
selected?: any;
|
|
30
|
-
placeholder?: string;
|
|
31
|
-
disabled?: boolean;
|
|
32
|
-
pagination?: Pagination;
|
|
33
|
-
optionFilterLabel?: string;
|
|
34
|
-
hasSearch?: boolean;
|
|
35
|
-
onSelectChange?: any;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const Select: FC<props> = ({
|
|
39
|
-
options,
|
|
40
|
-
label,
|
|
41
|
-
hasError,
|
|
42
|
-
title,
|
|
43
|
-
value,
|
|
44
|
-
api,
|
|
45
|
-
selected,
|
|
46
|
-
placeholder,
|
|
47
|
-
disabled = false,
|
|
48
|
-
pagination,
|
|
49
|
-
optionFilterLabel,
|
|
50
|
-
hasSearch = false,
|
|
51
|
-
onSelectChange
|
|
52
|
-
}) => {
|
|
53
|
-
let isSubscribed = true;
|
|
54
|
-
const getDeviceWidth = useWidth();
|
|
55
|
-
|
|
56
|
-
const isHashChanged = onHashChanges('#select');
|
|
57
|
-
const [isShow, setIsShow] = useState(false);
|
|
58
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
59
|
-
const [localSelected, setLocalSelected] = useState<string | null>(null);
|
|
60
|
-
const [localOptions, setLocalOptions] = useState(null);
|
|
61
|
-
const [searchTerm, setSearchTerm] = useState("");
|
|
62
|
-
const [localPagination, setLocalPagination] = useState<SDS>({
|
|
63
|
-
page: 1,
|
|
64
|
-
pageLabel: 'page',
|
|
65
|
-
size: 20,
|
|
66
|
-
sizeLabel: 'size',
|
|
67
|
-
isLoading: false
|
|
68
|
-
});
|
|
69
|
-
const localApi = useRef<string | undefined>(undefined);
|
|
70
|
-
const wrapperRef = useRef(undefined);
|
|
71
|
-
const handlerRef = useRef(undefined);
|
|
72
|
-
|
|
73
|
-
const getData = async () => {
|
|
74
|
-
if (localApi?.current) {
|
|
75
|
-
try {
|
|
76
|
-
const response = await fetch(localApi?.current);
|
|
77
|
-
if (!response.ok) {
|
|
78
|
-
throw new Error(`Response status: ${response.status}`);
|
|
79
|
-
}
|
|
80
|
-
return await response.json();
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error(error.message);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
return () => {
|
|
90
|
-
isSubscribed = false;
|
|
91
|
-
};
|
|
92
|
-
}, [])
|
|
93
|
-
useEffect(() => {
|
|
94
|
-
if (api?.length) {
|
|
95
|
-
localApi.current = api;
|
|
96
|
-
if (localApi.current.includes(pagination?.pageLabel || 'page')) {
|
|
97
|
-
const url = new URL(api);
|
|
98
|
-
url.searchParams.set(pagination?.pageLabel || 'page', (pagination?.page || localPagination.page).toString());
|
|
99
|
-
url.searchParams.set(pagination?.sizeLabel || 'size', (pagination?.size || localPagination.size).toString());
|
|
100
|
-
localApi.current = url.href;
|
|
101
|
-
}
|
|
102
|
-
setIsLoading(true);
|
|
103
|
-
getData().then((res) => {
|
|
104
|
-
if (isSubscribed) {
|
|
105
|
-
setIsLoading(false);
|
|
106
|
-
setLocalOptions(res);
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
}, [api, pagination]);
|
|
111
|
-
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
if (localPagination.isLoading) {
|
|
114
|
-
if (localApi.current.includes(pagination?.pageLabel || 'page')) {
|
|
115
|
-
const url = new URL(localApi.current);
|
|
116
|
-
url.searchParams.set(pagination?.pageLabel || 'page', (localPagination.page).toString());
|
|
117
|
-
localApi.current = url.href;
|
|
118
|
-
}
|
|
119
|
-
getData().then((res) => {
|
|
120
|
-
if (isSubscribed) {
|
|
121
|
-
setIsLoading(false);
|
|
122
|
-
setLocalPagination({
|
|
123
|
-
...localPagination,
|
|
124
|
-
isLoading: false
|
|
125
|
-
})
|
|
126
|
-
setLocalOptions([
|
|
127
|
-
...localOptions,
|
|
128
|
-
...res
|
|
129
|
-
]);
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
}, [localPagination]);
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
if (getDeviceWidth < 768) {
|
|
136
|
-
if (isShow) {
|
|
137
|
-
addNavigation('select');
|
|
138
|
-
document.body.style.overflow = 'hidden';
|
|
139
|
-
handlerRef.current?.focus();
|
|
140
|
-
} else {
|
|
141
|
-
if (window.location.hash && !document.referrer.includes('#')) {
|
|
142
|
-
removeNavigation();
|
|
143
|
-
}
|
|
144
|
-
document.body.style.overflow = 'auto';
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}, [isShow]);
|
|
148
|
-
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
if (selected && options?.length) {
|
|
151
|
-
if (options?.find(item => item[label] === selected)) {
|
|
152
|
-
setLocalSelected(options?.find(item => item[label] === selected));
|
|
153
|
-
} else {
|
|
154
|
-
setLocalSelected(selected);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}, [selected]);
|
|
158
|
-
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
if (localSelected) {
|
|
161
|
-
if (hasSearch) {
|
|
162
|
-
if (value?.length && localOptions?.find(item => item[label] === localSelected[label])) {
|
|
163
|
-
setSearchTerm(localOptions?.find(item => item[label] === localSelected[label])[value] || '');
|
|
164
|
-
} else {
|
|
165
|
-
setSearchTerm(localSelected);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}, [localSelected]);
|
|
170
|
-
|
|
171
|
-
useEffect(() => {
|
|
172
|
-
if (isHashChanged) {
|
|
173
|
-
setIsShow(false)
|
|
174
|
-
}
|
|
175
|
-
}, [isHashChanged])
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
useEffect(() => {
|
|
179
|
-
if (options?.length) {
|
|
180
|
-
setLocalOptions(options)
|
|
181
|
-
}
|
|
182
|
-
}, [options]);
|
|
183
|
-
|
|
184
|
-
const onToggle = () => {
|
|
185
|
-
if (hasSearch) {
|
|
186
|
-
setLocalOptions(options)
|
|
187
|
-
}
|
|
188
|
-
setIsShow(prevState => !prevState);
|
|
189
|
-
}
|
|
190
|
-
const onClose = () => {
|
|
191
|
-
if (hasSearch) {
|
|
192
|
-
setLocalOptions(options)
|
|
193
|
-
if (typeof localSelected === "string") {
|
|
194
|
-
setSearchTerm(localSelected);
|
|
195
|
-
} else {
|
|
196
|
-
setSearchTerm(localSelected ? localSelected[value] : "")
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
setIsShow(false);
|
|
200
|
-
}
|
|
201
|
-
const onSelect = (item) => {
|
|
202
|
-
if (hasSearch) {
|
|
203
|
-
if (value?.length) {
|
|
204
|
-
setSearchTerm(item[value]);
|
|
205
|
-
} else {
|
|
206
|
-
setSearchTerm(item);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
setLocalSelected(item);
|
|
210
|
-
onToggle();
|
|
211
|
-
if (onSelectChange) {
|
|
212
|
-
onSelectChange(item);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const getActiveClass = (item) => {
|
|
217
|
-
if (!localSelected) {
|
|
218
|
-
return "";
|
|
219
|
-
}
|
|
220
|
-
if (label?.length && item[label] === localSelected[label]) {
|
|
221
|
-
return "bg-grey-100"
|
|
222
|
-
}
|
|
223
|
-
if (item === localSelected) {
|
|
224
|
-
return "bg-grey-100"
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const onScroll = (e) => {
|
|
228
|
-
if (localOptions?.length && !localPagination.isLoading) {
|
|
229
|
-
const bottom = e.target.offsetHeight + e.target.scrollTop >= e.target.scrollHeight - 100;
|
|
230
|
-
|
|
231
|
-
if (bottom) {
|
|
232
|
-
setLocalPagination({
|
|
233
|
-
page: localPagination.page + 1,
|
|
234
|
-
isLoading: true
|
|
235
|
-
})
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
const onSearch = (e) => {
|
|
241
|
-
const tempList = e?.target?.value?.length ? options.filter(val => typeof val === "object" ? val[value].includes(e?.target?.value) : val.includes(e?.target?.value)) : options
|
|
242
|
-
setLocalOptions(tempList)
|
|
243
|
-
setSearchTerm(e?.target?.value)
|
|
244
|
-
if (!isShow) {
|
|
245
|
-
setIsShow(true)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
useClickOutside(wrapperRef, handlerRef, onClose);
|
|
249
|
-
return (
|
|
250
|
-
<div className={`nariaSelect ${disabled ? 'nariaSelect-disabled' : ''}`}>
|
|
251
|
-
<label
|
|
252
|
-
className={`cursor-pointer
|
|
253
|
-
${hasError && "!text-danger-100"}`}>
|
|
254
|
-
<span className={``}>{title}</span>
|
|
255
|
-
{
|
|
256
|
-
hasSearch ? (
|
|
257
|
-
<div className="nariaSearchInput">
|
|
258
|
-
<input ref={handlerRef}
|
|
259
|
-
placeholder={placeholder?.length ? placeholder : "Select"}
|
|
260
|
-
className={`${localSelected ? "text-dark-100" : "text-grey-300"}
|
|
261
|
-
${hasError && "!border-danger-100 focus:border-danger-100 outline-danger-100"}`}
|
|
262
|
-
value={searchTerm}
|
|
263
|
-
disabled={disabled} type="text" onClick={onToggle} onChange={onSearch}/>
|
|
264
|
-
{
|
|
265
|
-
isShow ? (
|
|
266
|
-
<Search
|
|
267
|
-
className="nariaSearchIcon"/>
|
|
268
|
-
) : (
|
|
269
|
-
<AngleDown
|
|
270
|
-
className={`nariaArrowIcon ${isShow ? "nariaArrowIcon-rotate-180" : ""}`}/>
|
|
271
|
-
)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
</div>
|
|
276
|
-
) : (
|
|
277
|
-
<button type="button"
|
|
278
|
-
ref={handlerRef}
|
|
279
|
-
disabled={disabled}
|
|
280
|
-
className={`nariaHandler ${localSelected ? "text-dark-100" : "text-grey-300"}
|
|
281
|
-
${hasError && "!border-danger-100 focus:border-danger-100 outline-danger-100"}`}
|
|
282
|
-
onClick={onToggle}>
|
|
283
|
-
{
|
|
284
|
-
localSelected ? (
|
|
285
|
-
value?.length ? localSelected[value] : localSelected
|
|
286
|
-
) : (placeholder?.length ? placeholder : "Select")
|
|
287
|
-
} <AngleDown
|
|
288
|
-
className={`nariaArrowIcon ${isShow ? "nariaArrowIcon-rotate-180" : ""}`}/>
|
|
289
|
-
</button>
|
|
290
|
-
)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
</label>
|
|
294
|
-
|
|
295
|
-
{
|
|
296
|
-
isShow ? (
|
|
297
|
-
<div
|
|
298
|
-
className={`nariaListWrapper ${getDeviceWidth < 768 ? "nariaListWrapper-mobile" : ""}`}
|
|
299
|
-
ref={wrapperRef}>
|
|
300
|
-
{
|
|
301
|
-
hasSearch && getDeviceWidth < 768 ? (
|
|
302
|
-
<div className="nariaSearchInput">
|
|
303
|
-
<input ref={handlerRef}
|
|
304
|
-
placeholder={placeholder?.length ? placeholder : "Select"}
|
|
305
|
-
className={`${localSelected ? "text-dark-100" : "text-grey-300"}
|
|
306
|
-
${hasError && "!border-danger-100 focus:border-danger-100 outline-danger-100"}`}
|
|
307
|
-
value={searchTerm}
|
|
308
|
-
disabled={disabled} type="text" onChange={onSearch}/>
|
|
309
|
-
<Search
|
|
310
|
-
className="nariaSearchIcon"/>
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
</div>
|
|
314
|
-
) : undefined
|
|
315
|
-
}
|
|
316
|
-
<div
|
|
317
|
-
className={`nariaList ${getDeviceWidth < 768 ? "nariaList-mobile" : `nariaList-desktop`}`}
|
|
318
|
-
onScroll={onScroll}>
|
|
319
|
-
{
|
|
320
|
-
api && isLoading ? (
|
|
321
|
-
<div className="nariaLoadingWrapper">
|
|
322
|
-
<Loading/>
|
|
323
|
-
</div>
|
|
324
|
-
) : (
|
|
325
|
-
<>
|
|
326
|
-
{
|
|
327
|
-
getDeviceWidth < 768 ? (
|
|
328
|
-
<div className="sticky top-0 text-left">
|
|
329
|
-
<button className="p-3" onClick={onClose} disabled={disabled}>
|
|
330
|
-
<Close className="w-6"/>
|
|
331
|
-
</button>
|
|
332
|
-
</div>
|
|
333
|
-
) : undefined
|
|
334
|
-
}
|
|
335
|
-
{
|
|
336
|
-
localOptions?.length ? (
|
|
337
|
-
<>
|
|
338
|
-
{
|
|
339
|
-
localOptions?.map((item, index) => {
|
|
340
|
-
return (
|
|
341
|
-
<button type="button" onClick={() => onSelect(item)}
|
|
342
|
-
disabled={disabled}
|
|
343
|
-
key={index.toString()}
|
|
344
|
-
className={`text-right py-2.5 px-4 text-base hover:bg-grey-100 rounded-lg ${getActiveClass(item)}`}>
|
|
345
|
-
{value?.length ? item[value] : item}
|
|
346
|
-
</button>
|
|
347
|
-
)
|
|
348
|
-
})
|
|
349
|
-
}
|
|
350
|
-
</>
|
|
351
|
-
) : (
|
|
352
|
-
<div>
|
|
353
|
-
No Data
|
|
354
|
-
</div>
|
|
355
|
-
)
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
{
|
|
360
|
-
localPagination.isLoading ? (
|
|
361
|
-
<div className="nariaLoadingMoreWrapper">
|
|
362
|
-
<Loading/>
|
|
363
|
-
</div>
|
|
364
|
-
) : undefined
|
|
365
|
-
}
|
|
366
|
-
</>
|
|
367
|
-
)
|
|
368
|
-
}
|
|
369
|
-
</div>
|
|
370
|
-
</div>
|
|
371
|
-
) : undefined
|
|
372
|
-
}
|
|
373
|
-
{
|
|
374
|
-
hasError &&
|
|
375
|
-
<p className="text-xs mt-1 text-danger-100">{hasError}</p>
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
</div>
|
|
379
|
-
);
|
|
380
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Select } from './Select';
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
.nariaSelect {
|
|
3
|
-
position: relative;
|
|
4
|
-
|
|
5
|
-
.nariaListWrapper {
|
|
6
|
-
overflow: hidden;
|
|
7
|
-
|
|
8
|
-
&.nariaListWrapper-mobile {
|
|
9
|
-
position: fixed;
|
|
10
|
-
top: 0;
|
|
11
|
-
right: 0;
|
|
12
|
-
height: 100%;
|
|
13
|
-
width: 100%;
|
|
14
|
-
z-index: 97;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.nariaList {
|
|
19
|
-
display: flex;
|
|
20
|
-
flex-direction: column;
|
|
21
|
-
width: 100%;
|
|
22
|
-
z-index: 99;
|
|
23
|
-
position: relative;
|
|
24
|
-
overflow: auto;
|
|
25
|
-
|
|
26
|
-
&.nariaList-mobile {
|
|
27
|
-
position: relative;
|
|
28
|
-
height: 100%;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
&.nariaList-desktop {
|
|
32
|
-
position: absolute;
|
|
33
|
-
animation: fadeInTranslateY 0.3s ease-out forwards;
|
|
34
|
-
max-height: 100px;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.nariaLoadingWrapper {
|
|
38
|
-
padding: 24px 0;
|
|
39
|
-
display: flex;
|
|
40
|
-
justify-content: center;
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
.nariaLoadingMoreWrapper {
|
|
45
|
-
position: sticky;
|
|
46
|
-
bottom: 0;
|
|
47
|
-
text-align: center;
|
|
48
|
-
width: 100%;
|
|
49
|
-
|
|
50
|
-
.nariaLoading {
|
|
51
|
-
width: 20px;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.nariaSearchInput {
|
|
57
|
-
position: relative;
|
|
58
|
-
display: flex;
|
|
59
|
-
|
|
60
|
-
input {
|
|
61
|
-
width: 100%;
|
|
62
|
-
padding-right: 20px;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.nariaArrowIcon, .nariaSearchIcon {
|
|
66
|
-
position: absolute;
|
|
67
|
-
bottom: 0;
|
|
68
|
-
margin-top: auto;
|
|
69
|
-
margin-bottom: auto;
|
|
70
|
-
top: 0;
|
|
71
|
-
right: 6px;
|
|
72
|
-
width: 12px;
|
|
73
|
-
height: 12px;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.nariaHandler {
|
|
79
|
-
position: relative;
|
|
80
|
-
display: flex;
|
|
81
|
-
gap: 4px;
|
|
82
|
-
width: 100%;
|
|
83
|
-
align-items: center;
|
|
84
|
-
justify-content: space-between;
|
|
85
|
-
|
|
86
|
-
.nariaArrowIcon {
|
|
87
|
-
width: 12px;
|
|
88
|
-
height: 12px;
|
|
89
|
-
transition: transform 0.4s;
|
|
90
|
-
|
|
91
|
-
-webkit-transform: rotate(0deg);
|
|
92
|
-
-moz-transform: rotate(0deg);
|
|
93
|
-
-o-transform: rotate(0deg);
|
|
94
|
-
-ms-transform: rotate(0deg);
|
|
95
|
-
transform: rotate(0deg);
|
|
96
|
-
|
|
97
|
-
&.nariaArrowIcon-rotate-180 {
|
|
98
|
-
-webkit-transform: rotate(180deg);
|
|
99
|
-
-moz-transform: rotate(180deg);
|
|
100
|
-
-o-transform: rotate(180deg);
|
|
101
|
-
-ms-transform: rotate(180deg);
|
|
102
|
-
transform: rotate(180deg);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
html[dir="rtl"] {
|
|
109
|
-
.nariaSelect {
|
|
110
|
-
.nariaSearchInput {
|
|
111
|
-
input {
|
|
112
|
-
padding-left: 20px;
|
|
113
|
-
padding-right: 0;
|
|
114
|
-
}
|
|
115
|
-
.nariaArrowIcon, .nariaSearchIcon {
|
|
116
|
-
left: 6px;
|
|
117
|
-
right: auto;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
@keyframes fadeInTranslateY {
|
|
124
|
-
from {
|
|
125
|
-
opacity: 0;
|
|
126
|
-
transform: translateY(10px);
|
|
127
|
-
}
|
|
128
|
-
to {
|
|
129
|
-
opacity: 1;
|
|
130
|
-
transform: translateY(0);
|
|
131
|
-
}
|
|
132
|
-
}
|
package/lib/components/index.ts
DELETED
package/lib/index.ts
DELETED
package/lib/utils/capitalize.ts
DELETED
package/lib/utils/index.ts
DELETED
package/lib/utils/navigator.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {useEffect, useState} from "react";
|
|
2
|
-
|
|
3
|
-
export const removeNavigation = () => {
|
|
4
|
-
const newUrl = `${window.location.pathname}${window.location.search}`;
|
|
5
|
-
window.history.replaceState(null, '', newUrl);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const addNavigation = (state: string) => {
|
|
9
|
-
window.location.hash = state;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export const onHashChanges = (state: string) => {
|
|
14
|
-
const [isHashChanged, setIsHashChanged] = useState(false)
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
const handleHashChange = (e) => {
|
|
17
|
-
if(window.location.hash !== state) {
|
|
18
|
-
setIsHashChanged(true);
|
|
19
|
-
} else {
|
|
20
|
-
setIsHashChanged(false);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
window.addEventListener('hashchange', handleHashChange);
|
|
24
|
-
return () => {
|
|
25
|
-
window.removeEventListener('hashchange', handleHashChange);
|
|
26
|
-
};
|
|
27
|
-
}, [])
|
|
28
|
-
return isHashChanged
|
|
29
|
-
};
|