{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "carousel",
  "type": "registry:ui",
  "title": "Carousel",
  "description": "Touch/swipe carousel (Embla) with autoplay, looping, and custom controls for galleries and sliders.",
  "dependencies": [
    "@saasflare/ui",
    "embla-carousel-react"
  ],
  "files": [
    {
      "path": "components/ui/carousel.tsx",
      "type": "registry:ui",
      "content": "// @toreview\n\"use client\"\n\n/**\n * @fileoverview Carousel primitive — scrollable content carousel with navigation controls.\n * Built on Embla Carousel. Supports horizontal and vertical orientation,\n * keyboard navigation, and plugin extensibility.\n * Part of the Saasflare base component layer.\n * @module packages/ui/components/ui/carousel\n * @layer core\n *\n * @requires embla-carousel-react — peer dependency. Shipped via the `/carousel`\n *   subpath: `import { Carousel } from \"@saasflare/ui/carousel\"`.\n *\n * @component\n * @example\n * import { Carousel, CarouselContent, CarouselItem, CarouselPrevious, CarouselNext } from '@saasflare/ui/carousel';\n * <Carousel>\n *   <CarouselContent>\n *     <CarouselItem>Slide 1</CarouselItem>\n *     <CarouselItem>Slide 2</CarouselItem>\n *   </CarouselContent>\n *   <CarouselPrevious />\n *   <CarouselNext />\n * </Carousel>\n */\n\nimport * as React from \"react\"\nimport useEmblaCarousel, {\n  type UseEmblaCarouselType,\n} from \"embla-carousel-react\"\nimport { ArrowLeftIcon, ArrowRightIcon } from \"@saasflare/ui\"\n\nimport { cn } from \"@saasflare/ui\"\nimport { useSaasflareProps, type SaasflareComponentProps } from \"@saasflare/ui\"\nimport { Button } from \"@saasflare/ui\"\n\n/** Embla carousel API instance, handed to consumers via the `setApi` prop for imperative control (`scrollTo`, `on`/`off` events, …). */\ntype CarouselApi = UseEmblaCarouselType[1]\ntype UseCarouselParameters = Parameters<typeof useEmblaCarousel>\ntype CarouselOptions = UseCarouselParameters[0]\ntype CarouselPlugin = UseCarouselParameters[1]\n\ntype CarouselProps = SaasflareComponentProps & {\n  /** Embla Carousel options (loop, align, dragFree, etc.). */\n  opts?: CarouselOptions\n  /** Embla Carousel plugins (autoplay, wheel gestures, etc.). */\n  plugins?: CarouselPlugin\n  /** Scroll direction of the carousel. Drives Embla's axis. @default \"horizontal\" */\n  orientation?: \"horizontal\" | \"vertical\"\n  /** Receives the Embla API instance once initialized, for imperative control. */\n  setApi?: (api: CarouselApi) => void\n}\n\ntype CarouselContextProps = {\n  carouselRef: ReturnType<typeof useEmblaCarousel>[0]\n  api: ReturnType<typeof useEmblaCarousel>[1]\n  scrollPrev: () => void\n  scrollNext: () => void\n  canScrollPrev: boolean\n  canScrollNext: boolean\n} & CarouselProps\n\nconst CarouselContext = React.createContext<CarouselContextProps | null>(null)\n\nfunction useCarousel() {\n  const context = React.useContext(CarouselContext)\n\n  if (!context) {\n    throw new Error(\"useCarousel must be used within a <Carousel />\")\n  }\n\n  return context\n}\n\n/**\n * Carousel root — provides the Embla context and the carousel region.\n * Owns the design-system axes (`surface`, `radius`, `animated`, `iconWeight`)\n * and emits the corresponding data attributes on its root element.\n *\n * @example\n * <Carousel orientation=\"vertical\" setApi={setApi} opts={{ loop: true }}>\n *   <CarouselContent>\n *     <CarouselItem>Slide 1</CarouselItem>\n *   </CarouselContent>\n *   <CarouselPrevious />\n *   <CarouselNext />\n * </Carousel>\n */\nfunction Carousel({\n  orientation = \"horizontal\",\n  opts,\n  setApi,\n  plugins,\n  className,\n  children,\n  surface,\n  radius,\n  animated,\n  iconWeight,\n  ...props\n}: Omit<React.ComponentProps<\"div\">, keyof SaasflareComponentProps> & CarouselProps) {\n  const sf = useSaasflareProps({ surface, radius, animated, iconWeight })\n  const [carouselRef, api] = useEmblaCarousel(\n    {\n      ...opts,\n      axis: orientation === \"horizontal\" ? \"x\" : \"y\",\n    },\n    plugins\n  )\n  const [canScrollPrev, setCanScrollPrev] = React.useState(false)\n  const [canScrollNext, setCanScrollNext] = React.useState(false)\n\n  const onSelect = React.useCallback((api: CarouselApi) => {\n    if (!api) return\n    setCanScrollPrev(api.canScrollPrev())\n    setCanScrollNext(api.canScrollNext())\n  }, [])\n\n  const scrollPrev = React.useCallback(() => {\n    api?.scrollPrev()\n  }, [api])\n\n  const scrollNext = React.useCallback(() => {\n    api?.scrollNext()\n  }, [api])\n\n  const handleKeyDown = React.useCallback(\n    (event: React.KeyboardEvent<HTMLDivElement>) => {\n      if (event.key === \"ArrowLeft\") {\n        event.preventDefault()\n        scrollPrev()\n      } else if (event.key === \"ArrowRight\") {\n        event.preventDefault()\n        scrollNext()\n      }\n    },\n    [scrollPrev, scrollNext]\n  )\n\n  React.useEffect(() => {\n    if (!api || !setApi) return\n    setApi(api)\n  }, [api, setApi])\n\n  React.useEffect(() => {\n    if (!api) return\n    onSelect(api)\n    api.on(\"reInit\", onSelect)\n    api.on(\"select\", onSelect)\n\n    return () => {\n      api?.off(\"select\", onSelect)\n    }\n  }, [api, onSelect])\n\n  return (\n    <CarouselContext.Provider\n      value={{\n        carouselRef,\n        api: api,\n        opts,\n        orientation,\n        scrollPrev,\n        scrollNext,\n        canScrollPrev,\n        canScrollNext,\n      }}\n    >\n      <div\n        {...props}\n        onKeyDownCapture={handleKeyDown}\n        className={cn(\"relative\", className)}\n        role=\"region\"\n        aria-roledescription=\"carousel\"\n        data-slot=\"carousel\"\n        data-surface={sf.surface}\n        data-radius={sf.radius}\n        data-animated={String(sf.animated)}\n      >\n        {children}\n      </div>\n    </CarouselContext.Provider>\n  )\n}\n\n/**\n * Carousel viewport + scroll track. Wraps {@link CarouselItem}s and binds the\n * Embla ref. Lays items out along the active orientation.\n */\nfunction CarouselContent({ className, ...props }: React.ComponentProps<\"div\">) {\n  const { carouselRef, orientation } = useCarousel()\n\n  return (\n    <div\n      ref={carouselRef}\n      className=\"overflow-hidden\"\n      data-slot=\"carousel-content\"\n    >\n      <div\n        className={cn(\n          \"flex\",\n          orientation === \"horizontal\" ? \"-ml-4\" : \"-mt-4 flex-col\",\n          className\n        )}\n        {...props}\n      />\n    </div>\n  )\n}\n\n/**\n * A single carousel slide. Renders as a full-basis flex child with\n * orientation-aware spacing.\n */\nfunction CarouselItem({ className, ...props }: React.ComponentProps<\"div\">) {\n  const { orientation } = useCarousel()\n\n  return (\n    <div\n      role=\"group\"\n      aria-roledescription=\"slide\"\n      data-slot=\"carousel-item\"\n      className={cn(\n        \"min-w-0 shrink-0 grow-0 basis-full\",\n        orientation === \"horizontal\" ? \"pl-4\" : \"pt-4\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\n/**\n * Navigates to the previous slide. Disabled when there is no previous slide.\n * Inherits the provider `iconWeight` for its arrow icon.\n */\nfunction CarouselPrevious({\n  className,\n  variant = \"outline\",\n  size = \"icon\",\n  ...props\n}: React.ComponentProps<typeof Button>) {\n  const sf = useSaasflareProps()\n  const { orientation, scrollPrev, canScrollPrev } = useCarousel()\n\n  return (\n    <Button\n      data-slot=\"carousel-previous\"\n      variant={variant}\n      size={size}\n      className={cn(\n        \"absolute size-8 rounded-full\",\n        orientation === \"horizontal\"\n          ? \"top-1/2 -left-12 -translate-y-1/2\"\n          : \"-top-12 left-1/2 -translate-x-1/2 rotate-90\",\n        className\n      )}\n      disabled={!canScrollPrev}\n      onClick={scrollPrev}\n      {...props}\n    >\n      <ArrowLeftIcon weight={sf.iconWeight} />\n      <span className=\"sr-only\">Previous slide</span>\n    </Button>\n  )\n}\n\n/**\n * Navigates to the next slide. Disabled when there is no next slide.\n * Inherits the provider `iconWeight` for its arrow icon.\n */\nfunction CarouselNext({\n  className,\n  variant = \"outline\",\n  size = \"icon\",\n  ...props\n}: React.ComponentProps<typeof Button>) {\n  const sf = useSaasflareProps()\n  const { orientation, scrollNext, canScrollNext } = useCarousel()\n\n  return (\n    <Button\n      data-slot=\"carousel-next\"\n      variant={variant}\n      size={size}\n      className={cn(\n        \"absolute size-8 rounded-full\",\n        orientation === \"horizontal\"\n          ? \"top-1/2 -right-12 -translate-y-1/2\"\n          : \"-bottom-12 left-1/2 -translate-x-1/2 rotate-90\",\n        className\n      )}\n      disabled={!canScrollNext}\n      onClick={scrollNext}\n      {...props}\n    >\n      <ArrowRightIcon weight={sf.iconWeight} />\n      <span className=\"sr-only\">Next slide</span>\n    </Button>\n  )\n}\n\nexport {\n  type CarouselApi,\n  Carousel,\n  CarouselContent,\n  CarouselItem,\n  CarouselPrevious,\n  CarouselNext,\n}\n",
      "target": "components/ui/carousel.tsx"
    }
  ],
  "$meta": {
    "source": "https://ui.saasflare.io/r/carousel.json"
  }
}
