2021-04-15 09:13:16 -07:00
|
|
|
import React, { FunctionComponent } from 'react'
|
2021-04-15 06:22:39 -07:00
|
|
|
import styled from '@emotion/styled'
|
2021-07-22 04:34:03 -07:00
|
|
|
import { LinkIcon } from '@heroicons/react/outline'
|
2021-04-15 06:22:39 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
|
|
|
import { MoveIcon } from './icons'
|
2021-07-22 04:34:03 -07:00
|
|
|
import EmptyState from './EmptyState'
|
2021-03-30 15:47:08 -07:00
|
|
|
|
2021-04-15 06:22:39 -07:00
|
|
|
const StyledDragWrapperContent = styled.div`
|
|
|
|
transition: all 0.25s ease-in;
|
|
|
|
opacity: 0;
|
|
|
|
`
|
|
|
|
|
|
|
|
const StyledDragBkg = styled.div`
|
|
|
|
transition: all 0.25s ease-in;
|
|
|
|
opacity: 0;
|
|
|
|
`
|
|
|
|
|
|
|
|
const StyledDragWrapper = styled.div`
|
|
|
|
:hover {
|
|
|
|
${StyledDragWrapperContent} {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
${StyledDragBkg} {
|
|
|
|
opacity: 0.9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2021-04-14 23:16:36 -07:00
|
|
|
|
2021-04-15 09:13:16 -07:00
|
|
|
interface FloatingElementProps {
|
|
|
|
className?: string
|
2021-07-22 04:34:03 -07:00
|
|
|
showConnect?: boolean
|
2021-04-15 09:13:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const FloatingElement: FunctionComponent<FloatingElementProps> = ({
|
|
|
|
className,
|
|
|
|
children,
|
2021-07-22 04:34:03 -07:00
|
|
|
showConnect,
|
2021-04-15 09:13:16 -07:00
|
|
|
}) => {
|
2021-04-15 06:22:39 -07:00
|
|
|
const { uiLocked } = useMangoStore((s) => s.settings)
|
2021-07-22 04:34:03 -07:00
|
|
|
const connected = useMangoStore((s) => s.wallet.connected)
|
|
|
|
const wallet = useMangoStore((s) => s.wallet.current)
|
2021-03-30 15:47:08 -07:00
|
|
|
return (
|
2021-04-16 11:55:48 -07:00
|
|
|
<div className="m-1 p-1 bg-th-bkg-2 rounded-lg h-full">
|
|
|
|
<div
|
2021-04-19 09:15:49 -07:00
|
|
|
className={`thin-scroll p-2.5 overflow-auto overflow-x-hidden relative h-full ${className}`}
|
2021-04-16 11:55:48 -07:00
|
|
|
>
|
2021-07-22 04:34:03 -07:00
|
|
|
{!connected && showConnect ? (
|
|
|
|
<div className="absolute top-0 left-0 w-full h-full z-30">
|
|
|
|
<div className="flex flex-col h-full items-center justify-center relative z-30">
|
|
|
|
<EmptyState
|
|
|
|
buttonText="Connect"
|
|
|
|
icon={<LinkIcon />}
|
2021-08-24 09:28:25 -07:00
|
|
|
onClickButton={() => (wallet ? wallet.connect() : null)}
|
2021-07-22 04:34:03 -07:00
|
|
|
title="Connect Wallet"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="absolute top-0 left-0 rounded-lg opacity-50 w-full h-full bg-th-bkg-2" />
|
|
|
|
</div>
|
|
|
|
) : null}
|
2021-04-16 11:55:48 -07:00
|
|
|
{!uiLocked ? (
|
|
|
|
<StyledDragWrapper className="absolute top-0 left-0 w-full h-full cursor-move z-50">
|
|
|
|
<StyledDragWrapperContent className="relative flex flex-col items-center justify-center text-th-fgd-3 h-full z-50">
|
|
|
|
<MoveIcon className="w-8 h-8" />
|
|
|
|
<div className="mt-2">Drag to reposition</div>
|
|
|
|
</StyledDragWrapperContent>
|
|
|
|
<StyledDragBkg className="absolute top-0 left-0 rounded-lg w-full h-full bg-th-bkg-3" />
|
|
|
|
</StyledDragWrapper>
|
|
|
|
) : null}
|
|
|
|
{children}
|
|
|
|
</div>
|
2021-04-11 14:25:01 -07:00
|
|
|
</div>
|
2021-03-30 15:47:08 -07:00
|
|
|
)
|
|
|
|
}
|
2021-04-15 09:13:16 -07:00
|
|
|
|
|
|
|
export default FloatingElement
|