{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popover-09",
  "title": "Guided tour",
  "description": "A popover that moves from one spot to the next with its arrow.",
  "dependencies": [
    "@base-ui/react",
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/popover.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/popover/popover-09.tsx",
      "content": "'use client';\n\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover';\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { POPUP_TRANSITION } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  POPOVER_GLIDE,\n  Popover,\n  PopoverTrigger,\n} from '@/registry/ndeko/ui/popover';\n\nconst TOUR_STEPS = [\n  {\n    title: 'Your workspace',\n    description:\n      'This is your new workspace. Your projects, recent activity and settings all live here.',\n  },\n  {\n    title: 'Quick actions',\n    description:\n      'Use the toolbar above to create a project, invite a teammate or open the settings.',\n  },\n  {\n    title: 'Help center',\n    description:\n      'The support icon in the top right corner opens the help center and the documentation.',\n  },\n  {\n    title: 'Command palette',\n    description:\n      'Press ⌘K to open the command palette, the arrow keys to move and Enter to run an action.',\n  },\n];\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst TEXT_VARIANTS: Variants = {\n  enter: { opacity: 0, filter: 'blur(2px)' },\n  visible: { opacity: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nconst ARROW = [\n  'flex fill-popover stroke-border',\n  'transition-[left,top,opacity] duration-[250ms,250ms,150ms] ease-(--ease-out-strong) starting:opacity-0',\n  'data-[side=bottom]:-top-[6px]',\n  'data-[side=top]:-bottom-[6px] data-[side=top]:rotate-180',\n  'data-[side=left]:-right-[9px] data-[side=left]:rotate-90',\n  'data-[side=right]:-left-[9px] data-[side=right]:-rotate-90',\n].join(' ');\n\ntype TileRef = (tile: HTMLDivElement | null) => void;\n\nfunction textVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return TEXT_VARIANTS;\n}\n\nfunction nextLabelOf(isLastStep: boolean) {\n  if (isLastStep) {\n    return 'Start over';\n  }\n  return 'Next';\n}\n\nfunction tileRefOf(isCurrent: boolean, setAnchorTile: TileRef) {\n  if (isCurrent) {\n    return setAnchorTile;\n  }\n  return undefined;\n}\n\nfunction sideOf(stepIndex: number) {\n  const isLeftColumn = stepIndex % 2 === 0;\n  if (isLeftColumn) {\n    return 'left';\n  }\n  return 'right';\n}\n\nexport default function Popover09() {\n  const [stepIndex, setStepIndex] = useState(0);\n  const [anchorTile, setAnchorTile] = useState<HTMLDivElement | null>(null);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const textVariants = textVariantsOf(shouldReduceMotion);\n  const step = TOUR_STEPS[stepIndex];\n  const stepNumber = stepIndex + 1;\n  const isLastStep = stepNumber === TOUR_STEPS.length;\n  const nextLabel = nextLabelOf(isLastStep);\n  const side = sideOf(stepIndex);\n\n  function restartWhenOpening(isOpen: boolean) {\n    if (!isOpen) {\n      return;\n    }\n    setStepIndex(0);\n  }\n\n  function showNextStep() {\n    if (isLastStep) {\n      setStepIndex(0);\n      return;\n    }\n    setStepIndex(stepIndex + 1);\n  }\n\n  return (\n    <Popover onOpenChange={restartWhenOpening}>\n      <div className='flex flex-col items-center gap-4'>\n        <div className='grid grid-cols-2 gap-4'>\n          {TOUR_STEPS.map((tourStep, index) => {\n            const isCurrent = index === stepIndex;\n\n            return (\n              <div\n                key={tourStep.title}\n                ref={tileRefOf(isCurrent, setAnchorTile)}\n                className='bg-foreground/[0.04] text-muted-foreground flex size-10 items-center justify-center rounded-lg text-[13px] font-medium tabular-nums'\n              >\n                {index + 1}\n              </div>\n            );\n          })}\n        </div>\n        <PopoverTrigger render={<Button variant='outline' />}>\n          Start tour\n        </PopoverTrigger>\n      </div>\n      <PopoverPrimitive.Portal>\n        <PopoverPrimitive.Positioner\n          anchor={anchorTile}\n          side={side}\n          sideOffset={10}\n          className={cn('z-50', POPOVER_GLIDE)}\n        >\n          <PopoverPrimitive.Popup\n            className={cn(\n              'surface-raised flex w-64 flex-col gap-3 rounded-xl p-3 text-[13px] outline-none',\n              POPUP_TRANSITION\n            )}\n          >\n            <AnimatedSize contentClassName='relative flex' aria-live='polite'>\n              <AnimatePresence mode='popLayout' initial={false}>\n                <motion.div\n                  key={stepIndex}\n                  className='flex flex-col gap-1'\n                  variants={textVariants}\n                  initial='enter'\n                  animate='visible'\n                  exit='exit'\n                  transition={SWAP_TRANSITION}\n                >\n                  <PopoverPrimitive.Title className='font-medium'>\n                    {step.title}\n                  </PopoverPrimitive.Title>\n                  <PopoverPrimitive.Description className='text-muted-foreground text-xs'>\n                    {step.description}\n                  </PopoverPrimitive.Description>\n                </motion.div>\n              </AnimatePresence>\n            </AnimatedSize>\n            <div className='flex items-center justify-between gap-2'>\n              <span className='text-muted-foreground flex text-xs tabular-nums'>\n                <MotionNumber value={stepNumber} />/{TOUR_STEPS.length}\n              </span>\n              <Button\n                variant='link'\n                size='sm'\n                onClick={showNextStep}\n                className='h-auto p-0 text-xs'\n              >\n                <AnimatePresence mode='popLayout' initial={false}>\n                  <motion.span\n                    key={nextLabel}\n                    className='flex'\n                    variants={textVariants}\n                    initial='enter'\n                    animate='visible'\n                    exit='exit'\n                    transition={SWAP_TRANSITION}\n                  >\n                    {nextLabel}\n                  </motion.span>\n                </AnimatePresence>\n              </Button>\n            </div>\n            <PopoverPrimitive.Arrow key={side} className={ARROW}>\n              <svg width='12' height='6' viewBox='0 0 12 6' aria-hidden='true'>\n                <path d='M0 6 6 0l6 6Z' stroke='none' />\n                <polyline points='0,6 6,0.5 12,6' fill='none' strokeWidth='1' />\n              </svg>\n            </PopoverPrimitive.Arrow>\n          </PopoverPrimitive.Popup>\n        </PopoverPrimitive.Positioner>\n      </PopoverPrimitive.Portal>\n    </Popover>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "popover"
  ],
  "type": "registry:component"
}