import React, { useCallback, useMemo } from 'react' import { Listbox } from '@headlessui/react' import { ChevronDownIcon } from '@heroicons/react/20/solid' import Decimal from 'decimal.js' const GroupSize = ({ tickSize, value, onChange, className, }: { tickSize: number value: number onChange: (x: number) => void className?: string }) => { const formatSize = useCallback( (multiplier: number) => { return new Decimal(tickSize).mul(multiplier).toNumber() }, [tickSize], ) const sizes = useMemo( () => [ tickSize, formatSize(5), formatSize(10), formatSize(50), formatSize(100), formatSize(500), formatSize(1000), ], [tickSize], ) return (
{({ open }) => ( <>
{value}
{open ? ( {sizes.map((size) => ( {({ selected }) => (
{size}
)}
))}
) : null} )}
) } export default React.memo(GroupSize)