<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Implemented internationalization support across various components using the `useTranslate` function for dynamic content translation. - **Enhancements** - Updated UI elements such as buttons, tooltips, placeholders, and labels to display translated text, improving accessibility and user experience for non-English speakers. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Baptiste Arnaud <contact@baptiste-arnaud.fr> Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
38 lines
876 B
TypeScript
38 lines
876 B
TypeScript
import React, { useEffect } from 'react'
|
|
import { ButtonProps, Button, useClipboard } from '@chakra-ui/react'
|
|
import { useTranslate } from '@tolgee/react'
|
|
|
|
interface CopyButtonProps extends ButtonProps {
|
|
textToCopy: string
|
|
onCopied?: () => void
|
|
text?: {
|
|
copy: string
|
|
copied: string
|
|
}
|
|
}
|
|
|
|
export const CopyButton = (props: CopyButtonProps) => {
|
|
const { textToCopy, onCopied, ...buttonProps } = props
|
|
const { hasCopied, onCopy, setValue } = useClipboard(textToCopy)
|
|
const { t } = useTranslate()
|
|
|
|
useEffect(() => {
|
|
setValue(textToCopy)
|
|
}, [setValue, textToCopy])
|
|
|
|
return (
|
|
<Button
|
|
isDisabled={hasCopied}
|
|
onClick={() => {
|
|
onCopy()
|
|
if (onCopied) onCopied()
|
|
}}
|
|
{...buttonProps}
|
|
>
|
|
{!hasCopied
|
|
? props.text?.copy ?? t('copy')
|
|
: props.text?.copied ?? t('copied')}
|
|
</Button>
|
|
)
|
|
}
|