{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"sticky-contact-bar","type":"registry:ui","title":"Sticky contact bar","description":"Mobile bottom bar with Call, Text, Directions and Book that hides on scroll down and returns on scroll up.","dependencies":["lucide-react","motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/sticky-contact-bar/sticky-contact-bar.tsx","type":"registry:ui","target":"components/facade/sticky-contact-bar.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { Calendar, MapPin, MessageCircle, Phone } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ContactAction {\n  key: string;\n  label: string;\n  href: string;\n  icon: React.ComponentType<{ className?: string; \"aria-hidden\"?: boolean }>;\n  /** Render as the filled, emphasized action. */\n  primary?: boolean;\n  /** Open in a new tab (e.g. maps, external booking). */\n  external?: boolean;\n}\n\nexport interface StickyContactBarProps {\n  /** Phone number in any format, used for tel: and sms: links. */\n  phone?: string;\n  /** Street address for the directions link. */\n  address?: string;\n  /** Booking URL. */\n  bookingUrl?: string;\n  /** Override the default four actions. */\n  actions?: ContactAction[];\n  /** Pixels scrolled before the bar first appears. */\n  threshold?: number;\n  /** Pixels of continued downward scrolling before the bar tucks away. Scrolling up brings it back. */\n  hideAfter?: number;\n  /** Render absolute inside the nearest positioned parent instead of fixed to the viewport. */\n  contained?: boolean;\n  /** Element to watch for scroll. Defaults to window. Useful with `contained`. */\n  scrollContainerRef?: React.RefObject<HTMLElement | null>;\n  /** Hide on md screens and up. Ignored when `contained`. */\n  mobileOnly?: boolean;\n  className?: string;\n}\n\nfunction digits(phone: string) {\n  return phone.replace(/[^\\d+]/g, \"\");\n}\n\nexport function buildDefaultActions(phone?: string, address?: string, bookingUrl?: string): ContactAction[] {\n  const out: ContactAction[] = [];\n  if (phone) {\n    out.push({ key: \"call\", label: \"Call\", href: `tel:${digits(phone)}`, icon: Phone });\n    out.push({ key: \"text\", label: \"Text\", href: `sms:${digits(phone)}`, icon: MessageCircle });\n  }\n  if (address) {\n    out.push({\n      key: \"directions\",\n      label: \"Directions\",\n      href: `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(address)}`,\n      icon: MapPin,\n      external: true,\n    });\n  }\n  if (bookingUrl) {\n    out.push({ key: \"book\", label: \"Book\", href: bookingUrl, icon: Calendar, primary: true });\n  }\n  return out;\n}\n\nexport function StickyContactBar({\n  phone = \"(512) 555-0142\",\n  address = \"1200 S Congress Ave, Austin, TX 78704\",\n  bookingUrl = \"#book\",\n  actions,\n  threshold = 240,\n  hideAfter = 120,\n  contained = false,\n  scrollContainerRef,\n  mobileOnly = true,\n  className,\n}: StickyContactBarProps) {\n  const reduce = useReducedMotion();\n  const [visible, setVisible] = React.useState(false);\n  const items = actions ?? buildDefaultActions(phone, address, bookingUrl);\n\n  React.useEffect(() => {\n    const target: HTMLElement | Window = scrollContainerRef?.current ?? window;\n    const read = () => (target instanceof Window ? target.scrollY : target.scrollTop);\n    let last = read();\n    // Distance scrolled down since the bar was last shown.\n    let downRun = 0;\n    let shown = false;\n    let frame = 0;\n\n    const set = (v: boolean) => {\n      if (v !== shown) {\n        shown = v;\n        setVisible(v);\n      }\n    };\n\n    const update = () => {\n      const y = read();\n      const delta = y - last;\n      last = y;\n      if (y < threshold) {\n        downRun = 0;\n        set(false);\n        return;\n      }\n      if (delta < -4) {\n        // Scrolling up: always bring the bar back.\n        downRun = 0;\n        set(true);\n      } else if (delta > 0) {\n        if (!shown && downRun === 0 && y - delta < threshold) {\n          // Just crossed the threshold: reveal once.\n          set(true);\n        } else {\n          downRun += delta;\n          if (downRun > hideAfter) set(false);\n        }\n      }\n    };\n\n    const onScroll = () => {\n      cancelAnimationFrame(frame);\n      frame = requestAnimationFrame(update);\n    };\n\n    // Already past the threshold on mount (e.g. restored scroll position): show right away.\n    if (last >= threshold) set(true);\n    update();\n    target.addEventListener(\"scroll\", onScroll, { passive: true });\n    return () => {\n      cancelAnimationFrame(frame);\n      target.removeEventListener(\"scroll\", onScroll);\n    };\n  }, [threshold, hideAfter, scrollContainerRef]);\n\n  return (\n    <AnimatePresence>\n      {visible && (\n        <motion.nav\n          aria-label=\"Quick contact\"\n          initial={reduce ? { opacity: 0 } : { y: \"110%\" }}\n          animate={reduce ? { opacity: 1 } : { y: 0 }}\n          exit={reduce ? { opacity: 0 } : { y: \"110%\" }}\n          transition={{ type: \"spring\", stiffness: 400, damping: 38 }}\n          className={cn(\n            contained ? \"absolute\" : \"fixed\",\n            \"inset-x-0 bottom-0 z-40 px-3 pb-[calc(env(safe-area-inset-bottom)+0.75rem)] pt-2\",\n            !contained && mobileOnly && \"md:hidden\",\n            className,\n          )}\n        >\n          <ul className=\"glass mx-auto flex max-w-md items-stretch gap-1 rounded-[22px] p-1.5 text-foreground shadow-float\">\n            {items.map((a) => {\n              const Icon = a.icon;\n              return (\n                <li key={a.key} className={cn(a.primary ? \"flex-[1.4]\" : \"flex-1\")}>\n                  <a\n                    href={a.href}\n                    target={a.external ? \"_blank\" : undefined}\n                    rel={a.external ? \"noopener noreferrer\" : undefined}\n                    className={cn(\n                      \"flex h-12 w-full flex-col items-center justify-center gap-0.5 rounded-2xl text-[11px] font-medium transition-colors\",\n                      \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n                      a.primary\n                        ? \"bg-brand text-brand-foreground hover:bg-brand/90\"\n                        : \"text-foreground/80 hover:bg-muted hover:text-foreground active:bg-muted\",\n                    )}\n                  >\n                    <Icon className=\"size-[18px]\" aria-hidden />\n                    {a.label}\n                  </a>\n                </li>\n              );\n            })}\n          </ul>\n        </motion.nav>\n      )}\n    </AnimatePresence>\n  );\n}\n\nexport default StickyContactBar;\n"}],"categories":["navigation"],"meta":{"tier":"free","demo":"\"use client\";\n\nimport * as React from \"react\";\nimport { ArrowRight, Scissors, Star } from \"lucide-react\";\nimport { StickyContactBar } from \"./sticky-contact-bar\";\n\nconst services = [\n  { name: \"Signature cut\", price: \"$48\", time: \"45 min\" },\n  { name: \"Skin fade\", price: \"$42\", time: \"40 min\" },\n  { name: \"Beard sculpt and hot towel\", price: \"$30\", time: \"30 min\" },\n  { name: \"Cut and beard combo\", price: \"$70\", time: \"75 min\" },\n  { name: \"Kids cut (under 12)\", price: \"$28\", time: \"30 min\" },\n  { name: \"Gray blending\", price: \"$35\", time: \"30 min\" },\n];\n\nexport default function Demo() {\n  const scrollRef = React.useRef<HTMLDivElement>(null);\n\n  return (\n    <div className=\"flex w-full items-center justify-center py-4\">\n      {/* Phone frame */}\n      <div className=\"relative h-[420px] w-[250px] overflow-hidden rounded-[2.5rem] bg-foreground p-[6px] shadow-device\">\n        <div className=\"relative h-full w-full overflow-hidden rounded-[2.1rem] bg-background\">\n          <div className=\"absolute left-1/2 top-2 z-50 h-4 w-16 -translate-x-1/2 rounded-full bg-foreground\" aria-hidden />\n          <div ref={scrollRef} className=\"h-full overflow-y-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\">\n            {/* Hero */}\n            <header className=\"px-5 pb-6 pt-10\">\n              <div className=\"flex items-center gap-2\">\n                <span className=\"grid size-7 place-items-center rounded-lg bg-foreground text-background\">\n                  <Scissors className=\"size-3.5\" aria-hidden />\n                </span>\n                <span className=\"text-[12px] font-semibold tracking-[-0.01em]\">Fifth & Main Barbers</span>\n              </div>\n              <h1 className=\"mt-5 font-display text-[24px] font-semibold leading-[1.1] tracking-[-0.03em]\">\n                Sharp cuts in East Nashville.\n              </h1>\n              <p className=\"mt-2 text-[12px] leading-relaxed text-muted-foreground\">\n                Walk-ins welcome. Most appointments open same day.\n              </p>\n              <div className=\"mt-3 flex items-center gap-1 text-[11px] text-muted-foreground\">\n                <Star className=\"size-3 fill-star text-star\" aria-hidden />\n                <span className=\"font-medium text-foreground\">4.9</span> · 860 Google reviews\n              </div>\n              <p className=\"mt-6 flex items-center gap-1 text-[11px] font-medium text-muted-foreground\">\n                Scroll down <ArrowRight className=\"size-3 rotate-90\" aria-hidden />\n              </p>\n            </header>\n\n            {/* Services */}\n            <section className=\"px-5 pb-28\">\n              <h2 className=\"mb-2 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground\">Services</h2>\n              <ul className=\"rounded-2xl bg-muted px-3.5 py-1.5\">\n                {services.map((s) => (\n                  <li key={s.name} className=\"flex items-center justify-between gap-2 py-2.5\">\n                    <span>\n                      <span className=\"block text-[12px] font-medium\">{s.name}</span>\n                      <span className=\"mt-0.5 block text-[10px] text-muted-foreground\">{s.time}</span>\n                    </span>\n                    <span className=\"text-[12px] font-medium tabular-nums\">{s.price}</span>\n                  </li>\n                ))}\n              </ul>\n              <h2 className=\"mb-2 mt-6 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground\">Visit us</h2>\n              <div className=\"rounded-2xl bg-muted p-3.5 text-[12px] leading-relaxed text-muted-foreground\">\n                1008 Woodland St, Nashville, TN 37206\n                <br />\n                Tue to Sat, 9 AM to 7 PM\n              </div>\n              <div className=\"mt-4 h-24 rounded-2xl bg-muted\" />\n            </section>\n          </div>\n\n          <StickyContactBar\n            contained\n            scrollContainerRef={scrollRef}\n            threshold={120}\n            hideAfter={80}\n            phone=\"(615) 555-0187\"\n            address=\"1008 Woodland St, Nashville, TN 37206\"\n            bookingUrl=\"#book\"\n            className=\"px-2 pb-2\"\n          />\n        </div>\n      </div>\n    </div>\n  );\n}\n"}}