@danielcruzcode/ui-core 0.1.5 → 0.1.6
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/components/Carousel/Carousel.d.ts +2 -1
- package/dist/components/Carousel/Carousel.d.ts.map +1 -1
- package/dist/components/Carousel/Carousel.js +87 -0
- package/dist/components/Carousel/Carousel.js.map +1 -0
- package/dist/index.cjs9.js +3 -3
- package/dist/index.esm9.js +76 -60
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ export interface CarouselProps {
|
|
|
9
9
|
children: React.ReactNode[];
|
|
10
10
|
autoplay?: boolean;
|
|
11
11
|
autoplayMs?: number;
|
|
12
|
+
pauseOnHover?: boolean;
|
|
12
13
|
showArrows?: boolean;
|
|
13
14
|
showDots?: boolean;
|
|
14
15
|
loop?: boolean;
|
|
@@ -17,6 +18,6 @@ export interface CarouselProps {
|
|
|
17
18
|
gap?: keyof typeof tokens.space;
|
|
18
19
|
onSlideChange?: (index: number) => void;
|
|
19
20
|
}
|
|
20
|
-
export declare function Carousel({ children, autoplay, autoplayMs, showArrows, showDots, loop, slidesPerView, slidesPerGroup, gap, onSlideChange, }: CarouselProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function Carousel({ children, autoplay, autoplayMs, pauseOnHover, showArrows, showDots, loop, slidesPerView, slidesPerGroup, gap, onSlideChange, }: CarouselProps): import("react/jsx-runtime").JSX.Element;
|
|
21
22
|
export {};
|
|
22
23
|
//# sourceMappingURL=Carousel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Carousel.d.ts","sourceRoot":"","sources":["../../../src/components/Carousel/Carousel.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAEtD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,KAAK,aAAa,GAAG,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC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AE,OAAO,CAAA;IACd,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,GAAG,CAAC,EAAE,MAAM,OAAO,MAAM,CAAC,KAAK,CAAA;IAC/B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AAmCD,wBAAgB,QAAQ,CAAC,EACvB,QAAQ,EAAE,QAAgB,EAAE,UAAiB,EAAE,YAAmB,EAClE,UAAiB,EAAE,QAAe,EAClC,IAAY,EAAE,aAAiB,EAAE,cAAkB,EAAE,GAAG,EAAE,aAAa,GACxE,EAAE,aAAa,2CAwFf"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import styled from '@emotion/styled';
|
|
3
|
+
import { tokens } from '@danielcruzcode/design-tokens';
|
|
4
|
+
import useEmblaCarousel from 'embla-carousel-react';
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
6
|
+
const GAP_PX = { sm: 8, md: 16, lg: 24, xl: 32 };
|
|
7
|
+
function getSpv(slidesPerView, width) {
|
|
8
|
+
if (typeof slidesPerView === 'number')
|
|
9
|
+
return slidesPerView;
|
|
10
|
+
if (width >= 1024)
|
|
11
|
+
return slidesPerView.desktop;
|
|
12
|
+
if (width >= 640)
|
|
13
|
+
return slidesPerView.tablet;
|
|
14
|
+
return slidesPerView.mobile;
|
|
15
|
+
}
|
|
16
|
+
const ArrowBtn = styled.button `
|
|
17
|
+
position:absolute;top:50%;transform:translateY(-50%);z-index:10;
|
|
18
|
+
display:flex;align-items:center;justify-content:center;
|
|
19
|
+
width:36px;height:36px;border-radius:${tokens.radius.full};
|
|
20
|
+
border:1px solid ${tokens.color.border};background-color:${tokens.color.background};
|
|
21
|
+
color:${tokens.color.text};cursor:pointer;box-shadow:${tokens.shadow.sm};
|
|
22
|
+
transition:box-shadow ${tokens.transition.fast};
|
|
23
|
+
&:hover{box-shadow:${tokens.shadow.md};}
|
|
24
|
+
&:focus-visible{outline:2px solid ${tokens.color.borderFocus};outline-offset:2px;}
|
|
25
|
+
&:disabled{opacity:0.4;cursor:not-allowed;}
|
|
26
|
+
`;
|
|
27
|
+
const ArrowPrev = styled(ArrowBtn) `left:${tokens.space.sm};`;
|
|
28
|
+
const ArrowNext = styled(ArrowBtn) `right:${tokens.space.sm};`;
|
|
29
|
+
const Dot = styled.button `
|
|
30
|
+
width:${({ active }) => (active ? '20px' : '8px')};height:8px;
|
|
31
|
+
border-radius:${tokens.radius.full};
|
|
32
|
+
background-color:${({ active }) => (active ? tokens.color.brand : tokens.color.border)};
|
|
33
|
+
border:none;cursor:pointer;padding:0;
|
|
34
|
+
transition:background-color ${tokens.transition.fast},width ${tokens.transition.fast};
|
|
35
|
+
&:focus-visible{outline:2px solid ${tokens.color.borderFocus};outline-offset:2px;}
|
|
36
|
+
`;
|
|
37
|
+
const Dots = styled.div `display:flex;justify-content:center;gap:${tokens.space.sm};margin-top:${tokens.space.sm};`;
|
|
38
|
+
export function Carousel({ children, autoplay = false, autoplayMs = 4000, pauseOnHover = true, showArrows = true, showDots = true, loop = false, slidesPerView = 1, slidesPerGroup = 1, gap, onSlideChange, }) {
|
|
39
|
+
const gapPx = gap ? (GAP_PX[gap] ?? 0) : 0;
|
|
40
|
+
const [emblaRef, emblaApi] = useEmblaCarousel({ loop, slidesToScroll: slidesPerGroup, align: 'start' });
|
|
41
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
42
|
+
const [scrollSnaps, setScrollSnaps] = useState([]);
|
|
43
|
+
const [hovered, setHovered] = useState(false);
|
|
44
|
+
const slidesPerViewRef = useRef(slidesPerView);
|
|
45
|
+
slidesPerViewRef.current = slidesPerView;
|
|
46
|
+
const containerRef = useRef(null);
|
|
47
|
+
const [spv, setSpv] = useState(1);
|
|
48
|
+
// Use ResizeObserver on the container — reliable in iframes and custom viewports
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const el = containerRef.current;
|
|
51
|
+
if (!el)
|
|
52
|
+
return;
|
|
53
|
+
const ro = new ResizeObserver(([entry]) => {
|
|
54
|
+
const width = entry.contentRect.width;
|
|
55
|
+
setSpv(getSpv(slidesPerViewRef.current, width));
|
|
56
|
+
});
|
|
57
|
+
ro.observe(el);
|
|
58
|
+
return () => ro.disconnect();
|
|
59
|
+
}, []);
|
|
60
|
+
const onSelect = useCallback(() => {
|
|
61
|
+
if (!emblaApi)
|
|
62
|
+
return;
|
|
63
|
+
const index = emblaApi.selectedScrollSnap();
|
|
64
|
+
setSelectedIndex(index);
|
|
65
|
+
onSlideChange?.(index);
|
|
66
|
+
}, [emblaApi, onSlideChange]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!emblaApi)
|
|
69
|
+
return;
|
|
70
|
+
setScrollSnaps(emblaApi.scrollSnapList());
|
|
71
|
+
emblaApi.on('select', onSelect);
|
|
72
|
+
emblaApi.on('reInit', onSelect);
|
|
73
|
+
return () => { emblaApi.off('select', onSelect); emblaApi.off('reInit', onSelect); };
|
|
74
|
+
}, [emblaApi, onSelect]);
|
|
75
|
+
useEffect(() => { emblaApi?.reInit(); }, [emblaApi, spv]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!autoplay || !emblaApi)
|
|
78
|
+
return;
|
|
79
|
+
if (pauseOnHover && hovered)
|
|
80
|
+
return;
|
|
81
|
+
const id = setInterval(() => emblaApi.scrollNext(), autoplayMs);
|
|
82
|
+
return () => clearInterval(id);
|
|
83
|
+
}, [autoplay, autoplayMs, emblaApi, pauseOnHover, hovered]);
|
|
84
|
+
const slideWidth = `calc((100% - ${gapPx * (spv - 1)}px) / ${spv})`;
|
|
85
|
+
return (_jsxs("div", { ref: containerRef, style: { position: 'relative', width: '100%' }, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), children: [_jsx("div", { ref: emblaRef, style: { overflow: 'hidden' }, children: _jsx("div", { style: { display: 'flex', gap: gapPx }, children: children.map((child, i) => (_jsx("div", { style: { flex: `0 0 ${slideWidth}`, minWidth: 0 }, children: child }, i))) }) }), showArrows && (_jsxs(_Fragment, { children: [_jsx(ArrowPrev, { type: "button", "aria-label": "Slide anterior", onClick: () => emblaApi?.scrollPrev(), children: _jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M10 12L6 8l4-4", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), _jsx(ArrowNext, { type: "button", "aria-label": "Slide siguiente", onClick: () => emblaApi?.scrollNext(), children: _jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M6 4l4 4-4 4", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) })] })), showDots && (_jsx(Dots, { children: scrollSnaps.map((_, i) => (_jsx(Dot, { active: i === selectedIndex, type: "button", onClick: () => emblaApi?.scrollTo(i), "aria-label": `Ir al slide ${i + 1}` }, i))) }))] }));
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=Carousel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Carousel.js","sourceRoot":"","sources":["../../../src/components/Carousel/Carousel.tsx"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AACtD,OAAO,gBAAgB,MAAM,sBAAsB,CAAA;AAEnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAkBhE,MAAM,MAAM,GAA2B,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAA;AAExE,SAAS,MAAM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CAAA;AACH,CAAC"}
|
package/dist/index.cjs9.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),d=require("@emotion/styled"),t=require("./index.cjs14.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),d=require("@emotion/styled"),t=require("./index.cjs14.js"),N=require("./index.cjs15.js"),s=require("react"),T={sm:8,md:16,lg:24,xl:32};function _(r,i){return typeof r=="number"?r:i>=1024?r.desktop:i>=640?r.tablet:r.mobile}const w=d.button`
|
|
2
2
|
position:absolute;top:50%;transform:translateY(-50%);z-index:10;
|
|
3
3
|
display:flex;align-items:center;justify-content:center;
|
|
4
4
|
width:36px;height:36px;border-radius:${t.tokens.radius.full};
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
&:hover{box-shadow:${t.tokens.shadow.md};}
|
|
9
9
|
&:focus-visible{outline:2px solid ${t.tokens.color.borderFocus};outline-offset:2px;}
|
|
10
10
|
&:disabled{opacity:0.4;cursor:not-allowed;}
|
|
11
|
-
`,z=d(
|
|
11
|
+
`,z=d(w)`left:${t.tokens.space.sm};`,D=d(w)`right:${t.tokens.space.sm};`,P=d.button`
|
|
12
12
|
width:${({active:r})=>r?"20px":"8px"};height:8px;
|
|
13
13
|
border-radius:${t.tokens.radius.full};
|
|
14
14
|
background-color:${({active:r})=>r?t.tokens.color.brand:t.tokens.color.border};
|
|
15
15
|
border:none;cursor:pointer;padding:0;
|
|
16
16
|
transition:background-color ${t.tokens.transition.fast},width ${t.tokens.transition.fast};
|
|
17
17
|
&:focus-visible{outline:2px solid ${t.tokens.color.borderFocus};outline-offset:2px;}
|
|
18
|
-
`,
|
|
18
|
+
`,G=d.div`display:flex;justify-content:center;gap:${t.tokens.space.sm};margin-top:${t.tokens.space.sm};`;function O({children:r,autoplay:i=!1,autoplayMs:f=4e3,pauseOnHover:x=!0,showArrows:m=!0,showDots:y=!0,loop:S=!1,slidesPerView:h=1,slidesPerGroup:R=1,gap:p,onSlideChange:u}){var g;const k=p&&(g=T[p])!=null?g:0,[I,e]=N({loop:S,slidesToScroll:R,align:"start"}),[L,q]=s.useState(0),[E,C]=s.useState([]),[b,v]=s.useState(!1),$=s.useRef(h);$.current=h;const j=s.useRef(null),[a,M]=s.useState(1);s.useEffect(()=>{const n=j.current;if(!n)return;const c=new ResizeObserver(([B])=>{const F=B.contentRect.width;M(_($.current,F))});return c.observe(n),()=>c.disconnect()},[]);const l=s.useCallback(()=>{if(!e)return;const n=e.selectedScrollSnap();q(n),u==null||u(n)},[e,u]);s.useEffect(()=>{if(e)return C(e.scrollSnapList()),e.on("select",l),e.on("reInit",l),()=>{e.off("select",l),e.off("reInit",l)}},[e,l]),s.useEffect(()=>{e==null||e.reInit()},[e,a]),s.useEffect(()=>{if(!i||!e||x&&b)return;const n=setInterval(()=>e.scrollNext(),f);return()=>clearInterval(n)},[i,f,e,x,b]);const W=`calc((100% - ${k*(a-1)}px) / ${a})`;return o.jsxs("div",{ref:j,style:{position:"relative",width:"100%"},onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),children:[o.jsx("div",{ref:I,style:{overflow:"hidden"},children:o.jsx("div",{style:{display:"flex",gap:k},children:r.map((n,c)=>o.jsx("div",{style:{flex:`0 0 ${W}`,minWidth:0},children:n},c))})}),m&&o.jsxs(o.Fragment,{children:[o.jsx(z,{type:"button","aria-label":"Slide anterior",onClick:()=>e==null?void 0:e.scrollPrev(),children:o.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:o.jsx("path",{d:"M10 12L6 8l4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),o.jsx(D,{type:"button","aria-label":"Slide siguiente",onClick:()=>e==null?void 0:e.scrollNext(),children:o.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:o.jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),y&&o.jsx(G,{children:E.map((n,c)=>o.jsx(P,{active:c===L,type:"button",onClick:()=>e==null?void 0:e.scrollTo(c),"aria-label":`Ir al slide ${c+1}`},c))})]})}exports.Carousel=O;
|
package/dist/index.esm9.js
CHANGED
|
@@ -1,76 +1,92 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { tokens as
|
|
4
|
-
import
|
|
5
|
-
import { useState as
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
return typeof r == "number" ? r :
|
|
1
|
+
import { jsxs as y, jsx as o, Fragment as _ } from "react/jsx-runtime";
|
|
2
|
+
import c from "@emotion/styled";
|
|
3
|
+
import { tokens as e } from "./index.esm14.js";
|
|
4
|
+
import G from "./index.esm15.js";
|
|
5
|
+
import { useState as a, useRef as S, useEffect as u, useCallback as P } from "react";
|
|
6
|
+
const X = { sm: 8, md: 16, lg: 24, xl: 32 };
|
|
7
|
+
function Y(r, i) {
|
|
8
|
+
return typeof r == "number" ? r : i >= 1024 ? r.desktop : i >= 640 ? r.tablet : r.mobile;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const I = c.button`
|
|
11
11
|
position:absolute;top:50%;transform:translateY(-50%);z-index:10;
|
|
12
12
|
display:flex;align-items:center;justify-content:center;
|
|
13
|
-
width:36px;height:36px;border-radius:${
|
|
14
|
-
border:1px solid ${
|
|
15
|
-
color:${
|
|
16
|
-
transition:box-shadow ${
|
|
17
|
-
&:hover{box-shadow:${
|
|
18
|
-
&:focus-visible{outline:2px solid ${
|
|
13
|
+
width:36px;height:36px;border-radius:${e.radius.full};
|
|
14
|
+
border:1px solid ${e.color.border};background-color:${e.color.background};
|
|
15
|
+
color:${e.color.text};cursor:pointer;box-shadow:${e.shadow.sm};
|
|
16
|
+
transition:box-shadow ${e.transition.fast};
|
|
17
|
+
&:hover{box-shadow:${e.shadow.md};}
|
|
18
|
+
&:focus-visible{outline:2px solid ${e.color.borderFocus};outline-offset:2px;}
|
|
19
19
|
&:disabled{opacity:0.4;cursor:not-allowed;}
|
|
20
|
-
`,
|
|
20
|
+
`, q = c(I)`left:${e.space.sm};`, H = c(I)`right:${e.space.sm};`, J = c.button`
|
|
21
21
|
width:${({ active: r }) => r ? "20px" : "8px"};height:8px;
|
|
22
|
-
border-radius:${
|
|
23
|
-
background-color:${({ active: r }) => r ?
|
|
22
|
+
border-radius:${e.radius.full};
|
|
23
|
+
background-color:${({ active: r }) => r ? e.color.brand : e.color.border};
|
|
24
24
|
border:none;cursor:pointer;padding:0;
|
|
25
|
-
transition:background-color ${
|
|
26
|
-
&:focus-visible{outline:2px solid ${
|
|
27
|
-
`,
|
|
28
|
-
function
|
|
25
|
+
transition:background-color ${e.transition.fast},width ${e.transition.fast};
|
|
26
|
+
&:focus-visible{outline:2px solid ${e.color.borderFocus};outline-offset:2px;}
|
|
27
|
+
`, K = c.div`display:flex;justify-content:center;gap:${e.space.sm};margin-top:${e.space.sm};`;
|
|
28
|
+
function V({
|
|
29
29
|
children: r,
|
|
30
|
-
autoplay:
|
|
31
|
-
autoplayMs:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
autoplay: i = !1,
|
|
31
|
+
autoplayMs: p = 4e3,
|
|
32
|
+
pauseOnHover: h = !0,
|
|
33
|
+
showArrows: L = !0,
|
|
34
|
+
showDots: j = !0,
|
|
35
|
+
loop: R = !1,
|
|
36
|
+
slidesPerView: x = 1,
|
|
37
|
+
slidesPerGroup: W = 1,
|
|
38
|
+
gap: b,
|
|
39
|
+
onSlideChange: d
|
|
39
40
|
}) {
|
|
40
|
-
var
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
var w;
|
|
42
|
+
const v = b && (w = X[b]) != null ? w : 0, [B, t] = G({ loop: R, slidesToScroll: W, align: "start" }), [C, E] = a(0), [F, M] = a([]), [m, $] = a(!1), k = S(x);
|
|
43
|
+
k.current = x;
|
|
44
|
+
const g = S(null), [f, N] = a(1);
|
|
45
|
+
u(() => {
|
|
46
|
+
const n = g.current;
|
|
47
|
+
if (!n) return;
|
|
48
|
+
const s = new ResizeObserver(([D]) => {
|
|
49
|
+
const T = D.contentRect.width;
|
|
50
|
+
N(Y(k.current, T));
|
|
51
|
+
});
|
|
52
|
+
return s.observe(n), () => s.disconnect();
|
|
53
|
+
}, []);
|
|
54
|
+
const l = P(() => {
|
|
48
55
|
if (!t) return;
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
}, [t,
|
|
52
|
-
|
|
56
|
+
const n = t.selectedScrollSnap();
|
|
57
|
+
E(n), d == null || d(n);
|
|
58
|
+
}, [t, d]);
|
|
59
|
+
u(() => {
|
|
53
60
|
if (t)
|
|
54
|
-
return
|
|
61
|
+
return M(t.scrollSnapList()), t.on("select", l), t.on("reInit", l), () => {
|
|
55
62
|
t.off("select", l), t.off("reInit", l);
|
|
56
63
|
};
|
|
57
|
-
}, [t, l]),
|
|
64
|
+
}, [t, l]), u(() => {
|
|
58
65
|
t == null || t.reInit();
|
|
59
|
-
}, [t, f]),
|
|
60
|
-
if (!
|
|
61
|
-
const
|
|
62
|
-
return () => clearInterval(
|
|
63
|
-
}, [
|
|
64
|
-
const
|
|
65
|
-
return /* @__PURE__ */
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
}, [t, f]), u(() => {
|
|
67
|
+
if (!i || !t || h && m) return;
|
|
68
|
+
const n = setInterval(() => t.scrollNext(), p);
|
|
69
|
+
return () => clearInterval(n);
|
|
70
|
+
}, [i, p, t, h, m]);
|
|
71
|
+
const z = `calc((100% - ${v * (f - 1)}px) / ${f})`;
|
|
72
|
+
return /* @__PURE__ */ y(
|
|
73
|
+
"div",
|
|
74
|
+
{
|
|
75
|
+
ref: g,
|
|
76
|
+
style: { position: "relative", width: "100%" },
|
|
77
|
+
onMouseEnter: () => $(!0),
|
|
78
|
+
onMouseLeave: () => $(!1),
|
|
79
|
+
children: [
|
|
80
|
+
/* @__PURE__ */ o("div", { ref: B, style: { overflow: "hidden" }, children: /* @__PURE__ */ o("div", { style: { display: "flex", gap: v }, children: r.map((n, s) => /* @__PURE__ */ o("div", { style: { flex: `0 0 ${z}`, minWidth: 0 }, children: n }, s)) }) }),
|
|
81
|
+
L && /* @__PURE__ */ y(_, { children: [
|
|
82
|
+
/* @__PURE__ */ o(q, { type: "button", "aria-label": "Slide anterior", onClick: () => t == null ? void 0 : t.scrollPrev(), children: /* @__PURE__ */ o("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ o("path", { d: "M10 12L6 8l4-4", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }),
|
|
83
|
+
/* @__PURE__ */ o(H, { type: "button", "aria-label": "Slide siguiente", onClick: () => t == null ? void 0 : t.scrollNext(), children: /* @__PURE__ */ o("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ o("path", { d: "M6 4l4 4-4 4", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) })
|
|
84
|
+
] }),
|
|
85
|
+
j && /* @__PURE__ */ o(K, { children: F.map((n, s) => /* @__PURE__ */ o(J, { active: s === C, type: "button", onClick: () => t == null ? void 0 : t.scrollTo(s), "aria-label": `Ir al slide ${s + 1}` }, s)) })
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
);
|
|
73
89
|
}
|
|
74
90
|
export {
|
|
75
|
-
|
|
91
|
+
V as Carousel
|
|
76
92
|
};
|