refactor: header.vue to composition api
Some checks failed
ci/woodpecker/pr/lint-backend Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint-client Pipeline failed
ci/woodpecker/pr/test Pipeline failed

This commit is contained in:
Norm 2022-07-28 22:42:12 -04:00
parent b7c0e26da9
commit 2938ff368e
Signed by: norm
GPG key ID: 7123E30E441E80DE

View file

@ -1,5 +1,5 @@
<template> <template>
<div class="sqxihjet"> <div ref="header" class="sqxihjet">
<div v-if="narrow === false" class="wide"> <div v-if="narrow === false" class="wide">
<div class="content"> <div class="content">
<MkA to="/" class="link" active-class="active"><i class="fas fa-home icon"></i>{{ $ts.home }}</MkA> <MkA to="/" class="link" active-class="active"><i class="fas fa-home icon"></i>{{ $ts.home }}</MkA>
@ -13,7 +13,9 @@
<span v-if="info.title" class="text">{{ info.title }}</span> <span v-if="info.title" class="text">{{ info.title }}</span>
<MkUserName v-else-if="info.userName" :user="info.userName" :nowrap="false" class="text"/> <MkUserName v-else-if="info.userName" :user="info.userName" :nowrap="false" class="text"/>
</div> </div>
<button v-if="info.action" class="_button action" @click.stop="info.action.handler"><!-- TODO --></button> <button v-if="info.action" class="_button action" @click.stop="info.action.handler">
<!-- TODO -->
</button>
</div> </div>
<div class="right"> <div class="right">
<button class="_button search" @click="search()"><i class="fas fa-search icon"></i><span>{{ $ts.search }}</span></button> <button class="_button search" @click="search()"><i class="fas fa-search icon"></i><span>{{ $ts.search }}</span></button>
@ -22,8 +24,8 @@
</div> </div>
</div> </div>
</div> </div>
<div v-else-if="narrow === true" class="narrow"> <div v-else-if="narrow" class="narrow">
<button class="menu _button" @click="$parent.showMenu = true"> <button class="menu _button" @click="showMenu = true">
<i class="fas fa-bars icon"></i> <i class="fas fa-bars icon"></i>
</button> </button>
<div v-if="info" class="title"> <div v-if="info" class="title">
@ -39,47 +41,38 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { onMounted, ref, Ref } from 'vue';
import XSigninDialog from '@/components/signin-dialog.vue'; import XSigninDialog from '@/components/signin-dialog.vue';
import XSignupDialog from '@/components/signup-dialog.vue'; import XSignupDialog from '@/components/signup-dialog.vue';
import * as os from '@/os'; import * as os from '@/os';
import { search } from '@/scripts/search'; import { search } from '@/scripts/search';
export default defineComponent({ defineProps<{
props: { info: any;
info: { }>();
required: true
},
},
data() { const narrow = ref(false);
return { const showMenu = ref(false);
narrow: null, const header: Ref<HTMLElement | null> = ref(null);
showMenu: false,
};
},
mounted() { onMounted(() => {
this.narrow = this.$el.clientWidth < 1300; if (header.value) {
}, narrow.value = header.value.clientWidth < 1300;
methods: {
signin() {
os.popup(XSigninDialog, {
autoSet: true
}, {}, 'closed');
},
signup() {
os.popup(XSignupDialog, {
autoSet: true
}, {}, 'closed');
},
search
} }
}); });
function signin(): void {
os.popup(XSigninDialog, {
autoSet: true,
}, {}, 'closed');
}
function signup(): void {
os.popup(XSignupDialog, {
autoSet: true,
}, {}, 'closed');
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -94,14 +87,14 @@ export default defineComponent({
backdrop-filter: var(--blur, blur(32px)); backdrop-filter: var(--blur, blur(32px));
background-color: var(--X16); background-color: var(--X16);
> .wide { >.wide {
> .content { >.content {
max-width: 1400px; max-width: 1400px;
margin: 0 auto; margin: 0 auto;
display: flex; display: flex;
align-items: center; align-items: center;
> .link { >.link {
$line: 3px; $line: 3px;
display: inline-block; display: inline-block;
padding: 0 16px; padding: 0 16px;
@ -109,7 +102,7 @@ export default defineComponent({
border-top: solid $line transparent; border-top: solid $line transparent;
border-bottom: solid $line transparent; border-bottom: solid $line transparent;
> .icon { >.icon {
margin-right: 0.5em; margin-right: 0.5em;
} }
@ -118,8 +111,8 @@ export default defineComponent({
} }
} }
> .page { >.page {
> .title { >.title {
display: inline-block; display: inline-block;
vertical-align: bottom; vertical-align: bottom;
white-space: nowrap; white-space: nowrap;
@ -127,11 +120,11 @@ export default defineComponent({
text-overflow: ellipsis; text-overflow: ellipsis;
position: relative; position: relative;
> .icon + .text { >.icon+.text {
margin-left: 8px; margin-left: 8px;
} }
> .avatar { >.avatar {
$size: 32px; $size: 32px;
display: inline-block; display: inline-block;
width: $size; width: $size;
@ -151,17 +144,11 @@ export default defineComponent({
box-shadow: 0 -2px 0 0 var(--accent) inset; box-shadow: 0 -2px 0 0 var(--accent) inset;
color: var(--fgHighlighted); color: var(--fgHighlighted);
} }
}
> .action { el>.right {
padding: 0 0 0 16px;
}
}
> .right {
margin-left: auto; margin-left: auto;
> .search { >.search {
background: var(--bg); background: var(--bg);
border-radius: 999px; border-radius: 999px;
width: 230px; width: 230px;
@ -169,39 +156,39 @@ export default defineComponent({
margin-right: 16px; margin-right: 16px;
text-align: left; text-align: left;
> * { >* {
opacity: 0.7; opacity: 0.7;
} }
> .icon { >.icon {
padding: 0 16px; padding: 0 16px;
} }
} }
> .signup { >.signup {
border-radius: 999px; border-radius: 999px;
padding: 0 24px; padding: 0 24px;
line-height: $height - 20px; line-height: $height - 20px;
} }
> .login { >.login {
padding: 0 16px; padding: 0 16px;
} }
} }
} }
} }
> .narrow { >.narrow {
display: flex; display: flex;
> .menu, >.menu,
> .action { >.action {
width: $height; width: $height;
height: $height; height: $height;
font-size: 20px; font-size: 20px;
} }
> .title { >.title {
flex: 1; flex: 1;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
@ -209,11 +196,11 @@ export default defineComponent({
position: relative; position: relative;
text-align: center; text-align: center;
> .icon + .text { >.icon+.text {
margin-left: 8px; margin-left: 8px;
} }
> .avatar { >.avatar {
$size: 32px; $size: 32px;
display: inline-block; display: inline-block;
width: $size; width: $size;
@ -224,5 +211,7 @@ export default defineComponent({
} }
} }
} }
}
}
} }
</style> </style>