1.0.0-alpha.58 • Published 7 years ago

ng2-limber v1.0.0-alpha.58

Weekly downloads
5
License
ISC
Repository
github
Last release
7 years ago

ng2-limber

ng2-limber is an Angular 2 (final release) module that simplifies the grunt work of creating navigation links. Each nav menu is stored in a json file as an array of ILimberLink and pulled at runtime to create menus using ng2-limber's LimberLinkGroupComponent.

installation

  1. import your favorite bootstrap css file
  2. npm i --save ng2-limber

Usage

Store navs in a json file that will be accessed via http:

let 'some.domain/app/core/nav/navbar-right-links.json' point to the file below:

[
  {"text": "Home", "route": "home", "faIcon": "home"},
  {"text": "About WebGL", "href": "https://developer.mozilla.org/en-US/docs/Learn/WebGL", "faIcon": "info-circle"},
  {"text": "Something special", "href": "https://www.duckduckgo.com", "img": "assets/img/asterisk.png"},
  {"text": "More options", "links":
    [
      { "text": "option 1", "route": "#", "faIcon": "question-circle" },
      { "text": "option 2", "href": "https://www.duckduckgo.com", "faIcon": "map-o" }
    ]
  }
]

what the above properties do:

  • "text" - the text to be displayed
  • "route" - the ties to RouterLink attributes (if a "href" is also present, then the default behavior is to ditch the "href" and use "route")
  • "href" - the url to launch in a new browser window
  • "faIcon" - a font-awesome icon. see ng2-font-awesome
  • "img" - an image file you'd like to use as an icon
  • "links" - an array of ILimberLink

say your component's template looks like this:

<nav class="navbar navbar-dark navbar-dp bg-primary">
  <limber-link-group [endPoint]="'app/core/nav/navbar-right-links.json'" [navClass]="'nav navbar-nav pull-xs-right'"></limber-link-group>
</nav>

you end up with a nav ul containing router directives, hyperlinks, and a dropdown menu.:

alt text

make it do what you want

the idea is to program less but limber does let you override the properties of a link at run time through a callback function:

create a function with the signature:

@Input() customize: (link: ILimberLink) => ILimberLink;

for example:

customizeLink = (link: ILimberLink): ILimberLink => {
  delete link.route;
  link.href = 'https://www.duckduckgo.com';
  link.text.match(/option \d/i) ? link.faIcon = 'arrow-up' : link.faIcon = 'arrow-left';
  link.text = 'I`m with stupid';

  return link;
}

The customize callback above removes the router link from each link, creates a hyperlink to duckduckgo, sets a faIcon and sets the text to "I'm with stupid".

the customize callback is called over each link and recursively over link.links.

now update your template:

<limber-link-group [customize]="customizeLink" [endPoint]="'app/core/nav/navbar-right-links.json'" [navClass]="'nav navbar-nav pull-xs-right'" [allowEdit]="editMode"></limber-link-group>

and you end up with this:

alt text

inputs

LimberLinkGroupComponent:

  @Input() endPoint: string;  // the http endpoint to get your json
  @Input() navClass: string;  // css class e.g., 'nav nav-bar' 
  @Input() allowEdit: boolean = false;  // NOT YET IMPLEMENTED
  @Input() customize: (link: ILimberLink) => ILimberLink; // modify your link as it is loaded
1.0.0-alpha.58

7 years ago

1.0.0-alpha.57

7 years ago

1.0.0-alpha.56

7 years ago

1.0.0-alpha.55

7 years ago

1.0.0-alpha.54

7 years ago

1.0.0-alpha.53

7 years ago

1.0.0-alpha.52

7 years ago

1.0.0-alpha.51

7 years ago

1.0.0-alpha.50

7 years ago

1.0.0-alpha.49

7 years ago

1.0.0-alpha.48

7 years ago

1.0.0-alpha.47

7 years ago

1.0.0-alpha.46

7 years ago

1.0.0-alpha.45

7 years ago

1.0.0-alpha.44

7 years ago

1.0.0-alpha.43

7 years ago

1.0.0-alpha.42

7 years ago

1.0.0-alpha.41

7 years ago

1.0.0-alpha.40

7 years ago

1.0.0-alpha.39

7 years ago

1.0.0-alpha.38

7 years ago

1.0.0-alpha.37

7 years ago

1.0.0-alpha.36

7 years ago

1.0.0-alpha.35

7 years ago

1.0.0-alpha.34

7 years ago

1.0.0-alpha.33

7 years ago

1.0.0-alpha.32

8 years ago

1.0.0-alpha.31

8 years ago

1.0.0-alpha.30

8 years ago

1.0.0-alpha.29

8 years ago

1.0.0-alpha.28

8 years ago

1.0.0-alpha.27

8 years ago

1.0.0-alpha.26

8 years ago

1.0.0-alpha.24

8 years ago

1.0.0-alpha.23

8 years ago

1.0.0-alpha.22

8 years ago

1.0.0-alpha.21

8 years ago

1.0.0-alpha.20

8 years ago

1.0.0-alpha.19

8 years ago

1.0.0-alpha.18

8 years ago

1.0.0-alpha.17

8 years ago

1.0.0-alpha.16

8 years ago

1.0.0-alpha.15

8 years ago

1.0.0-alpha.14

8 years ago

1.0.0-alpha.13

8 years ago

1.0.0-alpha.12

8 years ago

1.0.0-alpha.11

8 years ago

1.0.0-alpha.10

8 years ago

1.0.0-alpha.9

8 years ago

1.0.0-alpha.8

8 years ago

1.0.0-alpha.7

8 years ago

1.0.0-alpha.6

8 years ago

1.0.0-alpha.5

8 years ago

1.0.0-alpha.4

8 years ago

1.0.0-alpha.3

8 years ago

1.0.0-alpha.2

8 years ago

1.0.0-alpha.1

8 years ago