-
-
Notifications
You must be signed in to change notification settings - Fork 932
/
add-nav-menu-item.ts
77 lines (75 loc) · 2.44 KB
/
add-nav-menu-item.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { APP_INITIALIZER, Provider } from '@angular/core';
import { NavMenuItem, NavMenuSection } from '../providers/nav-builder/nav-builder-types';
import { NavBuilderService } from '../providers/nav-builder/nav-builder.service';
/**
* @description
* Add a section to the main nav menu. Providing the `before` argument will
* move the section before any existing section with the specified id. If
* omitted (or if the id is not found) the section will be appended to the
* existing set of sections.
* This should be used in the NgModule `providers` array of your ui extension module.
*
* @example
* ```ts title="providers.ts"
* import { addNavMenuSection } from '\@vendure/admin-ui/core';
*
* export default [
* addNavMenuSection({
* id: 'reports',
* label: 'Reports',
* items: [{
* // ...
* }],
* },
* 'settings'),
* ];
* ```
* @docsCategory nav-menu
*/
export function addNavMenuSection(config: NavMenuSection, before?: string): Provider {
return {
provide: APP_INITIALIZER,
multi: true,
useFactory: (navBuilderService: NavBuilderService) => () => {
navBuilderService.addNavMenuSection(config, before);
},
deps: [NavBuilderService],
};
}
/**
* @description
* Add a menu item to an existing section specified by `sectionId`. The id of the section
* can be found by inspecting the DOM and finding the `data-section-id` attribute.
* Providing the `before` argument will move the item before any existing item with the specified id.
* If omitted (or if the name is not found) the item will be appended to the
* end of the section.
*
* This should be used in the NgModule `providers` array of your ui extension module.
*
* @example
* ```ts title="providers.ts"
* import { addNavMenuItem } from '\@vendure/admin-ui/core';
*
* export default [
* addNavMenuItem({
* id: 'reviews',
* label: 'Product Reviews',
* routerLink: ['/extensions/reviews'],
* icon: 'star',
* },
* 'marketing'),
* ];
* ```
*
* @docsCategory nav-menu
*/
export function addNavMenuItem(config: NavMenuItem, sectionId: string, before?: string): Provider {
return {
provide: APP_INITIALIZER,
multi: true,
useFactory: (navBuilderService: NavBuilderService) => () => {
navBuilderService.addNavMenuItem(config, sectionId, before);
},
deps: [NavBuilderService],
};
}