{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pay-tip-selector",
  "type": "registry:component",
  "title": "Pay Tip Selector",
  "description": "Tip percentage chips with the amount under each one, a custom amount field, and a total that rolls to the new value.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "payments",
    "tip",
    "gratuity",
    "checkout",
    "chips",
    "payment",
    "total"
  ],
  "docs": "https://hyperblur.dev/effects/pay-tip-selector",
  "files": [
    {
      "path": "registry/hyperblur/pay-tip-selector.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/pay-tip-selector.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PayTipChange {\n  percent: number | null;\n  amount: number;\n  total: number;\n}\n\nexport interface PayTipSelectorProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  subtotal?: number;\n  currency?: string;\n  options?: number[];\n  percent?: number | null;\n  defaultPercent?: number | null;\n  onChange?: (tip: PayTipChange) => void;\n  title?: string;\n  note?: string;\n  allowCustom?: boolean;\n  accent?: string;\n}\n\nconst css = `\n.hb-qf8 {\n  box-sizing: border-box;\n  width: 100%;\n  padding: 12px 14px;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 1.4;\n  background: #111111;\n  border: 1px solid #262626;\n  border-radius: 14px;\n}\n.hb-qf8 *, .hb-qf8 *::before, .hb-qf8 *::after { box-sizing: border-box; }\n.hb-qf8-hd { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }\n.hb-qf8-hd b { font-size: 13.5px; font-weight: 600; }\n.hb-qf8-hd span { overflow: hidden; color: #8f8f8f; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-qf8-chips { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; margin: 10px 0 0; }\n.hb-qf8-chip {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  min-width: 0;\n  height: 42px;\n  margin: 0;\n  padding: 0 4px;\n  color: #ededed;\n  font: inherit;\n  background: #0a0a0a;\n  border: 1px solid #2a2a2a;\n  border-radius: 10px;\n  cursor: pointer;\n  transition: border-color 0.2s ease, background-color 0.25s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-qf8-chip:hover { border-color: #3d3d3d; }\n.hb-qf8-chip:active { transform: scale(0.96); }\n.hb-qf8-chip:focus-visible { outline: 2px solid var(--hb-qf8-x); outline-offset: 2px; }\n.hb-qf8-chip[aria-pressed=\"true\"] {\n  background: color-mix(in srgb, var(--hb-qf8-x) 16%, #0a0a0a);\n  border-color: var(--hb-qf8-x);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-qf8-x) 14%, transparent);\n}\n.hb-qf8-chip b { font-size: 13px; font-weight: 600; line-height: 1.2; }\n.hb-qf8-chip span { color: #8f8f8f; font-size: 11px; font-variant-numeric: tabular-nums; line-height: 1.2; }\n.hb-qf8-chip[aria-pressed=\"true\"] span { color: color-mix(in srgb, var(--hb-qf8-x) 50%, #fff); }\n.hb-qf8-rows { margin: 8px 0 0; }\n.hb-qf8-row { display: flex; align-items: center; justify-content: space-between; min-height: 22px; margin: 0; color: #a1a1a1; }\n.hb-qf8-row dd { margin: 0; color: #ededed; font-weight: 500; }\n.hb-qf8-total { margin-top: 4px; padding-top: 6px; color: #ededed; border-top: 1px dashed #333333; }\n.hb-qf8-total dt { font-weight: 600; }\n.hb-qf8-total dd { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }\n.hb-qf8-field {\n  display: inline-flex;\n  align-items: center;\n  height: 24px;\n  padding: 0 8px;\n  color: #ededed;\n  background: #0a0a0a;\n  border: 1px solid var(--hb-qf8-x);\n  border-radius: 8px;\n  animation: hb-qf8-in 0.3s ease both;\n}\n.hb-qf8-field:focus-within { box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-qf8-x) 25%, transparent); }\n.hb-qf8-field span { color: #8f8f8f; }\n.hb-qf8-field input {\n  width: 64px;\n  margin: 0 0 0 3px;\n  padding: 0;\n  color: inherit;\n  font: inherit;\n  font-weight: 500;\n  font-variant-numeric: tabular-nums;\n  text-align: right;\n  background: none;\n  border: 0;\n  outline: none;\n}\n.hb-qf8-roll { position: relative; display: inline-flex; align-items: flex-start; height: calc(var(--hb-qf8-lh) * 1em); font-variant-numeric: tabular-nums; line-height: var(--hb-qf8-lh); white-space: pre; --hb-qf8-lh: 1.25; }\n.hb-qf8-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n.hb-qf8-d { display: inline-block; height: calc(var(--hb-qf8-lh) * 1em); overflow: hidden; }\n.hb-qf8-dc { display: flex; flex-direction: column; transition: transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1); }\n.hb-qf8-dc > span { display: block; height: calc(var(--hb-qf8-lh) * 1em); }\n@keyframes hb-qf8-in { from { opacity: 0; transform: translateX(6px); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qf8-chip, .hb-qf8-dc { transition: none; }\n  .hb-qf8-field { animation: none; }\n}\n`;\n\nfunction money(cents: number, currency: string) {\n  const whole = Math.floor(cents / 100)\n    .toString()\n    .replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n  return `${currency}${whole}.${(cents % 100).toString().padStart(2, \"0\")}`;\n}\n\nfunction Roll({ text }: { text: string }) {\n  const chars = text.split(\"\");\n  return (\n    <span className=\"hb-qf8-roll\">\n      <span className=\"hb-qf8-sr\">{text}</span>\n      {chars.map((ch, i) => {\n        const key = chars.length - i;\n        if (ch < \"0\" || ch > \"9\") {\n          return (\n            <span key={key} aria-hidden=\"true\">\n              {ch}\n            </span>\n          );\n        }\n        return (\n          <span key={key} className=\"hb-qf8-d\" aria-hidden=\"true\">\n            <span className=\"hb-qf8-dc\" style={{ transform: `translateY(calc(${Number(ch)} * var(--hb-qf8-lh) * -1em))` }}>\n              {\"0123456789\".split(\"\").map((d) => (\n                <span key={d}>{d}</span>\n              ))}\n            </span>\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nexport function PayTipSelector({\n  subtotal = 4200,\n  currency = \"$\",\n  options = [10, 15, 20],\n  percent,\n  defaultPercent = 15,\n  onChange,\n  title = \"Add a tip\",\n  note = \"100% goes to the team\",\n  allowCustom = true,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: PayTipSelectorProps) {\n  const [innerPercent, setInnerPercent] = React.useState<number | null>(defaultPercent);\n  const [custom, setCustom] = React.useState(\"5.00\");\n  const current = percent === undefined ? innerPercent : percent;\n  const isCustom = current === null;\n\n  const amount = isCustom\n    ? Math.round(Math.max(0, parseFloat(custom) || 0) * 100)\n    : Math.round((subtotal * (current ?? 0)) / 100);\n  const total = subtotal + amount;\n\n  function emit(nextPercent: number | null, nextCustom: string) {\n    const nextAmount =\n      nextPercent === null\n        ? Math.round(Math.max(0, parseFloat(nextCustom) || 0) * 100)\n        : Math.round((subtotal * nextPercent) / 100);\n    onChange?.({ percent: nextPercent, amount: nextAmount, total: subtotal + nextAmount });\n  }\n\n  function pick(next: number | null) {\n    if (percent === undefined) setInnerPercent(next);\n    emit(next, custom);\n  }\n\n  function onCustom(raw: string) {\n    const cleaned = raw.replace(/[^0-9.]/g, \"\").replace(/(\\..*)\\./g, \"$1\").replace(/^(\\d*\\.\\d{0,2}).*$/, \"$1\").slice(0, 7);\n    setCustom(cleaned);\n    emit(null, cleaned);\n  }\n\n  const chips: { key: string; label: string; value: number | null; sub: string }[] = [\n    { key: \"none\", label: \"No tip\", value: 0, sub: money(0, currency) },\n    ...options.map((p) => ({ key: `p${p}`, label: `${p}%`, value: p, sub: money(Math.round((subtotal * p) / 100), currency) })),\n  ];\n  if (allowCustom) chips.push({ key: \"custom\", label: \"Custom\", value: null, sub: \"Other\" });\n\n  const vars = { \"--hb-qf8-x\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div className={`hb-qf8 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-pay-tip-selector\" precedence=\"default\">{css}</style>\n      <div className=\"hb-qf8-hd\">\n        <b>{title}</b>\n        {note && <span>{note}</span>}\n      </div>\n      <div className=\"hb-qf8-chips\" role=\"group\" aria-label={title}>\n        {chips.map((chip) => (\n          <button key={chip.key} type=\"button\" className=\"hb-qf8-chip\" aria-pressed={current === chip.value} onClick={() => pick(chip.value)}>\n            <b>{chip.label}</b>\n            <span>{chip.sub}</span>\n          </button>\n        ))}\n      </div>\n      <dl className=\"hb-qf8-rows\">\n        <div className=\"hb-qf8-row\">\n          <dt>Subtotal</dt>\n          <dd>\n            <Roll text={money(subtotal, currency)} />\n          </dd>\n        </div>\n        <div className=\"hb-qf8-row\">\n          <dt>Tip</dt>\n          <dd>\n            {isCustom ? (\n              <label className=\"hb-qf8-field\">\n                <span>{currency}</span>\n                <input\n                  type=\"text\"\n                  inputMode=\"decimal\"\n                  aria-label=\"Custom tip amount\"\n                  value={custom}\n                  onChange={(e) => onCustom(e.target.value)}\n                />\n              </label>\n            ) : (\n              <Roll text={money(amount, currency)} />\n            )}\n          </dd>\n        </div>\n        <div className=\"hb-qf8-row hb-qf8-total\">\n          <dt>Total</dt>\n          <dd>\n            <Roll text={money(total, currency)} />\n          </dd>\n        </div>\n      </dl>\n    </div>\n  );\n}\n"
    }
  ]
}