Hovercard: attach to each element for better positioning
This commit is contained in:
parent
24bf880e0b
commit
72659f27c1
|
@ -4,6 +4,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import VerificationBadge from './verification_badge';
|
import VerificationBadge from './verification_badge';
|
||||||
import { acctFull } from '../utils/accounts';
|
import { acctFull } from '../utils/accounts';
|
||||||
import { List as ImmutableList } from 'immutable';
|
import { List as ImmutableList } from 'immutable';
|
||||||
|
import HoverRefWrapper from 'soapbox/components/hover_ref_wrapper';
|
||||||
|
|
||||||
export default class DisplayName extends React.PureComponent {
|
export default class DisplayName extends React.PureComponent {
|
||||||
|
|
||||||
|
@ -42,7 +43,9 @@ export default class DisplayName extends React.PureComponent {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className='display-name'>
|
<span className='display-name'>
|
||||||
|
<HoverRefWrapper accountId={account.get('id')} inline>
|
||||||
{displayName}
|
{displayName}
|
||||||
|
</HoverRefWrapper>
|
||||||
{suffix}
|
{suffix}
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -26,25 +26,31 @@ const handleMouseLeave = (dispatch) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const HoverRefWrapper = ({ accountId, children }) => {
|
export const HoverRefWrapper = ({ accountId, children, inline }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const ref = useRef();
|
const ref = useRef();
|
||||||
|
const Elem = inline ? 'span' : 'div';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<Elem
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className='hover-ref-wrapper'
|
className='hover-ref-wrapper'
|
||||||
onMouseEnter={handleMouseEnter(dispatch, ref, accountId)}
|
onMouseEnter={handleMouseEnter(dispatch, ref, accountId)}
|
||||||
onMouseLeave={handleMouseLeave(dispatch)}
|
onMouseLeave={handleMouseLeave(dispatch)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</Elem>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
HoverRefWrapper.propTypes = {
|
HoverRefWrapper.propTypes = {
|
||||||
accountId: PropTypes.string,
|
accountId: PropTypes.string,
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
|
inline: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
HoverRefWrapper.defaultProps = {
|
||||||
|
inline: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default HoverRefWrapper;
|
export default HoverRefWrapper;
|
||||||
|
|
|
@ -52,14 +52,7 @@ export const ProfileHoverCard = ({ visible }) => {
|
||||||
if (accountId) dispatch(fetchRelationships([accountId]));
|
if (accountId) dispatch(fetchRelationships([accountId]));
|
||||||
}, [dispatch, accountId]);
|
}, [dispatch, accountId]);
|
||||||
|
|
||||||
const { styles, attributes } = usePopper(targetRef, popperElement, {
|
const { styles, attributes } = usePopper(targetRef, popperElement);
|
||||||
modifiers: [{
|
|
||||||
name: 'offset',
|
|
||||||
options: {
|
|
||||||
offset: [-100, 0],
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!account) return null;
|
if (!account) return null;
|
||||||
const accountBio = { __html: account.get('note_emojified') };
|
const accountBio = { __html: account.get('note_emojified') };
|
||||||
|
|
|
@ -462,17 +462,18 @@ class Status extends ImmutablePureComponent {
|
||||||
<img src={favicon} alt='' title={domain} />
|
<img src={favicon} alt='' title={domain} />
|
||||||
</div>}
|
</div>}
|
||||||
|
|
||||||
<HoverRefWrapper accountId={status.getIn(['account', 'id'])}>
|
|
||||||
<div className='status__profile'>
|
<div className='status__profile'>
|
||||||
<div className='status__avatar'>
|
<div className='status__avatar'>
|
||||||
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='floating-link' />
|
<HoverRefWrapper accountId={status.getIn(['account', 'id'])}>
|
||||||
|
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])}>
|
||||||
{statusAvatar}
|
{statusAvatar}
|
||||||
|
</NavLink>
|
||||||
|
</HoverRefWrapper>
|
||||||
</div>
|
</div>
|
||||||
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='status__display-name'>
|
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='status__display-name'>
|
||||||
<DisplayName account={status.get('account')} others={otherAccounts} />
|
<DisplayName account={status.get('account')} others={otherAccounts} />
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
</HoverRefWrapper>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!group && status.get('group') && (
|
{!group && status.get('group') && (
|
||||||
|
|
|
@ -164,20 +164,22 @@ export default class DetailedStatus extends ImmutablePureComponent {
|
||||||
return (
|
return (
|
||||||
<div style={outerStyle}>
|
<div style={outerStyle}>
|
||||||
<div ref={this.setRef} className={classNames('detailed-status', { compact })}>
|
<div ref={this.setRef} className={classNames('detailed-status', { compact })}>
|
||||||
<HoverRefWrapper accountId={status.getIn(['account', 'id'])}>
|
|
||||||
<div className='detailed-status__profile'>
|
<div className='detailed-status__profile'>
|
||||||
<div className='detailed-status__display-name'>
|
<div className='detailed-status__display-name'>
|
||||||
<NavLink to={`/@${status.getIn(['account', 'acct'])}`}>
|
<NavLink to={`/@${status.getIn(['account', 'acct'])}`}>
|
||||||
<div className='detailed-status__display-avatar'>
|
<div className='detailed-status__display-avatar'>
|
||||||
|
<HoverRefWrapper accountId={status.getIn(['account', 'id'])}>
|
||||||
<Avatar account={status.get('account')} size={48} />
|
<Avatar account={status.get('account')} size={48} />
|
||||||
|
</HoverRefWrapper>
|
||||||
</div>
|
</div>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
<DisplayName account={status.get('account')}>
|
<DisplayName account={status.get('account')}>
|
||||||
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='floating-link' />
|
<HoverRefWrapper accountId={status.getIn(['account', 'id'])}>
|
||||||
|
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} />
|
||||||
|
</HoverRefWrapper>
|
||||||
</DisplayName>
|
</DisplayName>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</HoverRefWrapper>
|
|
||||||
|
|
||||||
{status.get('group') && (
|
{status.get('group') && (
|
||||||
<div className='status__meta'>
|
<div className='status__meta'>
|
||||||
|
|
|
@ -113,18 +113,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prevent floating avatars from intercepting with current card */
|
|
||||||
.status,
|
|
||||||
.detailed-status {
|
|
||||||
.floating-link {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover .floating-link {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Hide the popper when the reference is hidden */
|
/* Hide the popper when the reference is hidden */
|
||||||
#popper[data-popper-reference-hidden] {
|
#popper[data-popper-reference-hidden] {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
|
|
Loading…
Reference in New Issue