clipboard-toasts.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { GlobalToastGeneratorEntry } from '@/features/ide-react/components/global-toasts'
  2. import { useTranslation } from 'react-i18next'
  3. import { isMac } from '@/shared/utils/os'
  4. const ClipboardPasteErrorToast = ({ shortcut }: { shortcut?: string }) => {
  5. const { t } = useTranslation()
  6. const resolvedShortcut = shortcut ?? (isMac ? '⌘V' : 'Ctrl+V')
  7. return (
  8. <>
  9. <p>
  10. <b>{t('use_the_shortcut_key_to_paste')}</b>
  11. </p>
  12. {t('your_browser_cant_access_the_clipboard_so_use_this_shortcut')}{' '}
  13. <b>{resolvedShortcut}</b>
  14. <br />
  15. {t('or_enable_clipboard_access_in_your_browser_settings')}
  16. </>
  17. )
  18. }
  19. const generators: GlobalToastGeneratorEntry[] = [
  20. {
  21. key: 'clipboard:paste-error',
  22. generator: ({ shortcut }: { shortcut?: string }) => ({
  23. content: <ClipboardPasteErrorToast shortcut={shortcut} />,
  24. type: 'warning',
  25. autoHide: true,
  26. delay: 6000,
  27. isDismissible: true,
  28. }),
  29. },
  30. ]
  31. export default generators
  32. export const showClipboardPasteErrorToast = (shortcut?: string) => {
  33. window.dispatchEvent(
  34. new CustomEvent('ide:show-toast', {
  35. detail: { key: 'clipboard:paste-error', shortcut },
  36. })
  37. )
  38. }