Un-daisy share buttons (#1010)

* Make embed and challenge buttons non-daisyui

* Allow link Buttons. Change tweet, dupe buttons.

* lint
This commit is contained in:
Sinclair Chen 2022-10-05 15:51:10 -07:00 committed by GitHub
parent a3b841423f
commit 7863a4232d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 103 deletions

View File

@ -15,12 +15,49 @@ export type ColorType =
| 'gray-white' | 'gray-white'
| 'highlight-blue' | 'highlight-blue'
const sizeClasses = {
'2xs': 'px-2 py-1 text-xs',
xs: 'px-2.5 py-1.5 text-sm',
sm: 'px-3 py-2 text-sm',
md: 'px-4 py-2 text-sm',
lg: 'px-4 py-2 text-base',
xl: 'px-6 py-2.5 text-base font-semibold',
'2xl': 'px-6 py-3 text-xl font-semibold',
}
export function buttonClass(size: SizeType, color: ColorType | 'override') {
return clsx(
'font-md inline-flex items-center justify-center rounded-md border border-transparent shadow-sm transition-colors disabled:cursor-not-allowed',
sizeClasses[size],
color === 'green' &&
'disabled:bg-greyscale-2 bg-teal-500 text-white hover:bg-teal-600',
color === 'red' &&
'disabled:bg-greyscale-2 bg-red-400 text-white hover:bg-red-500',
color === 'yellow' &&
'disabled:bg-greyscale-2 bg-yellow-400 text-white hover:bg-yellow-500',
color === 'blue' &&
'disabled:bg-greyscale-2 bg-blue-400 text-white hover:bg-blue-500',
color === 'indigo' &&
'disabled:bg-greyscale-2 bg-indigo-500 text-white hover:bg-indigo-600',
color === 'gray' &&
'bg-greyscale-1 text-greyscale-6 hover:bg-greyscale-2 disabled:opacity-50',
color === 'gray-outline' &&
'border-greyscale-4 text-greyscale-4 hover:bg-greyscale-4 border-2 hover:text-white disabled:opacity-50',
color === 'gradient' &&
'disabled:bg-greyscale-2 border-none bg-gradient-to-r from-indigo-500 to-blue-500 text-white hover:from-indigo-700 hover:to-blue-700',
color === 'gray-white' &&
'text-greyscale-6 hover:bg-greyscale-2 border-none shadow-none disabled:opacity-50',
color === 'highlight-blue' &&
'text-highlight-blue disabled:bg-greyscale-2 border-none shadow-none'
)
}
export function Button(props: { export function Button(props: {
className?: string className?: string
onClick?: MouseEventHandler<any> | undefined onClick?: MouseEventHandler<any> | undefined
children?: ReactNode children?: ReactNode
size?: SizeType size?: SizeType
color?: ColorType color?: ColorType | 'override'
type?: 'button' | 'reset' | 'submit' type?: 'button' | 'reset' | 'submit'
disabled?: boolean disabled?: boolean
loading?: boolean loading?: boolean
@ -36,44 +73,10 @@ export function Button(props: {
loading, loading,
} = props } = props
const sizeClasses = {
'2xs': 'px-2 py-1 text-xs',
xs: 'px-2.5 py-1.5 text-sm',
sm: 'px-3 py-2 text-sm',
md: 'px-4 py-2 text-sm',
lg: 'px-4 py-2 text-base',
xl: 'px-6 py-2.5 text-base font-semibold',
'2xl': 'px-6 py-3 text-xl font-semibold',
}[size]
return ( return (
<button <button
type={type} type={type}
className={clsx( className={clsx(buttonClass(size, color), className)}
'font-md items-center justify-center rounded-md border border-transparent shadow-sm transition-colors disabled:cursor-not-allowed',
sizeClasses,
color === 'green' &&
'disabled:bg-greyscale-2 bg-teal-500 text-white hover:bg-teal-600',
color === 'red' &&
'disabled:bg-greyscale-2 bg-red-400 text-white hover:bg-red-500',
color === 'yellow' &&
'disabled:bg-greyscale-2 bg-yellow-400 text-white hover:bg-yellow-500',
color === 'blue' &&
'disabled:bg-greyscale-2 bg-blue-400 text-white hover:bg-blue-500',
color === 'indigo' &&
'disabled:bg-greyscale-2 bg-indigo-500 text-white hover:bg-indigo-600',
color === 'gray' &&
'bg-greyscale-1 text-greyscale-6 hover:bg-greyscale-2 disabled:opacity-50',
color === 'gray-outline' &&
'border-greyscale-4 text-greyscale-4 hover:bg-greyscale-4 border-2 hover:text-white disabled:opacity-50',
color === 'gradient' &&
'disabled:bg-greyscale-2 border-none bg-gradient-to-r from-indigo-500 to-blue-500 text-white hover:from-indigo-700 hover:to-blue-700',
color === 'gray-white' &&
'text-greyscale-6 hover:bg-greyscale-2 border-none shadow-none disabled:opacity-50',
color === 'highlight-blue' &&
'text-highlight-blue disabled:bg-greyscale-2 border-none shadow-none',
className
)}
disabled={disabled || loading} disabled={disabled || loading}
onClick={onClick} onClick={onClick}
> >

View File

@ -18,6 +18,7 @@ import { CHALLENGES_ENABLED } from 'common/challenge'
import ChallengeIcon from 'web/lib/icons/challenge-icon' import ChallengeIcon from 'web/lib/icons/challenge-icon'
import { QRCode } from '../qr-code' import { QRCode } from '../qr-code'
import { CopyLinkButton } from '../copy-link-button' import { CopyLinkButton } from '../copy-link-button'
import { Button } from '../button'
export function ShareModal(props: { export function ShareModal(props: {
contract: Contract contract: Contract
@ -59,24 +60,21 @@ export function ShareModal(props: {
<CopyLinkButton url={shareUrl} tracking="copy share link" /> <CopyLinkButton url={shareUrl} tracking="copy share link" />
<Row className="z-0 flex-wrap justify-center gap-4 self-center"> <Row className="z-0 flex-wrap justify-center gap-4 self-center">
<TweetButton <TweetButton tweetText={getTweetText(contract, shareUrl)} />
className="self-start"
tweetText={getTweetText(contract, shareUrl)}
/>
<ShareEmbedButton contract={contract} /> <ShareEmbedButton contract={contract} />
{showChallenge && ( {showChallenge && (
<button <Button
className={ size="2xs"
'btn btn-xs flex-nowrap border-2 !border-indigo-500 !bg-white normal-case text-indigo-500' color="override"
} className="gap-1 border-2 border-indigo-500 text-indigo-500 hover:bg-indigo-500 hover:text-white"
onClick={withTracking( onClick={withTracking(
() => setOpenCreateChallengeModal(true), () => setOpenCreateChallengeModal(true),
'click challenge button' 'click challenge button'
)} )}
> >
<ChallengeIcon className="mr-1 h-4 w-4" /> Challenge <ChallengeIcon className="h-4 w-4" /> Challenge
<CreateChallengeModal <CreateChallengeModal
isOpen={openCreateChallengeModal} isOpen={openCreateChallengeModal}
setOpen={(open) => { setOpen={(open) => {
@ -88,7 +86,7 @@ export function ShareModal(props: {
user={user} user={user}
contract={contract} contract={contract}
/> />
</button> </Button>
)} )}
</Row> </Row>
</Col> </Col>

View File

@ -3,27 +3,22 @@ import clsx from 'clsx'
import { Contract } from 'common/contract' import { Contract } from 'common/contract'
import { getMappedValue } from 'common/pseudo-numeric' import { getMappedValue } from 'common/pseudo-numeric'
import { trackCallback } from 'web/lib/service/analytics' import { trackCallback } from 'web/lib/service/analytics'
import { buttonClass } from './button'
export function DuplicateContractButton(props: { export function DuplicateContractButton(props: { contract: Contract }) {
contract: Contract const { contract } = props
className?: string
}) {
const { contract, className } = props
return ( return (
<a <a
className={clsx('btn btn-xs flex-nowrap normal-case', className)} className={clsx(
style={{ buttonClass('2xs', 'override'),
backgroundColor: 'white', 'gap-1 border-2 border-violet-400 text-violet-400 hover:bg-violet-400 hover:text-white'
border: '2px solid #a78bfa', )}
// violet-400
color: '#a78bfa',
}}
href={duplicateContractHref(contract)} href={duplicateContractHref(contract)}
onClick={trackCallback('duplicate market')} onClick={trackCallback('duplicate market')}
target="_blank" target="_blank"
> >
<DuplicateIcon className="mr-1.5 h-4 w-4" aria-hidden="true" /> <DuplicateIcon className="h-4 w-4" aria-hidden="true" />
<div>Duplicate</div> <div>Duplicate</div>
</a> </a>
) )

View File

@ -1,6 +1,5 @@
import React from 'react' import React from 'react'
import { CodeIcon } from '@heroicons/react/outline' import { CodeIcon } from '@heroicons/react/outline'
import { Menu } from '@headlessui/react'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { Contract } from 'common/contract' import { Contract } from 'common/contract'
@ -8,6 +7,7 @@ import { contractPath } from 'web/lib/firebase/contracts'
import { DOMAIN } from 'common/envs/constants' import { DOMAIN } from 'common/envs/constants'
import { copyToClipboard } from 'web/lib/util/copy' import { copyToClipboard } from 'web/lib/util/copy'
import { track } from 'web/lib/service/analytics' import { track } from 'web/lib/service/analytics'
import { Button } from './button'
export function embedContractCode(contract: Contract) { export function embedContractCode(contract: Contract) {
const title = contract.question const title = contract.question
@ -15,6 +15,7 @@ export function embedContractCode(contract: Contract) {
return `<iframe src="${src}" title="${title}" frameborder="0"></iframe>` return `<iframe src="${src}" title="${title}" frameborder="0"></iframe>`
} }
// TODO: move this function elsewhere
export function embedContractGridCode(contracts: Contract[]) { export function embedContractGridCode(contracts: Contract[]) {
const height = (contracts.length - (contracts.length % 2)) * 100 + 'px' const height = (contracts.length - (contracts.length % 2)) * 100 + 'px'
const src = `https://${DOMAIN}/embed/grid/${contracts const src = `https://${DOMAIN}/embed/grid/${contracts
@ -26,24 +27,21 @@ export function embedContractGridCode(contracts: Contract[]) {
export function ShareEmbedButton(props: { contract: Contract }) { export function ShareEmbedButton(props: { contract: Contract }) {
const { contract } = props const { contract } = props
const codeIcon = <CodeIcon className="mr-1.5 h-4 w-4" aria-hidden="true" /> const codeIcon = <CodeIcon className="h-4 w-4" aria-hidden />
return ( return (
<Menu <Button
as="div" size="2xs"
className="relative z-10 flex-shrink-0" color="gray-outline"
onMouseUp={() => { className="gap-1"
onClick={() => {
copyToClipboard(embedContractCode(contract)) copyToClipboard(embedContractCode(contract))
toast.success('Embed code copied!', { toast.success('Embed code copied!', { icon: codeIcon })
icon: codeIcon,
})
track('copy embed code') track('copy embed code')
}} }}
> >
<Menu.Button className="btn btn-xs border-2 !border-gray-500 !bg-white normal-case text-gray-500"> {codeIcon}
{codeIcon} Embed
Embed </Button>
</Menu.Button>
</Menu>
) )
} }

View File

@ -2,7 +2,6 @@ import { Modal } from './layout/modal'
import { Col } from './layout/col' import { Col } from './layout/col'
import { Title } from './title' import { Title } from './title'
import { TweetButton } from './tweet-button' import { TweetButton } from './tweet-button'
import { Row } from './layout/row'
import { CopyLinkButton } from './copy-link-button' import { CopyLinkButton } from './copy-link-button'
export function SharePostModal(props: { export function SharePostModal(props: {
@ -17,10 +16,9 @@ export function SharePostModal(props: {
<Col className="gap-4 rounded bg-white p-4"> <Col className="gap-4 rounded bg-white p-4">
<Title className="!mt-0 !mb-2" text="Share this post" /> <Title className="!mt-0 !mb-2" text="Share this post" />
<CopyLinkButton url={shareUrl} tracking="copy share post link" /> <CopyLinkButton url={shareUrl} tracking="copy share post link" />
<div className="self-center">
<Row className="z-0 justify-start gap-4 self-center"> <TweetButton tweetText={shareUrl} />
<TweetButton className="self-start" tweetText={shareUrl} /> </div>
</Row>
</Col> </Col>
</Modal> </Modal>
) )

View File

@ -1,22 +1,23 @@
import clsx from 'clsx' import clsx from 'clsx'
import TwitterLogo from 'web/lib/icons/twitter-logo'
import { trackCallback } from 'web/lib/service/analytics' import { trackCallback } from 'web/lib/service/analytics'
import { buttonClass } from './button'
export function TweetButton(props: { className?: string; tweetText: string }) { export function TweetButton(props: { tweetText: string }) {
const { tweetText, className } = props const { tweetText } = props
return ( return (
<a <a
className={clsx('btn btn-xs flex-nowrap normal-case', className)} // #1da1f2 is twitter blue
style={{ className={clsx(
backgroundColor: 'white', buttonClass('2xs', 'override'),
border: '2px solid #1da1f2', 'gap-1 border-2 border-[#1da1f2] text-[#1da1f2] hover:bg-[#1da1f2] hover:text-white'
color: '#1da1f2', )}
}}
href={getTweetHref(tweetText)} href={getTweetHref(tweetText)}
onClick={trackCallback('share tweet')} onClick={trackCallback('share tweet')}
target="_blank" target="_blank"
> >
<img className="mr-2" src={'/twitter-logo.svg'} width={15} height={15} /> <TwitterLogo width={15} height={15} />
<div>Tweet</div> <div>Tweet</div>
</a> </a>
) )

View File

@ -0,0 +1,28 @@
export default function TwitterLogo(props: React.SVGProps<SVGSVGElement>) {
return (
<svg
version="1.1"
id="Logo"
xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
viewBox="0 0 248 204"
stroke="currentColor"
fill="currentColor"
{...props}
>
<g id="Logo_1_">
<path
id="white_background"
className="st0"
d="M221.95,51.29c0.15,2.17,0.15,4.34,0.15,6.53c0,66.73-50.8,143.69-143.69,143.69v-0.04
C50.97,201.51,24.1,193.65,1,178.83c3.99,0.48,8,0.72,12.02,0.73c22.74,0.02,44.83-7.61,62.72-21.66
c-21.61-0.41-40.56-14.5-47.18-35.07c7.57,1.46,15.37,1.16,22.8-0.87C27.8,117.2,10.85,96.5,10.85,72.46c0-0.22,0-0.43,0-0.64
c7.02,3.91,14.88,6.08,22.92,6.32C11.58,63.31,4.74,33.79,18.14,10.71c25.64,31.55,63.47,50.73,104.08,52.76
c-4.07-17.54,1.49-35.92,14.61-48.25c20.34-19.12,52.33-18.14,71.45,2.19c11.31-2.23,22.15-6.38,32.07-12.26
c-3.77,11.69-11.66,21.62-22.2,27.93c10.01-1.18,19.79-3.86,29-7.95C240.37,35.29,231.83,44.14,221.95,51.29z"
/>
</g>
</svg>
)
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 248 204" style="enable-background:new 0 0 248 204;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
</style>
<g id="Logo_1_">
<path id="white_background" class="st0" d="M221.95,51.29c0.15,2.17,0.15,4.34,0.15,6.53c0,66.73-50.8,143.69-143.69,143.69v-0.04
C50.97,201.51,24.1,193.65,1,178.83c3.99,0.48,8,0.72,12.02,0.73c22.74,0.02,44.83-7.61,62.72-21.66
c-21.61-0.41-40.56-14.5-47.18-35.07c7.57,1.46,15.37,1.16,22.8-0.87C27.8,117.2,10.85,96.5,10.85,72.46c0-0.22,0-0.43,0-0.64
c7.02,3.91,14.88,6.08,22.92,6.32C11.58,63.31,4.74,33.79,18.14,10.71c25.64,31.55,63.47,50.73,104.08,52.76
c-4.07-17.54,1.49-35.92,14.61-48.25c20.34-19.12,52.33-18.14,71.45,2.19c11.31-2.23,22.15-6.38,32.07-12.26
c-3.77,11.69-11.66,21.62-22.2,27.93c10.01-1.18,19.79-3.86,29-7.95C240.37,35.29,231.83,44.14,221.95,51.29z"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB