{
  "generatedFrom": "counted-input.contract.json",
  "component": "Counted input",
  "slug": "counted-input",
  "group": "Settings",
  "tier": "leaf-lit",
  "summary": "A single-line settings field whose character counter shows only while the field is focused and is hidden at rest — the shared CountedInput pattern for option/answer text.",
  "install": {
    "package": "@ahaslides-product/design",
    "registry": "https://npm.pkg.github.com",
    "scope": "@ahaslides-product",
    "auth": "Published to GitHub Packages — needs a GitHub token with read:packages. Configure the @ahaslides-product scope in .npmrc before installing.",
    "npmrc": "@ahaslides-product:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}   # a GitHub token with read:packages",
    "command": "npm i @ahaslides-product/design",
    "tokenLayer": "import '@ahaslides-product/design/tokens.css';",
    "import": "import '@ahaslides-product/design/aha-counted-input';",
    "element": "aha-counted-input",
    "registers": "aha-counted-input"
  },
  "feeds": {
    "doc": "https://ahaslides-product.github.io/ahaslides-design/counted-input/index.html",
    "md": "https://ahaslides-product.github.io/ahaslides-design/counted-input/counted-input.md",
    "agentJson": "https://ahaslides-product.github.io/ahaslides-design/counted-input.agent.json",
    "llms": "https://ahaslides-product.github.io/ahaslides-design/counted-input.llms.txt",
    "index": "https://ahaslides-product.github.io/ahaslides-design/llms.txt"
  },
  "recommendedSnippet": "html",
  "vibeCode": "Emit the HTML snippet by default — <aha-counted-input> is a standard custom element that renders on open — React/Vue are thin adapters over the same element. Paste into an .html file and it renders with no build step.",
  "frameworks": {
    "react": {
      "via": "web-component",
      "ref": "aha-counted-input"
    },
    "vue": {
      "via": "web-component",
      "ref": "aha-counted-input"
    },
    "html": {
      "via": "web-component",
      "ref": "aha-counted-input",
      "runnable": "paste-and-run — no build step, renders on open"
    }
  },
  "props": [
    {
      "name": "value",
      "type": "string",
      "default": "\"\"",
      "desc": "Controlled text value"
    },
    {
      "name": "placeholder",
      "type": "string",
      "default": "—",
      "desc": "Hint shown when empty"
    },
    {
      "name": "maxlength",
      "type": "number",
      "default": "100",
      "desc": "Character cap (settings-lab default 100); drives the focus-only counter (shows current/max). Pass `none` to drop the cap and hide the counter"
    },
    {
      "name": "size",
      "type": "small | default | large",
      "default": "default",
      "desc": "Control height — small 24 · default 32 · large 40; radius stays 8"
    },
    {
      "name": "status",
      "type": "default | error",
      "default": "default",
      "desc": "Error recolours the border + ring and sets aria-invalid"
    },
    {
      "name": "disabled",
      "type": "boolean",
      "default": "false",
      "desc": "Non-interactive; grey fill"
    },
    {
      "name": "readonly",
      "type": "boolean",
      "default": "false",
      "desc": "Selectable but not editable; secondary fill"
    },
    {
      "name": "input",
      "type": "CustomEvent<{value}>",
      "default": "—",
      "desc": "Composed event on each keystroke; read e.detail.value"
    },
    {
      "name": "change",
      "type": "CustomEvent<{value}>",
      "default": "—",
      "desc": "Composed event on commit (blur/enter)"
    }
  ],
  "tokens": [
    "border",
    "border-hover",
    "color-primary",
    "bg-container",
    "bg-container-secondary",
    "bg-container-disabled",
    "text-default",
    "text-tertiary",
    "text-disabled",
    "radius-default",
    "focus-ring-soft",
    "border-error",
    "color-error",
    "border-disabled"
  ],
  "spec": [
    {
      "label": "Box",
      "value": "height 32 (default) · radius 8 · padding 0 12"
    },
    {
      "label": "Sizes",
      "value": "small 24 · default 32 · large 40 — all radius 8"
    },
    {
      "label": "Rest border",
      "value": "1px #E3E3E3"
    },
    {
      "label": "Focus",
      "value": "#6A1EBB border + 2px #D3B4FF@30% ring (on the persistent wrapper)"
    },
    {
      "label": "Counter",
      "value": "12/18 #8A8A8A, overlay inside the field, right 12; opacity 0 at rest → 1 on focus"
    },
    {
      "label": "Reveal",
      "value": "focus-only (:host([_focused][_counted])) — hidden at rest; space always reserved (no shift)"
    },
    {
      "label": "Error",
      "value": "#F5222D border + error-tinted ring; sets aria-invalid"
    },
    {
      "label": "Disabled",
      "value": "#F1F1F1 fill, #EBEBEB border, not-allowed"
    },
    {
      "label": "Text",
      "value": "Plus Jakarta 14/21; placeholder #8A8A8A"
    }
  ],
  "opinion": {
    "whenToUse": [
      {
        "what": "Counted input",
        "when": "a settings option/answer/label field that needs a character cap — the counter appears only on focus"
      },
      {
        "what": "Counted textarea",
        "when": "the same, but multi-line (descriptions, long answers)"
      },
      {
        "what": "Input",
        "when": "a general single-line field with no counter (names, search)"
      }
    ],
    "note": "Never show a permanent counter on every field — it reads as heavy and steals width. The counter belongs inside the field, revealed on focus. Label the field with a noun phrase; use placeholder for an example, never as the label.",
    "dsv3": "COVERED — the settings-lab CountedInput control mapped into the DS. Box, sizes, border, focus ring and error status reuse the DS V3 field family (input) tokens; the counter is the settings-specific addition — a focus-only overlay (SETTINGS-21/42), not a standing sibling."
  },
  "surfaces": [
    "editor",
    "settings"
  ],
  "snippets": {
    "html": "<!-- Paste-and-run: save as .html and open in a browser. No build step.\n     <aha-counted-input> is the SAME shared custom element React and Vue consume — here in its\n     native form. Theming comes only from the --aha-* tokens in tokens.css. The character counter\n     is revealed only while the field is focused (SETTINGS-21/42) — click in to see it. -->\n<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/ahaslides-product/ahaslides-design@master/lib/tokens.css\">\n<script type=\"module\">\n  import 'https://cdn.jsdelivr.net/gh/ahaslides-product/ahaslides-design@master/lib/aha-counted-input.js';   // registers <aha-counted-input>\n</script>\n\n<!-- maxlength turns the focus-only counter on (shows current/max) -->\n<aha-counted-input id=\"opt\" maxlength=\"80\" value=\"Paris\" placeholder=\"Option text\"></aha-counted-input>\n\n<!-- size: small | default | large   ·   status: error   ·   disabled / readonly -->\n<aha-counted-input size=\"large\" maxlength=\"40\" placeholder=\"Large\"></aha-counted-input>\n<aha-counted-input status=\"error\" maxlength=\"80\" value=\"Too long\" placeholder=\"Answer\"></aha-counted-input>\n\n<script>\n  // Plain DOM — no framework. Read e.detail.value off the composed CustomEvent.\n  document.getElementById('opt').addEventListener('input', (e) => {\n    console.log('value:', e.detail.value);\n  });\n</script>\n",
    "react": "import '@ahaslides-product/design/aha-counted-input'; // registers <aha-counted-input>\nimport { useRef, useEffect } from 'react';\n\n// React 18 needs a thin wrapper; React 19 can use <aha-counted-input> directly.\n// size: 'small' | 'default' | 'large'  ·  the counter shows only on focus when maxLength is set.\nfunction AhaCountedInput({ value, placeholder, maxLength, size, status, disabled, readOnly, onChange }) {\n  const ref = useRef();\n  useEffect(() => {\n    const el = ref.current;\n    el.value = value ?? '';\n    el.disabled = !!disabled;\n    const h = (e) => onChange?.(e.detail.value);   // composed CustomEvent\n    el.addEventListener('input', h);\n    return () => el.removeEventListener('input', h);\n  });\n  return (\n    <aha-counted-input\n      ref={ref}\n      placeholder={placeholder}\n      {...(maxLength ? { maxlength: String(maxLength) } : {})}\n      {...(size ? { size } : {})}\n      {...(status ? { status } : {})}\n      {...(readOnly ? { readonly: '' } : {})}\n    />\n  );\n}\n\n// usage\n<AhaCountedInput value={answer} placeholder=\"Answer\" maxLength={80} onChange={setAnswer} />\n",
    "vue": "// main.ts — register the element + mark aha-* as custom elements\nimport '@ahaslides-product/design/aha-counted-input';   // registers <aha-counted-input>\napp.config.compilerOptions.isCustomElement = (tag) => tag.startsWith('aha-');\n\n// Component.vue\n<script setup>\nimport { ref } from 'vue';\nconst answer = ref('');\n</script>\n\n<template>\n  <!-- size: small | default | large  ·  maxlength turns the focus-only counter on -->\n  <aha-counted-input\n    size=\"default\"\n    maxlength=\"80\"\n    placeholder=\"Answer\"\n    :value.prop=\"answer\"\n    @input=\"answer = $event.detail.value\"\n  />\n</template>\n"
  }
}
