2018-05-02 00:05:36 +00:00
|
|
|
|
<a class='main-nav-link {selected ? "selected" : ""}'
|
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
|
aria-current={selected}
|
2018-04-11 05:51:42 +00:00
|
|
|
|
on:click="onClick(event)"
|
2019-02-14 02:40:02 +00:00
|
|
|
|
rel="prefetch"
|
2018-05-02 00:05:36 +00:00
|
|
|
|
{href} >
|
2018-05-03 04:32:43 +00:00
|
|
|
|
<div class="nav-icon-and-label">
|
2019-02-19 00:27:52 +00:00
|
|
|
|
<NavItemIcon
|
|
|
|
|
{showBadge}
|
|
|
|
|
{badgeNumber}
|
|
|
|
|
{svg}
|
|
|
|
|
/>
|
2018-05-03 04:32:43 +00:00
|
|
|
|
<span class="nav-link-label">{label}</span>
|
|
|
|
|
</div>
|
2019-07-22 02:31:19 +00:00
|
|
|
|
<div class="nav-indicator" ref:indicator></div>
|
2018-01-13 07:24:05 +00:00
|
|
|
|
</a>
|
|
|
|
|
<style>
|
2018-01-20 20:35:38 +00:00
|
|
|
|
.main-nav-link {
|
2018-01-13 07:24:05 +00:00
|
|
|
|
text-decoration: none;
|
2018-05-03 04:32:43 +00:00
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
flex: 1;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.nav-icon-and-label {
|
2018-03-27 16:34:29 +00:00
|
|
|
|
padding: 15px 20px;
|
2018-01-13 07:24:05 +00:00
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
2018-03-27 16:34:29 +00:00
|
|
|
|
flex: 1;
|
2018-01-13 07:24:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:35:38 +00:00
|
|
|
|
.main-nav-link.selected {
|
2018-01-13 07:24:05 +00:00
|
|
|
|
background: var(--nav-a-selected-bg);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:35:38 +00:00
|
|
|
|
.main-nav-link.selected:hover {
|
2018-01-13 07:24:05 +00:00
|
|
|
|
background: var(--nav-a-selected-bg-hover);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-03 04:32:43 +00:00
|
|
|
|
.nav-indicator {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 1px;
|
|
|
|
|
background: var(--nav-a-border);
|
|
|
|
|
transform-origin: left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.nav-indicator.animate {
|
|
|
|
|
transition: transform 333ms ease-in-out;
|
2018-12-12 06:06:56 +00:00
|
|
|
|
will-change: transform;
|
2018-05-03 04:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.main-nav-link:hover .nav-indicator {
|
|
|
|
|
background: var(--nav-a-border-hover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.main-nav-link.selected .nav-indicator {
|
|
|
|
|
background: var(--nav-a-selected-border);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.main-nav-link.selected:hover .nav-indicator {
|
|
|
|
|
background: var(--nav-a-selected-border-hover);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:35:38 +00:00
|
|
|
|
.main-nav-link:hover {
|
2018-01-13 07:24:05 +00:00
|
|
|
|
background-color: var(--nav-a-bg-hover);
|
2018-03-14 14:24:24 +00:00
|
|
|
|
text-decoration: none;
|
2018-01-13 07:24:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 06:21:23 +00:00
|
|
|
|
.main-nav-link:hover .nav-link-label {
|
2018-01-13 07:24:05 +00:00
|
|
|
|
color: var(--nav-text-color-hover);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-16 03:03:18 +00:00
|
|
|
|
.main-nav-link:active {
|
|
|
|
|
background-color: var(--nav-active-bg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.main-nav-link.selected:active {
|
|
|
|
|
background-color: var(--nav-a-selected-active-bg);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 00:21:35 +00:00
|
|
|
|
.nav-link-label {
|
2018-01-13 07:24:05 +00:00
|
|
|
|
font-size: 16px;
|
|
|
|
|
color: var(--nav-text-color);
|
|
|
|
|
padding-left: 10px;
|
2018-01-23 05:16:27 +00:00
|
|
|
|
white-space: nowrap;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
2018-01-13 07:24:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 02:01:00 +00:00
|
|
|
|
@media (max-width: 991px) {
|
2018-02-16 06:21:23 +00:00
|
|
|
|
.main-nav-link .nav-link-label {
|
2018-01-13 07:24:05 +00:00
|
|
|
|
display: none;
|
|
|
|
|
}
|
2018-05-03 04:32:43 +00:00
|
|
|
|
.nav-icon-and-label {
|
2018-01-31 06:40:40 +00:00
|
|
|
|
padding: 20px 0;
|
2018-01-28 23:53:49 +00:00
|
|
|
|
}
|
2018-01-13 07:24:05 +00:00
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
<script>
|
2019-02-19 00:27:52 +00:00
|
|
|
|
import NavItemIcon from './NavItemIcon.html'
|
2018-02-16 06:21:23 +00:00
|
|
|
|
import { store } from '../_store/store'
|
2018-05-03 04:32:43 +00:00
|
|
|
|
import { on, emit } from '../_utils/eventBus'
|
|
|
|
|
import { mark, stop } from '../_utils/marks'
|
|
|
|
|
import { doubleRAF } from '../_utils/doubleRAF'
|
2019-03-18 16:09:24 +00:00
|
|
|
|
import { scrollToTop } from '../_utils/scrollToTop'
|
2018-02-16 06:21:23 +00:00
|
|
|
|
|
|
|
|
|
export default {
|
2018-05-03 04:32:43 +00:00
|
|
|
|
oncreate () {
|
2019-08-03 20:49:37 +00:00
|
|
|
|
const { name } = this.get()
|
|
|
|
|
const indicator = this.refs.indicator
|
2018-08-30 04:42:57 +00:00
|
|
|
|
on('animateNavPart1', this, ({ fromPage, toPage }) => {
|
2018-05-03 04:32:43 +00:00
|
|
|
|
if (fromPage !== name) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
mark('animateNavPart1 gBCR')
|
2019-08-03 20:49:37 +00:00
|
|
|
|
const fromRect = indicator.getBoundingClientRect()
|
2018-05-03 04:32:43 +00:00
|
|
|
|
stop('animateNavPart1 gBCR')
|
2018-08-30 04:42:57 +00:00
|
|
|
|
emit('animateNavPart2', { fromRect, fromPage, toPage })
|
2018-05-03 04:32:43 +00:00
|
|
|
|
})
|
2018-08-30 04:42:57 +00:00
|
|
|
|
on('animateNavPart2', this, ({ fromPage, fromRect, toPage }) => {
|
2018-05-03 04:32:43 +00:00
|
|
|
|
if (toPage !== name) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
mark('animateNavPart2 gBCR')
|
2019-08-03 20:49:37 +00:00
|
|
|
|
const toRect = indicator.getBoundingClientRect()
|
2018-05-03 04:32:43 +00:00
|
|
|
|
stop('animateNavPart2 gBCR')
|
2019-08-03 20:49:37 +00:00
|
|
|
|
const translateX = fromRect.left - toRect.left
|
|
|
|
|
const scaleX = fromRect.width / toRect.width
|
2018-05-03 04:32:43 +00:00
|
|
|
|
indicator.style.transform = `translateX(${translateX}px) scaleX(${scaleX})`
|
2019-08-03 20:49:37 +00:00
|
|
|
|
const onTransitionEnd = () => {
|
2018-05-03 04:32:43 +00:00
|
|
|
|
indicator.removeEventListener('transitionend', onTransitionEnd)
|
|
|
|
|
indicator.classList.remove('animate')
|
|
|
|
|
}
|
|
|
|
|
indicator.addEventListener('transitionend', onTransitionEnd)
|
|
|
|
|
doubleRAF(() => {
|
|
|
|
|
indicator.classList.add('animate')
|
|
|
|
|
indicator.style.transform = ''
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
2018-02-16 06:21:23 +00:00
|
|
|
|
store: () => store,
|
|
|
|
|
computed: {
|
2019-05-05 00:58:44 +00:00
|
|
|
|
selected: ({ page, name }) => {
|
|
|
|
|
return page === name ||
|
|
|
|
|
// special case – these should both highlight the notifications tab icon
|
|
|
|
|
(name === 'notifications' && page === 'notifications/mentions')
|
|
|
|
|
},
|
2018-05-02 00:05:36 +00:00
|
|
|
|
ariaLabel: ({ selected, name, label, $numberOfNotifications }) => {
|
2018-02-16 06:58:18 +00:00
|
|
|
|
let res = label
|
2018-04-11 05:51:42 +00:00
|
|
|
|
if (selected) {
|
2018-02-16 06:58:18 +00:00
|
|
|
|
res += ' (current page)'
|
|
|
|
|
}
|
2018-02-19 01:28:08 +00:00
|
|
|
|
if (name === 'notifications' && $numberOfNotifications) {
|
2018-12-30 22:51:03 +00:00
|
|
|
|
res += ` (${$numberOfNotifications} notification${$numberOfNotifications === 1 ? '' : 's'})`
|
2018-02-16 06:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
return res
|
2018-09-01 20:24:02 +00:00
|
|
|
|
},
|
2019-02-19 00:27:52 +00:00
|
|
|
|
showBadge: ({ name, $hasNotifications }) => name === 'notifications' && $hasNotifications,
|
|
|
|
|
badgeNumber: ({ name, $numberOfNotifications }) => name === 'notifications' && $numberOfNotifications
|
2018-04-11 05:51:42 +00:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
2018-04-20 04:38:01 +00:00
|
|
|
|
onClick (e) {
|
2019-08-03 20:49:37 +00:00
|
|
|
|
const { selected } = this.get()
|
2018-04-19 16:37:05 +00:00
|
|
|
|
if (!selected) {
|
2018-04-11 05:51:42 +00:00
|
|
|
|
return
|
|
|
|
|
}
|
2019-03-18 16:09:24 +00:00
|
|
|
|
if (scrollToTop(/* smooth */ true)) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
e.stopPropagation()
|
2019-02-16 03:03:18 +00:00
|
|
|
|
}
|
2018-04-11 05:51:42 +00:00
|
|
|
|
}
|
2019-02-19 00:27:52 +00:00
|
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
|
NavItemIcon
|
2018-02-16 06:21:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-07 16:20:16 +00:00
|
|
|
|
</script>
|