{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"carousel","type":"registry:ui","title":"Carousel","description":"A horizontally navigable content collection, built on Embla.","dependencies":["@base-ui/react","embla-carousel-react"],"registryDependencies":["@kobra/button"],"docs":"Sound: the data-slot attributes on this component are read by the Sound layer, installed separately with `npx shadcn@latest add @kobra/sound`.\nKeep the data-slot and data-sound attributes as written — they are the wiring, not decoration.\nWrap your app once in <SoundEffects> from components/ui/sound.tsx and every Kobra component answers a press.","files":[{"path":"components/ui/carousel.tsx","content":"'use client'\n\nimport { useDirection } from '@base-ui/react/direction-provider'\nimport { IconPlaceholder } from '@/components/icon-placeholder'\nimport * as React from 'react'\nimport useEmblaCarousel, { type UseEmblaCarouselType } from 'embla-carousel-react'\n\nimport { cn } from '@/lib/utils'\nimport { Button } from '@/components/ui/button'\n\ntype CarouselApi = UseEmblaCarouselType[1]\ntype UseCarouselParameters = Parameters<typeof useEmblaCarousel>\ntype CarouselOptions = UseCarouselParameters[0]\ntype CarouselPlugin = UseCarouselParameters[1]\n\ntype CarouselProps = {\n  opts?: CarouselOptions\n  plugins?: CarouselPlugin\n  orientation?: 'horizontal' | 'vertical'\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\nfunction Carousel({\n  orientation = 'horizontal',\n  opts,\n  setApi,\n  plugins,\n  className,\n  children,\n  ...props\n}: React.ComponentProps<'div'> & CarouselProps) {\n\n  const pageDirection = useDirection()\n  const direction = opts?.direction ?? pageDirection\n  const [carouselRef, api] = useEmblaCarousel(\n    {\n      ...opts,\n      direction,\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.defaultPrevented) return\n      const target = event.target as HTMLElement | null\n      if (\n        target?.isContentEditable ||\n        target?.closest('input, textarea, select, [contenteditable=\"true\"], [role=\"slider\"]')\n      ) {\n        return\n      }\n      const rtl = direction === 'rtl'\n      const back = orientation === 'vertical' ? 'ArrowUp' : rtl ? 'ArrowRight' : 'ArrowLeft'\n      const forward = orientation === 'vertical' ? 'ArrowDown' : rtl ? 'ArrowLeft' : 'ArrowRight'\n      if (event.key === back) {\n        event.preventDefault()\n        scrollPrev()\n      } else if (event.key === forward) {\n        event.preventDefault()\n        scrollNext()\n      }\n    },\n    [orientation, direction, 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: orientation || (opts?.axis === 'y' ? 'vertical' : 'horizontal'),\n        scrollPrev,\n        scrollNext,\n        canScrollPrev,\n        canScrollNext,\n      }}\n    >\n\n      <div\n        tabIndex={0}\n        onKeyDown={handleKeyDown}\n        className={cn(\n          'relative transition-ring outline-none focus-visible:ring-3 focus-visible:ring-ring/50',\n          className,\n        )}\n        role=\"region\"\n        aria-roledescription=\"carousel\"\n        data-slot=\"carousel\"\n        {...props}\n      >\n        {children}\n      </div>\n    </CarouselContext.Provider>\n  )\n}\n\nfunction CarouselContent({ className, ...props }: React.ComponentProps<'div'>) {\n  const { carouselRef, orientation } = useCarousel()\n\n  return (\n    <div ref={carouselRef} className=\"overflow-hidden\" data-slot=\"carousel-content\">\n      <div\n        className={cn('flex', orientation === 'horizontal' ? '-ms-4' : '-mt-4 flex-col', className)}\n        {...props}\n      />\n    </div>\n  )\n}\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' ? 'ps-4' : 'pt-4',\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction CarouselPrevious({\n  className,\n  variant = 'outline',\n  size = 'icon-sm',\n  ...props\n}: React.ComponentProps<typeof Button>) {\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 touch-manipulation rounded-full',\n        orientation === 'horizontal'\n          ? 'inset-y-0 -start-12 my-auto'\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\n      <IconPlaceholder tabler=\"IconChevronLeft\" lucide=\"ChevronLeft\" hugeicons=\"ArrowLeft01Icon\" phosphor=\"CaretLeftIcon\" remixicon=\"RiArrowLeftSLine\" className={orientation === 'horizontal' ? 'rtl:-scale-x-100' : undefined} />\n      <span className=\"sr-only\">Previous slide</span>\n    </Button>\n  )\n}\n\nfunction CarouselNext({\n  className,\n  variant = 'outline',\n  size = 'icon-sm',\n  ...props\n}: React.ComponentProps<typeof Button>) {\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 touch-manipulation rounded-full',\n        orientation === 'horizontal'\n          ? 'inset-y-0 -end-12 my-auto'\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      <IconPlaceholder tabler=\"IconChevronRight\" lucide=\"ChevronRight\" hugeicons=\"ArrowRight01Icon\" phosphor=\"CaretRightIcon\" remixicon=\"RiArrowRightSLine\" className={orientation === 'horizontal' ? 'rtl:-scale-x-100' : undefined} />\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  useCarousel,\n}\n","type":"registry:ui","target":"components/ui/carousel.tsx"}],"cssVars":{"theme":{"--ring-duration":"150ms"}},"css":{"@utility transition-ring":{"transition-property":"color, background-color, border-color, box-shadow, outline-color, outline-offset","transition-duration":"var(--ring-duration)","transition-timing-function":"var(--ease-out)","@media (prefers-reduced-motion: reduce)":{"transition-duration":"0ms"}}}}