Add copy link button in market share options

This commit is contained in:
James Grugett 2022-04-10 19:59:01 -05:00
parent 8c9da833bf
commit 9f2ac17ffb
2 changed files with 52 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import {
contractPath, contractPath,
getBinaryProbPercent, getBinaryProbPercent,
} from '../../lib/firebase/contracts' } from '../../lib/firebase/contracts'
import { CopyLinkButton } from '../copy-link-button'
import { Col } from '../layout/col' import { Col } from '../layout/col'
import { Modal } from '../layout/modal' import { Modal } from '../layout/modal'
import { Row } from '../layout/row' import { Row } from '../layout/row'
@ -100,6 +101,7 @@ export function ContractInfoDialog(props: { contract: Contract }) {
<div className="text-gray-500">Share</div> <div className="text-gray-500">Share</div>
<Row className="justify-start gap-4"> <Row className="justify-start gap-4">
<CopyLinkButton contract={contract} />
<TweetButton <TweetButton
className="self-start" className="self-start"
tweetText={getTweetText(contract, false)} tweetText={getTweetText(contract, false)}

View File

@ -0,0 +1,50 @@
import { Fragment } from 'react'
import { LinkIcon } from '@heroicons/react/outline'
import { Menu, Transition } from '@headlessui/react'
import { Contract } from '../../common/contract'
import { copyToClipboard } from '../lib/util/copy'
function copyCurrentUrl(contract: Contract) {
const url = window.location.href
copyToClipboard(url)
}
export function CopyLinkButton(props: { contract: Contract }) {
const { contract } = props
return (
<Menu
as="div"
className="relative z-10 flex-shrink-0"
onMouseUp={() => copyCurrentUrl(contract)}
>
<Menu.Button
className="btn btn-xs normal-case"
style={{
backgroundColor: 'white',
border: '2px solid #16A34A',
color: '#16A34A', // text-green-600
}}
>
<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 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">
<Menu.Item>
<div className="px-2 py-1">Link copied!</div>
</Menu.Item>
</Menu.Items>
</Transition>
</Menu>
)
}