mango-ui-v3/components/ResetLayout.tsx

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-04-22 06:10:43 -07:00
import { useEffect, useState } from 'react'
import { RefreshClockwiseIcon } from './icons'
2021-05-01 21:31:55 -07:00
import { defaultLayouts, GRID_LAYOUT_KEY } from './TradePageGrid'
import useLocalStorageState from '../hooks/useLocalStorageState'
2021-04-22 07:45:36 -07:00
import Tooltip from './Tooltip'
const ResetLayout = ({ className = '' }) => {
2021-04-22 06:10:43 -07:00
const [spin, setSpin] = useState(false)
const [, setSavedLayouts] = useLocalStorageState(
2021-05-01 21:31:55 -07:00
GRID_LAYOUT_KEY,
defaultLayouts
)
2021-04-22 06:10:43 -07:00
useEffect(() => {
const timer = setTimeout(() => {
setSpin(false)
}, 500)
return () => clearTimeout(timer)
}, [spin])
const handleResetLayout = () => {
setSavedLayouts(defaultLayouts)
setSpin(true)
}
return (
<div className={`flex relative ${className} mr-4`}>
<Tooltip content="Reset Layout" className="text-xs py-1">
2021-04-22 07:45:36 -07:00
<button
onClick={() => handleResetLayout()}
className="flex items-center justify-center rounded-full bg-th-bkg-3 w-8 h-8 hover:text-th-primary focus:outline-none"
2021-04-22 07:45:36 -07:00
>
<RefreshClockwiseIcon
className={`w-5 h-5 ${spin ? 'animate-spin' : null}`}
/>
2021-04-22 07:45:36 -07:00
</button>
</Tooltip>
</div>
)
}
export default ResetLayout