1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00
commons/src/components/molecules/AccountStatus/index.tsx

57 lines
1.5 KiB
TypeScript
Raw Normal View History

import React, { PureComponent } from 'react'
import TetherComponent from 'react-tether'
import AccountPopover from './Popover'
import AccountIndicator from './Indicator'
interface AccountStatusProps {
className?: string
}
interface AccountStatusState {
2019-02-27 00:26:53 +01:00
isPopoverOpen: boolean
}
export default class AccountStatus extends PureComponent<
AccountStatusProps,
AccountStatusState
> {
public state = {
2019-02-27 00:26:53 +01:00
isPopoverOpen: false
}
2019-02-27 00:26:53 +01:00
public togglePopover() {
this.setState(prevState => ({
isPopoverOpen: !prevState.isPopoverOpen
}))
}
public render() {
return (
<TetherComponent
// http://tether.io/#options
attachment="top center"
constraints={[
{
to: 'scrollParent',
attachment: 'together',
pin: true
}
]}
// https://github.com/danreeves/react-tether#props
renderTarget={ref => (
<AccountIndicator
togglePopover={() => this.togglePopover()}
className={this.props.className}
forwardedRef={ref}
/>
2019-02-27 00:26:53 +01:00
)}
renderElement={ref =>
this.state.isPopoverOpen && (
<AccountPopover forwardedRef={ref} />
)
}
/>
)
}
}