Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(MobileMenu & TheNavbar): convert to UnoCSS, reduce boilerplate #91

Merged
merged 31 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
30689f9
chore(package.json): add stylelint command
Readpato Aug 21, 2023
561e29f
refactor(App.vue): add proper RouterView casing
Readpato Aug 21, 2023
c1cfbd2
refactor(MobileMenu): add correct boolean type
Readpato Aug 21, 2023
f8fbbcb
refactor(App.vue): add space ahead of title
Readpato Aug 21, 2023
13c86d5
refactor(MobileMenu): convert to UnoCSS when possible
Readpato Aug 21, 2023
94d687b
refactor(CtaComponent): add safeguards for attributes
Readpato Aug 22, 2023
2e79788
refactor(useCtaComponent): add correct types and safeguarding
Readpato Aug 22, 2023
0c5350d
refactor(TheNavbar): utilize new single CtaComponent for links:
Readpato Aug 22, 2023
4b81dcd
refactor(TheNavbar): simplify computed boilerplate
Readpato Aug 23, 2023
89244ee
style(TheNavbar): update anchor style to UnoCSS
Readpato Aug 23, 2023
3c1b441
refactor(TheNavbar): simplify styles
Readpato Aug 24, 2023
4824065
feat(CtaIcon): create component
Readpato Sep 1, 2023
5746eea
refactor(TheNavbar): convert to UnoCSS, utilize CtaComponent and CtaIcon
Readpato Sep 1, 2023
eb1f601
refactor(TheNavbar): simplify logic naming
Readpato Sep 2, 2023
2e01a70
refactor(MobileMenu): simplify logic naming, separate own logic from …
Readpato Sep 2, 2023
a577e02
refactor(MobileMenu): simplify template and style boilerplate
Readpato Sep 2, 2023
2244293
refactor(TheNavbar): pass links to child
Readpato Sep 2, 2023
6622553
refactor(MobileMenu): simplify template and rewrite transition
Readpato Sep 2, 2023
5db1c10
refactor(TheNavbar): add MobileMenu as sticky component
Readpato Sep 2, 2023
7591981
feat(variables): add reduced opacity bg variables
Readpato Sep 3, 2023
f51c1d8
refactor(variables): increase opacity
Readpato Sep 3, 2023
88e8cf5
style(MobileMenu): change border style
Readpato Sep 3, 2023
582fe4d
refactor(TheNavbar): add blur to background and bottom border
Readpato Sep 3, 2023
ff085f7
refactor(TheNavbar): add correct i18n variables
Readpato Sep 4, 2023
72c0f6c
refactor(MobileMenu): correctly reset state
Readpato Sep 4, 2023
2850268
feat(useLockScroll): create function to lock page scroll
Readpato Sep 5, 2023
5653c33
fix(MobileMenu): prevent mobile menu to block scroll
Readpato Sep 6, 2023
8bdc2a6
refactor(TheNavbar): block scroll when mobile is open
Readpato Sep 6, 2023
be8aa38
refactor(useGlobalScrollLock): rename function to be more accurate
Readpato Sep 6, 2023
f83d46a
refactor(TheNavbar): implement function
Readpato Sep 6, 2023
b52b1bc
refactor(App): add correct casing to RouterView
Readpato Sep 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dev": "vite --host",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:scss": "stylelint \"./**/*.{css,scss,sass,vue}\"",
"serve": "vite preview",
"test": "vitest",
"coverage": "vitest run --coverage",
Expand Down
12 changes: 7 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import TheNavbar from '@/components/layout/TheNavbar.vue'
</script>

<template>
<TheNavbar />
<router-view />
<TheContributing />
<TheFooter />
<div class="relative">
<TheNavbar />
<RouterView />
<TheContributing />
<TheFooter />
</div>
</template>

<style lang="scss">
Expand Down Expand Up @@ -67,7 +69,7 @@ body {
vertical-align: super;
}

//Animations
// Animations

@keyframes scale {
0% {
Expand Down
32 changes: 32 additions & 0 deletions src/components/buttons/CtaIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script setup lang="ts">
import { useAttrs } from 'vue'
import { useCtaComponent } from '@/functions/useCtaComponent'

defineProps<{
icon: string
small?: boolean
}>()

const { component, bindings } = useCtaComponent(useAttrs())
</script>

<template>
<component
:is="component"
v-bind="bindings"
class="button mx-1 px-1 py-0.5 rounded-1"
:class="{ small }"
>
<i :class="icon" />
</component>
</template>

<style lang="scss" scoped>
.button {
font-size: rem(20px);

&.small {
font-size: rem(16px);
}
}
</style>
149 changes: 43 additions & 106 deletions src/components/layout/MobileMenu.vue
Original file line number Diff line number Diff line change
@@ -1,138 +1,75 @@
<script setup lang="ts">
import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'
import { watch } from 'vue'
import CtaComponent from '@/components/buttons/CtaComponent.vue'

interface Link {
id: string
to?: string
test?: string
text?: string
href?: string
target?: string
icon?: string
}

const props = defineProps<{
showMobileMenu: Boolean
smallerThanLg: Boolean
links: Link[]
show: boolean
}>()

const emit = defineEmits<{
(e: 'onCloseMenu'): void
(e: 'close'): void
}>()

const breakpoints = useBreakpoints(breakpointsTailwind)
const smallerThanMd = breakpoints.smaller('md')

watch(smallerThanMd, (value) => {
if (props.show && !value)
emit('close')
})
</script>

<template>
<transition name="slide">
<div v-if="props.showMobileMenu && props.smallerThanLg" class="mobile-menu-container">
<div class="mobile-menu-header">
<div class="logo">
<router-link
data-test="mobile-homepage-link"
:to="{ name: 'Home' }"
@click="emit('onCloseMenu')"
>
<img alt="SH logo" width="36" src="@/assets/sh-logo-small.png">
</router-link>
</div>
<button class="close-header" data-test="mobile-burger-menu-cta" @click="emit('onCloseMenu')">
<i class="fas fa-hamburger" />
</button>
</div>
<nav>
<div class="navbar" data-test="mobile-nav-link-wrapper">
<a
data-test="mobile-github-page-link"
href="https://github.com/Schrodinger-Hat"
target="_blank"
@click="emit('onCloseMenu')"
>GitHub
</a>
<router-link
data-test="mobile-team-page-link"
:to="{ name: 'Team' }"
@click="emit('onCloseMenu')"
>
{{ $t('navbar.team') }}
</router-link>
<router-link
data-test="mobile-event-page-link"
:to="{ name: 'EventList' }"
@click="emit('onCloseMenu')"
>
{{ $t('navbar.events') }}
</router-link>
<router-link
data-test="mobile-conduct-page-link"
:to="{ name: 'CodeOfConduct' }"
@click="emit('onCloseMenu')"
>
{{ $t('navbar.codeOfConduct') }}
</router-link>
<a
data-test="mobile-go-nord-page-link"
href="https://ign.schrodinger-hat.it"
target="_blank"
@click="emit('onCloseMenu')"
> ImageGoNord </a>
</div>
</nav>
</div>
<nav v-if="show && smallerThanMd" class="menu">
<CtaComponent
v-for="{ id, href, to, text, test, target } in links"
:key="id"
:data-test="`data-${test}`"
:href="href"
:target="target ? target : null"
:to="to ? { name: to } : null"
class="head-6 link block py-4 cursor-pointer border-b border-b-slate-300 dark:border-b-slate-50/[0.06] "
@click="$emit('close')"
>
<span>{{ $t(text as string) }}</span>
</CtaComponent>
</nav>
</transition>
</template>

<style scoped lang="scss">
.mobile-menu-container {
position: fixed;
z-index: 1;
left: 0;
width: 100%;
height: calc(100vh);
.menu {
background: $bg-primary;
transition: all 0.4s ease-in 0s;

nav {
.navbar {
text-align: center;

a {
display: block;
padding: 0.8em 0;
border-bottom: 1px solid $bg-secondary;
font-size: 1.3em;

&:last-child {
border-bottom: none;
}
}
}
}
}

.#{$dark-mode-class} {
.mobile-menu-container {
.menu{
background: $dark-bg-primary;
}
}

.slide-enter-active,
.slide-leave-active {
bottom: 0;
opacity: 1;
transition: bottom 0.25s ease-out 0s, opacity 0.3s ease-in-out 0s;
transition: 0.25s ease-out 0s;
}

.slide-enter-from,
.slide-leave-to {
bottom: 100vh;
opacity: 0;
}

.mobile-menu-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem;
}

button {
border: none;
border-radius: 0.25em;
margin: 0 0.4em;
background-color: transparent;
cursor: pointer;
font-size: 1.2em;
transition: background-color 100ms ease-in-out 0s;

&:hover {
background-color: $bg-secondary;
}
transform: translateY(-100%);
}
</style>
Loading