Files
medusa-store/www/packages/docs-ui/src/components/CopyButton/index.tsx
Shahed Nasser ddc0c9dfff docs: add anchor link to reference parameters (#6194)
- Added anchor links to items in parameter components
- Added sectionTitle prop in markdown theme

Note: Due to the second point, the change requires generating references to see the anchor links, which would result in a big diff in this PR. Instead, next time the references are generated for a release, this feature will available for use.
2024-01-24 08:42:55 +00:00

45 lines
992 B
TypeScript

"use client"
import React from "react"
import clsx from "clsx"
import { Tooltip } from "@/components"
import { useCopy } from "../../hooks"
export type CopyButtonProps = {
text: string
buttonClassName?: string
tooltipClassName?: string
tooltipText?: string
onCopy?: (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void
} & Omit<React.HTMLAttributes<HTMLDivElement>, "onCopy">
export const CopyButton = ({
text,
buttonClassName = "",
tooltipClassName = "",
tooltipText = "Copy to Clipboard",
children,
className,
onCopy,
}: CopyButtonProps) => {
const { isCopied, handleCopy } = useCopy(text)
return (
<Tooltip
text={isCopied ? `Copied!` : tooltipText}
tooltipClassName={tooltipClassName}
className={className}
>
<span
className={clsx("cursor-pointer", buttonClassName)}
onClick={(e) => {
onCopy?.(e)
handleCopy()
}}
>
{children}
</span>
</Tooltip>
)
}