{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "provenance-label",
  "type": "registry:ui",
  "title": "Provenance Label",
  "description": "A label that stays on a picture, a video or a 3D view and says what it is (a photograph, a reconstruction, made by a model), with a popover for its sources, placed so the media's own controls can never cover it.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/popover"
  ],
  "files": [
    {
      "path": "registry/ui/provenance-label.tsx",
      "type": "registry:ui",
      "target": "components/ui/provenance-label.tsx",
      "content": "\"use client\";\n/**\n * @name provenance-label\n * @category ui\n * @description A label that stays on a picture, a video or a 3D view and says what it is (a photograph, a reconstruction, made by a model), with a popover for its sources, placed so the media's own controls can never cover it.\n * @when A reader must not mistake what they are looking at: a reconstruction beside a photograph, a generated picture, an artist's impression, archive footage. Two placements. ProvenanceFrame puts the label in its own strip above the media, outside the media's box, where nothing the media draws can reach it: use this by default. `position` puts it over a top corner inside the media's box, above its controls and on a solid ground: use this when the label must also stay in full screen, with the label inside the element that goes full screen. The bottom edge is left to controls and captions. For the source of one fact in text use fact-row's SourceChip; for a key of classes inside a scene use certainty-legend.\n * @example\n * // In its own strip above the media\n * <ProvenanceFrame>\n *   <ProvenanceLabel details={<p>Drawn from the 1890 survey and two photographs. The roof is a guess.</p>}>Imagined reconstruction</ProvenanceLabel>\n *   <img src=\"/mill.jpg\" alt=\"The mill as it may have looked\" />\n * </ProvenanceFrame>\n *\n * // Over a corner of a player, so it stays in full screen\n * <VideoPlayer aria-label=\"The mill, reconstructed\">\n *   <VideoPlayerVideo src=\"/mill.mp4\" />\n *   <ProvenanceLabel position=\"top-start\">Imagined reconstruction</ProvenanceLabel>\n *   <VideoPlayerControls>…</VideoPlayerControls>\n * </VideoPlayer>\n */\nimport { Info } from \"lucide-react\";\nimport type { ComponentProps, ReactNode } from \"react\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"@/components/ui/popover\";\nimport { cn } from \"@/lib/cn\";\n\n/**\n * A box around a ProvenanceLabel and the media it describes. The label is the first row, in the normal\n * flow, and the media comes after it in a box of its own: controls, captions and hotspots are positioned\n * inside the media's box, so they cannot be drawn over the label, at any width. The frame is a named group\n * when given `aria-label`.\n */\nexport function ProvenanceFrame({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"provenance-frame\"\n      role={props[\"aria-label\"] || props[\"aria-labelledby\"] ? \"group\" : undefined}\n      className={cn(\n        \"flex w-full min-w-0 flex-col overflow-hidden rounded-surface border bg-background *:data-[slot=provenance-label]:border-x-0 *:data-[slot=provenance-label]:border-t-0 *:data-[slot=provenance-label]:rounded-none [&>img]:w-full\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type ProvenanceLabelProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n  /** What the thing is, in a few words: \"Imagined reconstruction\", \"Photograph, 1931\". */\n  children: ReactNode;\n  /** The sources and anything else worth knowing, shown in a popover. With it the label is a button. */\n  details?: ReactNode;\n  /** Said after the statement in the button's name, so it is clear what pressing it shows. Translate it with the interface. */\n  detailsLabel?: string;\n  /** Over a top corner of the media's box (which must be `relative`), above its controls. Left out, the label is a row in the flow, as inside ProvenanceFrame. */\n  position?: \"top-start\" | \"top-end\";\n  /** The popover's open state: controlled. */\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** A mark before the statement (an icon), hidden from assistive technology. */\n  icon?: ReactNode;\n};\n\n/**\n * The statement, always in the markup and always visible: it is text on the theme's own solid ground with\n * a border, so it reads on any picture in light and dark, and it does not fade, move or hide with the\n * media's controls. With `details` it is a button that opens a popover (Enter or Space; Escape closes it\n * and focus comes back). Positioned, it sits at `z-30`, above a player's controls and overlays. The\n * popover is rendered at the end of the page, so it is not shown while an element is in the browser's\n * full screen: the statement itself still is.\n */\nexport function ProvenanceLabel({ className, children, details, detailsLabel = \"sources and details\", position, open, defaultOpen, onOpenChange, icon, ...props }: ProvenanceLabelProps) {\n  const statement = (\n    <>\n      {icon ? (\n        <span aria-hidden=\"true\" className=\"inline-flex shrink-0 [&_svg]:size-4\">\n          {icon}\n        </span>\n      ) : null}\n      <span data-slot=\"provenance-label-text\" dir=\"auto\" className=\"min-w-0\">\n        {children}\n      </span>\n    </>\n  );\n  const content = \"flex min-h-8 w-full min-w-0 items-center gap-2 px-2.5 py-1 text-start pointer-coarse:min-h-(--control-h)\";\n  return (\n    <div\n      data-slot=\"provenance-label\"\n      data-position={position ?? \"flow\"}\n      className={cn(\n        \"flex min-w-0 rounded-control border border-border-strong bg-background text-sm font-medium text-foreground\",\n        position ? \"absolute top-2 z-30 max-w-[calc(100%-1rem)]\" : \"w-full\",\n        position === \"top-start\" && \"start-2\",\n        position === \"top-end\" && \"end-2\",\n        className,\n      )}\n      {...props}\n    >\n      {details === undefined ? (\n        <p className={content}>{statement}</p>\n      ) : (\n        <Popover {...(open === undefined ? {} : { open })} {...(defaultOpen === undefined ? {} : { defaultOpen })} {...(onOpenChange ? { onOpenChange } : {})}>\n          <PopoverTrigger className={cn(content, \"rounded-control transition-colors duration-instant ease-out hover:bg-accent motion-reduce:transition-none\")}>\n            {statement}\n            <span className=\"sr-only\">, {detailsLabel}</span>\n            <Info aria-hidden=\"true\" strokeWidth={1.5} className=\"ms-auto size-4 shrink-0 text-muted-foreground\" />\n          </PopoverTrigger>\n          <PopoverContent data-slot=\"provenance-label-details\" align=\"start\" className=\"flex flex-col gap-2\">\n            {details}\n          </PopoverContent>\n        </Popover>\n      )}\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "A reader must not mistake what they are looking at: a reconstruction beside a photograph, a generated picture, an artist's impression, archive footage. Two placements. ProvenanceFrame puts the label in its own strip above the media, outside the media's box, where nothing the media draws can reach it: use this by default. `position` puts it over a top corner inside the media's box, above its controls and on a solid ground: use this when the label must also stay in full screen, with the label inside the element that goes full screen. The bottom edge is left to controls and captions. For the source of one fact in text use fact-row's SourceChip; for a key of classes inside a scene use certainty-legend.",
    "example": "// In its own strip above the media\n<ProvenanceFrame>\n  <ProvenanceLabel details={<p>Drawn from the 1890 survey and two photographs. The roof is a guess.</p>}>Imagined reconstruction</ProvenanceLabel>\n  <img src=\"/mill.jpg\" alt=\"The mill as it may have looked\" />\n</ProvenanceFrame>\n\n// Over a corner of a player, so it stays in full screen\n<VideoPlayer aria-label=\"The mill, reconstructed\">\n  <VideoPlayerVideo src=\"/mill.mp4\" />\n  <ProvenanceLabel position=\"top-start\">Imagined reconstruction</ProvenanceLabel>\n  <VideoPlayerControls>…</VideoPlayerControls>\n</VideoPlayer>",
    "client": true
  }
}
