{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-quantity-picker",
  "type": "registry:component",
  "title": "Quantity Picker",
  "description": "An add to bag button that stretches into a quantity capsule on the first tap. Digits slide in the direction you count, a +1 floats off the plus, and at one the minus turns into a trash can that folds it back.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "quantity",
    "cart",
    "stepper",
    "ecommerce",
    "morph",
    "micro"
  ],
  "docs": "https://hyperblur.dev/effects/micro-quantity-picker",
  "files": [
    {
      "path": "registry/hyperblur/micro-quantity-picker.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-quantity-picker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MicroQuantityPickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\"> {\n  value?: number;\n  defaultValue?: number;\n  max?: number;\n  addLabel?: string;\n  itemLabel?: string;\n  accent?: string;\n  disabled?: boolean;\n  onChange?: (value: number) => void;\n}\n\nconst css = `\n.hb-wf10 {\n  --hb-wf10-c: #2f7bff;\n  --hb-wf10-w: 132px;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  height: 42px;\n  width: var(--hb-wf10-w);\n  box-sizing: border-box;\n  border-radius: 999px;\n  background: var(--hb-wf10-c);\n  color: #fff;\n  font-family: inherit;\n  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25), 0 10px 22px -10px color-mix(in srgb, var(--hb-wf10-c) 80%, transparent);\n  transition: width 0.45s cubic-bezier(0.3, 1.35, 0.45, 1), background 0.3s ease, box-shadow 0.3s ease;\n  user-select: none;\n  -webkit-user-select: none;\n}\n.hb-wf10 *, .hb-wf10 *::before, .hb-wf10 *::after { box-sizing: border-box; }\n.hb-wf10[data-open=\"true\"] {\n  width: 132px;\n  background: linear-gradient(180deg, #1c1c1c, #141414);\n  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 0 0 1px #2a2a2a, 0 10px 22px -12px rgba(0,0,0,0.9);\n}\n.hb-wf10[data-disabled=\"true\"] { opacity: 0.45; pointer-events: none; }\n.hb-wf10-add {\n  position: absolute;\n  inset: 0;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  padding: 0 18px 0 16px;\n  margin: 0;\n  border: 0;\n  border-radius: inherit;\n  background: transparent;\n  color: inherit;\n  font: inherit;\n  font-size: 13.5px;\n  font-weight: 600;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);\n}\n.hb-wf10-add:active { transform: scale(0.96); }\n.hb-wf10-add:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n.hb-wf10-add svg { width: 16px; height: 16px; flex: none; }\n.hb-wf10[data-open=\"true\"] .hb-wf10-add { opacity: 0; transform: scale(0.85); pointer-events: none; }\n.hb-wf10-ms {\n  position: absolute;\n  visibility: hidden;\n  white-space: nowrap;\n  font-size: 13.5px;\n  font-weight: 600;\n  padding: 0 18px 0 16px;\n  display: inline-flex;\n  gap: 8px;\n}\n.hb-wf10-st {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 0 4px;\n  opacity: 0;\n  pointer-events: none;\n  transition: opacity 0.2s ease 0.08s;\n}\n.hb-wf10[data-open=\"true\"] .hb-wf10-st { opacity: 1; pointer-events: auto; }\n.hb-wf10-b {\n  position: relative;\n  display: grid;\n  place-items: center;\n  width: 34px;\n  height: 34px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 999px;\n  background: #262626;\n  color: #e6e6e6;\n  cursor: pointer;\n  transition: background 0.2s ease, color 0.2s ease, transform 0.25s cubic-bezier(0.3, 1.8, 0.4, 1);\n}\n.hb-wf10-b:hover { background: #303030; color: #fff; }\n.hb-wf10-b:active { transform: scale(0.86); }\n.hb-wf10-b:focus-visible { outline: 2px solid var(--hb-wf10-c); outline-offset: 2px; }\n.hb-wf10-b:disabled { opacity: 0.35; cursor: not-allowed; }\n.hb-wf10-b[data-del=\"true\"] { color: #ff6b6b; }\n.hb-wf10-b[data-del=\"true\"]:hover { background: rgba(255,107,107,0.14); }\n.hb-wf10-b svg { position: absolute; width: 15px; height: 15px; transition: opacity 0.18s ease, transform 0.28s cubic-bezier(0.3, 1.6, 0.5, 1); }\n.hb-wf10-b .hb-wf10-tr { opacity: 0; transform: scale(0.4) rotate(-30deg); }\n.hb-wf10-b[data-del=\"true\"] .hb-wf10-tr { opacity: 1; transform: none; }\n.hb-wf10-b[data-del=\"true\"] .hb-wf10-mn { opacity: 0; transform: scale(0.4) rotate(30deg); }\n.hb-wf10-b[data-shake=\"a\"] { animation: hb-wf10-shake 0.36s ease; }\n.hb-wf10-b[data-shake=\"b\"] { animation: hb-wf10-shake2 0.36s ease; }\n@keyframes hb-wf10-shake { 20% { translate: 3px 0; } 45% { translate: -3px 0; } 70% { translate: 2px 0; } 100% { translate: 0 0; } }\n@keyframes hb-wf10-shake2 { 20% { translate: 3px 0; } 45% { translate: -3px 0; } 70% { translate: 2px 0; } 100% { translate: 0 0; } }\n.hb-wf10-n {\n  position: relative;\n  flex: 1;\n  height: 22px;\n  overflow: hidden;\n  text-align: center;\n  font-family: var(--font-mono), ui-monospace, monospace;\n  font-size: 15px;\n  font-weight: 600;\n  line-height: 22px;\n  font-variant-numeric: tabular-nums;\n}\n.hb-wf10-n span { display: block; }\n.hb-wf10-n[data-dir=\"1\"] span { animation: hb-wf10-up 0.32s cubic-bezier(0.2, 1.4, 0.4, 1); }\n.hb-wf10-n[data-dir=\"-1\"] span { animation: hb-wf10-dn 0.32s cubic-bezier(0.2, 1.4, 0.4, 1); }\n@keyframes hb-wf10-up { from { transform: translateY(100%); } to { transform: none; } }\n@keyframes hb-wf10-dn { from { transform: translateY(-100%); } to { transform: none; } }\n.hb-wf10-fx {\n  position: absolute;\n  right: 10px;\n  top: -4px;\n  font-family: var(--font-mono), ui-monospace, monospace;\n  font-size: 11px;\n  font-weight: 700;\n  color: var(--hb-wf10-c);\n  pointer-events: none;\n  animation: hb-wf10-fx 0.7s cubic-bezier(0.2, 0.8, 0.3, 1) both;\n}\n@keyframes hb-wf10-fx { 0% { opacity: 0; transform: translateY(6px) scale(0.7); } 25% { opacity: 1; transform: translateY(-4px) scale(1); } 100% { opacity: 0; transform: translateY(-20px) scale(0.9); } }\n.hb-wf10-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wf10, .hb-wf10-add, .hb-wf10-st, .hb-wf10-b, .hb-wf10-b svg { transition: none; }\n  .hb-wf10-n span, .hb-wf10-fx, .hb-wf10-b[data-shake] { animation: none; }\n  .hb-wf10-fx { display: none; }\n}\n`;\n\nexport function MicroQuantityPicker({\n  value,\n  defaultValue = 0,\n  max = 9,\n  addLabel = \"Add to bag\",\n  itemLabel = \"item\",\n  accent = \"#2f7bff\",\n  disabled = false,\n  onChange,\n  className = \"\",\n  style,\n  ...rest\n}: MicroQuantityPickerProps) {\n  const [inner, setInner] = React.useState(defaultValue);\n  const v = value ?? inner;\n  const [dir, setDir] = React.useState(0);\n  const [tick, setTick] = React.useState(0);\n  const [fx, setFx] = React.useState(0);\n  const [shake, setShake] = React.useState(0);\n  const [w, setW] = React.useState<number | null>(null);\n  const msRef = React.useRef<HTMLSpanElement>(null);\n  const addRef = React.useRef<HTMLButtonElement>(null);\n  const plusRef = React.useRef<HTMLButtonElement>(null);\n  const open = v > 0;\n  const wasOpen = React.useRef(open);\n\n  React.useLayoutEffect(() => {\n    const el = msRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setW(Math.ceil(el.getBoundingClientRect().width)));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [addLabel]);\n\n  React.useEffect(() => {\n    if (open && !wasOpen.current) plusRef.current?.focus({ preventScroll: true });\n    if (!open && wasOpen.current) addRef.current?.focus({ preventScroll: true });\n    wasOpen.current = open;\n  }, [open]);\n\n  const set = (next: number) => {\n    const c = Math.max(0, Math.min(max, next));\n    if (c === v) {\n      setShake((s) => s + 1);\n      return;\n    }\n    setDir(c > v ? 1 : -1);\n    setTick((t) => t + 1);\n    if (c > v) setFx((f) => f + 1);\n    if (value === undefined) setInner(c);\n    onChange?.(c);\n  };\n\n  return (\n    <div\n      className={`hb-wf10 ${className}`}\n      data-open={open}\n      data-disabled={disabled}\n      role=\"group\"\n      aria-label={`${addLabel} quantity`}\n      style={{ ...style, [\"--hb-wf10-c\" as string]: accent, [\"--hb-wf10-w\" as string]: w ? `${w}px` : \"auto\" }}\n      {...rest}\n    >\n      <style href=\"hb-micro-quantity-picker\" precedence=\"default\">\n        {css}\n      </style>\n      <span ref={msRef} className=\"hb-wf10-ms\" aria-hidden=\"true\">\n        <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" />\n        {addLabel}\n      </span>\n      <button ref={addRef} type=\"button\" className=\"hb-wf10-add\" tabIndex={open ? -1 : 0} aria-hidden={open} onClick={() => set(1)}>\n        <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n          <path d=\"M3.2 5.5h9.6l-.8 7.2a1.4 1.4 0 0 1-1.4 1.3H5.4A1.4 1.4 0 0 1 4 12.7z\" />\n          <path d=\"M5.8 5.5V4.6a2.2 2.2 0 0 1 4.4 0v.9\" />\n        </svg>\n        {addLabel}\n      </button>\n      <div className=\"hb-wf10-st\" aria-hidden={!open}>\n        <button\n          type=\"button\"\n          className=\"hb-wf10-b\"\n          data-del={v === 1}\n          tabIndex={open ? 0 : -1}\n          aria-label={v === 1 ? \"Remove from bag\" : `One less ${itemLabel}`}\n          onClick={() => set(v - 1)}\n        >\n          <svg className=\"hb-wf10-mn\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n            <path d=\"M3.5 8h9\" />\n          </svg>\n          <svg className=\"hb-wf10-tr\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M2.8 4.4h10.4M6.2 4.4V3a1 1 0 0 1 1-1h1.6a1 1 0 0 1 1 1v1.4M4.2 4.4l.6 8.4a1.3 1.3 0 0 0 1.3 1.2h3.8a1.3 1.3 0 0 0 1.3-1.2l.6-8.4\" />\n          </svg>\n        </button>\n        <span className=\"hb-wf10-n\" data-dir={dir}>\n          <span key={tick}>{v}</span>\n        </span>\n        <button\n          ref={plusRef}\n          type=\"button\"\n          className=\"hb-wf10-b\"\n          data-shake={shake ? (shake % 2 ? \"a\" : \"b\") : undefined}\n          tabIndex={open ? 0 : -1}\n          aria-label={`One more ${itemLabel}`}\n          aria-disabled={v >= max}\n          onClick={() => set(v + 1)}\n        >\n          <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n            <path d=\"M3.5 8h9M8 3.5v9\" />\n          </svg>\n        </button>\n        {fx > 0 ? (\n          <span key={fx} className=\"hb-wf10-fx\" aria-hidden=\"true\">\n            +1\n          </span>\n        ) : null}\n      </div>\n      <span className=\"hb-wf10-sr\" aria-live=\"polite\">\n        {open ? `${v} in bag` : \"\"}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}