gab-social/app/javascript/gabsocial/components/user_stat.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-02-19 23:57:07 +00:00
import { NavLink } from 'react-router-dom'
import Text from './text'
2020-04-23 07:13:29 +01:00
/**
* Renders a user stat component
* @param {string} props.title - bottom title
* @param {string} props.to - location to go to on click
* @param {string} props.value - top value
*/
2020-02-19 23:57:07 +00:00
export default class UserStat extends PureComponent {
2020-04-23 07:13:29 +01:00
2020-02-19 23:57:07 +00:00
static propTypes = {
2020-04-23 07:13:29 +01:00
title: PropTypes.string.isRequired,
to: PropTypes.string.isRequired,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
]).isRequired,
2020-02-19 23:57:07 +00:00
}
state = {
hovering: false,
}
handleOnMouseEnter = () => {
this.setState({ hovering: true })
}
handleOnMouseLeave = () => {
this.setState({ hovering: false })
}
render() {
const { to, title, value } = this.props
const { hovering } = this.state
return (
<NavLink
to={to}
title={`${value} ${title}`}
2020-03-11 23:56:18 +00:00
className={[_s.default, _s.flexGrow1, _s.cursorPointer, _s.noUnderline, _s.pr15].join(' ')}
2020-04-23 07:13:29 +01:00
onMouseEnter={this.handleOnMouseEnter}
onMouseLeave={this.handleOnMouseLeave}
2020-02-19 23:57:07 +00:00
>
<Text size='large' weight='bold' color='brand'>
{value}
</Text>
2020-04-23 07:13:29 +01:00
<Text size='small' weight='medium' color='secondary' hasUnderline={hovering}>
2020-02-19 23:57:07 +00:00
{title}
</Text>
</NavLink>
)
}
2020-04-23 07:13:29 +01:00
2020-02-19 23:57:07 +00:00
}