{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "liquid-glass-button",
  "title": "Liquid glass button",
  "description": "Frosted glass button and pill toolbar with backdrop blur, rim light and a specular highlight that follows the pointer, falling back to a solid tint without backdrop-filter.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/buttons/liquid-glass-button.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens, spring } from \"@/lib/goodui-motion\"\n\n// Glass = translucent tint + backdrop blur/saturate + inner rim light. ::before is the specular highlight that follows\n// the pointer (CSS variables, no re-render); ::after is a gradient rim drawn with a mask.\nconst CSS = `\n.pc-liquid-glass {\n  position: relative; isolation: isolate; color: #fff; text-shadow: 0 1px 2px rgb(0 0 0 / .22);\n  background: linear-gradient(180deg, rgb(255 255 255 / .26), rgb(255 255 255 / .08));\n  -webkit-backdrop-filter: blur(var(--pc-lg-blur, 14px)) saturate(170%);\n  backdrop-filter: blur(var(--pc-lg-blur, 14px)) saturate(170%);\n  box-shadow: inset 0 1px 0 rgb(255 255 255 / .5), inset 0 -1px 1px rgb(255 255 255 / .1), 0 10px 30px -10px rgb(0 0 0 / .35), 0 2px 6px -2px rgb(0 0 0 / .18);\n}\n.pc-liquid-glass[data-tone=\"dark\"] {\n  background: linear-gradient(180deg, rgb(24 24 32 / .42), rgb(24 24 32 / .22));\n  box-shadow: inset 0 1px 0 rgb(255 255 255 / .2), 0 10px 30px -10px rgb(0 0 0 / .55), 0 2px 6px -2px rgb(0 0 0 / .3);\n}\n.pc-liquid-glass::before {\n  content: \"\"; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;\n  background: radial-gradient(var(--pc-lg-size, 110px) circle at var(--pc-lg-x, 50%) var(--pc-lg-y, -20%), rgb(255 255 255 / .5), transparent 70%);\n  opacity: .35; transition: opacity .35s ease;\n}\n.pc-liquid-glass:hover::before { opacity: 1 }\n.pc-liquid-glass::after {\n  content: \"\"; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;\n  background: linear-gradient(140deg, rgb(255 255 255 / .85), rgb(255 255 255 / .15) 35%, rgb(255 255 255 / .05) 60%, rgb(255 255 255 / .45));\n  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);\n  -webkit-mask-composite: xor; mask-composite: exclude;\n}\n.pc-liquid-glass[data-tone=\"dark\"]::after { opacity: .45 }\n@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {\n  .pc-liquid-glass { background: rgb(255 255 255 / .78); color: #18181b; text-shadow: none }\n  .pc-liquid-glass[data-tone=\"dark\"] { background: rgb(24 24 32 / .85); color: #fff }\n}\n.pc-liquid-glass[data-fallback] {\n  -webkit-backdrop-filter: none; backdrop-filter: none;\n  background: rgb(255 255 255 / .78); color: #18181b; text-shadow: none;\n}\n.pc-liquid-glass[data-fallback][data-tone=\"dark\"] { background: rgb(24 24 32 / .85); color: #fff }\n@media (prefers-reduced-motion: reduce) { .pc-liquid-glass::before { transition: none } }\n`\n\nfunction Styles() {\n  return (\n    <style href=\"pc-liquid-glass-button\" precedence=\"default\">\n      {CSS}\n    </style>\n  )\n}\n\n/** Moves the specular highlight with the pointer by writing CSS variables (no React re-render). */\nfunction trackSpecular(e: React.PointerEvent<HTMLElement>) {\n  const el = e.currentTarget\n  const r = el.getBoundingClientRect()\n  el.style.setProperty(\"--pc-lg-x\", `${e.clientX - r.left}px`)\n  el.style.setProperty(\"--pc-lg-y\", `${e.clientY - r.top}px`)\n}\n\nconst SIZES = {\n  sm: \"h-8 gap-1.5 px-3.5 text-xs [&_svg]:size-3.5\",\n  md: \"h-10 gap-2 px-5 text-sm [&_svg]:size-4\",\n  lg: \"h-12 gap-2 px-7 text-base [&_svg]:size-5\",\n  icon: \"size-11 [&_svg]:size-5\",\n} as const\n\ntype GlassBase = {\n  /** \"light\" is a white tint for colorful or bright backdrops; \"dark\" a smoky tint. */\n  tone?: \"light\" | \"dark\"\n  /** Backdrop blur in px. */\n  blur?: number\n  /** Force the no-backdrop-filter look (to preview the fallback). */\n  fallback?: boolean\n}\n\nexport type LiquidGlassButtonProps = Omit<React.ComponentProps<\"button\">, \"onAnimationStart\" | \"onDrag\" | \"onDragStart\" | \"onDragEnd\"> &\n  GlassBase & {\n    /** \"sm\" | \"md\" | \"lg\" | \"icon\"; \"icon\" is a round 44px button. */\n    size?: keyof typeof SIZES\n  }\n\n/** Frosted \"liquid glass\" button: backdrop blur, rim light and a specular highlight that follows the pointer. */\nexport function LiquidGlassButton({ tone = \"light\", blur = 14, fallback, size = \"md\", className, style, onPointerMove, children, ...props }: LiquidGlassButtonProps) {\n  const reduce = useReducedMotion() ?? false\n  return (\n    <>\n      <GooduiTokens />\n      <Styles />\n      <motion.button\n        data-slot=\"button\"\n        data-tone={tone}\n        data-fallback={fallback || undefined}\n        whileHover={reduce ? undefined : { scale: 1.03 }}\n        whileTap={reduce ? undefined : { scale: 0.95 }}\n        transition={spring.play}\n        onPointerMove={(e) => {\n          trackSpecular(e)\n          onPointerMove?.(e)\n        }}\n        className={cn(\n          \"pc-liquid-glass inline-flex shrink-0 items-center justify-center rounded-full font-medium whitespace-nowrap outline-none select-none focus-visible:ring-3 focus-visible:ring-white/60 disabled:pointer-events-none disabled:opacity-50 [&_svg]:shrink-0 [&_svg]:drop-shadow-[0_1px_1px_rgb(0_0_0/0.2)]\",\n          SIZES[size],\n          className,\n        )}\n        style={{ ...style, [\"--pc-lg-blur\" as string]: `${blur}px` }}\n        {...props}\n      >\n        {children}\n      </motion.button>\n    </>\n  )\n}\n\ntype ToolbarCtx = { value: string | undefined; select: (v: string) => void; id: string; reduce: boolean }\nconst Ctx = React.createContext<ToolbarCtx | null>(null)\n\nexport type LiquidGlassToolbarProps = Omit<React.ComponentProps<\"div\">, \"defaultValue\"> &\n  GlassBase & {\n    /** Controlled selected item (the item's value). */\n    value?: string\n    /** Initially selected item when uncontrolled. */\n    defaultValue?: string\n    /** Called with the item's value when an item is clicked. */\n    onValueChange?: (value: string) => void\n  }\n\n/** Pill toolbar made of glass; the selected item gets a brighter lens that glides between items. Arrow keys move focus. */\nexport function LiquidGlassToolbar({\n  tone = \"light\",\n  blur = 16,\n  fallback,\n  value: valueProp,\n  defaultValue,\n  onValueChange,\n  className,\n  style,\n  children,\n  onKeyDown,\n  onPointerMove,\n  ...props\n}: LiquidGlassToolbarProps) {\n  const reduce = useReducedMotion() ?? false\n  const [inner, setInner] = React.useState(defaultValue)\n  const value = valueProp ?? inner\n  const id = React.useId()\n  const select = React.useCallback(\n    (v: string) => {\n      if (valueProp === undefined) setInner(v)\n      onValueChange?.(v)\n    },\n    [valueProp, onValueChange],\n  )\n\n  return (\n    <Ctx.Provider value={{ value, select, id, reduce }}>\n      <Styles />\n      <div\n        role=\"toolbar\"\n        aria-orientation=\"horizontal\"\n        data-tone={tone}\n        data-fallback={fallback || undefined}\n        onPointerMove={(e) => {\n          trackSpecular(e)\n          onPointerMove?.(e)\n        }}\n        onKeyDown={(e) => {\n          onKeyDown?.(e)\n          if (![\"ArrowLeft\", \"ArrowRight\", \"Home\", \"End\"].includes(e.key)) return\n          const items = Array.from(e.currentTarget.querySelectorAll<HTMLButtonElement>(\"[data-glass-item]:not(:disabled)\"))\n          const i = items.indexOf(document.activeElement as HTMLButtonElement)\n          if (i < 0) return\n          e.preventDefault()\n          // Under dir=\"rtl\" the next item sits to the left, so the arrows swap.\n          const forward = getComputedStyle(e.currentTarget).direction === \"rtl\" ? \"ArrowLeft\" : \"ArrowRight\"\n          const next = e.key === \"Home\" ? 0 : e.key === \"End\" ? items.length - 1 : (i + (e.key === forward ? 1 : -1) + items.length) % items.length\n          items[next]?.focus()\n        }}\n        className={cn(\"pc-liquid-glass inline-flex items-center gap-1 rounded-full p-1 [--pc-lg-size:160px]\", className)}\n        style={{ ...style, [\"--pc-lg-blur\" as string]: `${blur}px` }}\n        {...props}\n      >\n        {children}\n      </div>\n    </Ctx.Provider>\n  )\n}\n\nexport type LiquidGlassToolbarItemProps = Omit<React.ComponentProps<\"button\">, \"value\"> & {\n  /** Identifies the item; when it matches the toolbar's value the item is selected (aria-pressed). */\n  value: string\n  /** Hide the text label on small screens and keep only the icon. */\n  compact?: boolean\n}\n\nexport function LiquidGlassToolbarItem({ value, compact, className, children, onClick, ...props }: LiquidGlassToolbarItemProps) {\n  const ctx = React.useContext(Ctx)\n  if (!ctx) throw new Error(\"LiquidGlassToolbarItem must be used inside LiquidGlassToolbar\")\n  const selected = ctx.value === value\n  return (\n    <button\n      type=\"button\"\n      data-glass-item=\"\"\n      aria-pressed={selected}\n      tabIndex={selected || ctx.value === undefined ? 0 : -1}\n      onClick={(e) => {\n        ctx.select(value)\n        onClick?.(e)\n      }}\n      className={cn(\n        \"pc-press relative inline-flex h-9 items-center justify-center gap-1.5 rounded-full px-3 text-sm font-medium whitespace-nowrap outline-none select-none focus-visible:ring-2 focus-visible:ring-white/70 [&_svg]:size-4 [&_svg]:shrink-0\",\n        selected ? \"opacity-100\" : \"opacity-75 hover:opacity-100\",\n        compact && \"[&>span>span]:hidden sm:[&>span>span]:inline\",\n        className,\n      )}\n      {...props}\n    >\n      <GooduiTokens />\n      {selected && (\n        <motion.span\n          layoutId={`${ctx.id}-lens`}\n          aria-hidden=\"true\"\n          className=\"absolute inset-0 rounded-full bg-white/25 shadow-[inset_0_1px_0_rgb(255_255_255/0.6),inset_0_-1px_1px_rgb(0_0_0/0.06),0_2px_8px_-2px_rgb(0_0_0/0.25)] in-data-fallback:bg-black/8 in-data-[tone=dark]:bg-white/15\"\n          transition={ctx.reduce ? { duration: 0 } : spring.ui}\n        />\n      )}\n      <span className=\"relative inline-flex items-center gap-1.5\">{children}</span>\n    </button>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/liquid-glass-button.tsx"
    }
  ],
  "categories": [
    "components",
    "buttons"
  ],
  "type": "registry:component"
}