primevue-mirror/layouts/AppTopBar.vue

164 lines
6.6 KiB
Vue
Raw Normal View History

<template>
2022-02-23 13:44:06 +00:00
<div :ref="containerRef" class="layout-topbar">
2023-02-28 08:29:30 +00:00
<div class="layout-topbar-inner">
2023-07-10 14:42:43 +00:00
<button type="button" class="px-link menu-button" @click="onMenuButtonClick" aria-haspopup aria-label="Menu">
2023-02-28 08:29:30 +00:00
<i class="pi pi-bars"></i>
</button>
2023-03-04 17:18:40 +00:00
<div id="docsearch"></div>
<ul class="flex list-none m-0 p-0 gap-2 align-items-center">
2023-02-28 08:29:30 +00:00
<li>
<a
2023-03-09 08:51:21 +00:00
href="https://github.com/primefaces/primevue"
2023-10-07 10:28:08 +00:00
target="_blank"
rel="noopener noreferrer"
class="flex px-link border-1 border-solid w-2rem h-2rem surface-border border-round surface-card align-items-center justify-content-center transition-all transition-duration-300 hover:border-primary"
2023-02-28 08:29:30 +00:00
>
<i class="pi pi-github text-700"></i>
</a>
</li>
<li>
2023-10-07 10:28:08 +00:00
<a
href="https://discord.gg/gzKFYnpmCY"
target="_blank"
rel="noopener noreferrer"
class="flex px-link border-1 border-solid w-2rem h-2rem surface-border border-round surface-card align-items-center justify-content-center transition-all transition-duration-300 hover:border-primary"
>
2023-02-28 08:29:30 +00:00
<i class="pi pi-discord text-700"></i>
</a>
</li>
2023-10-07 10:28:08 +00:00
<li>
<a
href="https://github.com/orgs/primefaces/discussions"
target="_blank"
rel="noopener noreferrer"
class="flex px-link border-1 border-solid w-2rem h-2rem surface-border border-round surface-card align-items-center justify-content-center transition-all transition-duration-300 hover:border-primary"
>
<i class="pi pi-comments text-700"></i>
</a>
</li>
2023-02-28 08:29:30 +00:00
<li>
<button type="button" class="p-button flex border-1 w-2rem h-2rem p-0 align-items-center justify-content-center transition-all transition-duration-300 min-w-0" @click="onConfigButtonClick">
2023-10-07 10:28:08 +00:00
<i class="pi pi-palette"></i>
2023-02-28 08:29:30 +00:00
</button>
</li>
2021-11-15 07:55:18 +00:00
2023-02-28 08:29:30 +00:00
<li class="relative">
<button
v-styleclass="{ selector: '@next', enterClass: 'hidden', enterActiveClass: 'scalein', leaveToClass: 'hidden', leaveActiveClass: 'fadeout', hideOnOutsideClick: true }"
type="button"
2023-07-10 14:42:43 +00:00
class="px-link flex align-items-center surface-card h-2rem px-3 hover:surface-hover border-1 border-solid surface-border transition-all transition-duration-300 hover:border-primary"
2023-02-28 08:29:30 +00:00
>
<span class="text-900"> {{ versions[0].version }}</span>
<span class="ml-2 pi pi-angle-down text-600"></span>
</button>
2023-01-27 11:56:16 +00:00
2023-02-28 08:29:30 +00:00
<div class="p-3 surface-overlay hidden absolute right-0 top-auto border-round shadow-2 origin-top w-12rem">
<ul class="list-none m-0 p-0">
<li v-for="version in versions" :key="version.version" role="none">
<a :href="version.url" class="block p-2 border-round hover:surface-hover w-full">
<span class="font-bold text-900">{{ version.name }}</span>
<span class="ml-2 text-700">{{ version.version }}</span>
</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
2019-05-21 12:54:05 +00:00
</template>
<script>
2023-02-28 08:29:30 +00:00
import pkg from '@/package.json';
2023-03-04 17:18:40 +00:00
import docsearch from '@docsearch/js';
2022-02-23 19:52:21 +00:00
2019-05-21 12:54:05 +00:00
export default {
2023-02-28 08:29:30 +00:00
emits: ['menubutton-click', 'configbutton-click'],
2020-01-08 08:06:24 +00:00
outsideClickListener: null,
2019-05-21 12:54:05 +00:00
data() {
return {
2023-02-28 08:29:30 +00:00
versions: [
{
name: 'v3',
version: pkg.version,
url: 'https://www.primevue.org'
},
{
name: 'v2',
version: '2.10.1',
url: 'https://www.primefaces.org/primevue-v2'
}
]
2022-09-14 14:26:41 +00:00
};
2019-05-21 12:54:05 +00:00
},
2022-02-23 13:44:06 +00:00
scrollListener: null,
container: null,
2022-02-23 19:01:47 +00:00
mounted() {
2022-02-23 13:44:06 +00:00
this.bindScrollListener();
2023-03-04 17:18:40 +00:00
docsearch({
container: '#docsearch',
appId: '01CMUF4W4R',
indexName: 'primevue',
apiKey: '9bb5939e36897b26ff7de5b7b64d6c43'
});
2022-02-23 13:44:06 +00:00
},
beforeUnmount() {
if (this.scrollListener) {
this.unbindScrollListener();
}
},
2019-05-21 12:54:05 +00:00
methods: {
2023-02-28 08:29:30 +00:00
onConfigButtonClick(event) {
this.$emit('configbutton-click', event);
2019-12-10 08:05:47 +00:00
},
2023-02-28 08:29:30 +00:00
onMenuButtonClick(event) {
this.$emit('menubutton-click', event);
2019-12-10 08:05:47 +00:00
},
2022-02-23 13:44:06 +00:00
bindScrollListener() {
if (!this.scrollListener) {
if (this.container) {
this.scrollListener = () => {
2022-09-14 14:26:41 +00:00
if (window.scrollY > 0) this.container.classList.add('layout-topbar-sticky');
else this.container.classList.remove('layout-topbar-sticky');
};
2022-02-23 13:44:06 +00:00
}
}
2022-12-08 19:24:21 +00:00
2022-02-23 13:44:06 +00:00
window.addEventListener('scroll', this.scrollListener);
},
unbindScrollListener() {
if (this.scrollListener) {
window.removeEventListener('scroll', this.scrollListener);
this.scrollListener = null;
}
},
2020-01-08 08:06:24 +00:00
bindOutsideClickListener() {
if (!this.outsideClickListener) {
this.outsideClickListener = (event) => {
2023-02-28 08:29:30 +00:00
if (this.isOutsideTopbarMenuClicked(event)) {
2020-06-18 09:17:14 +00:00
this.unbindOutsideClickListener();
2019-05-21 12:54:05 +00:00
}
};
2022-12-08 19:24:21 +00:00
2020-01-08 08:06:24 +00:00
document.addEventListener('click', this.outsideClickListener);
2019-05-21 12:54:05 +00:00
}
},
2020-01-08 08:06:24 +00:00
unbindOutsideClickListener() {
if (this.outsideClickListener) {
document.removeEventListener('click', this.outsideClickListener);
this.outsideClickListener = null;
2019-05-21 12:54:05 +00:00
}
},
2020-01-08 08:07:46 +00:00
isOutsideTopbarMenuClicked(event) {
2020-01-08 08:06:24 +00:00
return !(this.$refs.topbarMenu.isSameNode(event.target) || this.$refs.topbarMenu.contains(event.target));
2022-02-23 13:44:06 +00:00
},
containerRef(el) {
this.container = el;
2022-02-24 16:27:26 +00:00
}
2019-05-21 12:54:05 +00:00
}
2022-09-14 14:26:41 +00:00
};
2019-12-20 14:22:50 +00:00
</script>