manifold/web/components/yes-no-selector.tsx

149 lines
4.1 KiB
TypeScript
Raw Normal View History

2021-12-14 00:00:02 +00:00
import clsx from 'clsx'
import React from 'react'
import { formatMoney } from '../../common/util/format'
import { Col } from './layout/col'
import { Row } from './layout/row'
export function YesNoSelector(props: {
selected?: 'YES' | 'NO'
onSelect: (selected: 'YES' | 'NO') => void
className?: string
2022-01-27 20:49:55 +00:00
btnClassName?: string
}) {
2022-01-27 20:49:55 +00:00
const { selected, onSelect, className, btnClassName } = props
return (
2021-12-14 00:00:02 +00:00
<Row className={clsx('space-x-3', className)}>
<button
className={clsx(
'hover:bg-primary-focus border-primary hover:border-primary-focus inline-flex flex-1 items-center justify-center rounded-lg border-2 p-2 hover:text-white',
selected == 'YES'
? 'bg-primary text-white'
: 'text-primary bg-transparent',
2022-01-27 20:49:55 +00:00
btnClassName
)}
onClick={() => onSelect('YES')}
>
2022-01-26 22:28:57 +00:00
Buy YES
</button>
<button
className={clsx(
'inline-flex flex-1 items-center justify-center rounded-lg border-2 border-red-400 p-2 hover:border-red-500 hover:bg-red-500 hover:text-white',
selected == 'NO'
? 'bg-red-400 text-white'
2022-01-27 20:49:55 +00:00
: 'bg-transparent text-red-400',
btnClassName
)}
onClick={() => onSelect('NO')}
>
2022-01-26 22:28:57 +00:00
Buy NO
</button>
2021-12-14 00:00:02 +00:00
</Row>
)
}
export function YesNoCancelSelector(props: {
selected: 'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined
onSelect: (selected: 'YES' | 'NO' | 'MKT' | 'CANCEL') => void
2021-12-14 00:00:02 +00:00
className?: string
btnClassName?: string
2021-12-14 00:00:02 +00:00
}) {
const { selected, onSelect, className } = props
const btnClassName = clsx('px-6 flex-1', props.btnClassName)
2021-12-14 00:00:02 +00:00
return (
<Col>
<Row className={clsx('w-full space-x-3', className)}>
<Button
color={selected === 'YES' ? 'green' : 'gray'}
onClick={() => onSelect('YES')}
className={btnClassName}
>
YES
</Button>
2021-12-14 00:00:02 +00:00
<Button
color={selected === 'NO' ? 'red' : 'gray'}
onClick={() => onSelect('NO')}
className={btnClassName}
>
NO
</Button>
</Row>
2021-12-14 00:00:02 +00:00
<Row className={clsx('w-full space-x-3', className)}>
<Button
color={selected === 'MKT' ? 'blue' : 'gray'}
onClick={() => onSelect('MKT')}
className={clsx(btnClassName, 'btn-sm')}
>
PROB
</Button>
<Button
color={selected === 'CANCEL' ? 'yellow' : 'gray'}
onClick={() => onSelect('CANCEL')}
className={clsx(btnClassName, 'btn-sm')}
>
N/A
</Button>
</Row>
</Col>
)
}
const fundAmounts = [500, 1000, 2500, 10000]
export function FundsSelector(props: {
selected: 500 | 1000 | 2500 | 10000
onSelect: (selected: 500 | 1000 | 2500 | 10000) => void
className?: string
btnClassName?: string
}) {
const { selected, onSelect, className } = props
2022-01-14 03:15:44 +00:00
const btnClassName = clsx('!px-2 whitespace-nowrap', props.btnClassName)
return (
<Row className={clsx('space-x-3', className)}>
{fundAmounts.map((amount) => (
<Button
key={amount}
color={selected === amount ? 'green' : 'gray'}
onClick={() => onSelect(amount as any)}
className={btnClassName}
>
{formatMoney(amount)}
</Button>
))}
</Row>
)
}
function Button(props: {
className?: string
onClick?: () => void
color: 'green' | 'red' | 'blue' | 'yellow' | 'gray'
children?: any
}) {
2021-12-14 00:00:02 +00:00
const { className, onClick, children, color } = props
return (
<button
type="button"
2021-12-14 00:00:02 +00:00
className={clsx(
'inline-flex flex-1 items-center justify-center rounded-md border border-transparent px-8 py-3 text-sm font-medium shadow-sm',
2022-02-08 05:52:03 +00:00
color === 'green' && 'btn-primary text-white',
color === 'red' && 'bg-red-400 text-white hover:bg-red-500',
color === 'yellow' && 'bg-yellow-400 text-white hover:bg-yellow-500',
color === 'blue' && 'bg-blue-400 text-white hover:bg-blue-500',
color === 'gray' && 'bg-gray-300 text-gray-700 hover:bg-gray-400',
className
)}
onClick={onClick}
>
{children}
</button>
)
}