2019-02-26 15:22:12 +01:00
|
|
|
import React, { PureComponent } from 'react'
|
2019-03-01 19:43:50 +01:00
|
|
|
import TetherComponent from 'react-tether'
|
2019-02-26 15:22:12 +01:00
|
|
|
import AccountPopover from './Popover'
|
|
|
|
import AccountIndicator from './Indicator'
|
|
|
|
|
|
|
|
interface AccountStatusProps {
|
|
|
|
className?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface AccountStatusState {
|
2019-02-27 00:26:53 +01:00
|
|
|
isPopoverOpen: boolean
|
2019-02-26 15:22:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class AccountStatus extends PureComponent<
|
|
|
|
AccountStatusProps,
|
|
|
|
AccountStatusState
|
|
|
|
> {
|
|
|
|
public state = {
|
2019-02-27 00:26:53 +01:00
|
|
|
isPopoverOpen: false
|
2019-02-26 15:22:12 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 00:26:53 +01:00
|
|
|
public togglePopover() {
|
|
|
|
this.setState(prevState => ({
|
|
|
|
isPopoverOpen: !prevState.isPopoverOpen
|
|
|
|
}))
|
2019-02-26 15:22:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return (
|
2019-03-01 19:43:50 +01:00
|
|
|
<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
|
|
|
)}
|
2019-03-01 19:43:50 +01:00
|
|
|
renderElement={ref =>
|
|
|
|
this.state.isPopoverOpen && (
|
|
|
|
<AccountPopover forwardedRef={ref} />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
2019-02-26 15:22:12 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|