the-omelet-ui 1.8.67 → 1.8.68
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.
|
@@ -31,9 +31,9 @@ interface CarouselProps {
|
|
|
31
31
|
*/
|
|
32
32
|
gap?: number;
|
|
33
33
|
/**
|
|
34
|
-
* ความสูงของแบนเนอร์ (px)
|
|
34
|
+
* ความสูงของแบนเนอร์ (px) หรือ 'auto' เพื่อให้สูงตาม content
|
|
35
35
|
*/
|
|
36
|
-
itemHeight?: number;
|
|
36
|
+
itemHeight?: number | "auto";
|
|
37
37
|
/**
|
|
38
38
|
* สีเมื่อ active (ตัวอักษรในแบนเนอร์ + จุด pagination) รองรับ hex เช่น #E00000
|
|
39
39
|
*/
|
package/dist/entries/carousel.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a}from'../chunk-6GLPXMGB.js';import {useRef,useState,useEffect,useCallback}from'react';import {jsxs,jsx}from'react/jsx-runtime';var L="#F9D9D9",_="#FBEBEB",B="#E00000",F="#D9D9D9";function
|
|
1
|
+
import {a}from'../chunk-6GLPXMGB.js';import {useRef,useState,useEffect,useCallback}from'react';import {jsxs,jsx}from'react/jsx-runtime';var L="#F9D9D9",_="#FBEBEB",B="#E00000",F="#D9D9D9";function R({items:r,autoplayInterval:h=0,showPagination:A=true,initialSlide:d=0,fullWidth:v=false,itemWidth:u,gap:l=12,itemHeight:E=120,activeColor:y=B,activeBgColor:D=L,className:M}){let C=useRef(null),s=useRef(null),[m,f]=useState(Math.min(Math.max(0,d),r.length-1)),[n,T]=useState(u??280),b=useRef(null);useEffect(()=>{if(!v&&u!=null){T(u);return}let e=C.current;if(!e)return;let t=()=>{let c=e.offsetWidth;T(v?c:Math.max(200,c*.85));},o=new ResizeObserver(t);return o.observe(e),t(),()=>o.disconnect()},[u,v]),useEffect(()=>{let e=s.current;if(!e||r.length===0)return;let t=Math.min(Math.max(0,d),r.length-1),o=t*(n+l);e.scrollTo({left:o,behavior:"auto"}),f(t);},[d,r.length,n,l]);let g=useCallback(()=>{let e=s.current;if(!e||r.length===0)return;let t=e.scrollLeft,o=n+l,c=Math.round(t/o),k=Math.min(Math.max(0,c),r.length-1);f(k);},[r.length,n,l]);useEffect(()=>{let e=s.current;if(e)return e.addEventListener("scroll",g),()=>e.removeEventListener("scroll",g)},[g]);let N=useCallback(e=>{let t=s.current;if(!t)return;let o=e*(n+l);t.scrollTo({left:o,behavior:"smooth"}),f(e);},[n,l]);return useEffect(()=>{if(!(h<=0||r.length<=1))return b.current=setInterval(()=>{f(e=>{let t=e>=r.length-1?0:e+1,o=s.current;if(o){let c=t*(n+l);o.scrollTo({left:c,behavior:"smooth"});}return t});},h*1e3),()=>{b.current&&clearInterval(b.current);}},[h,r.length,n,l]),r.length===0?null:jsxs("div",{ref:C,className:a("w-full",M),children:[jsx("div",{ref:s,className:"flex overflow-x-auto overflow-y-hidden scroll-smooth scrollbar-hide",style:{scrollSnapType:"x mandatory",WebkitOverflowScrolling:"touch"},children:r.map((e,t)=>jsx("div",{className:"relative flex items-center justify-center overflow-hidden font-bold text-center transition-colors duration-200 shrink-0 rounded-xl",style:{width:n,minWidth:n,height:E==="auto"?"auto":E,marginRight:t<r.length-1?l:0,backgroundColor:t===m?D:_,color:t===m?y:void 0,scrollSnapAlign:"start"},children:typeof e=="string"?jsx("span",{className:"relative px-4 wrap-break-word z-1",children:e}):e},t))}),A&&r.length>0&&jsx("div",{className:"flex justify-center items-center gap-1.5 mt-3",children:r.map((e,t)=>jsx("button",{type:"button","aria-label":`\u0E44\u0E1B\u0E17\u0E35\u0E48\u0E41\u0E1A\u0E19\u0E40\u0E19\u0E2D\u0E23\u0E4C ${t+1}`,className:"w-2 h-2 p-0 transition-colors duration-200 border-0 rounded-full cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1",style:{backgroundColor:t===m?y:F},onClick:()=>N(t)},t))})]})}export{R as default};
|