|
| 1 | + |
| 2 | +# Angular Breadcrumbs Light |
| 3 | + |
| 4 | +[](https://github.com/mopcweb/angular-breadcrumbs-light/releases) [](https://www.npmjs.com/package/angular-breadcrumbs-light) [](https://mopcweb.github.io/angular-breadcrumbs-light) [](https://github.com/mopcweb/angular-breadcrumbs-light/blob/master/LICENSE) |
| 5 | + |
| 6 | +## Demo |
| 7 | + |
| 8 | +[See demo here](https://mopcweb.github.io/angular-breadcrumbs-light) |
| 9 | + |
| 10 | +## Description |
| 11 | + |
| 12 | +Easy to use breadcrumbs for Angular. |
| 13 | + |
| 14 | +The package includes: |
| 15 | + |
| 16 | + - Service: just call it in some root component and it will be returning current breadcrumbs array |
| 17 | + - Breadcrumbs component: just import and use it. Could be manually configured and styled |
| 18 | + - TS Types for both |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +```bash |
| 23 | + |
| 24 | +npm i angular-breadcrumbs-light |
| 25 | + |
| 26 | +``` |
| 27 | + |
| 28 | +## Breadcrumbs service |
| 29 | + |
| 30 | +Provides function getBreadcrumbs, which returns an array of breadcrumbs. |
| 31 | + |
| 32 | +Example ([Argument Routes is specified in next subsection](#routes)): |
| 33 | + |
| 34 | +```js |
| 35 | + |
| 36 | +// Usage |
| 37 | +const crumbs = getBreadcrumbs(Routes, window.location.pathname); |
| 38 | + |
| 39 | +// Returned array |
| 40 | +[ |
| 41 | + { link: '/', title: 'Home', icon: 'person', iconClass: 'material-icons' }, |
| 42 | + { link: '/clients', title: 'Clients', icon: '...' }, |
| 43 | + { link: '/clients/1', title: 'Client № - 1, welcome!', icon: '...' } |
| 44 | +] |
| 45 | + |
| 46 | +``` |
| 47 | + |
| 48 | +There is only __1 required__ arguments and 5 optional: |
| 49 | + |
| 50 | +| Title | Type | Description | Default | |
| 51 | +| :-----: | :------: | :----------------------------------------: | :------------------: | |
| 52 | +| __routes *__ | _array_ | array of route objects ([see example below](#routes)) | - | |
| 53 | +| fullUrl | _string_ | current location full path | ([see example below](#fullurl)) | |
| 54 | +| base | _string_ | if project's base-href is provided manually, put it here also | - | |
| 55 | +| notFoundTitle | _string_ | title for not found route | 'Page Not Found' | |
| 56 | +| notFoundIcon | _string_ | icon for not found route | undefined | |
| 57 | +| notFoundClass | _string_ | icon class for not found route | undefined | |
| 58 | + |
| 59 | +### Routes |
| 60 | + |
| 61 | +Example: |
| 62 | + |
| 63 | + ```js |
| 64 | + |
| 65 | + const Routes = [ |
| 66 | + { title: 'Home', link: '/', icon: 'string', iconClass: 'material-icons' }, |
| 67 | + { title: 'Clients', link: '/clients', icon: '...', children: [ |
| 68 | + { title: 'Client № - ', suffix: ', welcome!', link: '/clients/:id', icon: '...' }, |
| 69 | + { title: 'Settings', link: '/clients/settings', icon: '...' } |
| 70 | + ] } |
| 71 | + ]; |
| 72 | + |
| 73 | + ``` |
| 74 | + |
| 75 | +__Fields:__ |
| 76 | + |
| 77 | +| Title | Type | Description | |
| 78 | +| :---------: | :------: | :---------------------------------------------------------------: | |
| 79 | +| __link *__ | _string_ | breadcrumb link | |
| 80 | +| title | _string_ | breadcrumb title | |
| 81 | +| suffix | _string_ | breadcrumb suffix (added at the end of output breadcrumb title) | |
| 82 | +| icon | _string_ | breadcrumb icon | |
| 83 | +| iconClass | _string_ | breadcrumb icon class | |
| 84 | +| children | _array_ | array of objects, similar to Routes, for nested routes | |
| 85 | + |
| 86 | +__Features__: |
| 87 | + |
| 88 | + - If __title__ is not provided, link will be used as breadcrumb title (First letter uppercased) |
| 89 | + - For root route ('' or '/') if __title__ not provided, the crumb title will be 'Root' by default |
| 90 | + - __link__ field may contain dynamic routes (ex.: '/route/:id') |
| 91 | + - For dynamic routes 'title' field will be used as prefix for current pathname (first letter uppercased), if provided |
| 92 | + |
| 93 | +### FullUrl |
| 94 | + |
| 95 | + It should be a current location. __DEFAULT VALUE IS: window.location.pathname__. |
| 96 | + |
| 97 | +### Important |
| 98 | + |
| 99 | +Example ([Play with example here](https://stackblitz.com/edit/angular-breadcrumbs-light-custom-crumbs?embed=1&file=src/app/app.component.ts): |
| 100 | + |
| 101 | +```js |
| 102 | + |
| 103 | +``` |
| 104 | + |
| 105 | +## Breadcrumbs component |
| 106 | + |
| 107 | +Provides a ready to use component. Can be styled and configured. |
| 108 | + |
| 109 | +[Play with example here](https://stackblitz.com/edit/angular-breadcrumbs-light?embed=1&file=src/app/app.component.ts). |
| 110 | + |
| 111 | +```html |
| 112 | + |
| 113 | +<angular-breadcrumbs-light [routes]="routes"></angular-breadcrumbs-light> |
| 114 | + |
| 115 | +``` |
| 116 | + |
| 117 | +There is only 1 __required__ argument. And bunch of optional: |
| 118 | + |
| 119 | +| Title | Type | Description | Default | |
| 120 | +| :---------------: | :-------: | :-----------------------------------------------: | :--------: | |
| 121 | +| __routes *__ | _array_ | array of route objects ([see example above](#routes))| - | |
| 122 | +| base | _string_ | if project's base-href is provided manually, put it here also | - | |
| 123 | +| separator | _string_ | separator for crumbs | / | |
| 124 | +| separatorClass | _string_ | separator class for crumbs | - | |
| 125 | +| icons | _boolean_ | whether to show icons | true | |
| 126 | +| titles | _boolean_ | whether to show titles | true | |
| 127 | +| noTitlesOnMobile | _boolean_ | if _true_ - hide titles when device width <= 600px (do not forget to provide icons in such case)| false | |
| 128 | +| notFoundTitle | _string_ | title for not found pages | 'Page Not Found' | |
| 129 | +| notFoundIcon | _string_ | icon for not found pages | - | |
| 130 | +| notFoundIconClass | _string_ | icon class for not found pages | - | |
| 131 | +| customClasses | _object_ | [classes](#customclasses) for each element of Breadcrumbs component | - | |
| 132 | + |
| 133 | +Similar to first required argument for Breadcrumbs service - __Routes__ array. |
| 134 | + |
| 135 | +#### customClasses |
| 136 | + |
| 137 | +| Title | Type | Description | Html Element | |
| 138 | +| ----------- | ------- | ----------------------------- | ------------------------- | |
| 139 | +| root | string | class for root element | nav | |
| 140 | +| list | string | class for list element | ul | |
| 141 | +| link | string | class for link element | a | |
| 142 | +| currentLink | string | class for currentLink element | li | |
| 143 | +| icon | string | class for icon element | span (holder for icon) | |
| 144 | +| title | string | class for title element | span | |
| 145 | +| separator | string | class for separator element | li (holder for separator) | |
| 146 | + |
| 147 | +## License |
| 148 | + |
| 149 | +This project is licensed under the terms of the [MIT license](https://github.com/mopcweb/angular-breadcrumbs-light/blob/master/LICENSE). |
0 commit comments