2022-03-21 20:23:21 +00:00
|
|
|
import { Fragment } from 'react'
|
|
|
|
import { CodeIcon } from '@heroicons/react/outline'
|
|
|
|
import { Menu, Transition } from '@headlessui/react'
|
|
|
|
import { Contract } from '../../common/contract'
|
|
|
|
import { contractPath } from '../lib/firebase/contracts'
|
|
|
|
import { DOMAIN } from '../../common/envs/constants'
|
2022-03-21 21:44:11 +00:00
|
|
|
import { copyToClipboard } from '../lib/util/copy'
|
2022-03-21 20:23:21 +00:00
|
|
|
|
|
|
|
export function ShareEmbedButton(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
|
|
|
|
|
|
|
const copyEmbed = () => {
|
|
|
|
const title = contract.question
|
|
|
|
const src = `https://${DOMAIN}/embed${contractPath(contract)}`
|
|
|
|
|
|
|
|
const embedCode = `<iframe width="560" height="405" src="${src}" title="${title}" frameborder="0"></iframe>`
|
|
|
|
|
2022-03-21 21:44:11 +00:00
|
|
|
copyToClipboard(embedCode)
|
2022-03-21 20:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-03-21 21:44:11 +00:00
|
|
|
<Menu
|
|
|
|
as="div"
|
2022-03-22 00:34:29 +00:00
|
|
|
className="relative z-10 flex-shrink-0"
|
2022-03-21 21:44:11 +00:00
|
|
|
onMouseUp={copyEmbed}
|
|
|
|
>
|
2022-03-21 21:54:09 +00:00
|
|
|
<Menu.Button
|
|
|
|
className="btn btn-xs normal-case"
|
|
|
|
style={{
|
|
|
|
backgroundColor: 'white',
|
|
|
|
border: '2px solid #9ca3af',
|
|
|
|
color: '#9ca3af', // text-gray-400
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<CodeIcon className="mr-1.5 h-4 w-4" aria-hidden="true" />
|
2022-03-21 20:23:21 +00:00
|
|
|
Embed
|
|
|
|
</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"
|
|
|
|
>
|
2022-03-21 21:54:09 +00:00
|
|
|
<Menu.Items className="origin-top-center absolute left-0 mt-2 w-40 rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
|
2022-03-21 20:23:21 +00:00
|
|
|
<Menu.Item>
|
|
|
|
<div className="px-2 py-1">Embed code copied!</div>
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu.Items>
|
|
|
|
</Transition>
|
|
|
|
</Menu>
|
|
|
|
)
|
|
|
|
}
|