// // Copyright 2023 DXOS.org // import React from 'react'; import { mx, osTranslations } from '@dxos/ui-theme'; import { useTranslation } from '../../primitives'; import { Button, type ButtonProps, IconButton } from '../Button'; import { Icon, type IconProps } from '../Icon'; import { type TooltipScopedProps, useTooltipContext } from '../Tooltip'; import { useClipboard } from './ClipboardProvider'; export type CopyButtonProps = ButtonProps & Pick & { value: string; }; const inactiveLabelStyles = 'invisible h-px -mb-px overflow-hidden'; export const CopyButton = ({ classNames, value, size = 5, ...props }: CopyButtonProps) => { const { t } = useTranslation(osTranslations); const { textValue, setTextValue } = useClipboard(); const isCopied = textValue === value; return ( ); }; type CopyButtonIconOnlyProps = CopyButtonProps & { label?: string; }; export const CopyButtonIconOnly = ({ __scopeTooltip, value, classNames, size, variant, ...props }: TooltipScopedProps) => { const { t } = useTranslation(osTranslations); const { textValue, setTextValue } = useClipboard(); const isCopied = textValue === value; const label = isCopied ? t('copy-success.label') : (props.label ?? t('copy.label')); const { onOpen } = useTooltipContext('CopyButton', __scopeTooltip); return ( setTextValue(value).then(onOpen)} data-testid='copy-invitation' /> ); };