1.0.14 • Published 2 years ago

@anupamtest/routes-menu-svelte v1.0.14

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Svelte SvelteKit Component to render Menu Navigation from a .json object

A SvelteKit component to render a Menu Navigation from a json object.

It uses the package @anupamtest/routes-menu to generates the menu object based on the Folder based Routing and render the navigation using that.

🟣Installation

npm i -D @anupamtest/routes-menu @anupamtest/routes-menu-svelte

🧩 Basic Markup

// +layout.server.ts
import { getMenu, type TMenuOptions } from '@anupamtest/routes-menu'

export const load = (async () => {
    return {
        menu: getMenu()
    };
})
// +layout.svelte
<script lang="ts">
	export let data: LayoutData

	const menuClicked = (e: CustomEvent<TMenuItem>) => {
        // e.detail contains the data for the Menu Item clicked
		console.log(e.detail)
	}
</script>

<div id="sidebar">
    <Menu menu={data.menu} openLevels={1} on:menuClicked={(menuItem) => menuClicked(menuItem)} />
</div>

🔘Props

PropDescription
menuThe menu json object. Structure as returned by the @simbeto/routes2menu package.
openLevelsHow many levels should be expanded by default, in the menu hierarchy .

🔘Events

EventDescription
menuClicked()Dispatched on any menu item click. The clicked menu item's data is passed to it. Checkout the example above.

🔘Styling

Some basic styling is set to visualize the navigation tree hierarchy. Rest can be styled as per the styling system you are using.

Below classes can be used to style various menu elements and their states:

Hierarchy goes like this:

nav.nav-list

li.nav-item

a.route / Menu Label /
li.nav-list \/* Sub Menu *\/

Menu Items

#sidebar .nav-item a.route {
    text-transform: capitalize;
}

Active Menu Item

#sidebar .nav-item a.active {
    font-weight: bold;
}

Toggle button icon

#sidebar .nav-item .toggle-btn::after {
    content: '🔼';
}
#sidebar .nav-item.closed .toggle-btn::after {
    content: '🔽';
}

Sub Menu

/* .nav-item .nav-list{} OR  */
#sidebar .sub-menu{
    padding-left: 5px;
}
#sidebar .sub-menu.closed {

}
1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago