Home / File/ copy-button.tsx — ui Source File

copy-button.tsx — ui Source File

Architecture documentation for copy-button.tsx, a tsx file in the ui codebase. 5 imports, 0 dependents.

File tsx Internationalization Dictionary 5 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  701779a9_8de2_59e1_59b9_463b82632b4d["copy-button.tsx"]
  1d141819_425e_b5fd_4c8e_32f7c6a42cf2["react"]
  701779a9_8de2_59e1_59b9_463b82632b4d --> 1d141819_425e_b5fd_4c8e_32f7c6a42cf2
  39a0d62e_8e7d_d097_eb95_91d2bca361f7["icons-react"]
  701779a9_8de2_59e1_59b9_463b82632b4d --> 39a0d62e_8e7d_d097_eb95_91d2bca361f7
  a9903b11_2f1d_8437_2ec7_acd8ba077fa8["events"]
  701779a9_8de2_59e1_59b9_463b82632b4d --> a9903b11_2f1d_8437_2ec7_acd8ba077fa8
  79081a1f_55a3_945a_fb8c_d53d6d3eab81["utils"]
  701779a9_8de2_59e1_59b9_463b82632b4d --> 79081a1f_55a3_945a_fb8c_d53d6d3eab81
  57e86e45_ac6e_7278_be08_9092724e8401["button"]
  701779a9_8de2_59e1_59b9_463b82632b4d --> 57e86e45_ac6e_7278_be08_9092724e8401
  style 701779a9_8de2_59e1_59b9_463b82632b4d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"use client"

import * as React from "react"
import { IconCheck, IconCopy } from "@tabler/icons-react"

import { trackEvent, type Event } from "@/lib/events"
import { cn } from "@/lib/utils"
import { Button } from "@/registry/new-york-v4/ui/button"

export function copyToClipboardWithMeta(value: string, event?: Event) {
  navigator.clipboard.writeText(value)
  if (event) {
    trackEvent(event)
  }
}

export function CopyButton({
  value,
  className,
  variant = "ghost",
  event,
  ...props
}: React.ComponentProps<typeof Button> & {
  value: string
  src?: string
  event?: Event["name"]
  tooltip?: string
}) {
  const [hasCopied, setHasCopied] = React.useState(false)

  React.useEffect(() => {
    if (hasCopied) {
      const timer = setTimeout(() => setHasCopied(false), 2000)
      return () => clearTimeout(timer)
    }
  }, [hasCopied])

  return (
    <Button
      data-slot="copy-button"
      data-copied={hasCopied}
      size="icon"
      variant={variant}
      className={cn(
        "bg-code absolute top-3 right-2 z-10 size-7 hover:opacity-100 focus-visible:opacity-100",
        className
      )}
      onClick={() => {
        copyToClipboardWithMeta(
          value,
          event
            ? {
                name: event,
                properties: {
                  code: value,
                },
              }
            : undefined
        )
        setHasCopied(true)
      }}
      {...props}
    >
      <span className="sr-only">Copy</span>
      {hasCopied ? <IconCheck /> : <IconCopy />}
    </Button>
  )
}

Subdomains

Dependencies

  • button
  • events
  • icons-react
  • react
  • utils

Frequently Asked Questions

What does copy-button.tsx do?
copy-button.tsx is a source file in the ui codebase, written in tsx. It belongs to the Internationalization domain, Dictionary subdomain.
What functions are defined in copy-button.tsx?
copy-button.tsx defines 2 function(s): CopyButton, copyToClipboardWithMeta.
What does copy-button.tsx depend on?
copy-button.tsx imports 5 module(s): button, events, icons-react, react, utils.
Where is copy-button.tsx in the architecture?
copy-button.tsx is located at apps/v4/components/copy-button.tsx (domain: Internationalization, subdomain: Dictionary, directory: apps/v4/components).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free