mango-ui-v3/components/MarketSelect.jsx

97 lines
3.5 KiB
React
Raw Normal View History

2021-04-06 15:11:42 -07:00
import xw from 'xwind'
2021-04-11 14:25:01 -07:00
import styled from '@emotion/styled'
2021-04-06 15:11:42 -07:00
import { Listbox, Transition } from '@headlessui/react'
import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/solid'
import useMarketList from '../hooks/useMarketList'
// import useMarket from '../hooks/useMarket'
import useMangoStore from '../stores/useMangoStore'
const MarketSelect = () => {
const { spotMarkets } = useMarketList()
const selectedMarket = useMangoStore((s) => s.selectedMarket)
const setMangoStore = useMangoStore((s) => s.set)
const handleChange = (mktName) => {
setMangoStore((state) => {
state.selectedMarket = { name: mktName, address: spotMarkets[mktName] }
})
}
return (
2021-04-12 09:20:17 -07:00
<div css={xw`bg-th-bkg-3`}>
2021-04-11 14:25:01 -07:00
{/*<div css={xw`opacity-50 p-2`}>Markets</div>*/}
2021-04-12 09:20:17 -07:00
<div
css={xw`flex items-center py-2 px-3 sm:px-8 divide-x divide-th-fgd-4 `}
>
{Object.entries(spotMarkets).map(([name, address]) => (
<div
css={[
xw`cursor-pointer`,
selectedMarket.name === name
? xw`px-3 py-1 text-th-primary text-xs font-normal`
: xw`px-3 py-1 text-th-fgd-3 hover:text-th-fgd-1 text-xs font-normal`,
]}
onClick={() => handleChange(name)}
key={address}
>
{name}
</div>
))}
</div>
2021-04-11 14:25:01 -07:00
{/*<Listbox value={selectedMarket.name} onChange={handleChange}>
2021-04-06 15:11:42 -07:00
{({ open }) => (
<>
<Listbox.Button
css={xw`border border-mango-dark-lighter focus:outline-none focus:ring-1 focus:ring-mango-yellow p-2 w-56`}
>
<div
css={xw`flex items-center text-lg justify-between font-light`}
>
{selectedMarket.name}
{open ? (
<ChevronUpIcon css={xw`h-5 w-5 mr-1`} />
) : (
<ChevronDownIcon css={xw`h-5 w-5 mr-1`} />
)}
</div>
</Listbox.Button>
<Transition
show={open}
enter="transition duration-100 ease-out"
enterFrom="transform scale-95 opacity-0"
enterTo="transform scale-100 opacity-100"
leave="transition duration-75 ease-out"
leaveFrom="transform scale-100 opacity-100"
leaveTo="transform scale-95 opacity-0"
>
<Listbox.Options
static
css={xw`z-20 p-1 absolute left-0 w-56 mt-1 bg-mango-dark-light origin-top-left divide-y divide-mango-dark-lighter shadow-lg outline-none`}
>
<div css={xw`opacity-50 p-2`}>Markets</div>
{Object.entries(spotMarkets).map(([name, address]) => (
<Listbox.Option key={address} value={name}>
{({ selected }) => (
<div
css={[
xw`p-2 text-base hover:bg-mango-dark-lighter hover:cursor-pointer tracking-wider font-light`,
selected &&
xw`text-mango-yellow bg-mango-dark-lighter`,
]}
>
{name}
</div>
)}
</Listbox.Option>
))}
</Listbox.Options>
</Transition>
</>
)}
2021-04-11 14:25:01 -07:00
</Listbox>*/}
2021-04-06 15:11:42 -07:00
</div>
)
}
export default MarketSelect