{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "user-screen-control",
  "title": "User Screen Control",
  "description": "Screen-share toggle with a preview tile while sharing.",
  "dependencies": [
    "@pipecat-ai/client-js@^1.14.0",
    "@pipecat-ai/client-react@^1.9.0",
    "lucide-react@^1.41.0"
  ],
  "registryDependencies": [
    "button"
  ],
  "files": [
    {
      "path": "src/components/user-screen-control.tsx",
      "content": "\"use client\";\n\nimport {\n  PipecatClientScreenShareToggle,\n  PipecatClientVideo,\n  usePipecatClientTransportState,\n} from \"@pipecat-ai/client-react\";\nimport { Loader2Icon, MonitorIcon, MonitorOffIcon } from \"lucide-react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/utils\";\n\ntype ButtonProps = React.ComponentProps<typeof Button>;\n\n// Inverse of the mic/camera controls: not-sharing is the neutral resting\n// state (plain surface), while sharing turns the button into a red\n// stop-sharing affordance, applied while sharing (data-state also flips\n// for consumer styling). Styled per variant like the other controls:\n// solid variants fill with the inactive color, outline keeps its border +\n// tint (nova's destructive-button idiom), secondary tints without a\n// border, ghost only recolors content. Unknown (consumer-added) variants\n// get the ghost treatment.\nconst ACTIVE_VARIANT_CLASSES: Record<string, string> = {\n  default: \"bg-inactive text-inactive-foreground hover:bg-inactive/80\",\n  outline:\n    \"border-inactive/30 bg-inactive/10 text-inactive hover:bg-inactive/20 hover:text-inactive dark:bg-inactive/20\",\n  secondary:\n    \"bg-inactive/10 text-inactive hover:bg-inactive/20 dark:bg-inactive/20\",\n  ghost: \"text-inactive hover:text-inactive\",\n};\n\nfunction activeClasses(variant: ButtonProps[\"variant\"]): string {\n  return (\n    ACTIVE_VARIANT_CLASSES[variant ?? \"default\"] ??\n    ACTIVE_VARIANT_CLASSES.ghost!\n  );\n}\n\n// Nova's icon-* sizes render a square button; the toggle responds by going\n// icon-only (no label, no min-width).\nfunction isIconSize(size: ButtonProps[\"size\"]): boolean {\n  return typeof size === \"string\" && size.startsWith(\"icon\");\n}\n\nexport interface UserScreenControlViewProps {\n  /** Whether screen sharing is currently active. */\n  isScreenEnabled?: boolean;\n  /** Called when the user clicks the toggle. */\n  onToggleScreen?: () => void;\n  /** Disables the control (e.g. while disconnected). */\n  disabled?: boolean;\n  /** Disables the control and shows a spinner. */\n  isLoading?: boolean;\n  /** Content shown next to the spinner while loading. Spinner only by default. */\n  loadingText?: React.ReactNode;\n  /**\n   * When set, the control renders disabled with this message instead of the\n   * toggle (sharing blocked, not supported, …). Takes precedence over the\n   * interactive state; isLoading takes precedence over both.\n   */\n  unavailableText?: React.ReactNode;\n  /** Never render the preview tile, even while sharing. */\n  noPreview?: boolean;\n  /** Video element rendered in the tile while sharing. */\n  video?: React.ReactNode;\n  /** Label shown while sharing. */\n  activeText?: React.ReactNode;\n  /** Label shown while not sharing. */\n  inactiveText?: React.ReactNode;\n  /** Hide the monitor icon. */\n  noIcon?: boolean;\n  /** Button variant for the toggle. */\n  variant?: ButtonProps[\"variant\"];\n  /**\n   * Button size for the toggle. Icon sizes (\"icon\", \"icon-sm\", …) render\n   * it icon-only: the label is hidden.\n   */\n  size?: ButtonProps[\"size\"];\n  /** Classes for the tile while sharing, otherwise for the button. */\n  className?: string;\n  /** Extra content rendered inside the toggle, after the label. */\n  children?: React.ReactNode;\n}\n\n/** Screen-share toggle with a preview while sharing. Loading takes precedence over unavailability. */\nexport function UserScreenControlView({\n  isScreenEnabled = false,\n  onToggleScreen,\n  disabled = false,\n  isLoading = false,\n  loadingText,\n  unavailableText,\n  noPreview = false,\n  video,\n  activeText,\n  inactiveText,\n  noIcon = false,\n  variant = \"outline\",\n  size = \"default\",\n  className,\n  children,\n}: UserScreenControlViewProps) {\n  const iconOnly = isIconSize(size);\n  const stateText = iconOnly\n    ? undefined\n    : isScreenEnabled\n      ? activeText\n      : inactiveText;\n  const showTile =\n    !noPreview && isScreenEnabled && !isLoading && !unavailableText;\n\n  let toggle: React.ReactNode;\n  if (isLoading || unavailableText) {\n    toggle = (\n      <Button\n        data-slot=\"user-screen-control\"\n        variant={variant}\n        size={size}\n        disabled\n        aria-busy={isLoading || undefined}\n        data-state={isLoading ? \"loading\" : \"unavailable\"}\n        aria-label={\n          !iconOnly\n            ? undefined\n            : isLoading\n              ? \"Screen share loading\"\n              : typeof unavailableText === \"string\"\n                ? unavailableText\n                : \"Screen share unavailable\"\n        }\n        className={cn(!iconOnly && \"min-w-32\", className)}\n      >\n        {isLoading ? (\n          <>\n            <Loader2Icon className=\"animate-spin\" />\n            {!iconOnly && loadingText}\n          </>\n        ) : (\n          <>\n            {!noIcon && <MonitorOffIcon />}\n            {!iconOnly && unavailableText}\n          </>\n        )}\n      </Button>\n    );\n  } else {\n    toggle = (\n      <Button\n        data-slot=\"user-screen-control\"\n        variant={variant}\n        size={size}\n        data-state={isScreenEnabled ? \"active\" : \"inactive\"}\n        aria-pressed={isScreenEnabled}\n        aria-label={\n          stateText\n            ? undefined\n            : isScreenEnabled\n              ? \"Stop screen sharing\"\n              : \"Start screen sharing\"\n        }\n        disabled={disabled}\n        onClick={onToggleScreen}\n        className={cn(\n          isScreenEnabled && activeClasses(variant),\n          !iconOnly && \"min-w-32\",\n          !showTile && className,\n        )}\n      >\n        {!noIcon && (isScreenEnabled ? <MonitorIcon /> : <MonitorOffIcon />)}\n        {stateText}\n        {children}\n      </Button>\n    );\n  }\n\n  if (!showTile) return toggle;\n\n  return (\n    <div\n      data-slot=\"user-screen-tile\"\n      className={cn(\n        \"bg-muted relative aspect-video overflow-hidden rounded-xl\",\n        className,\n      )}\n    >\n      <div className=\"absolute inset-0\">{video}</div>\n      <div className=\"absolute bottom-2 left-2\">{toggle}</div>\n    </div>\n  );\n}\n\nconst CONNECTED_STATES = [\"connected\", \"ready\"];\n\nexport interface UserScreenControlProps extends Omit<\n  UserScreenControlViewProps,\n  \"isScreenEnabled\" | \"onToggleScreen\" | \"video\" | \"disabled\"\n> {\n  /** Props for the underlying PipecatClientVideo element. */\n  videoProps?: Partial<React.ComponentProps<typeof PipecatClientVideo>>;\n}\n\n/** Requires PipecatClientProvider; sharing is disabled until the transport is connected. */\nexport function UserScreenControl({\n  videoProps,\n  ...props\n}: UserScreenControlProps) {\n  const transportState = usePipecatClientTransportState();\n  const isConnected = CONNECTED_STATES.includes(transportState);\n\n  return (\n    <PipecatClientScreenShareToggle>\n      {({ isScreenShareEnabled, onClick }) => (\n        <UserScreenControlView\n          isScreenEnabled={isScreenShareEnabled}\n          onToggleScreen={onClick}\n          disabled={!isConnected}\n          video={\n            <PipecatClientVideo\n              participant=\"local\"\n              trackType=\"screenVideo\"\n              className=\"h-full w-full object-cover\"\n              {...videoProps}\n            />\n          }\n          {...props}\n        />\n      )}\n    </PipecatClientScreenShareToggle>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/user-screen-control.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-inactive": "var(--inactive-background)",
      "color-inactive-foreground": "var(--inactive-foreground)"
    },
    "light": {
      "inactive-background": "oklch(0.702 0.189 22.23)",
      "inactive-foreground": "oklch(0.971 0.013 17.38)"
    },
    "dark": {
      "inactive-background": "oklch(0.702 0.189 22.23)",
      "inactive-foreground": "oklch(0.971 0.013 17.38)"
    }
  },
  "docs": "Render inside a PipecatClientProvider. Disabled until the transport is connected.",
  "categories": [
    "voice"
  ],
  "type": "registry:component"
}