mango-ui-v2/components/TradeType.jsx

54 lines
1.9 KiB
React
Raw Normal View History

import { Listbox } from '@headlessui/react'
2021-04-10 14:12:15 -07:00
import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/solid'
const TRADE_TYPES = ['Limit', 'Market']
const TradeType = ({ value, onChange, className = '' }) => {
2021-04-10 14:12:15 -07:00
return (
<div className={`relative ${className}`}>
2021-04-10 14:12:15 -07:00
<Listbox value={value} onChange={onChange}>
{({ open }) => (
<>
<Listbox.Button
2021-04-13 07:10:57 -07:00
className={`h-full w-full bg-th-bkg-1 border-l border-th-fgd-4 rounded rounded-l-none focus:outline-none focus:ring-1 focus:ring-th-primary`}
2021-04-10 14:12:15 -07:00
>
<div
2021-04-13 07:10:57 -07:00
className={`flex items-center justify-between space-x-4 pl-2 pr-1`}
2021-04-10 14:12:15 -07:00
>
<span>{value}</span>
2021-04-10 14:12:15 -07:00
{open ? (
2021-04-13 07:10:57 -07:00
<ChevronUpIcon className={`h-5 w-5 mr-1 text-th-primary`} />
2021-04-10 14:12:15 -07:00
) : (
2021-04-13 07:10:57 -07:00
<ChevronDownIcon className={`h-5 w-5 mr-1 text-th-primary`} />
2021-04-10 14:12:15 -07:00
)}
</div>
</Listbox.Button>
{open ? (
2021-04-10 14:12:15 -07:00
<Listbox.Options
static
2021-04-13 07:10:57 -07:00
className={`z-20 w-full p-1 absolute left-0 mt-1 bg-th-bkg-1 origin-top-left divide-y divide-th-bkg-3 shadow-lg outline-none rounded-md`}
2021-04-10 14:12:15 -07:00
>
{TRADE_TYPES.map((type) => (
<Listbox.Option key={type} value={type}>
2021-04-10 14:12:15 -07:00
{({ selected }) => (
<div
2021-04-13 07:10:57 -07:00
className={`p-2 hover:bg-th-bkg-3 hover:cursor-pointer tracking-wider ${
selected && `text-th-primary`
}`}
2021-04-10 14:12:15 -07:00
>
{type}
2021-04-10 14:12:15 -07:00
</div>
)}
</Listbox.Option>
))}
</Listbox.Options>
) : null}
2021-04-10 14:12:15 -07:00
</>
)}
</Listbox>
</div>
)
}
export default TradeType