Skip to content

Commit 0437219

Browse files
committed
fix: Navbar transition
1 parent 3f6d84c commit 0437219

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

.changeset/breezy-beers-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-5-ui-lib': patch
3+
---
4+
5+
fix: Navbar transition

src/lib/nav/NavUl.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
let { children, class: ulclass, ...attributes }: Props = $props();
1313
1414
let breakPoint: navbarType['breakPoint'];
15+
let navStatus: navbarType['navStatus'];
1516
const context = getContext<navbarType>('navbarContext');
1617
breakPoint = context.breakPoint ?? 'md';
18+
navStatus = context.navStatus;
19+
1720
const ulBreaks = {
1821
md: 'md:mt-0 md:flex-row md:space-x-8 md:border-0 md:p-0 md:dark:bg-gray-900',
1922
lg: 'lg:mt-0 lg:flex-row lg:space-x-8 lg:border-0 lg:p-0 lg:dark:bg-gray-900',

src/lib/nav/Navbar.svelte

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
children: Snippet;
1313
toggleNav?: () => void;
1414
closeNav?: () => void;
15-
openMainMenu?: boolean;
16-
navStatus?: boolean;
15+
navStatus?: boolean | undefined;
1716
fluid?: boolean;
1817
brand?: Snippet;
1918
breakPoint?: navbarType['breakPoint'];
@@ -29,7 +28,6 @@
2928
children,
3029
toggleNav,
3130
closeNav = () => {},
32-
openMainMenu = true,
3331
navStatus,
3432
fluid,
3533
brand,
@@ -44,7 +42,8 @@
4442
}: Props = $props();
4543
4644
setContext<navbarType>('navbarContext', {
47-
breakPoint: breakPoint,
45+
navStatus,
46+
breakPoint,
4847
activeClass: twMerge(
4948
'block py-2 px-3 text-white bg-primary-700 rounded dark:text-white',
5049
activeClass
@@ -98,39 +97,47 @@
9897
{#if brand}
9998
{@render brand()}
10099
{/if}
101-
{#if openMainMenu}
102-
<button
103-
onclick={toggleNav}
104-
type="button"
105-
class={btnCls}
106-
aria-controls="navbar-default"
100+
<button
101+
onclick={toggleNav}
102+
type="button"
103+
class={btnCls}
104+
aria-controls="navbar-default"
105+
>
106+
<span class="sr-only">Open main menu</span>
107+
<svg
108+
class="h-5 w-5"
109+
aria-hidden="true"
110+
xmlns="http://www.w3.org/2000/svg"
111+
fill="none"
112+
viewBox="0 0 17 14"
107113
>
108-
<span class="sr-only">Open main menu</span>
109-
<svg
110-
class="h-5 w-5"
111-
aria-hidden="true"
112-
xmlns="http://www.w3.org/2000/svg"
113-
fill="none"
114-
viewBox="0 0 17 14"
115-
>
116-
<path
117-
stroke="currentColor"
118-
stroke-linecap="round"
119-
stroke-linejoin="round"
120-
stroke-width="2"
121-
d="M1 1h15M1 7h15M1 13h15"
122-
/>
123-
</svg>
124-
</button>
125-
{/if}
114+
<path
115+
stroke="currentColor"
116+
stroke-linecap="round"
117+
stroke-linejoin="round"
118+
stroke-width="2"
119+
d="M1 1h15M1 7h15M1 13h15"
120+
/>
121+
</svg>
122+
</button>
123+
{#if navStatus}
126124
<div
127-
class="{navDisplay} {divChildrenCls}"
125+
class="block {divChildrenCls}"
128126
transition:slide={slideParams}
129127
role="button"
130128
tabindex="0"
131129
>
132130
{@render children()}
133131
</div>
132+
{:else}
133+
<div
134+
class="hidden {divChildrenCls}"
135+
role="button"
136+
tabindex="0"
137+
>
138+
{@render children()}
139+
</div>
140+
{/if}
134141
</div>
135142
</nav>
136143

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export interface ButtonClassesTypes {
152152
}
153153

154154
export type navbarType = {
155+
navStatus: boolean | undefined;
155156
breakPoint: 'md' | 'lg' | 'xl' | 'xxl';
156157
activeClass: string | undefined | null;
157158
nonActiveClass: string | undefined | null;

0 commit comments

Comments
 (0)