index.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { RiDownloadLine } from '@remixicon/react'
  5. import {
  6. useCSVDownloader,
  7. } from 'react-papaparse'
  8. import { useTranslation } from 'react-i18next'
  9. import ActionButton from '@/app/components/base/action-button'
  10. import Button from '@/app/components/base/button'
  11. import cn from '@/utils/classnames'
  12. export type IResDownloadProps = {
  13. isMobile: boolean
  14. values: Record<string, string>[]
  15. }
  16. const ResDownload: FC<IResDownloadProps> = ({
  17. isMobile,
  18. values,
  19. }) => {
  20. const { t } = useTranslation()
  21. const { CSVDownloader, Type } = useCSVDownloader()
  22. return (
  23. <CSVDownloader
  24. className="block cursor-pointer"
  25. type={Type.Link}
  26. filename={'result'}
  27. bom={true}
  28. config={{
  29. // delimiter: ';',
  30. }}
  31. data={values}
  32. >
  33. {isMobile && (
  34. <ActionButton>
  35. <RiDownloadLine className='w-4 h-4' />
  36. </ActionButton>
  37. )}
  38. {!isMobile && (
  39. <Button className={cn('space-x-1')}>
  40. <RiDownloadLine className='w-4 h-4' />
  41. <span>{t('common.operation.download')}</span>
  42. </Button>
  43. )}
  44. </CSVDownloader>
  45. )
  46. }
  47. export default React.memo(ResDownload)