2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-07-25 00:51:14 +01:00
|
|
|
import { CX } from '../constants'
|
|
|
|
import Button from './button'
|
|
|
|
import Icon from './icon'
|
|
|
|
import Text from './text'
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
class NavigationBarButton extends React.PureComponent {
|
2020-07-25 00:51:14 +01:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
title,
|
|
|
|
icon,
|
|
|
|
to,
|
|
|
|
href,
|
|
|
|
attrTitle,
|
2020-10-29 04:15:37 +00:00
|
|
|
count,
|
2020-10-16 23:00:33 +01:00
|
|
|
onClick,
|
2020-10-30 03:56:22 +00:00
|
|
|
isXS,
|
2020-07-25 00:51:14 +01:00
|
|
|
} = this.props
|
|
|
|
|
2020-11-03 21:09:13 +00:00
|
|
|
const active = `${window.location.pathname}`.indexOf(`${to}`) > -1
|
2020-07-25 00:51:14 +01:00
|
|
|
|
|
|
|
const classes = CX({
|
2020-08-18 21:49:11 +01:00
|
|
|
d: 1,
|
2020-08-18 21:43:06 +01:00
|
|
|
h53PX: 1,
|
|
|
|
aiCenter: 1,
|
|
|
|
jcCenter: 1,
|
2020-07-25 00:51:14 +01:00
|
|
|
outlineNone: 1,
|
|
|
|
cursorPointer: 1,
|
|
|
|
bgTransparent: 1,
|
|
|
|
noUnderline: 1,
|
|
|
|
colorNavigation: 1,
|
2020-11-03 21:09:13 +00:00
|
|
|
px15: !!title && !!icon,
|
2020-10-30 03:56:22 +00:00
|
|
|
px5: !title && !isXS,
|
|
|
|
px2: !title && isXS,
|
|
|
|
py5: !title && !isXS,
|
2020-08-18 21:43:06 +01:00
|
|
|
cWhite: !!title,
|
2020-07-25 00:51:14 +01:00
|
|
|
fs13PX: !!title,
|
2020-08-18 21:43:06 +01:00
|
|
|
fw400: !!title,
|
2020-10-29 04:15:37 +00:00
|
|
|
navigationUnderlineActive: !!title && active,
|
2020-07-25 00:51:14 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const iconClasses = CX({
|
2020-11-03 21:09:13 +00:00
|
|
|
inherit: (!!title || active) || isXS,
|
2020-10-30 03:56:22 +00:00
|
|
|
fillNavigationBlend: !title && !isXS,
|
|
|
|
px2: !title && !isXS,
|
|
|
|
py5: !title && !isXS,
|
|
|
|
px5: !title,
|
|
|
|
mr2: !title && isXS,
|
|
|
|
ml2: !title && isXS,
|
2020-07-25 00:51:14 +01:00
|
|
|
})
|
|
|
|
|
2020-10-29 04:15:37 +00:00
|
|
|
const countClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
fs12PX: 1,
|
|
|
|
posAbs: 1,
|
|
|
|
top0: 1,
|
|
|
|
mt15: 1,
|
|
|
|
right0: 1,
|
|
|
|
mr5: 1,
|
|
|
|
h4PX: 1,
|
|
|
|
w4PX: 1,
|
|
|
|
cBrand: 1,
|
|
|
|
bgNavigationBlend: 1,
|
|
|
|
radiusSmall: 1,
|
|
|
|
})
|
|
|
|
|
2020-10-30 03:56:22 +00:00
|
|
|
const iconContainerClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
aiCenter: 1,
|
|
|
|
jcCenter: 1,
|
|
|
|
bgNavigationBlendLight: !title,
|
|
|
|
circle: !title,
|
|
|
|
px5: !title,
|
|
|
|
py5: !title,
|
|
|
|
py10: !title && isXS,
|
|
|
|
})
|
|
|
|
|
2020-11-03 21:09:13 +00:00
|
|
|
const titleClasses = CX({
|
|
|
|
mt5: !!icon,
|
|
|
|
bgNavigationBlendLight: !!title && !icon,
|
|
|
|
px15: !!title && !icon,
|
|
|
|
py10: !!title && !icon,
|
|
|
|
radiusSmall: !!title && !icon,
|
|
|
|
})
|
|
|
|
|
2020-10-29 04:15:37 +00:00
|
|
|
const iconSize = !!title ? '18px' : '20px'
|
2020-11-03 21:09:13 +00:00
|
|
|
const titleSize = !!icon ? 'extraSmall' : 'large'
|
|
|
|
const titleWeight = !!icon ? 'normal' : 'bold'
|
2020-07-25 00:51:14 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
to={to}
|
|
|
|
href={href}
|
|
|
|
title={attrTitle}
|
2020-10-16 23:00:33 +01:00
|
|
|
onClick={onClick}
|
2020-07-25 00:51:14 +01:00
|
|
|
className={classes}
|
|
|
|
noClasses
|
2020-10-29 04:15:37 +00:00
|
|
|
>
|
2020-11-03 21:09:13 +00:00
|
|
|
{
|
|
|
|
!!icon &&
|
|
|
|
<div className={iconContainerClasses}>
|
|
|
|
<Icon className={iconClasses} id={icon} size={iconSize} />
|
|
|
|
</div>
|
|
|
|
}
|
2020-07-25 00:51:14 +01:00
|
|
|
{
|
|
|
|
!!title &&
|
2020-11-03 21:09:13 +00:00
|
|
|
<Text color='inherit' size={titleSize} weight={titleWeight} className={titleClasses}>
|
2020-07-25 00:51:14 +01:00
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
}
|
2020-10-29 04:15:37 +00:00
|
|
|
{
|
|
|
|
!title && count > 0 &&
|
|
|
|
<span className={countClasses} />
|
|
|
|
}
|
2020-07-25 00:51:14 +01:00
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NavigationBarButton.propTypes = {
|
|
|
|
title: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
|
|
|
to: PropTypes.string,
|
|
|
|
href: PropTypes.string,
|
|
|
|
attrTitle: PropTypes.string,
|
2020-10-29 04:15:37 +00:00
|
|
|
count: PropTypes.number,
|
2020-10-16 23:00:33 +01:00
|
|
|
onClick: PropTypes.func,
|
2020-10-30 03:56:22 +00:00
|
|
|
isXS: PropTypes.bool,
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default NavigationBarButton
|