{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "angle-slider-heading-compass",
  "title": "Angle Slider Heading Compass",
  "description": "A compass bearing control that shows the heading in degrees and as a cardinal point (N, NE, E and so on), snaps to 5 degrees and has quick buttons for the four directions.",
  "registryDependencies": [
    "button",
    "@tealmac/angle-slider"
  ],
  "files": [
    {
      "path": "registry/patterns/angle-slider-heading-compass/angle-slider-heading-compass.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { AngleSlider } from \"@/components/ui/angle-slider\"\nimport { Button } from \"@/components/ui/button\"\n\nexport interface AngleSliderHeadingCompassProps {\n  heading?: number\n  onChange?: (degrees: number, cardinal: string) => void\n}\n\nconst POINTS = [\"N\", \"NE\", \"E\", \"SE\", \"S\", \"SW\", \"W\", \"NW\"]\n\n/** The eight-point compass name for a bearing in degrees. */\nexport function cardinal(degrees: number) {\n  return POINTS[Math.round((((degrees % 360) + 360) % 360) / 45) % 8]\n}\n\n/**\n * Bearings are spoken as words as often as numbers, so the control prints both\n * (\"135° SE\"). The slider snaps to 5 degrees for a steadier hand; the four\n * buttons jump to N, E, S and W for the common case, and the live text is the\n * only thing announced, not every intermediate drag value.\n */\nexport function AngleSliderHeadingCompass({\n  heading: initial = 0,\n  onChange,\n}: AngleSliderHeadingCompassProps) {\n  const [heading, setHeading] = React.useState(initial)\n  const set = (d: number) => {\n    setHeading(d)\n    onChange?.(d, cardinal(d))\n  }\n\n  return (\n    <div className=\"bg-card flex w-fit flex-col items-center gap-3 rounded-xl border p-5\">\n      <AngleSlider\n        label=\"Heading\"\n        value={heading}\n        step={5}\n        onValueChange={set}\n      />\n      <p className=\"text-lg font-semibold tabular-nums\">\n        {heading}° {cardinal(heading)}\n      </p>\n      <p role=\"status\" className=\"sr-only\">\n        Heading {heading} degrees, {cardinal(heading)}\n      </p>\n      <div role=\"group\" aria-label=\"Quick headings\" className=\"flex gap-1.5\">\n        {[\n          [\"N\", 0],\n          [\"E\", 90],\n          [\"S\", 180],\n          [\"W\", 270],\n        ].map(([label, deg]) => (\n          <Button\n            key={label}\n            type=\"button\"\n            size=\"sm\"\n            variant={heading === deg ? \"default\" : \"outline\"}\n            aria-pressed={heading === deg}\n            onClick={() => set(deg as number)}\n          >\n            {label}\n          </Button>\n        ))}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}