Skip to content

Commit ef0ea13

Browse files
docs: [FC-86] Restructure Modify Items section with Add/Replace examples (#598)
* docs: example of adding Marketing links via the plugin slots * refactor: code refactoring * feat: added logoDestination props for Header component * refactor: after rebase * refactor: updated tests * refactor: after review * refactor: removed logoDestination prop * docs: Custom Marketing links mobile example * refactor: after review
1 parent b8b39bf commit ef0ea13

File tree

6 files changed

+112
-5
lines changed

6 files changed

+112
-5
lines changed

src/plugin-slots/DesktopMainMenuSlot/README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ This slot is used to replace/modify/hide the desktop main menu.
1313

1414
### Modify Items
1515

16-
The following `env.config.jsx` will modify the items in the desktop main menu.
16+
#### Replace All Items
1717

18-
![Screenshot of modified items](./images/desktop_main_menu_modify_items.png)
18+
The following `env.config.jsx` will replace all items in the desktop main menu.
19+
20+
![Screenshot of modified items](./images/desktop_main_menu_replace_all_items.png)
1921

2022
```jsx
2123
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
@@ -59,6 +61,58 @@ const config = {
5961
export default config;
6062
```
6163

64+
#### Add Items
65+
66+
The following `env.config.jsx` will add items in the desktop main menu.
67+
68+
![Screenshot of custom marketing links](./images/desktop_main_menu_add_items.png)
69+
70+
```jsx
71+
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
72+
73+
const modifyMainMenu = (widget) => {
74+
const existingMenu = widget.RenderWidget.props.menu || [];
75+
76+
const newMarketingLinks = [
77+
{
78+
type: 'item',
79+
href: 'https://example.com/how-it-works',
80+
content: 'How it works',
81+
},
82+
{
83+
type: 'item',
84+
href: 'https://example.com/courses',
85+
content: 'Courses',
86+
},
87+
{
88+
type: 'item',
89+
href: 'https://example.com/schools',
90+
content: 'Schools',
91+
}
92+
];
93+
94+
widget.content.menu = [...existingMenu, ...newMarketingLinks];
95+
return widget;
96+
};
97+
98+
const config = {
99+
pluginSlots: {
100+
'org.openedx.frontend.layout.header_desktop_main_menu.v1': {
101+
keepDefault: true,
102+
plugins: [
103+
{
104+
op: PLUGIN_OPERATIONS.Modify,
105+
widgetId: 'default_contents',
106+
fn: modifyMainMenu,
107+
},
108+
]
109+
},
110+
},
111+
}
112+
113+
export default config;
114+
```
115+
62116
### Replace Menu with Custom Component
63117

64118
The following `env.config.jsx` will replace the desktop main menu entirely (in this case with a centered 🗺️ `h1`)
@@ -134,4 +188,3 @@ const config = {
134188

135189
export default config;
136190
```
137-
5.03 KB
Loading

src/plugin-slots/MobileMainMenuSlot/README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ This slot is used to replace/modify/hide the mobile main menu.
1313

1414
### Modify Items
1515

16-
The following `env.config.jsx` will modify the items in the mobile main menu.
16+
#### Replace All Items
1717

18-
![Screenshot of modified items](./images/mobile_main_menu_modify_items.png)
18+
The following `env.config.jsx` will replace all items in the mobile main menu.
19+
20+
![Screenshot of modified items](./images/mobile_main_menu_replace_all_items.png)
1921

2022
```jsx
2123
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
@@ -59,6 +61,58 @@ const config = {
5961
export default config;
6062
```
6163

64+
#### Add Items
65+
66+
The following `env.config.jsx` will add items in the mobile main menu.
67+
68+
![Screenshot of custom marketing links](./images/mobile_main_menu_add_items.png)
69+
70+
```jsx
71+
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
72+
73+
const modifyMainMenu = (widget) => {
74+
const existingMenu = widget.RenderWidget.props.menu || [];
75+
76+
const newMarketingLinks = [
77+
{
78+
type: 'item',
79+
href: 'https://example.com/how-it-works',
80+
content: 'How it works',
81+
},
82+
{
83+
type: 'item',
84+
href: 'https://example.com/courses',
85+
content: 'Courses',
86+
},
87+
{
88+
type: 'item',
89+
href: 'https://example.com/schools',
90+
content: 'Schools',
91+
}
92+
];
93+
94+
widget.content.menu = [...existingMenu, ...newMarketingLinks];
95+
return widget;
96+
};
97+
98+
const config = {
99+
pluginSlots: {
100+
'org.openedx.frontend.layout.header_mobile_main_menu.v1': {
101+
keepDefault: true,
102+
plugins: [
103+
{
104+
op: PLUGIN_OPERATIONS.Modify,
105+
widgetId: 'default_contents',
106+
fn: modifyMainMenu,
107+
},
108+
]
109+
},
110+
},
111+
}
112+
113+
export default config;
114+
```
115+
62116
### Replace Menu with Custom Component
63117

64118
The following `env.config.jsx` will replace the mobile main menu entirely (in this case with a centered 🗺️ `h1`)
36.9 KB
Loading

0 commit comments

Comments
 (0)