2022-07-01 13:47:19 +00:00
|
|
|
import React, { useState } from 'react'
|
|
|
|
import { ShareIcon } from '@heroicons/react/outline'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
|
|
|
|
import { copyToClipboard } from 'web/lib/util/copy'
|
|
|
|
import { ToastClipboard } from 'web/components/toast-clipboard'
|
|
|
|
import { track } from 'web/lib/service/analytics'
|
|
|
|
import { contractDetailsButtonClassName } from 'web/components/contract/contract-info-dialog'
|
|
|
|
|
|
|
|
export function ShareIconButton(props: {
|
|
|
|
buttonClassName?: string
|
2022-07-21 05:45:53 +00:00
|
|
|
onCopyButtonClassName?: string
|
2022-07-01 13:47:19 +00:00
|
|
|
toastClassName?: string
|
|
|
|
children?: React.ReactNode
|
2022-07-21 05:45:53 +00:00
|
|
|
iconClassName?: string
|
|
|
|
copyPayload: string
|
2022-07-01 13:47:19 +00:00
|
|
|
}) {
|
|
|
|
const {
|
|
|
|
buttonClassName,
|
2022-07-21 05:45:53 +00:00
|
|
|
onCopyButtonClassName,
|
2022-07-01 13:47:19 +00:00
|
|
|
toastClassName,
|
|
|
|
children,
|
2022-07-21 05:45:53 +00:00
|
|
|
iconClassName,
|
|
|
|
copyPayload,
|
2022-07-01 13:47:19 +00:00
|
|
|
} = props
|
|
|
|
const [showToast, setShowToast] = useState(false)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="relative z-10 flex-shrink-0">
|
|
|
|
<button
|
2022-07-21 05:45:53 +00:00
|
|
|
className={clsx(
|
|
|
|
contractDetailsButtonClassName,
|
|
|
|
buttonClassName,
|
|
|
|
showToast ? onCopyButtonClassName : ''
|
|
|
|
)}
|
2022-07-01 13:47:19 +00:00
|
|
|
onClick={() => {
|
2022-07-21 05:45:53 +00:00
|
|
|
copyToClipboard(copyPayload)
|
2022-07-01 13:47:19 +00:00
|
|
|
track('copy share link')
|
|
|
|
setShowToast(true)
|
|
|
|
setTimeout(() => setShowToast(false), 2000)
|
|
|
|
}}
|
|
|
|
>
|
2022-07-21 05:45:53 +00:00
|
|
|
<ShareIcon
|
|
|
|
className={clsx(iconClassName ? iconClassName : 'h-[24px] w-5')}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-07-01 13:47:19 +00:00
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
|
|
|
|
{showToast && <ToastClipboard className={toastClassName} />}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|