@shopify/shop-minis-react
Version:
React component library for Shopify Shop Minis with Tailwind CSS v4 support (source-only, requires TypeScript)
180 lines (179 loc) • 4.59 kB
JavaScript
import { jsx as a, jsxs as h } from "react/jsx-runtime";
import * as l from "react";
import k from "../../shop-minis-react/node_modules/.pnpm/embla-carousel-react@8.6.0_react@19.1.0/node_modules/embla-carousel-react/esm/embla-carousel-react.esm.js";
import { cn as d } from "../../lib/utils.js";
import { BaseButton as v } from "./button.js";
import z from "../../shop-minis-react/node_modules/.pnpm/lucide-react@0.513.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/arrow-left.js";
import g from "../../shop-minis-react/node_modules/.pnpm/lucide-react@0.513.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/arrow-right.js";
const p = l.createContext(null);
function m() {
const o = l.useContext(p);
if (!o)
throw new Error("useCarousel must be used within a <Carousel />");
return o;
}
function I({
orientation: o = "horizontal",
opts: r,
setApi: t,
plugins: n,
className: c,
children: i,
...u
}) {
const [N, e] = k(
{
...r,
axis: o === "horizontal" ? "x" : "y"
},
n
), [b, w] = l.useState(!1), [S, y] = l.useState(!1), f = l.useCallback((s) => {
s && (w(s.canScrollPrev()), y(s.canScrollNext()));
}, []), x = l.useCallback(() => {
e?.scrollPrev();
}, [e]), C = l.useCallback(() => {
e?.scrollNext();
}, [e]), P = l.useCallback(
(s) => {
s.key === "ArrowLeft" ? (s.preventDefault(), x()) : s.key === "ArrowRight" && (s.preventDefault(), C());
},
[x, C]
);
return l.useEffect(() => {
!e || !t || t(e);
}, [e, t]), l.useEffect(() => {
if (e)
return f(e), e.on("reInit", f), e.on("select", f), () => {
e?.off("select", f);
};
}, [e, f]), /* @__PURE__ */ a(
p.Provider,
{
value: {
carouselRef: N,
api: e,
opts: r,
orientation: o || (r?.axis === "y" ? "vertical" : "horizontal"),
scrollPrev: x,
scrollNext: C,
canScrollPrev: b,
canScrollNext: S
},
children: /* @__PURE__ */ a(
"div",
{
onKeyDownCapture: P,
className: d("relative", c),
role: "region",
"aria-roledescription": "carousel",
"data-slot": "carousel",
...u,
children: i
}
)
}
);
}
function K({ className: o, ...r }) {
const { carouselRef: t, orientation: n } = m();
return /* @__PURE__ */ a(
"div",
{
ref: t,
className: "overflow-hidden",
"data-slot": "carousel-content",
children: /* @__PURE__ */ a(
"div",
{
className: d(
"flex",
n === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
o
),
...r
}
)
}
);
}
function L({ className: o, ...r }) {
const { orientation: t } = m();
return /* @__PURE__ */ a(
"div",
{
role: "group",
"aria-roledescription": "slide",
"data-slot": "carousel-item",
className: d(
"min-w-0 shrink-0 grow-0 basis-full",
t === "horizontal" ? "pl-4" : "pt-4",
o
),
...r
}
);
}
function q({
className: o,
variant: r = "icon",
size: t = "default",
...n
}) {
const { orientation: c, scrollPrev: i, canScrollPrev: u } = m();
return /* @__PURE__ */ h(
v,
{
"data-slot": "carousel-previous",
variant: r,
size: t,
className: d(
"absolute size-8 rounded-full",
c === "horizontal" ? "top-1/2 -left-12 -translate-y-1/2" : "-top-12 left-1/2 -translate-x-1/2 rotate-90",
o
),
disabled: !u,
onClick: i,
...n,
children: [
/* @__PURE__ */ a(z, {}),
/* @__PURE__ */ a("span", { className: "sr-only", children: "Previous slide" })
]
}
);
}
function F({
className: o,
variant: r = "icon",
size: t = "default",
...n
}) {
const { orientation: c, scrollNext: i, canScrollNext: u } = m();
return /* @__PURE__ */ h(
v,
{
"data-slot": "carousel-next",
variant: r,
size: t,
className: d(
"absolute size-8 rounded-full",
c === "horizontal" ? "top-1/2 -right-12 -translate-y-1/2" : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
o
),
disabled: !u,
onClick: i,
...n,
children: [
/* @__PURE__ */ a(g, {}),
/* @__PURE__ */ a("span", { className: "sr-only", children: "Next slide" })
]
}
);
}
export {
I as Carousel,
K as CarouselContent,
L as CarouselItem,
F as CarouselNext,
q as CarouselPrevious
};
//# sourceMappingURL=carousel.js.map