Bet panel: Quick vs Limit pill buttons. Also, pill buttons for Yes vs No.

This commit is contained in:
James Grugett 2022-07-13 18:23:03 -05:00
parent 98192ee580
commit 9240cd3d1c
3 changed files with 71 additions and 85 deletions

View File

@ -8,7 +8,6 @@ import { CPMMBinaryContract, PseudoNumericContract } from 'common/contract'
import { Col } from './layout/col' import { Col } from './layout/col'
import { Row } from './layout/row' import { Row } from './layout/row'
import { Spacer } from './layout/spacer' import { Spacer } from './layout/spacer'
import { YesNoSelector } from './yes-no-selector'
import { import {
formatMoney, formatMoney,
formatMoneyWithDecimals, formatMoneyWithDecimals,
@ -41,6 +40,7 @@ import { removeUndefinedProps } from 'common/util/object'
import { useUnfilledBets } from 'web/hooks/use-bets' import { useUnfilledBets } from 'web/hooks/use-bets'
import { LimitBets } from './limit-bets' import { LimitBets } from './limit-bets'
import { BucketInput } from './bucket-input' import { BucketInput } from './bucket-input'
import { PillButton } from './buttons/pill-button'
export function BetPanel(props: { export function BetPanel(props: {
contract: CPMMBinaryContract | PseudoNumericContract contract: CPMMBinaryContract | PseudoNumericContract
@ -54,10 +54,6 @@ export function BetPanel(props: {
const { sharesOutcome } = useSaveBinaryShares(contract, userBets) const { sharesOutcome } = useSaveBinaryShares(contract, userBets)
const [isLimitOrder, setIsLimitOrder] = useState(false) const [isLimitOrder, setIsLimitOrder] = useState(false)
const toggleLimitOrder = () => {
setIsLimitOrder(!isLimitOrder)
track('toggle limit order')
}
const showLimitOrders = const showLimitOrders =
(isLimitOrder && unfilledBets.length > 0) || yourUnfilledBets.length > 0 (isLimitOrder && unfilledBets.length > 0) || yourUnfilledBets.length > 0
@ -71,21 +67,33 @@ export function BetPanel(props: {
/> />
<Col <Col
className={clsx( className={clsx(
'relative rounded-b-md bg-white px-8 py-6', 'relative rounded-b-md bg-white px-6 py-6',
!sharesOutcome && 'rounded-t-md', !sharesOutcome && 'rounded-t-md',
className className
)} )}
> >
<Row className="align-center justify-between"> <Row className="align-center mb-4 justify-between">
<div className="mb-6 text-2xl"> <div className="text-4xl">Bet</div>
{isLimitOrder ? <>Limit order</> : <>Place your bet</>} <Row className="mt-2 items-center gap-2">
</div> <PillButton
<button selected={!isLimitOrder}
className="btn btn-ghost btn-sm text-sm normal-case" onSelect={() => {
onClick={toggleLimitOrder} setIsLimitOrder(false)
track('select quick order')
}}
> >
<SwitchHorizontalIcon className="inline h-6 w-6" /> Quick
</button> </PillButton>
<PillButton
selected={isLimitOrder}
onSelect={() => {
setIsLimitOrder(true)
track('select limit order')
}}
>
Limit
</PillButton>
</Row>
</Row> </Row>
<BuyPanel <BuyPanel
@ -287,13 +295,26 @@ function BuyPanel(props: {
return ( return (
<> <>
<YesNoSelector <div className="my-3 text-left text-sm text-gray-500">Direction</div>
className="mb-4" <Row className="mb-4 items-center gap-2">
btnClassName="flex-1" <PillButton
selected={betChoice} selected={betChoice === 'YES'}
onSelect={(choice) => onBetChoice(choice)} onSelect={() => onBetChoice('YES')}
isPseudoNumeric={isPseudoNumeric} big
/> color="bg-primary"
>
{isPseudoNumeric ? 'Higher' : 'Yes'}
</PillButton>
<PillButton
selected={betChoice === 'NO'}
onSelect={() => onBetChoice('NO')}
big
color="bg-red-400"
>
{isPseudoNumeric ? 'Lower' : 'No'}
</PillButton>
</Row>
<div className="my-3 text-left text-sm text-gray-500">Amount</div> <div className="my-3 text-left text-sm text-gray-500">Amount</div>
<BuyAmountInput <BuyAmountInput
inputClassName="w-full max-w-none" inputClassName="w-full max-w-none"

View File

@ -0,0 +1,27 @@
import clsx from 'clsx'
import { ReactNode } from 'react'
export function PillButton(props: {
selected: boolean
onSelect: () => void
color?: string
big?: boolean
children: ReactNode
}) {
const { children, selected, onSelect, color, big } = props
return (
<button
className={clsx(
'cursor-pointer select-none rounded-full',
selected
? ['text-white', color ?? 'bg-gray-700']
: 'bg-gray-100 hover:bg-gray-200',
big ? 'px-8 py-2' : 'px-3 py-1.5 text-sm'
)}
onClick={onSelect}
>
{children}
</button>
)
}

View File

@ -5,68 +5,6 @@ import { Col } from './layout/col'
import { Row } from './layout/row' import { Row } from './layout/row'
import { resolution } from 'common/contract' import { resolution } from 'common/contract'
export function YesNoSelector(props: {
selected?: 'YES' | 'NO'
onSelect: (selected: 'YES' | 'NO') => void
className?: string
btnClassName?: string
replaceYesButton?: React.ReactNode
replaceNoButton?: React.ReactNode
isPseudoNumeric?: boolean
}) {
const {
selected,
onSelect,
className,
btnClassName,
replaceNoButton,
replaceYesButton,
isPseudoNumeric,
} = props
const commonClassNames =
'inline-flex items-center justify-center rounded-3xl border-2 p-2'
return (
<Row className={clsx('space-x-3', className)}>
{replaceYesButton ? (
replaceYesButton
) : (
<button
className={clsx(
commonClassNames,
'hover:bg-primary-focus border-primary hover:border-primary-focus hover:text-white',
selected == 'YES'
? 'bg-primary text-white'
: 'text-primary bg-transparent',
btnClassName
)}
onClick={() => onSelect('YES')}
>
{isPseudoNumeric ? 'HIGHER' : 'YES'}
</button>
)}
{replaceNoButton ? (
replaceNoButton
) : (
<button
className={clsx(
commonClassNames,
'border-red-400 hover:border-red-500 hover:bg-red-500 hover:text-white',
selected == 'NO'
? 'bg-red-400 text-white'
: 'bg-transparent text-red-400',
btnClassName
)}
onClick={() => onSelect('NO')}
>
{isPseudoNumeric ? 'LOWER' : 'NO'}
</button>
)}
</Row>
)
}
export function YesNoCancelSelector(props: { export function YesNoCancelSelector(props: {
selected: resolution | undefined selected: resolution | undefined
onSelect: (selected: resolution) => void onSelect: (selected: resolution) => void