@bobbykim/mcl-header 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 0.2.0 (2024-02-27)
7
+
8
+
9
+ ### Features
10
+
11
+ * **manguito-theme,mcl-cards,mcl-header,mcl-footer,mcl-carousel:** add vueuse as one of dependencies, update code to make them ssr friendly ([119a327](https://github.com/bobbykim89/manguito-component-library/commit/119a327adf1ca9866e6ac063bce5acd4790db612))
12
+ * **mcl-container:** add mcl-container-b with story page ([95b522d](https://github.com/bobbykim89/manguito-component-library/commit/95b522d61a9a86422c5fbb8105a27a3957d453ac))
13
+ * **mcl-header:** init mcl-header package and add mcl-header-a component ([29fe8d7](https://github.com/bobbykim89/manguito-component-library/commit/29fe8d7b62bed93d307f340e9a378f1dfe58a03a))
14
+ * **stories/*:** ran package:build to build type declaration, move deprecated story files into deprecated folder ([ffc487d](https://github.com/bobbykim89/manguito-component-library/commit/ffc487dbcc093be7a3ccfeae98c5e10e8372a0e3))
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Bobby Kim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @bobbykim/mcl-header
2
+
3
+ Add description
4
+
5
+ ## Demo
6
+
7
+ [MCL Histoire Page](https://manguito-component-library.vercel.app/story/{%story-link%})
8
+
9
+ ## Install
10
+
11
+ ## Usage
12
+
13
+ `import MclHeader from "@bobbykim/mcl-header"`;
14
+
15
+ ## Maintainer
16
+
17
+ - **Bobby Kim** - _Initial work_
18
+
19
+ ## License
20
+
21
+ This project is licensed under the MIT License - see the [LICENSE.md](./LICENSE.md) file for details
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import MclHeaderA from './lib/mcl-header-a/MclHeaderA.vue';
2
+ export * from './lib/mcl-header-a/index.types';
3
+ export { MclHeaderA };
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import MclHeaderA from './lib/mcl-header-a/MclHeaderA.vue';
2
+ export * from './lib/mcl-header-a/index.types';
3
+ export { MclHeaderA };
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ import MclHeaderA from './lib/mcl-header-a/MclHeaderA.vue'
2
+ export * from './lib/mcl-header-a/index.types'
3
+
4
+ export { MclHeaderA }
@@ -0,0 +1,121 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import type { ColorPalette } from '@bobbykim/manguito-theme'
4
+ import generateClass from '@bobbykim/manguito-theme'
5
+
6
+ const props = withDefaults(
7
+ defineProps<{
8
+ color?: ColorPalette
9
+ displayBorder?: boolean
10
+ toggle: boolean
11
+ navColor: ColorPalette
12
+ }>(),
13
+ {
14
+ color: 'dark-2',
15
+ displayBorder: true,
16
+ }
17
+ )
18
+
19
+ const emit = defineEmits(['hbg-click'])
20
+
21
+ const handleButtonToggle = (e: Event): void => {
22
+ emit('hbg-click', e)
23
+ }
24
+
25
+ const hamburgetButtonState = computed({
26
+ get() {
27
+ return props.toggle
28
+ },
29
+ set(value) {
30
+ return value
31
+ },
32
+ })
33
+
34
+ const getBorderClass = (
35
+ bColor: ColorPalette,
36
+ border: boolean,
37
+ nColor: ColorPalette
38
+ ): string => {
39
+ /**
40
+ * @bColor - color
41
+ * @border - displayBorder
42
+ * @nColor - navColor
43
+ */
44
+
45
+ const classArray: string[] = [
46
+ generateClass('RINGCOLOR', bColor),
47
+ generateClass('OFFSETRING', nColor),
48
+ ]
49
+
50
+ if (border) {
51
+ classArray.push(generateClass('BORDER', bColor))
52
+ classArray.push('border')
53
+ }
54
+ return classArray.join(' ')
55
+ }
56
+
57
+ const getHamburgerButtonClass = (color: ColorPalette): string => {
58
+ /**
59
+ * @color - color
60
+ */
61
+ const classArray: string[] = [
62
+ generateClass('BGCOLOR', color),
63
+ generateClass('BEFOREBG', color),
64
+ generateClass('AFTERBG', color),
65
+ ]
66
+
67
+ return classArray.join(' ')
68
+ }
69
+ </script>
70
+
71
+ <template>
72
+ <button
73
+ class="p-3xs rounded-md aspect-square outline-none focus:ring-4 ring-offset-2 transition-all duration-300 ease-linear hover:opacity-70 focus:opacity-70 hamburger__button"
74
+ :class="getBorderClass(color, displayBorder, navColor)"
75
+ @click="handleButtonToggle"
76
+ >
77
+ <input
78
+ type="checkbox"
79
+ v-model="hamburgetButtonState"
80
+ class="hidden hamburger__checkbox"
81
+ />
82
+ <div
83
+ class="relative h-[3px] w-sm hamburger__icon before:w-sm after:w-sm before:h-[3px] after:h-[3px] transition-all duration-300 ease-linear"
84
+ :class="getHamburgerButtonClass(color)"
85
+ ></div>
86
+ </button>
87
+ </template>
88
+
89
+ <style lang="scss" scoped>
90
+ .hamburger__icon {
91
+ &::before,
92
+ &::after {
93
+ position: absolute;
94
+ left: 0;
95
+ transition: all 0.3s linear;
96
+ }
97
+ &::before {
98
+ top: -0.5rem;
99
+ }
100
+ &::after {
101
+ top: 0.5rem;
102
+ }
103
+ }
104
+ .hamburger__button {
105
+ &:focus .hamburger__icon,
106
+ &:hover .hamburger__icon {
107
+ scale: 1.05;
108
+ }
109
+ }
110
+ .hamburger__checkbox:checked + .hamburger__icon {
111
+ background-color: transparent;
112
+ }
113
+ .hamburger__checkbox:checked + .hamburger__icon::before {
114
+ top: 0;
115
+ transform: rotate(135deg);
116
+ }
117
+ .hamburger__checkbox:checked + .hamburger__icon::after {
118
+ top: 0;
119
+ transform: rotate(-135deg);
120
+ }
121
+ </style>
@@ -0,0 +1,43 @@
1
+ import type { ColorPalette } from '@bobbykim/manguito-theme';
2
+ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
3
+ color?: ColorPalette | undefined;
4
+ displayBorder?: boolean | undefined;
5
+ toggle: boolean;
6
+ navColor: ColorPalette;
7
+ }>, {
8
+ color: string;
9
+ displayBorder: boolean;
10
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
11
+ "hbg-click": (...args: any[]) => void;
12
+ }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
13
+ color?: ColorPalette | undefined;
14
+ displayBorder?: boolean | undefined;
15
+ toggle: boolean;
16
+ navColor: ColorPalette;
17
+ }>, {
18
+ color: string;
19
+ displayBorder: boolean;
20
+ }>>> & {
21
+ "onHbg-click"?: ((...args: any[]) => any) | undefined;
22
+ }, {
23
+ color: ColorPalette;
24
+ displayBorder: boolean;
25
+ }, {}>;
26
+ export default _default;
27
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
28
+ type __VLS_TypePropsToRuntimeProps<T> = {
29
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
30
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
31
+ } : {
32
+ type: import('vue').PropType<T[K]>;
33
+ required: true;
34
+ };
35
+ };
36
+ type __VLS_WithDefaults<P, D> = {
37
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
38
+ default: D[K];
39
+ }> : P[K];
40
+ };
41
+ type __VLS_Prettify<T> = {
42
+ [K in keyof T]: T[K];
43
+ } & {};
@@ -0,0 +1,382 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ BodyText,
4
+ ColorPalette,
5
+ CtaTarget,
6
+ HeadingSize,
7
+ } from '@bobbykim/manguito-theme'
8
+ import generateClass from '@bobbykim/manguito-theme'
9
+ import { useWindowScroll } from '@vueuse/core'
10
+ import { Transition, computed, ref, useSlots } from 'vue'
11
+ import HamburgerMenu from '../common/HamburgerMenu.vue'
12
+ import NavCollapse from './NavCollapse.vue'
13
+ import NavDropdown from './NavDropdown.vue'
14
+ import NavLink from './NavLink.vue'
15
+ import type {
16
+ MenuCollapseType,
17
+ MenuEventType,
18
+ MenuItemType,
19
+ NavChildClickEventType,
20
+ } from './index.types'
21
+
22
+ const props = withDefaults(
23
+ defineProps<{
24
+ logo: string
25
+ logoSmall?: string
26
+ logoAlt?: string
27
+ logoAsLink?: boolean
28
+ logoLink: string
29
+ logoLinkTarget?: CtaTarget
30
+ title: string
31
+ titleSize?: HeadingSize
32
+ titleColor?: ColorPalette
33
+ titleAsLink?: boolean
34
+ titleLink: string
35
+ titleLinkTarget?: CtaTarget
36
+ menuItems: Array<MenuItemType | MenuCollapseType>
37
+ menuItemAsLink?: boolean
38
+ menuTextSize?: BodyText
39
+ menuTextColor?: ColorPalette
40
+ menuTextBold?: boolean
41
+ displayHighlight?: boolean
42
+ highlightColor?: ColorPalette
43
+ bgColor?: ColorPalette
44
+ mobileMenuBgColor?: ColorPalette
45
+ secondaryColor?: ColorPalette
46
+ hamburgerBorder?: boolean
47
+ fadeInOnScroll?: boolean
48
+ scrollDistance?: number
49
+ }>(),
50
+ {
51
+ logoAsLink: true,
52
+ logoLinkTarget: '_self',
53
+ titleSize: 'md',
54
+ titleColor: 'dark-3',
55
+ titleAsLink: true,
56
+ titleLinkTarget: '_self',
57
+ menuItemAsLink: true,
58
+ menuTextSize: 'md',
59
+ menuTextColor: 'dark-3',
60
+ menuTextBold: false,
61
+ displayHighlight: true,
62
+ highlightColor: 'primary',
63
+ bgColor: 'light-1',
64
+ mobileMenuBgColor: 'light-2',
65
+ secondaryColor: 'dark-1',
66
+ hamburgerBorder: true,
67
+ fadeInOnScroll: true,
68
+ scrollDistance: 50,
69
+ }
70
+ )
71
+
72
+ const navOpen = ref<boolean>(false)
73
+ const slots = useSlots()
74
+ const emit = defineEmits([
75
+ 'toggle-menu',
76
+ 'menu-click',
77
+ 'title-click',
78
+ 'logo-click',
79
+ ])
80
+ const { y } = useWindowScroll()
81
+
82
+ type EmitType = 'menu' | 'title' | 'logo'
83
+
84
+ const closeNav = (): void => {
85
+ navOpen.value = false
86
+ }
87
+
88
+ const toggleNavButton = (e: Event): void => {
89
+ navOpen.value = !navOpen.value
90
+ emit('toggle-menu', e)
91
+ }
92
+
93
+ const navItemClick = (
94
+ e: Event,
95
+ title: string,
96
+ link: string,
97
+ target: CtaTarget = '_self',
98
+ itemLink: boolean,
99
+ emitType: EmitType
100
+ ): void => {
101
+ /**
102
+ * @param {Event} e - $event
103
+ * @param {string} link - menuItems[#].url / titleLink
104
+ * @param {CtaTarget} target - menuItems[#].target / titleLinkTaget
105
+ * @param {boolean} itemlink - menuItemAsLink /
106
+ * @param {EmitType} emitType - Non prop value type EmitType
107
+ */
108
+ navOpen.value = false
109
+ const menuEvent: MenuEventType = {
110
+ event: e,
111
+ title: title,
112
+ link: link,
113
+ target: target ? target : '_self',
114
+ }
115
+ if (!itemLink) {
116
+ e.preventDefault()
117
+ }
118
+ if (emitType === 'menu') {
119
+ emit('menu-click', menuEvent)
120
+ }
121
+ if (emitType === 'title') {
122
+ emit('title-click', menuEvent)
123
+ }
124
+ if (emitType === 'logo') {
125
+ emit('logo-click', menuEvent)
126
+ }
127
+ }
128
+ const navChildLinkClick = (e: NavChildClickEventType): void => {
129
+ /**
130
+ * @param {NavChildClickEventType} e - Event emitted from dropdown/collapse click events
131
+ */
132
+ const { title, url, target } = e.item
133
+ navOpen.value = false
134
+ const menuEvent: MenuEventType = {
135
+ event: e.event,
136
+ title,
137
+ link: url,
138
+ target: target ? target : '_self',
139
+ }
140
+ emit('menu-click', menuEvent)
141
+ }
142
+
143
+ const getTitleClass = (size: HeadingSize, color: ColorPalette): string => {
144
+ /**
145
+ * @param {HeadingSize} size - titleSize
146
+ * @param {ColorPalette} color - titleColor
147
+ */
148
+ const classArray: string[] = [
149
+ generateClass('H2', size),
150
+ generateClass('TEXTCOLOR', color),
151
+ ]
152
+ return classArray.join(' ')
153
+ }
154
+
155
+ /**
156
+ * @TransitionFunctions
157
+ * @param {HTMLElement} el - passed any since transition handlers don't accept HTMLElement (accepts Element)
158
+ */
159
+ const onEnter = (el: any) => {
160
+ el.style.height = 'auto'
161
+ const endWidth = getComputedStyle(el).height
162
+ el.style.height = '0px'
163
+ el.offsetHeight // force repaint
164
+ el.style.height = endWidth
165
+ }
166
+ const onAfterEnter = (el: any) => {
167
+ el.style.height = 'auto'
168
+ }
169
+ const onLeave = (el: any) => {
170
+ el.style.height = getComputedStyle(el).height
171
+ el.offsetHeight // force repaint
172
+ el.style.height = '0px'
173
+ }
174
+
175
+ const hasChildren = (item: MenuItemType | MenuCollapseType) => {
176
+ const NavCollapse = item as MenuCollapseType
177
+ if (typeof NavCollapse.children === 'undefined') {
178
+ return false
179
+ }
180
+ return NavCollapse.children.length > 0
181
+ }
182
+
183
+ const handleFadeInOnScroll = computed(() => {
184
+ const { fadeInOnScroll, scrollDistance } = props
185
+ if (!fadeInOnScroll) {
186
+ return ''
187
+ }
188
+ return y.value >= scrollDistance
189
+ ? 'lg:shadow-md bg-opacity-70'
190
+ : 'bg-opacity-100'
191
+ })
192
+ </script>
193
+
194
+ <template>
195
+ <header
196
+ class="w-full top-0 md:sticky items-center z-50 transition ease-in duration-500 delay-150"
197
+ :class="[handleFadeInOnScroll, generateClass('BGCOLOR', bgColor)]"
198
+ >
199
+ <nav
200
+ class="flex flex-wrap items-center py-xs md:py-2xs mx-xs md:mx-sm align-middle justify-between sm:max-w-[640px] md:max-w-[768px] lg:max-w-[1024px] xl:max-w-[1280px] 2xl:max-w-[1536px]"
201
+ >
202
+ <div class="flex flex-shrink-0 items-center self-center">
203
+ <div class="h-md md:h-lg lg:h-xl mr-2xs md:mr-sm align-middle">
204
+ <a
205
+ :href="logoLink"
206
+ :target="logoLinkTarget"
207
+ @click="
208
+ navItemClick(
209
+ $event,
210
+ title,
211
+ logoLink,
212
+ logoLinkTarget,
213
+ logoAsLink,
214
+ 'logo'
215
+ )
216
+ "
217
+ >
218
+ <img
219
+ :src="logo"
220
+ :alt="logoAlt"
221
+ class="h-full"
222
+ :class="[logoSmall ? 'hidden lg:inline-block' : 'inline-block']"
223
+ />
224
+ <img
225
+ v-if="logoSmall"
226
+ :src="logoSmall"
227
+ :alt="logoAlt"
228
+ class="inline-block lg:hidden h-full"
229
+ />
230
+ </a>
231
+ </div>
232
+ <div class="flex flex-col justify-center ml-2">
233
+ <a
234
+ :href="titleLink"
235
+ :target="titleLinkTarget"
236
+ @click="
237
+ navItemClick(
238
+ $event,
239
+ title,
240
+ titleLink,
241
+ titleLinkTarget,
242
+ titleAsLink,
243
+ 'title'
244
+ )
245
+ "
246
+ >
247
+ <h2
248
+ class="inline-block align-middle tracking-wider"
249
+ :class="getTitleClass(titleSize, titleColor)"
250
+ v-html="title"
251
+ ></h2>
252
+ </a>
253
+ <!-- desktop nav menu -->
254
+ <ul class="hidden lg:flex flex-wrap">
255
+ <li
256
+ class="mr-xs last:mr-0"
257
+ v-for="(item, index) in menuItems"
258
+ :key="`menu-${index}`"
259
+ >
260
+ <nav-link
261
+ v-if="!hasChildren(item)"
262
+ :nav-item="(item as MenuItemType)"
263
+ :menu-text-color="menuTextColor"
264
+ :menu-text-size="menuTextSize"
265
+ :menu-text-bold="menuTextBold"
266
+ :display-highlight="displayHighlight"
267
+ :highlight-color="highlightColor"
268
+ :as-link="menuItemAsLink"
269
+ @nav-link="
270
+ navItemClick(
271
+ $event,
272
+ item.title,
273
+ (item as MenuItemType).url,
274
+ (item as MenuItemType).target,
275
+ menuItemAsLink,
276
+ 'menu'
277
+ )
278
+ "
279
+ ></nav-link>
280
+ <nav-dropdown
281
+ v-else
282
+ :nav-item="(item as MenuCollapseType)"
283
+ :menu-text-color="menuTextColor"
284
+ :menu-text-size="menuTextSize"
285
+ :menu-text-bold="menuTextBold"
286
+ :display-highlight="displayHighlight"
287
+ :highlight-color="highlightColor"
288
+ :bg-color="bgColor"
289
+ :hover-bg-color="secondaryColor"
290
+ :as-link="menuItemAsLink"
291
+ @nav-link="navChildLinkClick"
292
+ ></nav-dropdown>
293
+ </li>
294
+ </ul>
295
+ </div>
296
+ </div>
297
+ <div>
298
+ <hamburger-menu
299
+ :color="secondaryColor"
300
+ :display-border="hamburgerBorder"
301
+ class="block lg:hidden"
302
+ @hbg-click="toggleNavButton"
303
+ :toggle="navOpen"
304
+ :nav-color="bgColor"
305
+ ></hamburger-menu>
306
+ <div v-if="slots['nav-slot']" class="hidden lg:block">
307
+ <slot name="nav-slot"></slot>
308
+ </div>
309
+ </div>
310
+ </nav>
311
+ <!-- mobile menu -->
312
+
313
+ <div class="overflow-hidden lg:hidden">
314
+ <transition
315
+ name="collapse"
316
+ @enter="onEnter"
317
+ @after-enter="onAfterEnter"
318
+ @leave="onLeave"
319
+ >
320
+ <div
321
+ class="bg-opacity-80 rounded-md my-2xs mx-xs overflow-hidden"
322
+ v-if="navOpen"
323
+ :class="generateClass('BGCOLOR', mobileMenuBgColor)"
324
+ >
325
+ <ul class="flex flex-col items-center justify-center p-xs">
326
+ <li
327
+ class="mb-2xs last:mb-0"
328
+ v-for="(item, index) in menuItems"
329
+ :key="`mobile-${index}`"
330
+ >
331
+ <nav-link
332
+ v-if="!hasChildren(item)"
333
+ :nav-item="(item as MenuItemType)"
334
+ :menu-text-color="menuTextColor"
335
+ :menu-text-size="menuTextSize"
336
+ :menu-text-bold="menuTextBold"
337
+ :display-highlight="displayHighlight"
338
+ :highlight-color="highlightColor"
339
+ :as-link="menuItemAsLink"
340
+ @nav-link="
341
+ navItemClick(
342
+ $event,
343
+ item.title,
344
+ (item as MenuItemType).url,
345
+ (item as MenuItemType).target,
346
+ menuItemAsLink,
347
+ 'menu'
348
+ )
349
+ "
350
+ ></nav-link>
351
+ <nav-collapse
352
+ v-else
353
+ :nav-id="item.title"
354
+ :nav-item="(item as MenuCollapseType)"
355
+ :menu-text-color="menuTextColor"
356
+ :menu-text-size="menuTextSize"
357
+ :menu-text-bold="menuTextBold"
358
+ :display-highlight="displayHighlight"
359
+ :highlight-color="highlightColor"
360
+ :nav-accordion-group="title"
361
+ :as-link="menuItemAsLink"
362
+ @nav-link="navChildLinkClick"
363
+ ></nav-collapse>
364
+ </li>
365
+ </ul>
366
+ <div v-if="slots['mobile-slot']">
367
+ <slot name="mobile-slot" :close-nav="closeNav"></slot>
368
+ </div>
369
+ </div>
370
+ </transition>
371
+ </div>
372
+ </header>
373
+ </template>
374
+
375
+ <style lang="scss" scoped>
376
+ .collapse-enter-active {
377
+ transition: height 0.5s ease-in;
378
+ }
379
+ .collapse-leave-active {
380
+ transition: height 0.5s ease-out;
381
+ }
382
+ </style>