{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "map-legend",
  "title": "Map Legend",
  "description": "Layer symbols, counts, a color ramp, and visibility toggles for a map.",
  "dependencies": [
    "class-variance-authority"
  ],
  "registryDependencies": [
    "checkbox",
    "https://uaiblocks.dev/r/uai-theme.json",
    "https://uaiblocks.dev/r/uai-utils.json"
  ],
  "files": [
    {
      "path": "src/registry/uai/components/map-legend.tsx",
      "content": "\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport {\n  type ComponentProps,\n  type CSSProperties,\n  createContext,\n  useContext,\n  useId,\n  useState,\n} from \"react\";\nimport { Checkbox } from \"@/components/ui/checkbox\";\nimport { cn } from \"@/lib/uai-utils\";\n\nexport const MAP_LEGEND_VARIANTS = [\"card\", \"floating\", \"compact\"] as const;\nexport type MapLegendVariant = (typeof MAP_LEGEND_VARIANTS)[number];\nexport const MAP_LEGEND_SWATCH_SHAPES = [\"fill\", \"line\", \"dot\"] as const;\nexport type MapLegendSwatchShape = (typeof MAP_LEGEND_SWATCH_SHAPES)[number];\nexport type MapLegendProps = Omit<ComponentProps<\"section\">, \"defaultValue\"> & {\n  variant?: MapLegendVariant;\n  /** Visible layers. Items without a value are not toggleable. */\n  value?: readonly string[];\n  defaultValue?: readonly string[];\n  onValueChange?: (value: string[]) => void;\n};\n\ntype LegendContext = {\n  variant: MapLegendVariant;\n  titleId: string;\n  visible: readonly string[];\n  toggle: (value: string, visible: boolean) => void;\n};\nconst Context = createContext<LegendContext | null>(null);\nfunction useLegend(part: string) {\n  const context = useContext(Context);\n  if (!context) throw new Error(`${part} must be used within MapLegend`);\n  return context;\n}\n\nconst mapLegendVariants = cva(\"grid min-w-0 text-[13px]/[18px] text-card-foreground\", {\n  variants: {\n    variant: {\n      card: \"w-64 gap-3 rounded-[14px] bg-card p-4 shadow-[0_0_0_1px_var(--border)]\",\n      floating:\n        \"w-64 gap-2.5 rounded-[14px] bg-card/88 p-3 shadow-[0_0_0_1px_var(--border-strong),0_12px_28px_-10px_oklch(0_0_0/0.32),0_2px_6px_-2px_oklch(0_0_0/0.12)] backdrop-blur-md\",\n      compact: \"w-56 gap-2 rounded-xl bg-card p-2.5 text-[12px]/4 shadow-[0_0_0_1px_var(--border)]\",\n    },\n  },\n});\n\n/** Explains map symbols and, optionally, toggles the layers they belong to. */\nexport function MapLegend({\n  variant = \"card\",\n  value,\n  defaultValue = [],\n  onValueChange,\n  className,\n  children,\n  ...props\n}: MapLegendProps) {\n  const titleId = useId();\n  const [internal, setInternal] = useState<readonly string[]>(defaultValue);\n  const visible = value ?? internal;\n  const toggle = (layer: string, show: boolean) => {\n    const next = show\n      ? [...visible.filter((item) => item !== layer), layer]\n      : visible.filter((item) => item !== layer);\n    if (value === undefined) setInternal(next);\n    onValueChange?.(next);\n  };\n  return (\n    <Context.Provider value={{ variant, titleId, visible, toggle }}>\n      <section\n        data-slot=\"map-legend\"\n        aria-labelledby={titleId}\n        className={cn(mapLegendVariants({ variant }), className)}\n        {...props}\n        data-variant={variant}\n      >\n        {children}\n      </section>\n    </Context.Provider>\n  );\n}\n\nexport function MapLegendHeader({ className, ...props }: ComponentProps<\"div\">) {\n  useLegend(\"MapLegendHeader\");\n  return (\n    <div\n      data-slot=\"map-legend-header\"\n      className={cn(\"flex min-w-0 items-baseline justify-between gap-2\", className)}\n      {...props}\n    />\n  );\n}\n\nexport function MapLegendTitle({ className, ...props }: ComponentProps<\"h2\">) {\n  const context = useLegend(\"MapLegendTitle\");\n  return (\n    <h2\n      data-slot=\"map-legend-title\"\n      className={cn(\n        \"m-0 font-medium text-foreground\",\n        context.variant === \"compact\" ? \"text-[12px]/4\" : \"text-[13px]/[18px]\",\n        className,\n      )}\n      {...props}\n      id={context.titleId}\n    />\n  );\n}\n\n/** Tertiary context, such as the data date or source. */\nexport function MapLegendDescription({ className, ...props }: ComponentProps<\"p\">) {\n  useLegend(\"MapLegendDescription\");\n  return (\n    <p\n      data-slot=\"map-legend-description\"\n      className={cn(\"m-0 text-[11.5px]/4 text-subtle-foreground tabular-nums\", className)}\n      {...props}\n    />\n  );\n}\n\nexport function MapLegendItems({ className, ...props }: ComponentProps<\"ul\">) {\n  const context = useLegend(\"MapLegendItems\");\n  return (\n    <ul\n      data-slot=\"map-legend-items\"\n      className={cn(\n        \"m-0 grid list-none p-0\",\n        context.variant === \"compact\" ? \"gap-0\" : \"gap-0.5\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type MapLegendItemProps = ComponentProps<\"li\"> & {\n  /** Layer id. When set, the row becomes a visibility checkbox. */\n  value?: string;\n  disabled?: boolean;\n};\n\nexport function MapLegendItem({\n  value,\n  disabled,\n  className,\n  children,\n  ...props\n}: MapLegendItemProps) {\n  const context = useLegend(\"MapLegendItem\");\n  const id = useId();\n  const compact = context.variant === \"compact\";\n  const visible = value === undefined || context.visible.includes(value);\n  const row = cn(\n    \"flex min-w-0 items-center gap-2.5 rounded-lg\",\n    compact ? \"min-h-7 gap-2 px-1.5\" : \"min-h-8 px-2\",\n  );\n  return (\n    <li\n      data-slot=\"map-legend-item\"\n      data-hidden={!visible || undefined}\n      className={cn(\"min-w-0\", className)}\n      {...props}\n    >\n      {value === undefined ? (\n        <span className={row}>{children}</span>\n      ) : (\n        <label\n          htmlFor={id}\n          className={cn(\n            row,\n            \"cursor-pointer transition-[background-color,opacity] duration-120 ease-out hover:bg-secondary has-disabled:cursor-not-allowed has-disabled:opacity-50 has-disabled:hover:bg-transparent motion-reduce:transition-none\",\n          )}\n        >\n          {children}\n          <Checkbox\n            id={id}\n            checked={visible}\n            disabled={disabled}\n            onCheckedChange={(checked) => context.toggle(value, checked === true)}\n            className={cn(\n              \"ml-auto rounded-[5px] border-subtle-foreground bg-transparent data-[state=checked]:border-primary data-checked:border-primary shadow-none focus-visible:ring-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring focus-visible:outline-solid dark:bg-transparent\",\n              compact && \"size-3.5 [&_svg]:size-3\",\n            )}\n          />\n        </label>\n      )}\n    </li>\n  );\n}\n\nexport type MapLegendSwatchProps = ComponentProps<\"span\"> & {\n  /** Any CSS color, usually the same value your map layer paints with. */\n  color: string;\n  shape?: MapLegendSwatchShape;\n};\n\n/** The symbol a layer uses on the map. Fades when its layer is hidden. */\nexport function MapLegendSwatch({\n  color,\n  shape = \"fill\",\n  className,\n  style,\n  ...props\n}: MapLegendSwatchProps) {\n  useLegend(\"MapLegendSwatch\");\n  return (\n    <span\n      data-slot=\"map-legend-swatch\"\n      data-shape={shape}\n      aria-hidden=\"true\"\n      className={cn(\n        \"shrink-0 bg-(--swatch) transition-opacity duration-180 ease-out in-data-hidden:opacity-35 motion-reduce:transition-none\",\n        shape === \"fill\" && \"size-3 rounded-[4px] shadow-[inset_0_0_0_1px_oklch(0_0_0/0.12)]\",\n        shape === \"line\" && \"h-[3px] w-3.5 rounded-full\",\n        shape === \"dot\" && \"size-2.5 rounded-full shadow-[0_0_0_2px_var(--card)]\",\n        className,\n      )}\n      style={{ \"--swatch\": color, ...style } as CSSProperties}\n      {...props}\n    />\n  );\n}\n\nexport function MapLegendLabel({ className, ...props }: ComponentProps<\"span\">) {\n  useLegend(\"MapLegendLabel\");\n  return (\n    <span\n      data-slot=\"map-legend-label\"\n      className={cn(\n        \"min-w-0 flex-1 truncate text-foreground transition-colors duration-180 in-data-hidden:text-subtle-foreground motion-reduce:transition-none\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** A count or measurement beside a label. */\nexport function MapLegendValue({ className, ...props }: ComponentProps<\"span\">) {\n  useLegend(\"MapLegendValue\");\n  return (\n    <span\n      data-slot=\"map-legend-value\"\n      className={cn(\"shrink-0 text-[11.5px]/4 text-subtle-foreground tabular-nums\", className)}\n      {...props}\n    />\n  );\n}\n\nexport type MapLegendScaleProps = ComponentProps<\"figure\"> & {\n  /** Colors from the lowest to the highest value, painted as one gradient. */\n  colors: readonly string[];\n  /** Describes the ramp for assistive technology, for example \"Rent from $1,200 to $3,400\". */\n  label: string;\n};\n\n/** A continuous color ramp. Pass the stop labels as children, lowest first. */\nexport function MapLegendScale({\n  colors,\n  label,\n  className,\n  children,\n  ...props\n}: MapLegendScaleProps) {\n  useLegend(\"MapLegendScale\");\n  return (\n    <figure data-slot=\"map-legend-scale\" className={cn(\"m-0 grid gap-1.5\", className)} {...props}>\n      <span\n        role=\"img\"\n        aria-label={label}\n        className=\"block h-2 rounded-full shadow-[inset_0_0_0_1px_oklch(0_0_0/0.08)]\"\n        style={{ backgroundImage: `linear-gradient(to right, ${colors.join(\", \")})` }}\n      />\n      <figcaption\n        aria-hidden=\"true\"\n        className=\"flex justify-between gap-2 text-[11.5px]/4 text-subtle-foreground tabular-nums\"\n      >\n        {children}\n      </figcaption>\n    </figure>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@ui/uai/map-legend.tsx"
    }
  ],
  "categories": [
    "maps",
    "data-display"
  ],
  "type": "registry:ui"
}