|
1 | 1 | <script lang="ts"> |
2 | | - import theme from '$lib/state/theme.svelte.js'; |
3 | | - import { calculateSkHref } from "@wjfe/n-savant-sk"; |
| 2 | + import { NavBar } from '$lib/bulma/NavBar'; |
| 3 | + import { calculateSkHref } from '@wjfe/n-savant-sk'; |
| 4 | + import ThemePicker from './ThemePicker.svelte'; |
| 5 | + import logo from '@wjfe/n-savant/logo64'; |
| 6 | + import { isSkRouteActive } from './isSkRouteActive'; |
| 7 | + import { location } from '@wjfe/n-savant'; |
| 8 | + import theme from './state/theme.svelte'; |
4 | 9 |
|
5 | | -</script> |
6 | | -<nav class="has-background-info-light is-flex is-flex-direction-row is-align-items-center is-justify-content-space-between"> |
7 | | - <ul> |
8 | | - <li><a href={calculateSkHref({ preserveQuery: true }, "/")}>Home</a></li> |
9 | | - <li><a href={calculateSkHref({ preserveQuery: true }, "/demo")}>Start Demo</a></li> |
10 | | - </ul> |
11 | | - <div> |
12 | | - <select bind:value={theme.current} class="select"> |
13 | | - <option value="light">Light</option> |
14 | | - <option value="dark">Dark</option> |
15 | | - <option value="system">System</option> |
16 | | - </select> |
17 | | - </div> |
18 | | -</nav> |
19 | | - |
20 | | -<style> |
21 | | - nav { |
22 | | - padding: 1rem; |
23 | | - border-bottom: 1px solid #dee2e6; |
24 | | - } |
| 10 | + const allPositions = [undefined, 'top', 'bottom'] as const; |
| 11 | + let posIndex = $state(0); |
| 12 | + const posIconData = [ |
| 13 | + { |
| 14 | + icon: 'fa-circle-dot', |
| 15 | + title: 'Remove fixed position', |
| 16 | + }, |
| 17 | + { |
| 18 | + icon: 'fa-chevron-up', |
| 19 | + title: 'Fix to top', |
| 20 | + }, |
| 21 | + { |
| 22 | + icon: 'fa-chevron-down', |
| 23 | + title: 'Fix to bottom', |
| 24 | + }, |
| 25 | + ]; |
| 26 | + let iconDataIndex = $derived((posIndex + 1) % allPositions.length); |
| 27 | + let navbarBg = $derived(theme.current === 'dark' ? 'is-dark' : 'is-light'); |
25 | 28 |
|
26 | | - ul { |
27 | | - list-style: none; |
28 | | - display: flex; |
29 | | - gap: 1rem; |
30 | | - margin: 0; |
31 | | - padding: 0; |
| 29 | + function nextPosition() { |
| 30 | + posIndex = (posIndex + 1) % allPositions.length; |
32 | 31 | } |
| 32 | +</script> |
33 | 33 |
|
34 | | - li { |
35 | | - margin: 0; |
36 | | - } |
37 | | -</style> |
| 34 | +<NavBar.Root fixed={allPositions[posIndex]} class={navbarBg} style="padding-top: 0.5rem; padding-bottom: 0.5rem;"> |
| 35 | + <NavBar.Brand> |
| 36 | + <NavBar.Item> |
| 37 | + <img src={logo} alt="Logo" /> |
| 38 | + </NavBar.Item> |
| 39 | + <NavBar.Item> |
| 40 | + <h1 class="title is-4">@wjfe/n-savant-sk Demo</h1> |
| 41 | + </NavBar.Item> |
| 42 | + </NavBar.Brand> |
| 43 | + <NavBar.Burger /> |
| 44 | + <NavBar.Menu> |
| 45 | + <NavBar.Item tag="a" isTab isActive={isSkRouteActive('/')} href={calculateSkHref({ preserveQuery: true }, '/')} |
| 46 | + >Home</NavBar.Item |
| 47 | + > |
| 48 | + <NavBar.Item |
| 49 | + tag="a" |
| 50 | + isTab |
| 51 | + isActive={isSkRouteActive('/demo')} |
| 52 | + href={calculateSkHref({ preserveQuery: true }, '/demo')}>Start Demo</NavBar.Item |
| 53 | + > |
| 54 | + {#snippet end()} |
| 55 | + <NavBar.Item> |
| 56 | + Sveltekit Path: <code>{location.url.pathname}</code> |
| 57 | + </NavBar.Item> |
| 58 | + <NavBar.Item> |
| 59 | + <button type="button" title={posIconData[iconDataIndex].title} onclick={nextPosition}> |
| 60 | + <i class={['fas', posIconData[iconDataIndex].icon]}></i> |
| 61 | + </button> |
| 62 | + </NavBar.Item> |
| 63 | + <NavBar.Item> |
| 64 | + <ThemePicker /> |
| 65 | + </NavBar.Item> |
| 66 | + {/snippet} |
| 67 | + </NavBar.Menu> |
| 68 | +</NavBar.Root> |
0 commit comments