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

133 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-02-19 23:57:07 +00:00
import classNames from 'classnames/bind'
import Button from './button'
import Icon from './icon'
const cx = classNames.bind(_s)
export default class SidebarSectionItem extends PureComponent {
static propTypes = {
to: PropTypes.string,
2020-03-14 17:31:29 +00:00
href: PropTypes.string,
onClick: PropTypes.func,
2020-02-19 23:57:07 +00:00
active: PropTypes.bool,
icon: PropTypes.string,
image: PropTypes.string,
title: PropTypes.string,
me: PropTypes.bool,
suffix: PropTypes.node,
2020-03-14 17:31:29 +00:00
buttonRef: PropTypes.func,
2020-02-19 23:57:07 +00:00
}
state = {
hovering: false,
}
handleOnMouseEnter = () => {
this.setState({ hovering: true })
}
handleOnMouseLeave = () => {
this.setState({ hovering: false })
}
render() {
2020-03-14 17:31:29 +00:00
const {
to,
active,
icon,
image,
title,
me,
count,
onClick,
href,
buttonRef
} = this.props
2020-02-19 23:57:07 +00:00
const { hovering } = this.state
const iconSize = '16px'
const shouldShowActive = hovering || active
const isNotifications = to === '/notifications'
const containerClasses = cx({
default: 1,
maxWidth100PC: 1,
width100PC: 1,
flexRow: 1,
2020-03-11 23:56:18 +00:00
py5: 1,
px10: 1,
2020-02-19 23:57:07 +00:00
alignItemsCenter: 1,
radiusSmall: 1,
// border1PX: shouldShowActive,
2020-02-21 00:57:29 +00:00
// borderColorSecondary: shouldShowActive,
2020-02-19 23:57:07 +00:00
backgroundSubtle2: shouldShowActive,
2020-03-14 17:31:29 +00:00
backgroundTransparent: 1,
2020-02-19 23:57:07 +00:00
})
const textClasses = cx({
default: 1,
fontWeightNormal: 1,
fontSize15PX: 1,
text: 1,
textOverflowEllipsis: 1,
colorPrimary: shouldShowActive || me,
colorSecondary: !hovering && !active && !me,
})
const iconClasses = cx({
fillColorBlack: shouldShowActive,
2020-03-14 17:31:29 +00:00
fillColorSecondary: !hovering && !active,
2020-02-19 23:57:07 +00:00
})
const countClasses = cx({
default: 1,
text: 1,
marginLeftAuto: 1,
fontSize12PX: 1,
2020-03-11 23:56:18 +00:00
px5: 1,
mr2: 1,
2020-02-19 23:57:07 +00:00
lineHeight15: 1,
2020-03-11 23:56:18 +00:00
ml5: 1,
2020-02-19 23:57:07 +00:00
colorSecondary: !isNotifications,
colorWhite: isNotifications,
backgroundColorBrand: isNotifications,
radiusSmall: isNotifications,
})
return (
2020-03-14 17:31:29 +00:00
<Button
2020-02-19 23:57:07 +00:00
to={to}
2020-03-14 17:31:29 +00:00
href={href}
onClick={onClick}
noClasses
buttonRef={buttonRef}
2020-02-19 23:57:07 +00:00
onMouseEnter={() => this.handleOnMouseEnter()}
onMouseLeave={() => this.handleOnMouseLeave()}
2020-03-27 15:29:52 +00:00
className={[_s.default, _s.noUnderline, _s.cursorPointer, _s.width100PC, _s.backgroundTransparent].join(' ')}
2020-02-19 23:57:07 +00:00
>
<div className={containerClasses}>
<div className={[_s.default]}>
{ icon && <Icon id={icon} className={iconClasses} width={iconSize} height={iconSize} /> }
{ image &&
<img
className={[_s.default, _s.circle].join(' ')}
width={iconSize}
height={iconSize}
src={image}
/>
}
</div>
2020-03-11 23:56:18 +00:00
<div className={[_s.default, _s.flexNormal, _s.px10, _s.textOverflowEllipsis, _s.overflowWrapBreakWord, _s.flexRow, _s.width100PC].join(' ')}>
2020-02-19 23:57:07 +00:00
<span className={textClasses}>{title}</span>
</div>
{ count > 0 &&
<span className={countClasses}>
{count}
</span>
}
</div>
2020-03-14 17:31:29 +00:00
</Button>
2020-02-19 23:57:07 +00:00
)
}
}