react-icons/ri#RiDownload2Fill JavaScript Examples

The following examples show how to use react-icons/ri#RiDownload2Fill. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CsvLink.js    From acy-dex-interface with MIT License 6 votes vote down vote up
export default function CsvLink({ data, fields, name = 'GMX stats' }) {
  const onClick = useCallback((evt) => {
    evt.preventDefault()

    const csvUrl = getCsvUrl(data, fields)
    const start = formatTimestamp(data[0].timestamp)
    const end = formatTimestamp(data[data.length - 1].timestamp)
    const fileName = `${name}_${start}_${end}.csv`

    const aElement = document.createElement('a')
    aElement.href = csvUrl
    aElement.download = fileName
    document.body.appendChild(aElement)
    aElement.click()
    document.body.removeChild(aElement)
  }, [data, fields, name])

  if (!data || data.length === 0 || !fields) {
    return null
  }

  return (
    <a title="Download CSV" className="csv-link" onClick={onClick}>
      <RiDownload2Fill size="1em" />
    </a>
  )
}