UNPKG

@payfit/unity-components

Version:

68 lines (67 loc) 2.27 kB
import { CarouselContext as e } from "./Carousel.context.js"; import { createCarouselAccessibilityOptions as t } from "./Carousel.options.js"; import { useCarouselAccessibility as n } from "./hooks/useCarouselAccessibility.js"; import { useCarouselState as r } from "./hooks/useCarouselState.js"; import { CarouselNav as i } from "./parts/CarouselNav.js"; import { forwardRef as a, useMemo as o } from "react"; import { uyTv as s } from "@payfit/unity-themes"; import { jsx as c, jsxs as l } from "react/jsx-runtime"; import { useIntl as u } from "react-intl"; import d from "embla-carousel-accessibility"; import f from "embla-carousel-react"; //#region src/components/carousel/Carousel.tsx var p = s({ base: "uy:relative uy:flex uy:flex-col uy:gap-200 uy:md:gap-300" }), m = a(({ children: a, className: s, options: m = { slidesToScroll: "auto" }, "aria-label": h, ...g }, _) => { let v = u(), y = o(() => t(v), [v]), [b, x] = f({ draggable: !0, ...m, axis: "x" }, [d(y)]), { canGoToNext: S, canGoToPrev: C, visibleSlideIndexes: w, focusedSlideIndex: T, goToPrev: E, goToNext: D, goTo: O, goToSlide: k, selectedSnap: A, snapCount: j } = r(x), { liveRegionRef: M, a11yIds: N, onKeyDown: P } = n({ api: x, visibleSlideIndexes: w, focusedSlideIndex: T, loop: m.loop ?? !1, goToSlide: k }); return /* @__PURE__ */ c(e.Provider, { value: { carouselRef: b, api: x, goToNext: D, goToPrev: E, goTo: O, canGoToPrev: C, canGoToNext: S, visibleSlideIndexes: w, selectedSnap: A, snapCount: j, a11yIds: N }, children: /* @__PURE__ */ l("div", { ref: _, className: p({ className: s }), role: "region", "aria-roledescription": v.formatMessage({ id: "unity:component:carousel:roledescription", defaultMessage: "carousel" }), "aria-label": h, "aria-labelledby": h ? void 0 : N.title, "data-unity-slot": "carousel", onKeyDownCapture: P, ...g, children: [ a, /* @__PURE__ */ c(i, { className: "uy:flex uy:justify-center uy:md:hidden" }), /* @__PURE__ */ c("div", { ref: M, "aria-live": "polite", "aria-atomic": "true", className: "uy:sr-only" }) ] }) }); }); m.displayName = "Carousel"; //#endregion export { m as Carousel, p as carousel };