@dgshahr/ui-kit 0.0.84 → 0.0.85
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 +1 @@
|
|
|
1
|
-
"use strict";require('../../assets/styles.css');const s=require("react/jsx-runtime"),d=require("../../clsx-C11secjj.cjs"),o=require("react"),
|
|
1
|
+
"use strict";require('../../assets/styles.css');const s=require("react/jsx-runtime"),d=require("../../clsx-C11secjj.cjs"),o=require("react"),W=require("../Checkbox/index.cjs"),F=require("../../Button/index.cjs"),R=require("../Input/index.cjs"),M=require("../../PickerWrapper-CoDy6coa.cjs");;/* empty css */const _=i=>s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"none",viewBox:"0 0 24 24",...i,children:s.jsx("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M11.767 20.755a8.989 8.989 0 1 0 0-17.977 8.989 8.989 0 0 0 0 17.977M18.018 18.485 21.542 22"})});function H(i,r=100){if(!i)return;if(window.innerWidth>768){i.focus(),i.click();return}const t=document.createElement("input");t.style.position="absolute",t.style.top=`${i.offsetTop+7}px`,t.style.left=`${i.offsetLeft}px`,t.style.height="0px",t.style.opacity="0px",document.body.appendChild(t),t.focus(),setTimeout(()=>{i.focus(),i.click(),document.body.removeChild(t)},r)}function z({label:i,isMultiple:r,isActive:t,disabled:u}){return r?s.jsx(W,{checked:t,label:i,readOnly:!0,disabled:u}):i}const D=i=>{const{option:r,onClick:t,value:u,mode:n,optionCellClassName:g,optionCell:a}=i;function c(){return Array.isArray(u)?u.includes(r.value):r.value===u}return s.jsx("button",{type:"button",onClick:t,className:d.clsx("dgs-ui-kit-w-full dgs-ui-kit-text-start dgs-ui-kit-px-3 disabled:dgs-ui-kit-cursor-not-allowed dgs-ui-kit-py-3 dgs-ui-kit-font-p1-regular disabled:dgs-ui-kit-bg-gray-50 dgs-ui-kit-transition",c()?"dgs-ui-kit-bg-primary-50 dgs-ui-kit-text-primary-500":"dgs-ui-kit-text-gray-700 disabled:dgs-ui-kit-text-gray-400",g),disabled:r.disabled,children:a?a(r,c()):z({label:r.label,isMultiple:n==="multiple",isActive:c(),disabled:r.disabled??!1})})},T=o.memo(D),K=20,U=i=>{const{options:r,mode:t="single",afterOptions:u,beforOptions:n,onChange:g,searchable:a=!0,separateSelectedOptions:c=!0,optionsTitle:w="عنوانها",value:p,optionCellClassName:P,emptyContent:q="نتیجهای یافت نشد !",showClearButtonOnEmpty:A=!0}=i,[f,N]=o.useState(""),[k,L]=o.useState(0),m=o.useRef(null),{toggleWrapperVisibility:$}=M.usePickerWrapperContext(),O=d.clsx("dgs-ui-kit-border-t dgs-ui-kit-border-solid dgs-ui-kit-border-gray-100",(!a&&!n||t==="multiple"&&c)&&"first-of-type:dgs-ui-kit-border-t-0",!!u&&"last-of-type:dgs-ui-kit-border-b");let h;const b=a;typeof a=="boolean"?h=a:h=Object.keys(a).length>0;const y=o.useMemo(()=>f?r?.filter(e=>e.label.includes(f)):r,[f,r]),v=o.useMemo(()=>t==="multiple"&&c?r?.filter(e=>p.includes(e.value))??[]:[],[r,p]),I=o.useMemo(()=>{let e=y;t==="multiple"&&c&&(e=e?.filter(j=>!p.includes(j.value)));const l=Math.min(k+K,e?.length??0);return e?.slice(k,l)},[y,k,p]),x=m?.current?.children[0]?.clientHeight??50,B=(y?.length??0)*x,C=o.useCallback(()=>{const e=m?.current?.parentElement;if(!e)return;const l=e.scrollTop,j=m.current.offsetTop,S=Math.floor((l-j)/x);L(S>=0?S:0)},[x]);o.useEffect(()=>{const e=m.current?.parentElement;if(e)return e.addEventListener("scroll",C),()=>e.removeEventListener("scroll",C)},[C]),o.useEffect(()=>{h&&H(document.getElementById("search-input"),400)},[]);const E=o.useCallback(e=>{if(typeof g=="function")if(t==="multiple"){const l=[...p??[]];l.includes(e)?l.splice(l.indexOf(e),1):l.push(e),g(l)}else g(e),$()},[p]);return s.jsxs(s.Fragment,{children:[h&&s.jsx(R,{id:"search-input",wrapperClassName:d.clsx("dgs-ui-kit-sticky dgs-ui-kit-top-0 dgs-ui-kit-pt-3 dgs-ui-kit-right-0 dgs-ui-kit-bg-white dgs-ui-kit-z-10 dgs-ui-kit-px-3",n?"dgs-ui-kit-pb-2":"dgs-ui-kit-pb-3",b?.wrapperClassName),placeholder:b?.placeholder??"جستجوی عنوان",value:f,onChange:e=>N(e.currentTarget.value),rightIcon:b?.rightIcon??s.jsx(_,{width:20,height:20}),...typeof a=="object"?a:{}}),n,t==="multiple"&&c&&v.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"dgs-ui-kit-font-p2-regular dgs-ui-kit-text-gray-400 dgs-ui-kit-px-3 dgs-ui-kit-py-2",children:`${w}ی انتخاب شده`}),v.map(e=>s.jsx(T,{onClick:()=>E(e.value),option:e,optionCellClassName:d.clsx(O,P),...i},e.value))]}),s.jsxs(s.Fragment,{children:[t==="multiple"&&c&&s.jsx("p",{className:"dgs-ui-kit-font-p2-regular dgs-ui-kit-text-gray-400 dgs-ui-kit-px-3 dgs-ui-kit-py-2",children:w}),s.jsx("div",{ref:m,className:"dgs-ui-kit-relative",style:{height:B},children:I?.map((e,l)=>s.jsx("div",{className:d.clsx("dgs-ui-kit-absolute dgs-ui-kit-w-full",O),style:{top:`${(k+l)*x}px`},children:s.jsx(T,{onClick:()=>E(e.value),option:e,...i})},e.value))}),!I?.length&&!v.length&&s.jsxs("div",{className:"dgs-ui-kit-text-center dgs-ui-kit-flex dgs-ui-kit-flex-col dgs-ui-kit-items-center dgs-ui-kit-mt-2",children:[s.jsx("p",{className:"dgs-ui-kit-text-gray-500 dgs-ui-kit-font-p3-medium",children:q}),A&&s.jsx(F,{type:"button",className:"dgs-ui-kit-mt-1",variant:"text",size:"small",onClick:()=>N(""),children:"پاک کردن"})]})]}),u]})};function V(i,r){return Array.isArray(i)?r.filter(t=>i.includes(t.value)).map(t=>t.label).join(", "):r.find(t=>t.value===i)?.label??""}const G=i=>{const{searchable:r=!0,value:t,options:u}=i,n={...i};return n.dropdownType==="popover"&&!r&&(n.popoverClassName=d.clsx("dgs-ui-kit-pt-3",n.popoverClassName)),n.dropdownType==="drawer"&&(n.drawerProps={...n.drawerProps,containerClassName:d.clsx(r?"!dgs-ui-kit-pt-0":"!dgs-ui-kit-pt-3",n.drawerProps?.containerClassName)}),n.customInput||(n.inputProps={...n.inputProps,value:V(t,u)}),s.jsx(M.PickerWrapper,{...n,children:s.jsx(U,{...i})})};module.exports=G;
|
|
@@ -29,6 +29,10 @@ const J = (i) => /* @__PURE__ */ n(
|
|
|
29
29
|
);
|
|
30
30
|
function Q(i, s = 100) {
|
|
31
31
|
if (!i) return;
|
|
32
|
+
if (window.innerWidth > 768) {
|
|
33
|
+
i.focus(), i.click();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
32
36
|
const t = document.createElement("input");
|
|
33
37
|
t.style.position = "absolute", t.style.top = `${i.offsetTop + 7}px`, t.style.left = `${i.offsetLeft}px`, t.style.height = "0px", t.style.opacity = "0px", document.body.appendChild(t), t.focus(), setTimeout(() => {
|
|
34
38
|
i.focus(), i.click(), document.body.removeChild(t);
|