2
0
Files
bot/apps/builder/src/components/CopyButton.tsx
Gabriel Pavão d42e4a9ce1 Add editor header translation keys (#1110)
<!-- 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>
2023-12-28 10:50:33 +01:00

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>
)
}