'use client' import type { InputProps } from '../input' import { RiClipboardFill, RiClipboardLine } from '@remixicon/react' import { useClipboard } from 'foxact/use-clipboard' import * as React from 'react' import { useTranslation } from 'react-i18next' import { cn } from '@/utils/classnames' import ActionButton from '../action-button' import Tooltip from '../tooltip' export type InputWithCopyProps = { showCopyButton?: boolean copyValue?: string // Value to copy, defaults to input value onCopy?: (value: string) => void // Callback when copy is triggered } & Omit // Remove conflicting props const prefixEmbedded = 'overview.appInfo.embedded' const InputWithCopy = React.forwardRef(( { showCopyButton = true, copyValue, onCopy, value, wrapperClassName, ...inputProps }, ref, ) => { const { t } = useTranslation() // Determine what value to copy const valueToString = typeof value === 'string' ? value : String(value || '') const finalCopyValue = copyValue || valueToString const { copied, copy, reset } = useClipboard() const handleCopy = () => { copy(finalCopyValue) onCopy?.(finalCopyValue) } return (
rest)(inputProps)} /> {showCopyButton && (
{copied ? ( ) : ( )}
)}
) }) InputWithCopy.displayName = 'InputWithCopy' export default InputWithCopy