najwer23morsels 0.3.0 → 0.3.1
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/lib/Slider.js +1 -1
- package/package.json +1 -1
package/lib/Slider.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t}from"react/jsx-runtime";import
|
|
1
|
+
import{jsxs as e,jsx as t}from"react/jsx-runtime";import l,{useState as r,useRef as n,useEffect as i,useCallback as s}from"react";import{s as o}from"./style-inject.es-BnTDb6vU.js";var a="Slider-module_sliderContainer__o7YCe",d="Slider-module_slideWrapper__Jll6Y",c="Slider-module_slide__G9U2-",h="Slider-module_sliderBtnControl__dtMGL",m="Slider-module_btn__FGB-r";o("@layer najwer23morselsSlider{.Slider-module_sliderContainer__o7YCe{display:flex;flex-direction:column;gap:10px;height:100%;position:relative;user-select:none;width:100%}.Slider-module_slideWrapper__Jll6Y{height:100%;overflow:hidden;position:relative;width:100%;will-change:transform}.Slider-module_slide__G9U2-{height:calc(100% - 2px);overflow:hidden;position:absolute;top:0;width:calc(100% - 100px);will-change:transform;&>*{height:100%;width:100%}}.Slider-module_sliderBtnControl__dtMGL{align-items:center;display:flex;height:100%;justify-content:space-between;left:0;padding:0 25px;pointer-events:none;position:absolute;right:0;z-index:100}.Slider-module_btn__FGB-r{background-color:#1f487e;border:1px solid #fff;border-radius:50%;color:#fff;cursor:pointer;display:flex;left:50%;padding:10px;pointer-events:auto;user-select:none}}");const f=(e,t,r=!1)=>(r?e.slice(0,t):e.slice(-t)).map((e,t)=>l.cloneElement(e,{key:`${r?"clone-first":"clone-last"}-${t}`,className:e.props.className})),p=({isCircular:o=!1,children:p})=>{const u=l.Children.toArray(p).filter(l.isValidElement),[g,_]=r(o&&u.length>=2?2:0),[w,v]=r(!1),[y,x]=r(0),[b,C]=r(0),N=n(null),S=n([]),E=o&&u.length>=2?[...f(u,2,!1),...u.map((e,t)=>l.cloneElement(e,{key:e.key??t,className:e.props.className})),...f(u,2,!0)]:u.map((e,t)=>l.cloneElement(e,{key:e.key??t,className:e.props.className}));S.current.length!==E.length&&(S.current=Array(E.length).fill(null)),i(()=>{_(o&&u.length>=2?2:0)},[o,u.length]);const L=s(()=>{const e=N.current;if(!e)return;const t=S.current[0];if(!t)return;const l=window.getComputedStyle(t);x(t.offsetWidth+parseFloat(l.marginLeft)+parseFloat(l.marginRight)),C(e.offsetWidth)},[]);i(()=>(L(),window.addEventListener("resize",L),()=>window.removeEventListener("resize",L)),[L]),i(()=>{const e=y+10;S.current.forEach((t,l)=>{if(t)if(o){const r=(l-g)*e+(b-y)/2;t.style.transition=w?"transform 0.4s cubic-bezier(.4,0,.2,1)":"none",t.style.transform=`translateX(${r}px)`,t.style.left=""}else{const r=e*(l-g)+(b-y)/2;if(w){const e=parseFloat(t.style.left||"0");t.animate([{left:`${e}px`},{left:`${r}px`}],{duration:400,easing:"ease-out",fill:"forwards"}).finished.then(()=>{t.style.left=`${r}px`,v(!1)})}else t.style.left=`${r}px`;t.style.transition="none",t.style.transform=""}})},[g,y,b,w,E.length,o]),i(()=>{if(!o||!w)return;const e=S.current.length,t=S.current[e-1];if(!t)return;const l=()=>{let r=g;1===g?r=e-3:g===e-2&&(r=2),r!==g&&_(r),v(!1),t.removeEventListener("transitionend",l)};return t.addEventListener("transitionend",l),()=>t.removeEventListener("transitionend",l)},[g,o,w]);return e("div",{className:a,children:[e("div",{className:h,children:[t("button",{className:m,onClick:()=>{w||(v(!0),_(o?e=>e-1:e=>Math.max(e-1,0)))},disabled:w,children:t("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"24",height:"24",fill:"currentColor",children:t("path",{d:"M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"})})}),t("button",{className:m,onClick:()=>{w||(v(!0),_(o?e=>e+1:e=>Math.min(e+1,E.length-1)))},disabled:w,children:t("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"24",height:"24",fill:"currentColor",children:t("path",{d:"M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"})})})]}),t("div",{className:d,ref:N,children:E.map((e,l)=>t("div",{ref:e=>{S.current[l]=e},className:`${c}`,"aria-hidden":g!==l,children:e},e.key??l))})]})};p.displayName="Slider";export{p as Slider};
|