|
1 | 1 | <script setup lang="ts">
|
2 |
| -import { onMounted } from "vue"; |
| 2 | +import { onMounted } from 'vue' |
| 3 | +import { DISCORD_URL, GITHUB_URL, INSTAGRAM_URL, LINKEDIN_URL, TWITTER_URL, WHATSAPP_URL } from '@/constants' |
3 | 4 |
|
4 |
| -const router = useRouter(); |
| 5 | +const router = useRouter() |
5 | 6 |
|
6 | 7 | interface TMenuItem {
|
7 |
| - title: string; |
8 |
| - href: string; |
9 |
| - class?: string; |
10 |
| - children?: TMenuItem[]; |
| 8 | + title: string |
| 9 | + href: string |
| 10 | + class?: string |
| 11 | + children?: TMenuItem[] |
11 | 12 | }
|
12 | 13 |
|
13 | 14 | interface TMenu {
|
14 |
| - [key: string]: TMenuItem; |
| 15 | + [key: string]: TMenuItem |
15 | 16 | }
|
16 | 17 |
|
17 | 18 | const links: TMenu = {
|
18 | 19 | about: {
|
19 |
| - title: "About", |
20 |
| - href: "/about", |
21 |
| - class: "hidden md:block", |
| 20 | + title: 'About', |
| 21 | + href: '/about', |
| 22 | + class: 'hidden md:block', |
22 | 23 | children: [
|
23 | 24 | // {
|
24 | 25 | // title: 'FAQ',
|
25 | 26 | // href: '/faq',
|
26 | 27 | // class: '',
|
27 | 28 | // },
|
28 | 29 | {
|
29 |
| - title: "History", |
30 |
| - href: "/history", |
31 |
| - class: "", |
| 30 | + title: 'History', |
| 31 | + href: '/history', |
| 32 | + class: '', |
32 | 33 | },
|
33 | 34 | {
|
34 |
| - title: "Contribute", |
35 |
| - href: "/contribute", |
36 |
| - class: "", |
| 35 | + title: 'Contribute', |
| 36 | + href: '/contribute', |
| 37 | + class: '', |
37 | 38 | },
|
38 | 39 | {
|
39 |
| - title: "Code of conduct", |
40 |
| - href: "/code_of_conduct", |
41 |
| - class: "", |
| 40 | + title: 'Code of conduct', |
| 41 | + href: '/code_of_conduct', |
| 42 | + class: '', |
42 | 43 | },
|
43 | 44 | {
|
44 |
| - title: "Coding Guidelines", |
45 |
| - href: "/coding_guidelines", |
46 |
| - class: "", |
| 45 | + title: 'Coding Guidelines', |
| 46 | + href: '/coding_guidelines', |
| 47 | + class: '', |
47 | 48 | },
|
48 | 49 | {
|
49 |
| - title: "WhatsApp", |
50 |
| - href: "https://chat.whatsapp.com/invite/0kQ2QX0ZQ0j1YQ4X6Q4Q4Q", |
51 |
| - class: "", |
| 50 | + title: 'WhatsApp', |
| 51 | + href: WHATSAPP_URL, |
| 52 | + class: '', |
52 | 53 | },
|
53 | 54 | {
|
54 |
| - title: "Instagram", |
55 |
| - href: "https://www.instagram.com/frontend.mu/?ref=frontend.mu", |
56 |
| - class: "", |
| 55 | + title: 'Instagram', |
| 56 | + href: INSTAGRAM_URL, |
| 57 | + class: '', |
57 | 58 | },
|
58 | 59 | {
|
59 |
| - title: "LinkedIn", |
60 |
| - href: "https://www.linkedin.com/company/81846464/admin/?ref=frontend.mu", |
61 |
| - class: "", |
| 60 | + title: 'LinkedIn', |
| 61 | + href: LINKEDIN_URL, |
| 62 | + class: '', |
62 | 63 | },
|
63 | 64 | {
|
64 |
| - title: "Join Discord", |
65 |
| - href: "https://discord.gg/WxXW9Jvv6k?ref=frontend.mu", |
66 |
| - class: "", |
| 65 | + title: 'Join Discord', |
| 66 | + href: DISCORD_URL, |
| 67 | + class: '', |
67 | 68 | },
|
68 | 69 | {
|
69 |
| - title: "GitHub", |
70 |
| - href: "https://github.com/frontendmu?ref=frontend.mu", |
71 |
| - class: "", |
| 70 | + title: 'GitHub', |
| 71 | + href: GITHUB_URL, |
| 72 | + class: '', |
72 | 73 | },
|
73 | 74 | {
|
74 |
| - title: "Twitter", |
75 |
| - href: "https://twitter.com/frontendmu?ref=frontend.mu", |
76 |
| - class: "", |
| 75 | + title: 'Twitter', |
| 76 | + href: TWITTER_URL, |
| 77 | + class: '', |
77 | 78 | },
|
78 | 79 | ],
|
79 | 80 | },
|
80 | 81 | meetups: {
|
81 |
| - title: "Meetups", |
82 |
| - href: "/meetups", |
| 82 | + title: 'Meetups', |
| 83 | + href: '/meetups', |
83 | 84 | },
|
84 | 85 | community: {
|
85 |
| - title: "Community", |
86 |
| - href: "/community", |
| 86 | + title: 'Community', |
| 87 | + href: '/community', |
87 | 88 | },
|
88 | 89 | team: {
|
89 |
| - title: "Team", |
90 |
| - href: "/team", |
91 |
| - class: "hidden md:block", |
| 90 | + title: 'Team', |
| 91 | + href: '/team', |
| 92 | + class: 'hidden md:block', |
92 | 93 | },
|
93 | 94 | sponsors: {
|
94 |
| - title: "Sponsors", |
95 |
| - href: "/sponsors", |
96 |
| - class: "hidden md:block", |
| 95 | + title: 'Sponsors', |
| 96 | + href: '/sponsors', |
| 97 | + class: 'hidden md:block', |
97 | 98 | },
|
98 |
| -}; |
| 99 | +} |
99 | 100 |
|
100 | 101 | function toggleHeader() {
|
101 |
| - const headerElement = document.querySelector(".menu-wrapper") as HTMLElement; |
| 102 | + const headerElement = document.querySelector('.menu-wrapper') as HTMLElement |
102 | 103 |
|
103 | 104 | // headerOffset tracks how much the header has been moved vertically
|
104 |
| - let headerOffset = 0; |
| 105 | + let headerOffset = 0 |
105 | 106 |
|
106 | 107 | // This keeps track of the previous scroll position to calculate whether the user is scrolling up or down.
|
107 |
| - let previousScrollPosition = 0; |
| 108 | + let previousScrollPosition = 0 |
108 | 109 |
|
109 | 110 | if (headerElement) {
|
110 | 111 | const handleScroll = () => {
|
111 | 112 | window.requestAnimationFrame(() => {
|
112 |
| - const headerHeight = headerElement.clientHeight; |
| 113 | + const headerHeight = headerElement.clientHeight |
113 | 114 |
|
114 | 115 | // the current vertical scroll position of the page
|
115 |
| - const currentScrollPosition = |
116 |
| - window.scrollY || document.documentElement.scrollTop; |
| 116 | + const currentScrollPosition |
| 117 | + = window.scrollY || document.documentElement.scrollTop |
117 | 118 |
|
118 | 119 | // the distance that the user has scrolled since the last scroll event
|
119 |
| - const distance = currentScrollPosition - previousScrollPosition; |
| 120 | + const distance = currentScrollPosition - previousScrollPosition |
120 | 121 |
|
121 | 122 | // New vertical position of the header
|
122 | 123 | const nextHeaderOffset = Math.min(
|
123 | 124 | Math.max(headerOffset + distance, 0),
|
124 |
| - headerHeight |
125 |
| - ); |
| 125 | + headerHeight, |
| 126 | + ) |
126 | 127 |
|
127 | 128 | // checks if the user has scrolled past the header and nextHeaderOffset differs from the current position
|
128 | 129 | if (
|
129 |
| - currentScrollPosition >= headerHeight && |
130 |
| - nextHeaderOffset !== headerOffset |
| 130 | + currentScrollPosition >= headerHeight |
| 131 | + && nextHeaderOffset !== headerOffset |
131 | 132 | ) {
|
132 |
| - headerOffset = nextHeaderOffset; |
133 |
| - headerElement.style.transform = `translateY(-${headerOffset}px)`; |
| 133 | + headerOffset = nextHeaderOffset |
| 134 | + headerElement.style.transform = `translateY(-${headerOffset}px)` |
134 | 135 | }
|
135 | 136 |
|
136 | 137 | // if the user has scrolled past the header, we add these classes
|
137 | 138 | if (currentScrollPosition > headerHeight) {
|
138 | 139 | headerElement.classList.add(
|
139 |
| - "intersect", |
140 |
| - "shadow-sm", |
141 |
| - "dark:bg-verse-900/50", |
142 |
| - "bg-verse-50/50" |
143 |
| - ); |
144 |
| - } else { |
| 140 | + 'intersect', |
| 141 | + 'shadow-sm', |
| 142 | + 'dark:bg-verse-900/50', |
| 143 | + 'bg-verse-50/50', |
| 144 | + ) |
| 145 | + } |
| 146 | + else { |
145 | 147 | headerElement.classList.remove(
|
146 |
| - "intersect", |
147 |
| - "shadow-sm", |
148 |
| - "dark:bg-verse-900/50", |
149 |
| - "bg-verse-50/50" |
150 |
| - ); |
| 148 | + 'intersect', |
| 149 | + 'shadow-sm', |
| 150 | + 'dark:bg-verse-900/50', |
| 151 | + 'bg-verse-50/50', |
| 152 | + ) |
151 | 153 | }
|
152 | 154 |
|
153 |
| - previousScrollPosition = currentScrollPosition; |
154 |
| - }); |
155 |
| - }; |
| 155 | + previousScrollPosition = currentScrollPosition |
| 156 | + }) |
| 157 | + } |
156 | 158 |
|
157 |
| - window.addEventListener("scroll", handleScroll, { passive: true }); |
| 159 | + window.addEventListener('scroll', handleScroll, { passive: true }) |
158 | 160 | }
|
159 | 161 | }
|
160 | 162 |
|
161 | 163 | function handleRightClick(event: MouseEvent) {
|
162 | 164 | // prevent default and navigate to /branding
|
163 |
| - event.preventDefault(); |
164 |
| - router.push("/branding"); |
| 165 | + event.preventDefault() |
| 166 | + router.push('/branding') |
165 | 167 | }
|
166 | 168 |
|
167 |
| -onMounted(toggleHeader); |
| 169 | +onMounted(toggleHeader) |
168 | 170 | </script>
|
169 | 171 |
|
170 | 172 | <template>
|
|
0 commit comments