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

109 lines
2.7 KiB
TypeScript
Raw Permalink Normal View History

2021-12-14 00:00:02 +00:00
import clsx from 'clsx'
import React from 'react'
import { Col } from './layout/col'
import { Row } from './layout/row'
export function YesNoSelector(props: {
selected: 'YES' | 'NO'
onSelect: (selected: 'YES' | 'NO') => void
className?: string
}) {
2021-12-14 00:00:02 +00:00
const { selected, onSelect, className } = props
return (
2021-12-14 00:00:02 +00:00
<Row className={clsx('space-x-3', className)}>
<Button
2021-12-14 00:00:02 +00:00
color={selected === 'YES' ? 'green' : 'gray'}
onClick={() => onSelect('YES')}
>
2021-12-15 09:06:03 +00:00
YES
</Button>
<Button
2021-12-14 00:00:02 +00:00
color={selected === 'NO' ? 'red' : 'gray'}
onClick={() => onSelect('NO')}
>
2021-12-15 09:06:03 +00:00
NO
2021-12-14 00:00:02 +00:00
</Button>
</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('space-x-3 w-full', 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('space-x-3 w-full', className)}>
<Button
color={selected === 'MKT' ? 'blue' : 'gray'}
onClick={() => onSelect('MKT')}
className={clsx(btnClassName, 'btn-sm')}
>
MKT
</Button>
<Button
color={selected === 'CANCEL' ? 'yellow' : 'gray'}
onClick={() => onSelect('CANCEL')}
className={clsx(btnClassName, 'btn-sm')}
>
N/A
</Button>
</Row>
</Col>
)
}
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(
'flex-1 inline-flex justify-center items-center px-8 py-3 border border-transparent rounded-md shadow-sm text-sm font-medium text-white',
2021-12-13 18:26:46 +00:00
color === 'green' && 'btn-primary',
2021-12-14 00:00:02 +00:00
color === 'red' && 'bg-red-400 hover:bg-red-500',
color === 'yellow' && 'bg-yellow-400 hover:bg-yellow-500',
color === 'blue' && 'bg-blue-400 hover:bg-blue-500',
2021-12-16 00:02:15 +00:00
color === 'gray' && 'text-gray-700 bg-gray-300 hover:bg-gray-400',
className
)}
onClick={onClick}
>
{children}
</button>
)
}