npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@byteowls/ng-hierarchical-menu

v0.1.0

Published

Hierarchical menu is a hierarchical / multi-level menu component for Angular 2+

Downloads

1

Readme

Hierarchical Menu for Angular Commitizen friendly Travis npm monthly downloads npm version

Hierarchical Menu (@byteowls/ng-hierarchical-menu) for Angular 2+ is a hierarchical / multi-level menu component

Installation

npm install @byteowls/ng-hierarchical-menu --save

Demo

Usage

If you use SystemJS to load your files, you might have to update your config:

System.config({
    map: {
        '@byteowls/ng-hierarchical-menu': 'node_modules/@byteowls/ng-hierarchical-menu/bundles/index.umd.js'
    }
});

Theming / Styles

The npm module includes both scss and css files. Depending on your use case you have to include them in your project to get the themes or default styles.

These themes are included

  • default ... hierarchical-menu.themes.default
  • dark ... TBD
Ionic 2

In Ionic we can use SASS but have to customize Ionic's build process so the module styles are recognized. For that can use the config section in our packages.json

{
  "dependencies": {
    "@angular/common": "2.4.8",
    "@angular/compiler": "2.4.8",
    "@angular/compiler-cli": "2.4.8",
    "@angular/core": "2.4.8",
    "@angular/forms": "2.4.8",
    "@angular/http": "2.4.8",
    "@angular/platform-browser": "2.4.8",
    "@angular/platform-browser-dynamic": "2.4.8",
    "@angular/platform-server": "2.4.8",
    "@ionic/storage": "2.0.1",
    "@byteowls/ng-hierarchical-menu": "~0.1.0",
    "angular2-jwt": "0.1.28",
    "ionic-angular": "2.2.0",
    "ionic-native": "2.8.1",
    "ionicons": "3.0.0",
    "ng2-translate": "5.0.0",
    "rxjs": "5.0.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@ionic/app-scripts": "~1.1.4",
    "typescript": "~2.0.9"
  },
  "config": {
    "ionic_sass": "./config/ionic.sass.config.js"
  }
}

In detail you have to overwrite the ionic_sass config script. A good starting point is the original script. Copy it for example to ./config/ionic.sass.config.js and add node_modules/@byteowls/ng-hierarchical-menu/themes/scss to the includePaths property.

/**
     * includePaths: Used by node-sass for additional
     * paths to search for sass imports by just name.
     */
    includePaths: [
        'node_modules/ionic-angular/themes',
        'node_modules/ionicons/dist/scss',
        'node_modules/ionic-angular/fonts',
        // add this line
        'node_modules/@byteowls/ng-hierarchical-menu/themes/scss'
    ]

Note: It would be nices to just add the line instead of overwriting the whole file, because on every new version of the ionic-app-scripts you have to check for changes.

Now simply import the styles in your page.

page-example {
  // overwrite component variables

  // menu container

  // menu item
  $hierarchical-menu-text-color: $color4;
  // separator
  $hierarchical-menu-item-separator-color: $color4;
  // active
  $hierarchical-menu-active-text-color: $color2;
  $hierarchical-menu-active-bg-color: $color4;
  // hover
  $hierarchical-menu-hover-text-color: $color4;
  $hierarchical-menu-hover-bg-color: $color2;

  @import "hierarchical-menu.themes.default";

  .other-styles {
  
  }
}

Resources:

  • https://ionicframework.com/docs/v2/resources/app-scripts/
  • https://github.com/driftyco/ionic-app-scripts#custom-configuration

Import the HierarchicalMenuModule

import {BrowserModule} from "@angular/platform-browser";
import {NgModule} from '@angular/core';
import {HierarchicalMenuModule} from '@byteowls/ng-hierarchical-menu';

@NgModule({
    imports: [
        BrowserModule,
        HierarchicalMenuModule.forRoot()
    ],
    bootstrap: [AppComponent]
})
export class AppModule {
}

Use the HierarchicalMenuComponent

This example show a menu page I use in a Ionic 2 project.

@Component({
    selector: 'page-menu',
    template: '<hierarchical-menu [config]="menuConfig"></hierarchical-menu>'
})
export class MenuPage {

    menuConfig: HierarchicalMenuConfig;
    
    constructor(
        // ionic2 event bus
        public eventBus: Events,
        // ngx-translate translation service
        public i18n: TranslateService) {
        this.buildMenu();
    }
    
    buildMenu() {
        // create the config object
        this.menuConfig = new HierarchicalMenuConfig();
        // the menu items are structured a flat list
        this.menuConfig.menuItemStructure = MenuItemStructure.FLAT;
        // translate menu item titles using this callback
        this.menuConfig.onTranslate = (code: string) => {
            return this.i18n.instant(code);
        };
        // if there is a page assigned to the menu item send a navigation event
        this.menuConfig.onClickLink = (item: HierarchicalMenuItem) => {
            if (item.page) {
                let navEvent = new NavEvent();
                navEvent.page = item.page;
                if (item.pageIndex) {
                    navEvent.pageIndex = item.pageIndex;
                }
                this.eventBus.publish(AppConstants.Event.GO_TO_PAGE, navEvent);
            }
        };
        // run this callback if the expander is clicked
        this.menuConfig.onClickExpander = (item: HierarchicalMenuItem) => {
             console.info("config: parent menu#"+item.id+" "+(item.expanded?"opened":"closed"));
        };

        // add a parent menu item with a special style and expand it per default
        this.menuConfig.add({title: "menu.personal.section", style: "top-section", expanded: true});
        // Add simple menu item with a reference to the parent. Because we said that items are delivered as flat list. 
        // The component will create the hierarchical structure by itself
        this.menuConfig.add({title: "menu.personal.home", parentRef: "menu.personal.section", page: HomePage});
        // Another menu item
        this.menuConfig.add({title: "menu.personal.profile", parentRef: "menu.personal.section", page: ProfilePage});
        // Another menu item with a pageIndex because its a tabbed page
        this.menuConfig.add({title: "menu.personal.events", parentRef: "menu.personal.section", page: TabsPage, pageIndex: 0});
        // A parent menu item
        this.menuConfig.add({title: "menu.settings.section", style: "top-section", expanded: true});
        this.menuConfig.add({title: "menu.settings.feedback", parentRef: "menu.settings.section"});
        this.menuConfig.add({title: "menu.settings.about", parentRef: "menu.settings.section"});
        // use a special click callback for this menu item
        this.menuConfig.add({title: "menu.settings.logout", parentRef: "menu.settings.section", onClickLink: ()=> {
            this.logout();
        }});
     }

It's also possible to load menu items after first init, e.g. from a backend service.

     // 
     loadMenuItems() {
         const ITEM_ID = "menu.chosen_club.section";
         this.menuConfig.addBefore("menu.settings.section", { id: ITEM_ID, title: "Special section", expanded: true, style: "special-section"});
         
         // this is a 
         this.backendService.getMenuItems().subscribe(
             (menuItems) => {
                 menuItems.forEach(i => {
                     if (i.parentRef == null) {
                         i.style = "top-section";
                         i.parentRef = ITEM_ID;
                     } else {
                         i.onClickLink = (item: HierarchicalMenuItem) => {
                            this.openRemoteMenuItemPage(item);
                         }
                     }
                 });
    
                 this.menuConfig.addArray(moduleMenuItems);
             },
             error => {
                 console.log(error);
             }
         );
     }
    
}

License

MIT