2022-05-17 15:55:26 +00:00
|
|
|
import React, { Fragment } from 'react'
|
2022-04-11 00:59:01 +00:00
|
|
|
import { LinkIcon } from '@heroicons/react/outline'
|
|
|
|
import { Menu, Transition } from '@headlessui/react'
|
2022-05-02 15:23:51 +00:00
|
|
|
import clsx from 'clsx'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { copyToClipboard } from 'web/lib/util/copy'
|
2022-05-17 15:55:26 +00:00
|
|
|
import { ToastClipboard } from 'web/components/toast-clipboard'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { track } from 'web/lib/service/analytics'
|
2022-07-20 16:42:49 +00:00
|
|
|
import { Row } from './layout/row'
|
2022-04-11 00:59:01 +00:00
|
|
|
|
2022-05-02 15:23:51 +00:00
|
|
|
export function CopyLinkButton(props: {
|
2022-07-20 16:42:49 +00:00
|
|
|
url: string
|
|
|
|
displayUrl?: string
|
|
|
|
tracking?: string
|
2022-05-02 15:23:51 +00:00
|
|
|
buttonClassName?: string
|
2022-05-17 15:55:26 +00:00
|
|
|
toastClassName?: string
|
2022-08-04 21:27:02 +00:00
|
|
|
icon?: React.ComponentType<{ className?: string }>
|
|
|
|
label?: string
|
2022-05-02 15:23:51 +00:00
|
|
|
}) {
|
2022-07-20 16:42:49 +00:00
|
|
|
const { url, displayUrl, tracking, buttonClassName, toastClassName } = props
|
2022-04-11 00:59:01 +00:00
|
|
|
|
|
|
|
return (
|
2022-07-20 16:42:49 +00:00
|
|
|
<Row className="w-full">
|
|
|
|
<input
|
|
|
|
className="input input-bordered flex-1 rounded-r-none text-gray-500"
|
|
|
|
readOnly
|
|
|
|
type="text"
|
|
|
|
value={displayUrl ?? url}
|
|
|
|
/>
|
2022-04-11 00:59:01 +00:00
|
|
|
|
2022-07-20 16:42:49 +00:00
|
|
|
<Menu
|
|
|
|
as="div"
|
|
|
|
className="relative z-10 flex-shrink-0"
|
|
|
|
onMouseUp={() => {
|
|
|
|
copyToClipboard(url)
|
|
|
|
track(tracking ?? 'copy share link')
|
|
|
|
}}
|
2022-04-11 00:59:01 +00:00
|
|
|
>
|
2022-07-20 16:42:49 +00:00
|
|
|
<Menu.Button
|
|
|
|
className={clsx(
|
|
|
|
'btn btn-xs border-2 border-green-600 bg-white normal-case text-green-600 hover:border-green-600 hover:bg-white',
|
|
|
|
buttonClassName
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<LinkIcon className="mr-1.5 h-4 w-4" aria-hidden="true" />
|
|
|
|
Copy link
|
|
|
|
</Menu.Button>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-out duration-100"
|
|
|
|
enterFrom="transform opacity-0 scale-95"
|
|
|
|
enterTo="transform opacity-100 scale-100"
|
|
|
|
leave="transition ease-in duration-75"
|
|
|
|
leaveFrom="transform opacity-100 scale-100"
|
|
|
|
leaveTo="transform opacity-0 scale-95"
|
|
|
|
>
|
|
|
|
<Menu.Items>
|
|
|
|
<Menu.Item>
|
|
|
|
<ToastClipboard className={toastClassName} />
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu.Items>
|
|
|
|
</Transition>
|
|
|
|
</Menu>
|
|
|
|
</Row>
|
2022-04-11 00:59:01 +00:00
|
|
|
)
|
|
|
|
}
|