{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rating",
  "title": "Rating",
  "description": "A level picked from a row of diamond pips.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/rating.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Field, FieldDescription, FieldLabel } from \"@ui-sdk/react/field\"\nimport { Rating as SdkRating, RatingItem } from \"@ui-sdk/react/rating\"\nimport \"@/registry/cyber/ui/cyber/rating.css\"\n\n// A level on a short scale: a threat, a tier, a clearance. A row of diamond\n// pips on a hairline, lit up to the level, with the one it ends in holding a\n// signal core; the level is printed at the end of the label's line as a\n// number, and in a word when `levels` names them.\n//\n// - `levels` are the names of each whole level, lowest first (\"Low\",\n//   \"Guarded\", …). The current one is printed, and all are read out by assistive\n//   technology, so a pip is \"Elevated, 3 of 5\" rather than \"3 stars\".\n// - `step={0.5}` (the SDK's) allows half levels; each pip widens so both of\n//   its halves stay big enough to press.\n// - `readOnly` shows a level that can't change, as one image named by its\n//   label and level. It can be any number, like 3.4.\nfunction Rating({\n  label,\n  hint,\n  levels,\n  max = 5,\n  step = 1,\n  value,\n  defaultValue,\n  onValueChange,\n  getValueLabel,\n  ...props\n}: Omit<React.ComponentProps<typeof SdkRating>, \"children\"> & {\n  label: string\n  hint?: string\n  levels?: string[]\n}) {\n  // The readout sits outside the pips, so it follows the value from here:\n  // the controlled one, or a copy kept of the uncontrolled one.\n  const [inner, setInner] = React.useState<number | null>(defaultValue ?? null)\n  const shown = value !== undefined ? value : inner\n  const levelOf = (score: number) => levels?.[Math.max(1, Math.ceil(score)) - 1]\n  const level = shown === null ? undefined : levelOf(shown)\n\n  const nameOf =\n    getValueLabel ??\n    ((score: number, of: number) => {\n      const name = levelOf(score)\n      return name ? `${name}, ${score} of ${of}` : `${score} of ${of}`\n    })\n\n  return (\n    <Field data-kit=\"field\">\n      <div data-kit=\"rating-head\">\n        {/* Read-only, the pips are one image that names itself, level\n            included, so the label is only what's seen. */}\n        {props.readOnly ? <span data-kit=\"label\">{label}</span> : <FieldLabel data-kit=\"label\">{label}</FieldLabel>}\n        <span data-kit=\"rating-readout\" data-empty={shown === null ? \"\" : undefined} data-disabled={props.disabled ? \"\" : undefined} aria-hidden>\n          {level && <span data-kit=\"rating-level\">{level}</span>}\n          {shown ?? \"-\"}\n          <span data-kit=\"rating-max\">/{max}</span>\n        </span>\n      </div>\n      <SdkRating\n        data-kit=\"rating\"\n        data-halves={step < 1 ? \"\" : undefined}\n        max={max}\n        step={step}\n        value={value}\n        defaultValue={defaultValue}\n        onValueChange={(next, details) => {\n          onValueChange?.(next, details)\n          if (!details.canceled) setInner(next)\n        }}\n        getValueLabel={props.readOnly ? (score, of) => `${label}: ${nameOf(score, of)}` : nameOf}\n        {...props}\n      >\n        <RatingItem data-kit=\"rating-item\">\n          <span data-kit=\"rating-pip\" aria-hidden />\n        </RatingItem>\n      </SdkRating>\n      {hint && <FieldDescription data-kit=\"hint\">{hint}</FieldDescription>}\n    </Field>\n  )\n}\n\nexport { Rating }\n",
      "type": "registry:ui",
      "target": "@ui/rating.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/rating.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  /* The label, a rule running off it, and the level as a number at the end\n     of the rule. */\n  [data-skin=\"cyber\"] [data-kit=\"rating-head\"] {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: center;\n    gap: 2px 8px;\n    min-width: 0;\n\n    & > [data-kit=\"label\"] {\n      flex: none;\n    }\n\n    &::after {\n      content: \"\";\n      order: 1;\n      flex: 1;\n      min-width: 12px;\n      height: 1px;\n      background: var(--cy-line-deco);\n    }\n  }\n\n  /* What it reads: the level's name if it has one, then the number. */\n  [data-skin=\"cyber\"] [data-kit=\"rating-readout\"] {\n    order: 2;\n    flex: none;\n    display: flex;\n    align-items: baseline;\n    font-family: var(--cy-mono);\n    font-size: var(--cy-text-sm);\n    font-variant-numeric: tabular-nums;\n    line-height: 1;\n    color: var(--cy-signal);\n\n    &:is([data-empty], [data-disabled]) {\n      color: var(--cy-ink-mute);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"rating-level\"] {\n    margin-inline-end: 8px;\n    font-size: var(--cy-text-xs);\n    letter-spacing: 0.08em;\n    text-transform: uppercase;\n  }\n\n  /* \"of how many\" is the quieter half. */\n  [data-skin=\"cyber\"] [data-kit=\"rating-max\"] {\n    color: var(--cy-ink-mute);\n  }\n\n  /* The row of pips, strung on a hairline that runs from the first pip's\n     centre to the last one's. */\n  [data-skin=\"cyber\"] [data-kit=\"rating\"] {\n    --pitch: 30px;\n    --pip: 14px;\n\n    position: relative;\n    justify-self: start;\n    display: inline-flex;\n    max-width: 100%;\n    /* The first pip's point sits on the label's edge, not half a pitch in. */\n    margin-inline-start: calc((var(--pitch) - var(--pip) * 1.414) / -2);\n\n    @media (pointer: coarse) {\n      --pitch: 44px;\n    }\n\n    /* Half levels: each half of a pip is its own target, so a pip is two\n       targets wide. */\n    &[data-halves] {\n      --pitch: 48px;\n    }\n\n    &::before {\n      content: \"\";\n      position: absolute;\n      inset-inline: calc(var(--pitch) / 2);\n      top: calc(var(--cy-h) / 2);\n      height: 1px;\n      background: var(--cy-line-deco);\n    }\n  }\n\n  /* One pip's slot: the target the SDK lays its radio (or two) over. */\n  [data-skin=\"cyber\"] [data-kit=\"rating-item\"] {\n    display: grid;\n    place-items: center;\n    width: var(--pitch);\n    height: var(--cy-h);\n\n    /* The radios themselves: one over the whole slot, or one over each\n       half. */\n    & > [role=\"radio\"] {\n      cursor: pointer;\n    }\n\n    &[data-readonly] > [role=\"radio\"] {\n      cursor: default;\n    }\n\n    &[data-disabled] > [role=\"radio\"] {\n      cursor: not-allowed;\n    }\n  }\n\n  /* The pip: a square turned on its corner, never a star. It fills from its\n     leading point as far as the level reaches, so half a level is half a\n     diamond; the gradient runs along the square's diagonal, which is the\n     diamond's width. */\n  [data-skin=\"cyber\"] [data-kit=\"rating-pip\"] {\n    --pip-line: var(--cy-line-ctl);\n    --pip-fill: var(--cy-accent);\n    --pip-angle: 45deg;\n\n    position: relative;\n    display: grid;\n    place-items: center;\n    width: var(--pip);\n    height: var(--pip);\n    border: var(--cy-line) solid var(--pip-line);\n    background: linear-gradient(var(--pip-angle), var(--pip-fill) calc(var(--rating-fill, 0) * 100%), var(--cy-panel) 0);\n    rotate: 45deg;\n    transition: border-color var(--cy-t-fast) linear;\n\n    :dir(rtl) & {\n      --pip-angle: 225deg;\n    }\n\n    :is([data-filled], [data-partial]) > & {\n      --pip-line: var(--cy-line-hot);\n    }\n\n    /* A pointer over the pips previews a level: the pips up to it show a\n       dimmer fill until it's pressed. */\n    [data-highlighted] > & {\n      --pip-line: var(--cy-line-hot);\n      --pip-fill: var(--cy-fill-active);\n    }\n\n    /* The pip the level ends in keeps a core in the signal color, like\n       every selection mark, so the set level is still marked while another\n       is being previewed. */\n    [data-checked] > &::after {\n      content: \"\";\n      width: 4px;\n      height: 4px;\n      background: var(--cy-signal);\n      outline: 2px solid var(--cy-panel);\n    }\n\n    /* Unavailable: hatched, not just dimmer. The hatching runs along the\n       square, so it reads as diagonal on the diamond. */\n    [data-disabled] > & {\n      --pip-line: var(--cy-line-deco);\n      --pip-fill: var(--cy-line-deco);\n      background-image:\n        repeating-linear-gradient(90deg, transparent 0 3px, var(--cy-line-deco) 3px 4px),\n        linear-gradient(var(--pip-angle), var(--pip-fill) calc(var(--rating-fill, 0) * 100%), var(--cy-panel) 0);\n\n      &::after {\n        background: var(--cy-ink-mute);\n      }\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/rating.css"
    }
  ],
  "type": "registry:ui"
}
