Compare commits
107 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43684dce91 | ||
|
|
3ddfbab1ef | ||
|
|
030758e078 | ||
|
|
c56b945f0d | ||
|
|
69750674c3 | ||
|
|
813cbb3156 | ||
|
|
20aaa4f2e2 | ||
|
|
4dfb1b3053 | ||
|
|
171a770235 | ||
|
|
f47c1ed1e6 | ||
|
|
c63da3051b | ||
|
|
04b35786d4 | ||
|
|
657e9c0190 | ||
|
|
2874c9603f | ||
|
|
ec5381ea17 | ||
|
|
d5ac171a5b | ||
|
|
3be690b34b | ||
|
|
441e1542ad | ||
|
|
c1db3d409e | ||
|
|
0c343cfdf0 | ||
|
|
f740d0107e | ||
|
|
98bc20a282 | ||
|
|
ca15863c82 | ||
|
|
ff9cb1b238 | ||
|
|
67967156f4 | ||
|
|
e4720ff6b0 | ||
|
|
df704ce6d7 | ||
|
|
a2dc80ffb8 | ||
|
|
95efe7fedd | ||
|
|
8df7d928dd | ||
|
|
5e77a47708 | ||
|
|
8ef3a27a62 | ||
|
|
e0841996d0 | ||
|
|
90f2e2540e | ||
|
|
6a02c517b9 | ||
|
|
5076d55314 | ||
|
|
2f3b9b87ca | ||
|
|
7970561181 | ||
|
|
8d46de8fe3 | ||
|
|
8341f17d46 | ||
|
|
d7c3e5a687 | ||
|
|
07b1c5bde1 | ||
|
|
5512faa9b0 | ||
|
|
48c49fe0b2 | ||
|
|
8c7778218b | ||
|
|
0dedbbd589 | ||
|
|
ef0b101fea | ||
|
|
edb22316b8 | ||
|
|
227a97afa1 | ||
|
|
d01486e5f7 | ||
|
|
a58f1eaf19 | ||
|
|
a5024c3fde | ||
|
|
d7be18e717 | ||
|
|
5e405da37e | ||
|
|
901f39f42c | ||
|
|
346a636b76 | ||
|
|
34dcc88880 | ||
|
|
a229c34535 | ||
|
|
5d7b4fecf4 | ||
|
|
f04130a7c6 | ||
|
|
cb7774b325 | ||
|
|
3e4eb21d8c | ||
|
|
a346dccd4c | ||
|
|
c64a201072 | ||
|
|
6496642643 | ||
|
|
a6c36654b4 | ||
|
|
ae5253c822 | ||
|
|
e44001e945 | ||
|
|
e07cf665a4 | ||
|
|
8213ee7460 | ||
|
|
8a7d6eecdf | ||
|
|
a2497eeb22 | ||
|
|
a703abad76 | ||
|
|
3f4d987d12 | ||
|
|
45e551ea44 | ||
|
|
a0d7fd7cf2 | ||
|
|
97d1bdedfb | ||
|
|
4351a09c9f | ||
|
|
9647a74507 | ||
|
|
9cef77349f | ||
|
|
ad7c42bcf9 | ||
|
|
266386fe24 | ||
|
|
f42ee37e16 | ||
|
|
354f9fdc38 | ||
|
|
85b07acfb5 | ||
|
|
3e647f7394 | ||
|
|
848b0f37b9 | ||
|
|
818b3800aa | ||
|
|
63e47bc45a | ||
|
|
7ba5371f69 | ||
|
|
9f0c286897 | ||
|
|
4cc5b91d6d | ||
|
|
3d75a72f0c | ||
|
|
0541dc194e | ||
|
|
b92127fd12 | ||
|
|
b2b9f3fa00 | ||
|
|
b9b6282b4b | ||
|
|
8606585978 | ||
|
|
159072779f | ||
|
|
de843d330d | ||
|
|
d554de89ca | ||
|
|
72be96c230 | ||
|
|
564f34a7c6 | ||
|
|
ab15b3d2bf | ||
|
|
59db41c61e | ||
|
|
0415c00353 | ||
|
|
9d01c074e0 |
11
.github/workflows/ci.yml
vendored
@@ -14,18 +14,18 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Nodejs Env
|
||||
run: echo "NODE_VER=`cat .nvmrc`" >> $GITHUB_ENV
|
||||
- name: Setup Nodejs
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VER }}
|
||||
node-version-file: '.nvmrc'
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Validate package-lock.json changes
|
||||
run: make validate-no-uncommitted-package-lock-changes
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
- name: Type check
|
||||
run: npm run types
|
||||
- name: Test
|
||||
run: npm run test
|
||||
- name: Build
|
||||
@@ -33,4 +33,7 @@ jobs:
|
||||
- name: i18n_extract
|
||||
run: npm run i18n_extract
|
||||
- name: Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
fail_ci_if_error: true
|
||||
|
||||
2
.github/workflows/lockfileversion-check.yml
vendored
@@ -10,4 +10,4 @@ on:
|
||||
|
||||
jobs:
|
||||
version-check:
|
||||
uses: openedx/.github/.github/workflows/lockfile-check.yml@master
|
||||
uses: openedx/.github/.github/workflows/lockfileversion-check-v3.yml@master
|
||||
|
||||
7
.github/workflows/release.yml
vendored
@@ -25,12 +25,17 @@ jobs:
|
||||
run: make validate-no-uncommitted-package-lock-changes
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
- name: Type check
|
||||
run: npm run types
|
||||
- name: Test
|
||||
run: npm run test
|
||||
- name: i18n_extract
|
||||
run: npm run i18n_extract
|
||||
- name: Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
fail_ci_if_error: false
|
||||
- name: Build
|
||||
run: npm run build
|
||||
- name: Release
|
||||
|
||||
2
.gitignore
vendored
@@ -9,4 +9,4 @@ module.config.js
|
||||
.idea/
|
||||
|
||||
.vscode
|
||||
src/i18n/messages
|
||||
src/i18n/messages
|
||||
|
||||
@@ -95,6 +95,12 @@ This library has the following exports:
|
||||
* ``messages``: Internationalization messages suitable for use with `@edx/frontend-platform/i18n <https://edx.github.io/frontend-platform/module-Internationalization.html>`_
|
||||
* ``dist/index.scss``: A SASS file which contains style information for the component. It should be imported into the micro-frontend's own SCSS file.
|
||||
|
||||
Plugins
|
||||
-------
|
||||
This can be customized using `Frontend Plugin Framework <https://github.com/openedx/frontend-plugin-framework>`_.
|
||||
|
||||
The parts of this that can be customized in that manner are documented `here </src/plugin-slots>`_.
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
|
||||
14
catalog-info.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file records information about this repo. Its use is described in OEP-55:
|
||||
# https://open-edx-proposals.readthedocs.io/en/latest/processes/oep-0055-proc-project-maintainers.html
|
||||
|
||||
apiVersion: backstage.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: "frontend-component-header"
|
||||
description: "A generic header for the Open edX micro-frontend applications."
|
||||
annotations:
|
||||
openedx.org/arch-interest-groups: ""
|
||||
spec:
|
||||
owner: group:committers-frontend
|
||||
type: "library"
|
||||
lifecycle: "production"
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'babel-polyfill';
|
||||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { initialize, getConfig, subscribe, APP_READY } from '@edx/frontend-platform';
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
@import "@edx/brand/paragon/fonts";
|
||||
@import "@edx/brand/paragon/variables";
|
||||
@import "@openedx/paragon/scss/core/core";
|
||||
@import "@edx/brand/paragon/overrides";
|
||||
@use "@openedx/paragon/dist/core.min.css" as paragonCore;
|
||||
@use "@openedx/paragon/dist/light.min.css" as paragonLight;
|
||||
|
||||
@import "@edx/frontend-component-header/index";
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
# openedx.yaml
|
||||
|
||||
---
|
||||
owner: edx/fedx-team
|
||||
tags:
|
||||
- library
|
||||
- component
|
||||
- react
|
||||
15042
package-lock.json
generated
56
package.json
@@ -10,18 +10,16 @@
|
||||
"build": "make build",
|
||||
"i18n_extract": "fedx-scripts formatjs extract",
|
||||
"lint": "fedx-scripts eslint --ext .js --ext .jsx .",
|
||||
"lint:fix": "fedx-scripts eslint --fix --ext .js --ext .jsx .",
|
||||
"snapshot": "fedx-scripts jest --updateSnapshot",
|
||||
"start": "fedx-scripts webpack-dev-server --progress",
|
||||
"test": "fedx-scripts jest --coverage"
|
||||
"test": "fedx-scripts jest --coverage",
|
||||
"test:dev": "fedx-scripts jest --watchAll",
|
||||
"types": "tsc --noEmit"
|
||||
},
|
||||
"files": [
|
||||
"/dist"
|
||||
],
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "npm run lint"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/openedx/frontend-component-header.git"
|
||||
@@ -35,42 +33,42 @@
|
||||
"devDependencies": {
|
||||
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.2",
|
||||
"@edx/browserslist-config": "^1.1.1",
|
||||
"@edx/frontend-platform": "8.0.0",
|
||||
"@edx/frontend-platform": "^8.3.1",
|
||||
"@edx/reactifex": "^2.1.1",
|
||||
"@openedx/frontend-build": "14.0.3",
|
||||
"@openedx/paragon": "22.2.2",
|
||||
"@testing-library/dom": "10.0.0",
|
||||
"@openedx/frontend-build": "^14.3.2",
|
||||
"@openedx/paragon": "^23.0.0",
|
||||
"@testing-library/dom": "^10.4.0",
|
||||
"@testing-library/jest-dom": "5.17.0",
|
||||
"@testing-library/react": "10.4.9",
|
||||
"husky": "8.0.3",
|
||||
"jest": "29.7.0",
|
||||
"jest-chain": "1.1.6",
|
||||
"@testing-library/react": "^16.2.0",
|
||||
"jest": "30.0.5",
|
||||
"jest-environment-jsdom": "^30.0.0",
|
||||
"prop-types": "15.8.1",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2",
|
||||
"react-redux": "7.2.9",
|
||||
"react-router-dom": "6.22.3",
|
||||
"react-test-renderer": "17.0.2",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-redux": "^8.1.1",
|
||||
"react-router-dom": "6.30.1",
|
||||
"react-test-renderer": "^18.3.1",
|
||||
"redux": "4.2.1",
|
||||
"redux-saga": "1.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-svg-core": "6.5.2",
|
||||
"@fortawesome/free-brands-svg-icons": "6.5.2",
|
||||
"@fortawesome/free-regular-svg-icons": "6.5.2",
|
||||
"@fortawesome/free-solid-svg-icons": "6.5.2",
|
||||
"@fortawesome/fontawesome-svg-core": "6.7.2",
|
||||
"@fortawesome/free-brands-svg-icons": "6.7.2",
|
||||
"@fortawesome/free-regular-svg-icons": "6.7.2",
|
||||
"@fortawesome/free-solid-svg-icons": "6.7.2",
|
||||
"@fortawesome/react-fontawesome": "^0.2.0",
|
||||
"axios-mock-adapter": "1.22.0",
|
||||
"babel-polyfill": "6.26.0",
|
||||
"jest-environment-jsdom": "^29.7.0",
|
||||
"@openedx/frontend-plugin-framework": "^1.7.0",
|
||||
"classnames": "^2.5.1",
|
||||
"react-responsive": "8.2.0",
|
||||
"react-transition-group": "4.4.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@edx/frontend-platform": "^7.0.0 || ^8.0.0",
|
||||
"@openedx/paragon": ">= 21.5.7 < 23.0.0",
|
||||
"@openedx/paragon": ">= 22.0.0 < 24.0.0",
|
||||
"prop-types": "^15.5.10",
|
||||
"react": "^16.9.0 || ^17.0.0",
|
||||
"react-dom": "^16.9.0 || ^17.0.0"
|
||||
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
||||
"react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
||||
"react-router-dom": "^6.14.2"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
|
||||
// Local Components
|
||||
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
||||
import Avatar from './Avatar';
|
||||
import { LinkedLogo, Logo } from './Logo';
|
||||
|
||||
// i18n
|
||||
import messages from './Header.messages';
|
||||
|
||||
// Assets
|
||||
import { CaretIcon } from './Icons';
|
||||
|
||||
class DesktopHeader extends React.Component {
|
||||
constructor(props) { // eslint-disable-line no-useless-constructor
|
||||
super(props);
|
||||
}
|
||||
|
||||
renderMenu(menu) {
|
||||
// Nodes are accepted as a prop
|
||||
if (!Array.isArray(menu)) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
return menu.map((menuItem) => {
|
||||
const {
|
||||
type,
|
||||
href,
|
||||
content,
|
||||
submenuContent,
|
||||
disabled,
|
||||
isActive,
|
||||
} = menuItem;
|
||||
|
||||
if (type === 'item') {
|
||||
return (
|
||||
<a
|
||||
key={`${type}-${content}`}
|
||||
className={`nav-link${disabled ? ' disabled' : ''}${isActive ? ' active' : ''}`}
|
||||
href={href}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Menu key={`${type}-${content}`} tag="div" className="nav-item" respondToPointerEvents>
|
||||
<MenuTrigger tag="a" className="nav-link d-inline-flex align-items-center" href={href}>
|
||||
{content} <CaretIcon role="img" aria-hidden focusable="false" />
|
||||
</MenuTrigger>
|
||||
<MenuContent className="pin-left pin-right shadow py-2">
|
||||
{submenuContent}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
renderMainMenu() {
|
||||
const { mainMenu } = this.props;
|
||||
return this.renderMenu(mainMenu);
|
||||
}
|
||||
|
||||
renderSecondaryMenu() {
|
||||
const { secondaryMenu } = this.props;
|
||||
return this.renderMenu(secondaryMenu);
|
||||
}
|
||||
|
||||
renderUserMenu() {
|
||||
const {
|
||||
userMenu,
|
||||
avatar,
|
||||
username,
|
||||
intl,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<Menu transitionClassName="menu-dropdown" transitionTimeout={250}>
|
||||
<MenuTrigger
|
||||
tag="button"
|
||||
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { username })}
|
||||
className="btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
|
||||
>
|
||||
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" />
|
||||
{username} <CaretIcon role="img" aria-hidden focusable="false" />
|
||||
</MenuTrigger>
|
||||
<MenuContent className="mb-0 dropdown-menu show dropdown-menu-right pin-right shadow py-2">
|
||||
{userMenu.map((group, index) => (
|
||||
// eslint-disable-next-line react/jsx-no-comment-textnodes,react/no-array-index-key
|
||||
<React.Fragment key={index}>
|
||||
{group.heading && <div className="dropdown-header" role="heading" aria-level="1">{group.heading}</div>}
|
||||
{group.items.map(({
|
||||
type, content, href, disabled, isActive,
|
||||
}) => (
|
||||
<a
|
||||
className={`dropdown-${type}${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
|
||||
key={`${type}-${content}`}
|
||||
href={href}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
))}
|
||||
{index < userMenu.length - 1 && <div className="dropdown-divider" role="separator" />}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
renderLoggedOutItems() {
|
||||
const { loggedOutItems } = this.props;
|
||||
|
||||
return loggedOutItems.map((item, i, arr) => (
|
||||
<a
|
||||
key={`${item.type}-${item.content}`}
|
||||
className={i < arr.length - 1 ? 'btn mr-2 btn-link' : 'btn mr-2 btn-outline-primary'}
|
||||
href={item.href}
|
||||
>
|
||||
{item.content}
|
||||
</a>
|
||||
));
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
logo,
|
||||
logoAltText,
|
||||
logoDestination,
|
||||
loggedIn,
|
||||
intl,
|
||||
} = this.props;
|
||||
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
||||
const logoClasses = getConfig().AUTHN_MINIMAL_HEADER ? 'mw-100' : null;
|
||||
|
||||
return (
|
||||
<header className="site-header-desktop">
|
||||
<a className="nav-skip sr-only sr-only-focusable" href="#main">{intl.formatMessage(messages['header.label.skip.nav'])}</a>
|
||||
<div className={`container-fluid ${logoClasses}`}>
|
||||
<div className="nav-container position-relative d-flex align-items-center">
|
||||
{logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} />}
|
||||
<nav
|
||||
aria-label={intl.formatMessage(messages['header.label.main.nav'])}
|
||||
className="nav main-nav"
|
||||
>
|
||||
{this.renderMainMenu()}
|
||||
</nav>
|
||||
<nav
|
||||
aria-label={intl.formatMessage(messages['header.label.secondary.nav'])}
|
||||
className="nav secondary-menu-container align-items-center ml-auto"
|
||||
>
|
||||
{loggedIn
|
||||
? (
|
||||
<>
|
||||
{this.renderSecondaryMenu()}
|
||||
{this.renderUserMenu()}
|
||||
</>
|
||||
) : this.renderLoggedOutItems()}
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
DesktopHeader.propTypes = {
|
||||
mainMenu: PropTypes.oneOfType([
|
||||
PropTypes.node,
|
||||
PropTypes.array,
|
||||
]),
|
||||
secondaryMenu: PropTypes.oneOfType([
|
||||
PropTypes.node,
|
||||
PropTypes.array,
|
||||
]),
|
||||
userMenu: PropTypes.arrayOf(PropTypes.shape({
|
||||
heading: PropTypes.string,
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.oneOf(['item', 'menu']),
|
||||
href: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
isActive: PropTypes.bool,
|
||||
})),
|
||||
})),
|
||||
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.oneOf(['item', 'menu']),
|
||||
href: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
})),
|
||||
logo: PropTypes.string,
|
||||
logoAltText: PropTypes.string,
|
||||
logoDestination: PropTypes.string,
|
||||
avatar: PropTypes.string,
|
||||
username: PropTypes.string,
|
||||
loggedIn: PropTypes.bool,
|
||||
|
||||
// i18n
|
||||
intl: intlShape.isRequired,
|
||||
};
|
||||
|
||||
DesktopHeader.defaultProps = {
|
||||
mainMenu: [],
|
||||
secondaryMenu: [],
|
||||
userMenu: [],
|
||||
loggedOutItems: [],
|
||||
logo: null,
|
||||
logoAltText: null,
|
||||
logoDestination: null,
|
||||
avatar: null,
|
||||
username: null,
|
||||
loggedIn: false,
|
||||
};
|
||||
|
||||
export default injectIntl(DesktopHeader);
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
} from '@edx/frontend-platform';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
import DesktopHeader from './DesktopHeader';
|
||||
import MobileHeader from './MobileHeader';
|
||||
import DesktopHeaderSlot from './plugin-slots/DesktopHeaderSlot';
|
||||
import MobileHeaderSlot from './plugin-slots/MobileHeaderSlot';
|
||||
|
||||
import messages from './Header.messages';
|
||||
|
||||
@@ -123,10 +123,10 @@ const Header = ({
|
||||
return (
|
||||
<>
|
||||
<Responsive maxWidth={769}>
|
||||
<MobileHeader {...props} />
|
||||
<MobileHeaderSlot props={props} />
|
||||
</Responsive>
|
||||
<Responsive minWidth={769}>
|
||||
<DesktopHeader {...props} />
|
||||
<DesktopHeaderSlot props={props} />
|
||||
</Responsive>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -33,6 +33,7 @@ describe('<Header />', () => {
|
||||
};
|
||||
const component = <HeaderComponent width={{ width: 1280 }} contextValue={contextValue} />;
|
||||
|
||||
// FIXME: react-test-renderer is deprecated. Convert to @testing-library/react.
|
||||
const wrapper = TestRenderer.create(component);
|
||||
|
||||
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||
@@ -56,6 +57,7 @@ describe('<Header />', () => {
|
||||
};
|
||||
const component = <HeaderComponent width={{ width: 1280 }} contextValue={contextValue} />;
|
||||
|
||||
// FIXME: react-test-renderer is deprecated. Convert to @testing-library/react.
|
||||
const wrapper = TestRenderer.create(component);
|
||||
|
||||
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||
@@ -74,6 +76,7 @@ describe('<Header />', () => {
|
||||
};
|
||||
const component = <HeaderComponent width={{ width: 500 }} contextValue={contextValue} />;
|
||||
|
||||
// FIXME: react-test-renderer is deprecated. Convert to @testing-library/react.
|
||||
const wrapper = TestRenderer.create(component);
|
||||
|
||||
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||
|
||||
18
src/Logo.jsx
@@ -1,31 +1,23 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const Logo = ({ src, alt, ...attributes }) => (
|
||||
<img src={src} alt={alt} {...attributes} />
|
||||
);
|
||||
|
||||
Logo.propTypes = {
|
||||
src: PropTypes.string.isRequired,
|
||||
alt: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
const LinkedLogo = ({
|
||||
const Logo = ({
|
||||
href,
|
||||
src,
|
||||
alt,
|
||||
...attributes
|
||||
}) => (
|
||||
<a href={href} {...attributes}>
|
||||
<a href={href} className="logo" {...attributes}>
|
||||
<img className="d-block" src={src} alt={alt} />
|
||||
</a>
|
||||
);
|
||||
|
||||
LinkedLogo.propTypes = {
|
||||
export const logoDataShape = {
|
||||
href: PropTypes.string.isRequired,
|
||||
src: PropTypes.string.isRequired,
|
||||
alt: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export { LinkedLogo, Logo };
|
||||
Logo.propTypes = logoDataShape;
|
||||
|
||||
export default Logo;
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
.menu {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.menu-content {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
z-index: 10;
|
||||
background: #fff;
|
||||
background: var(--pgn-color-white, #fff);
|
||||
min-width: 10rem;
|
||||
|
||||
&.pin-left {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
&.pin-right {
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.menu-dropdown-enter {
|
||||
opacity: 0;
|
||||
transform-origin: 75% 0;
|
||||
transform: scale3d(0.8, 0.8, 1);
|
||||
}
|
||||
|
||||
.menu-dropdown-enter-active {
|
||||
transform-origin: 75% 0;
|
||||
transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||
transform: scale3d(1, 1, 1);
|
||||
opacity: 1;
|
||||
}
|
||||
.menu-dropdown-enter-done {
|
||||
}
|
||||
|
||||
.menu-dropdown-exit {
|
||||
transform-origin: 75% 0;
|
||||
transform: scale3d(1, 1, 1);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.menu-dropdown-exit-active {
|
||||
transform-origin: 75% 0;
|
||||
transform: scale3d(0.8, 0.8, 1);
|
||||
transition: all 250ms cubic-bezier(0.8, 0, 0.6, 1);
|
||||
opacity: 0;
|
||||
}
|
||||
.menu-dropdown-exit-done {
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ exports[`<Header /> renders correctly for anonymous desktop 1`] = `
|
||||
<a
|
||||
className="nav-link"
|
||||
href="http://localhost:18000/dashboard"
|
||||
onClick={null}
|
||||
>
|
||||
Courses
|
||||
</a>
|
||||
@@ -229,6 +230,7 @@ exports[`<Header /> renders correctly for authenticated desktop 1`] = `
|
||||
<a
|
||||
className="nav-link"
|
||||
href="http://localhost:18000/dashboard"
|
||||
onClick={null}
|
||||
>
|
||||
Courses
|
||||
</a>
|
||||
|
||||
152
src/desktop-header/DesktopHeader.jsx
Normal file
@@ -0,0 +1,152 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
|
||||
// Local Components
|
||||
import DesktopUserMenuToggleSlot
|
||||
from '../plugin-slots/DesktopUserMenuToggleSlot';
|
||||
import { Menu, MenuTrigger, MenuContent } from '../Menu';
|
||||
import LogoSlot from '../plugin-slots/LogoSlot';
|
||||
import DesktopLoggedOutItemsSlot from '../plugin-slots/DesktopLoggedOutItemsSlot';
|
||||
import { desktopLoggedOutItemsDataShape } from './DesktopLoggedOutItems';
|
||||
import DesktopMainMenuSlot from '../plugin-slots/DesktopMainMenuSlot';
|
||||
import { desktopHeaderMainOrSecondaryMenuDataShape } from './DesktopHeaderMainOrSecondaryMenu';
|
||||
import DesktopSecondaryMenuSlot from '../plugin-slots/DesktopSecondaryMenuSlot';
|
||||
import DesktopUserMenuSlot from '../plugin-slots/DesktopUserMenuSlot';
|
||||
import { desktopUserMenuDataShape } from './DesktopHeaderUserMenu';
|
||||
|
||||
// i18n
|
||||
import messages from '../Header.messages';
|
||||
|
||||
// Assets
|
||||
|
||||
class DesktopHeader extends React.Component {
|
||||
constructor(props) { // eslint-disable-line @typescript-eslint/no-useless-constructor
|
||||
super(props);
|
||||
}
|
||||
|
||||
renderMainMenu() {
|
||||
const { mainMenu } = this.props;
|
||||
return <DesktopMainMenuSlot menu={mainMenu} />;
|
||||
}
|
||||
|
||||
renderSecondaryMenu() {
|
||||
const { secondaryMenu } = this.props;
|
||||
return <DesktopSecondaryMenuSlot menu={secondaryMenu} />;
|
||||
}
|
||||
|
||||
renderUserMenu() {
|
||||
const {
|
||||
userMenu,
|
||||
avatar,
|
||||
username,
|
||||
intl,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<Menu transitionClassName="menu-dropdown" transitionTimeout={250}>
|
||||
<MenuTrigger
|
||||
tag="button"
|
||||
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { username })}
|
||||
className="btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
|
||||
>
|
||||
<DesktopUserMenuToggleSlot avatar={avatar} label={username} />
|
||||
</MenuTrigger>
|
||||
<MenuContent className="mb-0 dropdown-menu show dropdown-menu-right pin-right shadow py-2">
|
||||
<DesktopUserMenuSlot menu={userMenu} />
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
renderLoggedOutItems() {
|
||||
const { loggedOutItems } = this.props;
|
||||
return <DesktopLoggedOutItemsSlot items={loggedOutItems} />;
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
logo,
|
||||
logoAltText,
|
||||
logoDestination,
|
||||
loggedIn,
|
||||
intl,
|
||||
} = this.props;
|
||||
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
||||
const logoClasses = getConfig().AUTHN_MINIMAL_HEADER ? 'mw-100' : null;
|
||||
|
||||
return (
|
||||
<header className="site-header-desktop">
|
||||
<a className="nav-skip sr-only sr-only-focusable" href="#main">{intl.formatMessage(messages['header.label.skip.nav'])}</a>
|
||||
<div className={`container-fluid ${logoClasses}`}>
|
||||
<div className="nav-container position-relative d-flex align-items-center">
|
||||
<LogoSlot {...logoProps} />
|
||||
<nav
|
||||
aria-label={intl.formatMessage(messages['header.label.main.nav'])}
|
||||
className="nav main-nav"
|
||||
>
|
||||
{this.renderMainMenu()}
|
||||
</nav>
|
||||
<nav
|
||||
aria-label={intl.formatMessage(messages['header.label.secondary.nav'])}
|
||||
className="nav secondary-menu-container align-items-center ml-auto"
|
||||
>
|
||||
{loggedIn
|
||||
? (
|
||||
<>
|
||||
{this.renderSecondaryMenu()}
|
||||
{this.renderUserMenu()}
|
||||
</>
|
||||
) : this.renderLoggedOutItems()}
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const desktopHeaderDataShape = {
|
||||
mainMenu: desktopHeaderMainOrSecondaryMenuDataShape,
|
||||
secondaryMenu: desktopHeaderMainOrSecondaryMenuDataShape,
|
||||
userMenu: desktopUserMenuDataShape,
|
||||
loggedOutItems: desktopLoggedOutItemsDataShape,
|
||||
logo: PropTypes.string,
|
||||
logoAltText: PropTypes.string,
|
||||
logoDestination: PropTypes.string,
|
||||
avatar: PropTypes.string,
|
||||
username: PropTypes.string,
|
||||
loggedIn: PropTypes.bool,
|
||||
};
|
||||
|
||||
DesktopHeader.propTypes = {
|
||||
mainMenu: desktopHeaderDataShape.mainMenu,
|
||||
secondaryMenu: desktopHeaderDataShape.secondaryMenu,
|
||||
userMenu: desktopHeaderDataShape.userMenu,
|
||||
loggedOutItems: desktopHeaderDataShape.loggedOutItems,
|
||||
logo: desktopHeaderDataShape.logo,
|
||||
logoAltText: desktopHeaderDataShape.logoAltText,
|
||||
logoDestination: desktopHeaderDataShape.logoDestination,
|
||||
avatar: desktopHeaderDataShape.avatar,
|
||||
username: desktopHeaderDataShape.username,
|
||||
loggedIn: desktopHeaderDataShape.loggedIn,
|
||||
|
||||
// i18n
|
||||
intl: intlShape.isRequired,
|
||||
};
|
||||
|
||||
DesktopHeader.defaultProps = {
|
||||
mainMenu: [],
|
||||
secondaryMenu: [],
|
||||
userMenu: [],
|
||||
loggedOutItems: [],
|
||||
logo: null,
|
||||
logoAltText: null,
|
||||
logoDestination: null,
|
||||
avatar: null,
|
||||
username: null,
|
||||
loggedIn: false,
|
||||
};
|
||||
|
||||
export default injectIntl(DesktopHeader);
|
||||
59
src/desktop-header/DesktopHeaderMainOrSecondaryMenu.jsx
Normal file
@@ -0,0 +1,59 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { Menu, MenuTrigger, MenuContent } from '../Menu';
|
||||
import { CaretIcon } from '../Icons';
|
||||
|
||||
const DesktopHeaderMainOrSecondaryMenu = ({ menu }) => {
|
||||
// Nodes are accepted as a prop
|
||||
if (!Array.isArray(menu)) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
return menu.map((menuItem) => {
|
||||
const {
|
||||
type,
|
||||
href,
|
||||
content,
|
||||
submenuContent,
|
||||
disabled,
|
||||
isActive,
|
||||
onClick,
|
||||
} = menuItem;
|
||||
|
||||
if (type === 'item') {
|
||||
return (
|
||||
<a
|
||||
key={`${type}-${content}`}
|
||||
className={`nav-link${disabled ? ' disabled' : ''}${isActive ? ' active' : ''}`}
|
||||
href={href}
|
||||
onClick={onClick || null}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Menu key={`${type}-${content}`} tag="div" className="nav-item" respondToPointerEvents>
|
||||
<MenuTrigger onClick={onClick || null} tag="a" className="nav-link d-inline-flex align-items-center" href={href}>
|
||||
{content} <CaretIcon role="img" aria-hidden focusable="false" />
|
||||
</MenuTrigger>
|
||||
<MenuContent className="pin-left pin-right shadow py-2">
|
||||
{submenuContent}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export const desktopHeaderMainOrSecondaryMenuDataShape = PropTypes.oneOfType([
|
||||
PropTypes.node,
|
||||
PropTypes.array,
|
||||
]);
|
||||
|
||||
DesktopHeaderMainOrSecondaryMenu.propTypes = {
|
||||
menu: desktopHeaderMainOrSecondaryMenuDataShape,
|
||||
};
|
||||
|
||||
export default DesktopHeaderMainOrSecondaryMenu;
|
||||
39
src/desktop-header/DesktopHeaderUserMenu.jsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const DesktopHeaderUserMenu = ({ menu }) => menu.map((group, index) => (
|
||||
// eslint-disable-next-line react/jsx-no-comment-textnodes,react/no-array-index-key
|
||||
<React.Fragment key={index}>
|
||||
{group.heading && <div className="dropdown-header" role="heading" aria-level="1">{group.heading}</div>}
|
||||
{group.items.map(({
|
||||
type, content, href, disabled, isActive, onClick,
|
||||
}) => (
|
||||
<a
|
||||
className={`dropdown-${type}${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
|
||||
key={`${type}-${content}`}
|
||||
href={href}
|
||||
onClick={onClick || null}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
))}
|
||||
{index < menu.length - 1 && <div className="dropdown-divider" role="separator" />}
|
||||
</React.Fragment>
|
||||
));
|
||||
|
||||
export const desktopUserMenuDataShape = PropTypes.arrayOf(PropTypes.shape({
|
||||
heading: PropTypes.string,
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.oneOf(['item', 'menu']),
|
||||
href: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
isActive: PropTypes.bool,
|
||||
onClick: PropTypes.func,
|
||||
})),
|
||||
}));
|
||||
|
||||
DesktopHeaderUserMenu.propTypes = {
|
||||
menu: desktopUserMenuDataShape,
|
||||
};
|
||||
|
||||
export default DesktopHeaderUserMenu;
|
||||
24
src/desktop-header/DesktopLoggedOutItems.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const DesktopLoggedOutItems = ({ items }) => items.map((item, i, arr) => (
|
||||
<a
|
||||
key={`${item.type}-${item.content}`}
|
||||
className={i < arr.length - 1 ? 'btn mr-2 btn-link' : 'btn mr-2 btn-outline-primary'}
|
||||
href={item.href}
|
||||
>
|
||||
{item.content}
|
||||
</a>
|
||||
));
|
||||
|
||||
export const desktopLoggedOutItemsDataShape = PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.oneOf(['item', 'menu']),
|
||||
href: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
}));
|
||||
|
||||
DesktopLoggedOutItems.propTypes = {
|
||||
items: desktopLoggedOutItemsDataShape,
|
||||
};
|
||||
|
||||
export default DesktopLoggedOutItems;
|
||||
20
src/desktop-header/DesktopUserMenuToggle.jsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { CaretIcon } from '../Icons';
|
||||
import Avatar from '../Avatar';
|
||||
|
||||
const DesktopUserMenuToggle = ({ avatar, label }) => (
|
||||
<>
|
||||
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" />
|
||||
{label} <CaretIcon role="img" aria-hidden focusable="false" />
|
||||
</>
|
||||
);
|
||||
|
||||
export const DesktopUserMenuTogglePropTypes = {
|
||||
avatar: PropTypes.string,
|
||||
label: PropTypes.string,
|
||||
};
|
||||
|
||||
DesktopUserMenuToggle.propTypes = DesktopUserMenuTogglePropTypes;
|
||||
|
||||
export default DesktopUserMenuToggle;
|
||||
41
src/frontend-platform.d.ts
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// frontend-platform currently doesn't provide types... do it ourselves for i18n module at least.
|
||||
// We can remove this in the future when we migrate to frontend-shell, or when frontend-platform gets types
|
||||
// (whichever comes first).
|
||||
|
||||
declare module '@edx/frontend-platform/i18n' {
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { injectIntl as _injectIntl } from 'react-intl';
|
||||
/** @deprecated Use useIntl() hook instead. */
|
||||
export const injectIntl: typeof _injectIntl;
|
||||
/** @deprecated Use useIntl() hook instead. */
|
||||
export const intlShape: any;
|
||||
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
export {
|
||||
createIntl,
|
||||
FormattedDate,
|
||||
FormattedTime,
|
||||
FormattedRelativeTime,
|
||||
FormattedNumber,
|
||||
FormattedPlural,
|
||||
FormattedMessage,
|
||||
defineMessages,
|
||||
IntlProvider,
|
||||
useIntl,
|
||||
} from 'react-intl';
|
||||
|
||||
// Other exports from the i18n module:
|
||||
export const configure: any;
|
||||
export const getPrimaryLanguageSubtag: (code: string) => string;
|
||||
export const getLocale: (locale?: string) => string;
|
||||
export const getMessages: any;
|
||||
export const isRtl: (locale?: string) => boolean;
|
||||
export const handleRtl: any;
|
||||
export const mergeMessages: any;
|
||||
export const LOCALE_CHANGED: any;
|
||||
export const LOCALE_TOPIC: any;
|
||||
export const getCountryList: any;
|
||||
export const getCountryMessages: any;
|
||||
export const getLanguageList: any;
|
||||
export const getLanguageMessages: any;
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
$spacer: 1rem;
|
||||
$blue: #007db8;
|
||||
$white: #fff;
|
||||
$component-active-bg: #0A3055FF !default;
|
||||
$component-active-color: $white !default;
|
||||
$rounded-pill: 50rem !default;
|
||||
|
||||
@import './Menu/menu.scss';
|
||||
@import './studio-header/StudioHeader.scss';
|
||||
@@ -21,8 +24,9 @@ $white: #fff;
|
||||
padding: .75rem;
|
||||
justify-content: center;
|
||||
align-items:center;
|
||||
|
||||
&:hover, &:focus {
|
||||
background: rgba(0,0,0,.1);
|
||||
background: rgba(0, 0, 0, .1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,17 +40,12 @@ $white: #fff;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
padding-bottom: 0.1rem;
|
||||
padding-bottom: calc(var(--pgn-spacing-spacer-base, $spacer)* 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.user-dropdown {
|
||||
.btn {
|
||||
height: 3rem;
|
||||
// @media (max-width: -1 + map-get($grid-breakpoints, "sm")) {
|
||||
// padding: 0 0.5rem;
|
||||
// }
|
||||
}
|
||||
.user-dropdown .btn {
|
||||
height: 3rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +62,7 @@ $white: #fff;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
img {
|
||||
height: 1.5rem;
|
||||
}
|
||||
@@ -70,19 +70,22 @@ $white: #fff;
|
||||
|
||||
|
||||
.site-header-desktop {
|
||||
box-shadow: 0 1px 0 0 rgba(0,0,0,.1);
|
||||
background: $white;
|
||||
box-shadow: 0 1px 0 0 rgba(0, 0, 0, .1);
|
||||
background: var(--pgn-color-white, $white);
|
||||
|
||||
.nav-link {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: block;
|
||||
box-sizing: content-box;
|
||||
position: relative;
|
||||
top: -.05em;
|
||||
height: 1.75rem;
|
||||
padding: 1rem 0;
|
||||
margin-right: 1rem;
|
||||
padding: var(--pgn-spacing-spacer-base, $spacer) 0;
|
||||
margin-right: var(--pgn-spacing-spacer-base, $spacer);
|
||||
|
||||
img {
|
||||
display: block;
|
||||
height: 100%;
|
||||
@@ -93,38 +96,42 @@ $white: #fff;
|
||||
.nav-link:focus,
|
||||
.nav-link.active,
|
||||
.expanded .nav-link {
|
||||
background: $component-active-bg;
|
||||
color: $component-active-color;
|
||||
background: var(--pgn-color-bg-active, $component-active-bg);
|
||||
color: var(--pgn-color-active, $component-active-color);
|
||||
}
|
||||
}
|
||||
.main-nav {
|
||||
.nav-link {
|
||||
padding: 1.125rem 1rem;
|
||||
padding: 1.125rem var(--pgn-spacing-spacer-base, $spacer);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
letter-spacing: .01em;
|
||||
}
|
||||
|
||||
.nav-link:hover,
|
||||
.nav-link:focus,
|
||||
.nav-link.active,
|
||||
.expanded .nav-link {
|
||||
background: $component-active-bg;
|
||||
color: $component-active-color;
|
||||
background: var(--pgn-color-bg-active, $component-active-bg);
|
||||
color: var(--pgn-color-active, $component-active-color);
|
||||
}
|
||||
|
||||
.menu {
|
||||
position: static;
|
||||
|
||||
.menu-content {
|
||||
border-top: solid 2px $component-active-bg;
|
||||
border-top: solid 2px var(--pgn-color-bg-active);
|
||||
left: 0;
|
||||
right: 0;
|
||||
box-shadow: 0 1px 2px rgba(0,0,0,.25);
|
||||
box-shadow: var(--pgn-elevation-box-shadow-down-1, 0 1px 2px rgba(0,0,0,.25));
|
||||
border-bottom-left-radius: 2px;
|
||||
border-bottom-right-radius: 2px;
|
||||
padding: 1rem;
|
||||
padding: var(--pgn-spacing-spacer-base, $spacer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.search-input {
|
||||
border-radius: $rounded-pill;
|
||||
border-radius: var(--pgn-size-rounded-pill, $rounded-pill);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,25 @@ import React from 'react';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { getLoginRedirectUrl } from '@edx/frontend-platform/auth';
|
||||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||
import { Button } from '@openedx/paragon';
|
||||
import LearningLoggedOutItemsSlot from '../plugin-slots/LearningLoggedOutItemsSlot';
|
||||
|
||||
import genericMessages from '../generic/messages';
|
||||
|
||||
const AnonymousUserMenu = ({ intl }) => (
|
||||
<div>
|
||||
<Button
|
||||
className="mr-3"
|
||||
variant="outline-primary"
|
||||
href={`${getConfig().LMS_BASE_URL}/register?next=${encodeURIComponent(global.location.href)}`}
|
||||
>
|
||||
{intl.formatMessage(genericMessages.registerSentenceCase)}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
href={`${getLoginRedirectUrl(global.location.href)}`}
|
||||
>
|
||||
{intl.formatMessage(genericMessages.signInSentenceCase)}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
const AnonymousUserMenu = ({ intl }) => {
|
||||
const buttonsInfo = [
|
||||
{
|
||||
message: intl.formatMessage(genericMessages.registerSentenceCase),
|
||||
href: `${getConfig().LMS_BASE_URL}/register?next=${encodeURIComponent(global.location.href)}`,
|
||||
},
|
||||
{
|
||||
message: intl.formatMessage(genericMessages.signInSentenceCase),
|
||||
href: getLoginRedirectUrl(global.location.href),
|
||||
variant: 'primary',
|
||||
},
|
||||
];
|
||||
|
||||
return <LearningLoggedOutItemsSlot buttonsInfo={buttonsInfo} />;
|
||||
};
|
||||
|
||||
AnonymousUserMenu.propTypes = {
|
||||
intl: intlShape.isRequired,
|
||||
|
||||
@@ -1,50 +1,49 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faUserCircle } from '@fortawesome/free-solid-svg-icons';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||
import { Dropdown } from '@openedx/paragon';
|
||||
|
||||
import LearningUserMenuToggleSlot from '../plugin-slots/LearningUserMenuToggleSlot';
|
||||
import LearningUserMenuSlot from '../plugin-slots/LearningUserMenuSlot';
|
||||
|
||||
import messages from './messages';
|
||||
|
||||
const AuthenticatedUserDropdown = ({ intl, username }) => {
|
||||
const dashboardMenuItem = (
|
||||
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/dashboard`}>
|
||||
{intl.formatMessage(messages.dashboard)}
|
||||
</Dropdown.Item>
|
||||
);
|
||||
const dropdownItems = [
|
||||
{
|
||||
message: intl.formatMessage(messages.dashboard),
|
||||
href: `${getConfig().LMS_BASE_URL}/dashboard`,
|
||||
},
|
||||
{
|
||||
message: intl.formatMessage(messages.profile),
|
||||
href: `${getConfig().ACCOUNT_PROFILE_URL}/u/${username}`,
|
||||
},
|
||||
{
|
||||
message: intl.formatMessage(messages.account),
|
||||
href: getConfig().ACCOUNT_SETTINGS_URL,
|
||||
},
|
||||
...(getConfig().ORDER_HISTORY_URL ? [{
|
||||
message: intl.formatMessage(messages.orderHistory),
|
||||
href: getConfig().ORDER_HISTORY_URL,
|
||||
}] : []),
|
||||
{
|
||||
message: intl.formatMessage(messages.signOut),
|
||||
href: getConfig().LOGOUT_URL,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<a className="text-gray-700" href={`${getConfig().SUPPORT_URL}`}>{intl.formatMessage(messages.help)}</a>
|
||||
<Dropdown className="user-dropdown ml-3">
|
||||
<Dropdown.Toggle variant="outline-primary">
|
||||
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" />
|
||||
<span data-hj-suppress className="d-none d-md-inline">
|
||||
{username}
|
||||
</span>
|
||||
</Dropdown.Toggle>
|
||||
<Dropdown.Menu className="dropdown-menu-right">
|
||||
{dashboardMenuItem}
|
||||
<Dropdown.Item href={`${getConfig().ACCOUNT_PROFILE_URL}/u/${username}`}>
|
||||
{intl.formatMessage(messages.profile)}
|
||||
</Dropdown.Item>
|
||||
<Dropdown.Item href={getConfig().ACCOUNT_SETTINGS_URL}>
|
||||
{intl.formatMessage(messages.account)}
|
||||
</Dropdown.Item>
|
||||
{ getConfig().ORDER_HISTORY_URL && (
|
||||
<Dropdown.Item href={getConfig().ORDER_HISTORY_URL}>
|
||||
{intl.formatMessage(messages.orderHistory)}
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
<Dropdown.Item href={getConfig().LOGOUT_URL}>
|
||||
{intl.formatMessage(messages.signOut)}
|
||||
</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
</>
|
||||
<Dropdown className="user-dropdown ml-3">
|
||||
<Dropdown.Toggle variant="outline-primary" aria-label={intl.formatMessage(messages.userOptionsDropdownLabel)}>
|
||||
<LearningUserMenuToggleSlot label={username} icon={faUserCircle} />
|
||||
</Dropdown.Toggle>
|
||||
<Dropdown.Menu className="dropdown-menu-right">
|
||||
<LearningUserMenuSlot items={dropdownItems} />
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -6,24 +6,11 @@ import { AppContext } from '@edx/frontend-platform/react';
|
||||
|
||||
import AnonymousUserMenu from './AnonymousUserMenu';
|
||||
import AuthenticatedUserDropdown from './AuthenticatedUserDropdown';
|
||||
import LogoSlot from '../plugin-slots/LogoSlot';
|
||||
import CourseInfoSlot from '../plugin-slots/CourseInfoSlot';
|
||||
import { courseInfoDataShape } from './LearningHeaderCourseInfo';
|
||||
import messages from './messages';
|
||||
|
||||
const LinkedLogo = ({
|
||||
href,
|
||||
src,
|
||||
alt,
|
||||
...attributes
|
||||
}) => (
|
||||
<a href={href} {...attributes}>
|
||||
<img className="d-block" src={src} alt={alt} />
|
||||
</a>
|
||||
);
|
||||
|
||||
LinkedLogo.propTypes = {
|
||||
href: PropTypes.string.isRequired,
|
||||
src: PropTypes.string.isRequired,
|
||||
alt: PropTypes.string.isRequired,
|
||||
};
|
||||
import LearningHelpSlot from '../plugin-slots/LearningHelpSlot';
|
||||
|
||||
const LearningHeader = ({
|
||||
courseOrg, courseNumber, courseTitle, intl, showUserDropdown,
|
||||
@@ -31,8 +18,7 @@ const LearningHeader = ({
|
||||
const { authenticatedUser } = useContext(AppContext);
|
||||
|
||||
const headerLogo = (
|
||||
<LinkedLogo
|
||||
className="logo"
|
||||
<LogoSlot
|
||||
href={`${getConfig().LMS_BASE_URL}/dashboard`}
|
||||
src={getConfig().LOGO_URL}
|
||||
alt={getConfig().SITE_NAME}
|
||||
@@ -44,14 +30,16 @@ const LearningHeader = ({
|
||||
<a className="sr-only sr-only-focusable" href="#main-content">{intl.formatMessage(messages.skipNavLink)}</a>
|
||||
<div className="container-xl py-2 d-flex align-items-center">
|
||||
{headerLogo}
|
||||
<div className="flex-grow-1 course-title-lockup" style={{ lineHeight: 1 }}>
|
||||
<span className="d-block small m-0">{courseOrg} {courseNumber}</span>
|
||||
<span className="d-block m-0 font-weight-bold course-title">{courseTitle}</span>
|
||||
<div className="flex-grow-1 course-title-lockup d-flex" style={{ lineHeight: 1 }}>
|
||||
<CourseInfoSlot courseOrg={courseOrg} courseNumber={courseNumber} courseTitle={courseTitle} />
|
||||
</div>
|
||||
{showUserDropdown && authenticatedUser && (
|
||||
<AuthenticatedUserDropdown
|
||||
username={authenticatedUser.username}
|
||||
/>
|
||||
<>
|
||||
<LearningHelpSlot />
|
||||
<AuthenticatedUserDropdown
|
||||
username={authenticatedUser.username}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{showUserDropdown && !authenticatedUser && (
|
||||
<AnonymousUserMenu />
|
||||
@@ -62,9 +50,9 @@ const LearningHeader = ({
|
||||
};
|
||||
|
||||
LearningHeader.propTypes = {
|
||||
courseOrg: PropTypes.string,
|
||||
courseNumber: PropTypes.string,
|
||||
courseTitle: PropTypes.string,
|
||||
courseOrg: courseInfoDataShape.courseOrg,
|
||||
courseNumber: courseInfoDataShape.courseNumber,
|
||||
courseTitle: courseInfoDataShape.courseTitle,
|
||||
intl: intlShape.isRequired,
|
||||
showUserDropdown: PropTypes.bool,
|
||||
};
|
||||
|
||||
23
src/learning-header/LearningHeaderCourseInfo.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const LearningHeaderCourseInfo = ({
|
||||
courseOrg,
|
||||
courseNumber,
|
||||
courseTitle,
|
||||
}) => (
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<span className="d-block small m-0">{courseOrg} {courseNumber}</span>
|
||||
<span className="d-block m-0 font-weight-bold course-title">{courseTitle}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const courseInfoDataShape = {
|
||||
courseOrg: PropTypes.string,
|
||||
courseNumber: PropTypes.string,
|
||||
courseTitle: PropTypes.string,
|
||||
};
|
||||
|
||||
LearningHeaderCourseInfo.propTypes = courseInfoDataShape;
|
||||
|
||||
export default LearningHeaderCourseInfo;
|
||||
14
src/learning-header/LearningHeaderHelpLink.jsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import messages from './messages';
|
||||
|
||||
const LearningHeaderHelpLink = () => {
|
||||
const intl = useIntl();
|
||||
return (
|
||||
<a className="text-gray-700" href={`${getConfig().SUPPORT_URL}`}>{intl.formatMessage(messages.help)}</a>
|
||||
);
|
||||
};
|
||||
|
||||
export default LearningHeaderHelpLink;
|
||||
21
src/learning-header/LearningHeaderUserMenuItems.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { Dropdown } from '@openedx/paragon';
|
||||
|
||||
const LearningHeaderUserMenuItems = ({ items }) => items.map((item) => (
|
||||
<Dropdown.Item href={item.href}>
|
||||
{item.message}
|
||||
</Dropdown.Item>
|
||||
));
|
||||
|
||||
export const learningHeaderUserMenuDataShape = {
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
message: PropTypes.string,
|
||||
href: PropTypes.string,
|
||||
})),
|
||||
};
|
||||
|
||||
LearningHeaderUserMenuItems.propTypes = learningHeaderUserMenuDataShape;
|
||||
|
||||
export default LearningHeaderUserMenuItems;
|
||||
26
src/learning-header/LearningLoggedOutButtons.jsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { Button } from '@openedx/paragon';
|
||||
|
||||
const LearningLoggedOutButtons = ({ buttonsInfo }) => buttonsInfo.map(buttonInfo => (
|
||||
<Button
|
||||
className="ml-3"
|
||||
variant={buttonInfo.variant ?? 'outline-primary'}
|
||||
href={buttonInfo.href}
|
||||
>
|
||||
{buttonInfo.message}
|
||||
</Button>
|
||||
));
|
||||
|
||||
export const learningHeaderLoggedOutItemsDataShape = {
|
||||
buttonsInfo: PropTypes.arrayOf(PropTypes.shape({
|
||||
message: PropTypes.string,
|
||||
href: PropTypes.string,
|
||||
variant: PropTypes.string,
|
||||
})),
|
||||
};
|
||||
|
||||
LearningLoggedOutButtons.propTypes = learningHeaderLoggedOutItemsDataShape;
|
||||
|
||||
export default LearningLoggedOutButtons;
|
||||
28
src/learning-header/LearningUserMenuToggle.jsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import React from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const LearningUserMenuToggle = ({
|
||||
label,
|
||||
icon,
|
||||
}) => (
|
||||
<>
|
||||
<FontAwesomeIcon icon={icon} className="d-md-none" size="lg" />
|
||||
<span data-hj-suppress className="d-none d-md-inline">
|
||||
{label}
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
|
||||
export const LearningUserMenuTogglePropTypes = {
|
||||
label: PropTypes.string.isRequired,
|
||||
// Full shape available by examining @fortawesome/fontawesome-common-types/index.d.ts.
|
||||
icon: PropTypes.shape({
|
||||
prefix: PropTypes.string.isRequired,
|
||||
iconName: PropTypes.string.isRequired,
|
||||
}).isRequired,
|
||||
};
|
||||
|
||||
LearningUserMenuToggle.propTypes = LearningUserMenuTogglePropTypes;
|
||||
|
||||
export default LearningUserMenuToggle;
|
||||
@@ -36,6 +36,11 @@ const messages = defineMessages({
|
||||
defaultMessage: 'Sign Out',
|
||||
description: 'The label for the user menu Sign Out action.',
|
||||
},
|
||||
userOptionsDropdownLabel: {
|
||||
id: 'header.menu.aria-label',
|
||||
defaultMessage: 'User Options',
|
||||
description: 'The aria-label for the user options dropdown.',
|
||||
},
|
||||
});
|
||||
|
||||
export default messages;
|
||||
|
||||
@@ -4,104 +4,45 @@ import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
|
||||
// Local Components
|
||||
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
||||
import Avatar from './Avatar';
|
||||
import { LinkedLogo, Logo } from './Logo';
|
||||
import MobileUserMenuToggleSlot from '../plugin-slots/MobileUserMenuToggleSlot';
|
||||
import { Menu, MenuTrigger, MenuContent } from '../Menu';
|
||||
import LogoSlot from '../plugin-slots/LogoSlot';
|
||||
import MobileLoggedOutItemsSlot from '../plugin-slots/MobileLoggedOutItemsSlot';
|
||||
import { mobileHeaderLoggedOutItemsDataShape } from './MobileLoggedOutItems';
|
||||
import MobileMainMenuSlot from '../plugin-slots/MobileMainMenuSlot';
|
||||
import { mobileHeaderMainMenuDataShape } from './MobileHeaderMainMenu';
|
||||
import MobileUserMenuSlot from '../plugin-slots/MobileUserMenuSlot';
|
||||
import { mobileHeaderUserMenuDataShape } from './MobileHeaderUserMenu';
|
||||
|
||||
// i18n
|
||||
import messages from './Header.messages';
|
||||
import messages from '../Header.messages';
|
||||
|
||||
// Assets
|
||||
import { MenuIcon } from './Icons';
|
||||
import { MenuIcon } from '../Icons';
|
||||
|
||||
class MobileHeader extends React.Component {
|
||||
constructor(props) { // eslint-disable-line no-useless-constructor
|
||||
constructor(props) { // eslint-disable-line @typescript-eslint/no-useless-constructor
|
||||
super(props);
|
||||
}
|
||||
|
||||
renderMenu(menu) {
|
||||
// Nodes are accepted as a prop
|
||||
if (!Array.isArray(menu)) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
return menu.map((menuItem) => {
|
||||
const {
|
||||
type,
|
||||
href,
|
||||
content,
|
||||
submenuContent,
|
||||
disabled,
|
||||
isActive,
|
||||
} = menuItem;
|
||||
|
||||
if (type === 'item') {
|
||||
return (
|
||||
<a
|
||||
key={`${type}-${content}`}
|
||||
className={`nav-link${disabled ? ' disabled' : ''}${isActive ? ' active' : ''}`}
|
||||
href={href}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Menu key={`${type}-${content}`} tag="div" className="nav-item">
|
||||
<MenuTrigger tag="a" role="button" tabIndex="0" className="nav-link">
|
||||
{content}
|
||||
</MenuTrigger>
|
||||
<MenuContent className="position-static pin-left pin-right py-2">
|
||||
{submenuContent}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
renderMainMenu() {
|
||||
const { mainMenu } = this.props;
|
||||
return this.renderMenu(mainMenu);
|
||||
}
|
||||
|
||||
renderSecondaryMenu() {
|
||||
const { secondaryMenu } = this.props;
|
||||
return this.renderMenu(secondaryMenu);
|
||||
const { mainMenu, secondaryMenu } = this.props;
|
||||
return <MobileMainMenuSlot menu={[...mainMenu, ...secondaryMenu]} />;
|
||||
}
|
||||
|
||||
renderUserMenuItems() {
|
||||
const { userMenu } = this.props;
|
||||
|
||||
return userMenu.map((group) => (
|
||||
group.items.map(({
|
||||
type, content, href, disabled, isActive,
|
||||
}) => (
|
||||
<li className="nav-item" key={`${type}-${content}`}>
|
||||
<a
|
||||
className={`nav-link${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
|
||||
href={href}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
</li>
|
||||
))
|
||||
));
|
||||
return <MobileUserMenuSlot menu={userMenu} />;
|
||||
}
|
||||
|
||||
renderLoggedOutItems() {
|
||||
const { loggedOutItems } = this.props;
|
||||
return <MobileLoggedOutItemsSlot items={loggedOutItems} />;
|
||||
}
|
||||
|
||||
return loggedOutItems.map(({ type, href, content }, i, arr) => (
|
||||
<li className="nav-item px-3 my-2" key={`${type}-${content}`}>
|
||||
<a
|
||||
className={i < arr.length - 1 ? 'btn btn-block btn-outline-primary' : 'btn btn-block btn-primary'}
|
||||
href={href}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
</li>
|
||||
));
|
||||
renderUserMenuToggle() {
|
||||
const { avatar, username } = this.props;
|
||||
return <MobileUserMenuToggleSlot avatar={avatar} label={username} />;
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -110,8 +51,6 @@ class MobileHeader extends React.Component {
|
||||
logoAltText,
|
||||
logoDestination,
|
||||
loggedIn,
|
||||
avatar,
|
||||
username,
|
||||
stickyOnMobile,
|
||||
intl,
|
||||
mainMenu,
|
||||
@@ -146,13 +85,12 @@ class MobileHeader extends React.Component {
|
||||
className="nav flex-column pin-left pin-right border-top shadow py-2"
|
||||
>
|
||||
{this.renderMainMenu()}
|
||||
{this.renderSecondaryMenu()}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
</div>
|
||||
) : null}
|
||||
<div className={`w-100 d-flex ${logoClasses}`}>
|
||||
{ logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} itemType="http://schema.org/Organization" />}
|
||||
<LogoSlot {...logoProps} itemType="http://schema.org/Organization" />
|
||||
</div>
|
||||
{userMenu.length > 0 || loggedOutItems.length > 0 ? (
|
||||
<div className="w-100 d-flex justify-content-end align-items-center">
|
||||
@@ -163,7 +101,7 @@ class MobileHeader extends React.Component {
|
||||
aria-label={intl.formatMessage(messages['header.label.account.menu'])}
|
||||
title={intl.formatMessage(messages['header.label.account.menu'])}
|
||||
>
|
||||
<Avatar size="1.5rem" src={avatar} alt={username} />
|
||||
{this.renderUserMenuToggle()}
|
||||
</MenuTrigger>
|
||||
<MenuContent tag="ul" className="nav flex-column pin-left pin-right border-top shadow py-2">
|
||||
{loggedIn ? this.renderUserMenuItems() : this.renderLoggedOutItems()}
|
||||
@@ -176,29 +114,11 @@ class MobileHeader extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
MobileHeader.propTypes = {
|
||||
mainMenu: PropTypes.oneOfType([
|
||||
PropTypes.node,
|
||||
PropTypes.array,
|
||||
]),
|
||||
secondaryMenu: PropTypes.oneOfType([
|
||||
PropTypes.node,
|
||||
PropTypes.array,
|
||||
]),
|
||||
userMenu: PropTypes.arrayOf(PropTypes.shape({
|
||||
heading: PropTypes.string,
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.oneOf(['item', 'menu']),
|
||||
href: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
isActive: PropTypes.bool,
|
||||
})),
|
||||
})),
|
||||
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.oneOf(['item', 'menu']),
|
||||
href: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
})),
|
||||
export const mobileHeaderDataShape = {
|
||||
mainMenu: mobileHeaderMainMenuDataShape,
|
||||
secondaryMenu: mobileHeaderMainMenuDataShape,
|
||||
userMenu: mobileHeaderUserMenuDataShape,
|
||||
loggedOutItems: mobileHeaderLoggedOutItemsDataShape,
|
||||
logo: PropTypes.string,
|
||||
logoAltText: PropTypes.string,
|
||||
logoDestination: PropTypes.string,
|
||||
@@ -206,6 +126,20 @@ MobileHeader.propTypes = {
|
||||
username: PropTypes.string,
|
||||
loggedIn: PropTypes.bool,
|
||||
stickyOnMobile: PropTypes.bool,
|
||||
};
|
||||
|
||||
MobileHeader.propTypes = {
|
||||
mainMenu: mobileHeaderDataShape.mainMenu,
|
||||
secondaryMenu: mobileHeaderDataShape.secondaryMenu,
|
||||
userMenu: mobileHeaderDataShape.userMenu,
|
||||
loggedOutItems: mobileHeaderDataShape.loggedOutItems,
|
||||
logo: mobileHeaderDataShape.logo,
|
||||
logoAltText: mobileHeaderDataShape.logoAltText,
|
||||
logoDestination: mobileHeaderDataShape.logoDestination,
|
||||
avatar: mobileHeaderDataShape.avatar,
|
||||
username: mobileHeaderDataShape.username,
|
||||
loggedIn: mobileHeaderDataShape.loggedIn,
|
||||
stickyOnMobile: mobileHeaderDataShape.stickyOnMobile,
|
||||
|
||||
// i18n
|
||||
intl: intlShape.isRequired,
|
||||
58
src/mobile-header/MobileHeaderMainMenu.jsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { Menu, MenuTrigger, MenuContent } from '../Menu';
|
||||
|
||||
const MobileHeaderMainMenu = ({ menu }) => {
|
||||
// Nodes are accepted as a prop
|
||||
if (!Array.isArray(menu)) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
return menu.map((menuItem) => {
|
||||
const {
|
||||
type,
|
||||
href,
|
||||
content,
|
||||
submenuContent,
|
||||
disabled,
|
||||
isActive,
|
||||
onClick,
|
||||
} = menuItem;
|
||||
|
||||
if (type === 'item') {
|
||||
return (
|
||||
<a
|
||||
key={`${type}-${content}`}
|
||||
className={`nav-link${disabled ? ' disabled' : ''}${isActive ? ' active' : ''}`}
|
||||
href={href}
|
||||
onClick={onClick || null}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Menu key={`${type}-${content}`} tag="div" className="nav-item">
|
||||
<MenuTrigger onClick={onClick || null} tag="a" role="button" tabIndex="0" className="nav-link">
|
||||
{content}
|
||||
</MenuTrigger>
|
||||
<MenuContent className="position-static pin-left pin-right py-2">
|
||||
{submenuContent}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export const mobileHeaderMainMenuDataShape = PropTypes.oneOfType([
|
||||
PropTypes.node,
|
||||
PropTypes.array,
|
||||
]);
|
||||
|
||||
MobileHeaderMainMenu.propTypes = {
|
||||
menu: mobileHeaderMainMenuDataShape,
|
||||
};
|
||||
|
||||
export default MobileHeaderMainMenu;
|
||||
35
src/mobile-header/MobileHeaderUserMenu.jsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const MobileHeaderUserMenu = ({ menu }) => menu.map((group) => (
|
||||
group.items.map(({
|
||||
type, content, href, disabled, isActive, onClick,
|
||||
}) => (
|
||||
<li className="nav-item" key={`${type}-${content}`}>
|
||||
<a
|
||||
className={`nav-link${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
|
||||
href={href}
|
||||
onClick={onClick || null}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
</li>
|
||||
))
|
||||
));
|
||||
|
||||
export const mobileHeaderUserMenuDataShape = PropTypes.arrayOf(PropTypes.shape({
|
||||
heading: PropTypes.string,
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.oneOf(['item', 'menu']),
|
||||
href: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
isActive: PropTypes.bool,
|
||||
onClick: PropTypes.func,
|
||||
})),
|
||||
}));
|
||||
|
||||
MobileHeaderUserMenu.propTypes = {
|
||||
menu: mobileHeaderUserMenuDataShape,
|
||||
};
|
||||
|
||||
export default MobileHeaderUserMenu;
|
||||
25
src/mobile-header/MobileLoggedOutItems.jsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const MobileLoggedOutItems = ({ items }) => items.map(({ type, href, content }, i, arr) => (
|
||||
<li className="nav-item px-3 my-2" key={`${type}-${content}`}>
|
||||
<a
|
||||
className={i < arr.length - 1 ? 'btn btn-block btn-outline-primary' : 'btn btn-block btn-primary'}
|
||||
href={href}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
</li>
|
||||
));
|
||||
|
||||
export const mobileHeaderLoggedOutItemsDataShape = PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.oneOf(['item', 'menu']),
|
||||
href: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
}));
|
||||
|
||||
MobileLoggedOutItems.propTypes = {
|
||||
menu: mobileHeaderLoggedOutItemsDataShape,
|
||||
};
|
||||
|
||||
export default MobileLoggedOutItems;
|
||||
14
src/mobile-header/MobileUserMenuToggle.jsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Avatar from '../Avatar';
|
||||
|
||||
const MobileUserMenuToggle = ({ avatar, username }) => <Avatar size="1.5rem" src={avatar} alt={username} />;
|
||||
|
||||
export const MobileUserMenuTogglePropTypes = {
|
||||
avatar: PropTypes.string,
|
||||
username: PropTypes.string,
|
||||
};
|
||||
|
||||
MobileUserMenuToggle.propTypes = MobileUserMenuTogglePropTypes;
|
||||
|
||||
export default MobileUserMenuToggle;
|
||||
128
src/plugin-slots/CourseInfoSlot/README.md
Normal file
@@ -0,0 +1,128 @@
|
||||
# Course Info Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_learning_course_info.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `course_info_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the course info.
|
||||
|
||||
## Examples
|
||||
|
||||
### Replace Course Title
|
||||
|
||||
The following `env.config.jsx` will replace the course title.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const replaceCourseTitle = ( widget ) => {
|
||||
widget.content.courseTitle = "Custom Course Title";
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_course_info.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: replaceCourseTitle,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Course Info with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the course info entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_course_info.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_course_info_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after Course Info
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the course info (in this case centered `h1`s with 🌜 and 🌛).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_course_info.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_course_info_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h3 style={{
|
||||
marginTop: 'auto',
|
||||
marginBottom: 'auto',
|
||||
marginRight: '0.5rem',
|
||||
}}>🌜</h3>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_course_info_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h3 style={{
|
||||
marginTop: 'auto',
|
||||
marginBottom: 'auto',
|
||||
marginLeft: '0.5rem',
|
||||
}}>🌛</h3>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 13 KiB |
BIN
src/plugin-slots/CourseInfoSlot/images/replace_course_title.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
34
src/plugin-slots/CourseInfoSlot/index.jsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import LearningHeaderCourseInfo, { courseInfoDataShape } from '../../learning-header/LearningHeaderCourseInfo';
|
||||
|
||||
const CourseInfoSlot = ({
|
||||
courseOrg,
|
||||
courseNumber,
|
||||
courseTitle,
|
||||
...attributes
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_learning_course_info.v1"
|
||||
idAliases={['course_info_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
pluginProps={{
|
||||
courseOrg,
|
||||
courseNumber,
|
||||
courseTitle,
|
||||
}}
|
||||
>
|
||||
<LearningHeaderCourseInfo
|
||||
courseOrg={courseOrg}
|
||||
courseNumber={courseNumber}
|
||||
courseTitle={courseTitle}
|
||||
{...attributes}
|
||||
/>
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
CourseInfoSlot.propTypes = courseInfoDataShape;
|
||||
|
||||
export default CourseInfoSlot;
|
||||
44
src/plugin-slots/DesktopHeaderSlot/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Desktop Header Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_desktop.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `desktop_header_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the entire desktop header.
|
||||
|
||||
## Examples
|
||||
|
||||
### Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the desktop header entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_desktop_header_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 27 KiB |
21
src/plugin-slots/DesktopHeaderSlot/index.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import DesktopHeader, { desktopHeaderDataShape } from '../../desktop-header/DesktopHeader';
|
||||
|
||||
const DesktopHeaderSlot = ({
|
||||
props,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_desktop.v1"
|
||||
idAliases={['desktop_header_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<DesktopHeader {...props} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
DesktopHeaderSlot.propTypes = desktopHeaderDataShape;
|
||||
|
||||
export default DesktopHeaderSlot;
|
||||
137
src/plugin-slots/DesktopLoggedOutItemsSlot/README.md
Normal file
@@ -0,0 +1,137 @@
|
||||
# Desktop Logged Out Items Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_desktop_logged_out_items.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `desktop_logged_out_items_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the items shown on desktop when the user is logged out.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items shown on desktop when the user is logged out.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyLoggedOutItems = ( widget ) => {
|
||||
widget.content.items = [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://openedx.org/',
|
||||
content: 'openedx.org',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://docs.openedx.org/en/latest/',
|
||||
content: 'Documentation',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://discuss.openedx.org/',
|
||||
content: 'Forums',
|
||||
}
|
||||
];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_logged_out_items.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyLoggedOutItems,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the items shown on desktop when the user is logged out entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_logged_out_items.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the items shown on desktop when the user is logged out (in this case centered `h1`s with 🌜 and 🌛).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_logged_out_items.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌜</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌛</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 13 KiB |
23
src/plugin-slots/DesktopLoggedOutItemsSlot/index.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import DesktopLoggedOutItems, { desktopLoggedOutItemsDataShape } from '../../desktop-header/DesktopLoggedOutItems';
|
||||
|
||||
const DesktopLoggedOutItemsSlot = ({
|
||||
items,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_desktop_logged_out_items.v1"
|
||||
idAliases={['desktop_logged_out_items_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<DesktopLoggedOutItems items={items} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
DesktopLoggedOutItemsSlot.propTypes = {
|
||||
items: desktopLoggedOutItemsDataShape,
|
||||
};
|
||||
|
||||
export default DesktopLoggedOutItemsSlot;
|
||||
137
src/plugin-slots/DesktopMainMenuSlot/README.md
Normal file
@@ -0,0 +1,137 @@
|
||||
# Desktop Main Menu Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_desktop_main_menu.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `desktop_main_menu_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the desktop main menu.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items in the desktop main menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyMainMenu = ( widget ) => {
|
||||
widget.content.menu = [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://openedx.org/',
|
||||
content: 'openedx.org',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://docs.openedx.org/en/latest/',
|
||||
content: 'Documentation',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://discuss.openedx.org/',
|
||||
content: 'Forums',
|
||||
}
|
||||
];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_main_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyMainMenu,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the desktop main menu entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_main_menu.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_main_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after Menu
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the desktop main menu (in this case centered `h1`s with 🌜 and 🌛).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_main_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_main_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌜</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_main_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌛</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 10 KiB |
23
src/plugin-slots/DesktopMainMenuSlot/index.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import DesktopHeaderMainOrSecondaryMenu, { desktopHeaderMainOrSecondaryMenuDataShape } from '../../desktop-header/DesktopHeaderMainOrSecondaryMenu';
|
||||
|
||||
const DesktopMainMenuSlot = ({
|
||||
menu,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_desktop_main_menu.v1"
|
||||
idAliases={['desktop_main_menu_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<DesktopHeaderMainOrSecondaryMenu menu={menu} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
DesktopMainMenuSlot.propTypes = {
|
||||
menu: desktopHeaderMainOrSecondaryMenuDataShape,
|
||||
};
|
||||
|
||||
export default DesktopMainMenuSlot;
|
||||
132
src/plugin-slots/DesktopSecondaryMenuSlot/README.md
Normal file
@@ -0,0 +1,132 @@
|
||||
# Desktop Secondary Menu Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_desktop_secondary_menu.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `desktop_secondary_menu_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the desktop secondary menu.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items in the desktop secondary menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifySecondaryMenu = ( widget ) => {
|
||||
widget.content.menu = [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://www.youtube.com/c/openedx',
|
||||
content: 'Open edX on YouTube',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://github.com/openedx/',
|
||||
content: 'Open edX on GitHub',
|
||||
}
|
||||
];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_secondary_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifySecondaryMenu,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the desktop secondary menu entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_secondary_menu.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_secondary_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after Menu
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the desktop secondary menu (in this case centered `h1`s with 🌜 and 🌛).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_secondary_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_secondary_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌜</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_secondary_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌛</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 16 KiB |
23
src/plugin-slots/DesktopSecondaryMenuSlot/index.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import DesktopHeaderMainOrSecondaryMenu, { desktopHeaderMainOrSecondaryMenuDataShape } from '../../desktop-header/DesktopHeaderMainOrSecondaryMenu';
|
||||
|
||||
const DesktopSecondaryMenuSlot = ({
|
||||
menu,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_desktop_secondary_menu.v1"
|
||||
idAliases={['desktop_secondary_menu_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<DesktopHeaderMainOrSecondaryMenu menu={menu} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
DesktopSecondaryMenuSlot.propTypes = {
|
||||
menu: desktopHeaderMainOrSecondaryMenuDataShape,
|
||||
};
|
||||
|
||||
export default DesktopSecondaryMenuSlot;
|
||||
144
src/plugin-slots/DesktopUserMenuSlot/README.md
Normal file
@@ -0,0 +1,144 @@
|
||||
# Desktop User Menu Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_desktop_user_menu.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `desktop_user_menu_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the desktop user menu.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items in the desktop user menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyUserMenu = ( widget ) => {
|
||||
widget.content.menu = [
|
||||
{
|
||||
items: [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://openedx.org/',
|
||||
content: 'openedx.org',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://docs.openedx.org/en/latest/',
|
||||
content: 'Documentation',
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
items: [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://discuss.openedx.org/',
|
||||
content: 'Forums',
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_user_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyUserMenu,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the desktop user menu entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_user_menu.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_user_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after Menu
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the desktop user menu (in this case centered `h1`s with 🌞 and 🌚).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_user_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_user_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌞</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_user_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌚</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 11 KiB |
23
src/plugin-slots/DesktopUserMenuSlot/index.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import DesktopHeaderUserMenu, { desktopUserMenuDataShape } from '../../desktop-header/DesktopHeaderUserMenu';
|
||||
|
||||
const DesktopUserMenuSlot = ({
|
||||
menu,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_desktop_user_menu.v1"
|
||||
idAliases={['desktop_user_menu_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<DesktopHeaderUserMenu menu={menu} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
DesktopUserMenuSlot.propTypes = {
|
||||
menu: desktopUserMenuDataShape,
|
||||
};
|
||||
|
||||
export default DesktopUserMenuSlot;
|
||||
74
src/plugin-slots/DesktopUserMenuToggleSlot/README.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Desktop User Menu Toggle Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_desktop_user_menu_toggle.v1`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the contents of the user menu toggle button on desktop sized screens.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Label Text
|
||||
|
||||
The following `env.config.jsx` will modify the label text to be something more generic:
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
import { faHouse } from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
const modifyUserMenuToggle = ( widget ) => {
|
||||
widget.content.label = "My Profile";
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_user_menu_toggle.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyUserMenuToggle,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu toggle contents with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the contents of the learning user menu toggle button entirely (in this case with an emoji)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_user_menu_toggle.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_desktop_user_menu_toggle',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<span>🦊</span>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
21
src/plugin-slots/DesktopUserMenuToggleSlot/index.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import DesktopUserMenuToggle, { DesktopUserMenuTogglePropTypes } from '../../desktop-header/DesktopUserMenuToggle';
|
||||
|
||||
const DesktopUserMenuToggleSlot = ({
|
||||
avatar,
|
||||
label,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_desktop_user_menu_toggle.v1"
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<DesktopUserMenuToggle avatar={avatar} label={label} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
DesktopUserMenuToggleSlot.propTypes = DesktopUserMenuTogglePropTypes;
|
||||
|
||||
export default DesktopUserMenuToggleSlot;
|
||||
44
src/plugin-slots/LearningHelpSlot/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Learning Help Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_learning_help.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `learning_help_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the learning help link.
|
||||
|
||||
## Examples
|
||||
|
||||
### Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the help link entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_help.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_learning_help_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 18 KiB |
11
src/plugin-slots/LearningHelpSlot/index.jsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import LearningHeaderHelpLink from '../../learning-header/LearningHeaderHelpLink';
|
||||
|
||||
const LearningHelpSlot = () => (
|
||||
<PluginSlot id="org.openedx.frontend.layout.header_learning_help.v1" idAliases={['learning_help_slot']}>
|
||||
<LearningHeaderHelpLink />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
export default LearningHelpSlot;
|
||||
135
src/plugin-slots/LearningLoggedOutItemsSlot/README.md
Normal file
@@ -0,0 +1,135 @@
|
||||
# Learning Logged Out Items Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_learning_logged_out_items.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `learning_logged_out_items_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the items shown on the learning header when the user is logged out.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items shown on the learning header when the user is logged out.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyLoggedOutItems = ( widget ) => {
|
||||
widget.content.buttonsInfo = [
|
||||
{
|
||||
href: 'https://docs.openedx.org/en/latest/',
|
||||
message: 'Documentation',
|
||||
},
|
||||
{
|
||||
href: 'https://discuss.openedx.org/',
|
||||
message: 'Forums',
|
||||
},
|
||||
{
|
||||
href: 'https://openedx.org/',
|
||||
message: 'openedx.org',
|
||||
variant: 'primary',
|
||||
},
|
||||
];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_logged_out_items.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyLoggedOutItems,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the items shown in the learning header when the user is logged out entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_logged_out_items.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the items shown in the learning header when the user is logged out (in this case centered `h1`s with 🌜 and 🌛).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_logged_out_items.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌜</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌛</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 18 KiB |
21
src/plugin-slots/LearningLoggedOutItemsSlot/index.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import LearningLoggedOutButtons, { learningHeaderLoggedOutItemsDataShape } from '../../learning-header/LearningLoggedOutButtons';
|
||||
|
||||
const LearningLoggedOutItemsSlot = ({
|
||||
buttonsInfo,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_learning_logged_out_items.v1"
|
||||
idAliases={['learning_logged_out_items_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<LearningLoggedOutButtons buttonsInfo={buttonsInfo} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
LearningLoggedOutItemsSlot.propTypes = learningHeaderLoggedOutItemsDataShape;
|
||||
|
||||
export default LearningLoggedOutItemsSlot;
|
||||
133
src/plugin-slots/LearningUserMenuSlot/README.md
Normal file
@@ -0,0 +1,133 @@
|
||||
# Learning User Menu Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_learning_user_menu.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `learning_user_menu_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the learning user menu.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items in the learning user menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyUserMenu = ( widget ) => {
|
||||
widget.content.items = [
|
||||
{
|
||||
href: 'https://openedx.org/',
|
||||
message: 'openedx.org',
|
||||
},
|
||||
{
|
||||
href: 'https://docs.openedx.org/en/latest/',
|
||||
message: 'Documentation',
|
||||
},
|
||||
{
|
||||
href: 'https://discuss.openedx.org/',
|
||||
message: 'Forums',
|
||||
}
|
||||
];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_user_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyUserMenu,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the items in the learning user menu entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_user_menu.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_user_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after Menu
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the learning user menu (in this case centered `h1`s with 🌞 and 🌚).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_user_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_user_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌞</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_user_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌚</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
21
src/plugin-slots/LearningUserMenuSlot/index.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import LearningHeaderUserMenuItems, { learningHeaderUserMenuDataShape } from '../../learning-header/LearningHeaderUserMenuItems';
|
||||
|
||||
const LearningUserMenuSlot = ({
|
||||
items,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_learning_user_menu.v1"
|
||||
idAliases={['learning_user_menu_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<LearningHeaderUserMenuItems items={items} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
LearningUserMenuSlot.propTypes = learningHeaderUserMenuDataShape;
|
||||
|
||||
export default LearningUserMenuSlot;
|
||||
74
src/plugin-slots/LearningUserMenuToggleSlot/README.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Learning User Menu Toggle Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_learning_user_menu_toggle.v1`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the contents of the learning user menu toggle button.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Icon
|
||||
|
||||
The following `env.config.jsx` will modify the icon for the learning user menu toggle button. **Note:** The icon is only shown on mobile screens.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
import { faHouse } from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
const modifyUserMenuToggle = ( widget ) => {
|
||||
widget.content.icon = faHouse;
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_user_menu_toggle.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyUserMenuToggle,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu toggle contents with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the contents of the learning user menu toggle button's contents entirely (in this case with an emoji)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_learning_user_menu_toggle.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_learning_user_menu_toggle',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<span>🦊</span>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
22
src/plugin-slots/LearningUserMenuToggleSlot/index.jsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import LearningUserMenuToggle, {
|
||||
LearningUserMenuTogglePropTypes,
|
||||
} from '../../learning-header/LearningUserMenuToggle';
|
||||
|
||||
const LearningUserMenuToggleSlot = ({
|
||||
label, icon,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_learning_user_menu_toggle.v1"
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<LearningUserMenuToggle label={label} icon={icon} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
LearningUserMenuToggleSlot.propTypes = LearningUserMenuTogglePropTypes;
|
||||
|
||||
export default LearningUserMenuToggleSlot;
|
||||
72
src/plugin-slots/LogoSlot/README.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# Logo Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_logo.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `logo_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the logo.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify URL
|
||||
|
||||
The following `env.config.jsx` will modify the link href for the logo.
|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyLogoHref = ( widget ) => {
|
||||
widget.content.href = "https://openedx.org/";
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_logo.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyLogoHref,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the logo entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_logo.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_logo_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
21
src/plugin-slots/LogoSlot/index.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import Logo, { logoDataShape } from '../../Logo';
|
||||
|
||||
const LogoSlot = ({
|
||||
href, src, alt, ...attributes
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_logo.v1"
|
||||
idAliases={['logo_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<Logo href={href} src={src} alt={alt} {...attributes} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
LogoSlot.propTypes = logoDataShape;
|
||||
|
||||
export default LogoSlot;
|
||||
44
src/plugin-slots/MobileHeaderSlot/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Mobile Header Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_mobile.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `mobile_header_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the entire mobile header.
|
||||
|
||||
## Examples
|
||||
|
||||
### Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the mobile header entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_mobile.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_mobile_header_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 16 KiB |
21
src/plugin-slots/MobileHeaderSlot/index.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import MobileHeader, { mobileHeaderDataShape } from '../../mobile-header/MobileHeader';
|
||||
|
||||
const MobileHeaderSlot = ({
|
||||
props,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_mobile.v1"
|
||||
idAliases={['mobile_header_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<MobileHeader {...props} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
MobileHeaderSlot.propTypes = mobileHeaderDataShape;
|
||||
|
||||
export default MobileHeaderSlot;
|
||||
136
src/plugin-slots/MobileLoggedOutItemsSlot/README.md
Normal file
@@ -0,0 +1,136 @@
|
||||
# Mobile Logged Out Items Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_mobile_logged_out_items.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `mobile_logged_out_items_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the mobile user menu when logged out.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items in mobile user menu when logged out.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyLoggedOutItems = ( widget ) => {
|
||||
widget.content.items = [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://openedx.org/',
|
||||
content: 'openedx.org',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://docs.openedx.org/en/latest/',
|
||||
content: 'Documentation',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://discuss.openedx.org/',
|
||||
content: 'Forums',
|
||||
}
|
||||
];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_mobile_logged_out_items.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyLoggedOutItems,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Items with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the items in mobile user menu when logged out entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_mobile_logged_out_items.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after Items
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the items in mobile user menu when logged out (in this case centered `h1`s with 🌞 and 🌚).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_mobile_logged_out_items.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌞</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_logged_out_items_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌚</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
23
src/plugin-slots/MobileLoggedOutItemsSlot/index.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import MobileLoggedOutItems, { mobileHeaderLoggedOutItemsDataShape } from '../../mobile-header/MobileLoggedOutItems';
|
||||
|
||||
const MobileLoggedOutItemsSlot = ({
|
||||
items,
|
||||
}) => (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.header_mobile_logged_out_items.v1"
|
||||
idAliases={['mobile_logged_out_items_slot']}
|
||||
slotOptions={{
|
||||
mergeProps: true,
|
||||
}}
|
||||
>
|
||||
<MobileLoggedOutItems items={items} />
|
||||
</PluginSlot>
|
||||
);
|
||||
|
||||
MobileLoggedOutItemsSlot.propTypes = {
|
||||
items: mobileHeaderLoggedOutItemsDataShape,
|
||||
};
|
||||
|
||||
export default MobileLoggedOutItemsSlot;
|
||||
136
src/plugin-slots/MobileMainMenuSlot/README.md
Normal file
@@ -0,0 +1,136 @@
|
||||
# Mobile Main Menu Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.header_mobile_main_menu.v1`
|
||||
|
||||
### Slot ID Aliases
|
||||
* `mobile_main_menu_slot`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the mobile main menu.
|
||||
|
||||
## Examples
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items in the mobile main menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyMainMenu = ( widget ) => {
|
||||
widget.content.menu = [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://openedx.org/',
|
||||
content: 'openedx.org',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://docs.openedx.org/en/latest/',
|
||||
content: 'Documentation',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://discuss.openedx.org/',
|
||||
content: 'Forums',
|
||||
}
|
||||
];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_mobile_main_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyMainMenu,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the mobile main menu entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_mobile_main_menu.v1': {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_main_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🗺️</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add Custom Components before and after Menu
|
||||
|
||||
The following `env.config.jsx` will place custom components before and after the mobile main menu (in this case centered `h1`s with 🌞 and 🌚).
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_mobile_main_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_before_main_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 10,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌞</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: 'custom_after_main_menu_component',
|
||||
type: DIRECT_PLUGIN,
|
||||
priority: 90,
|
||||
RenderWidget: () => (
|
||||
<h1 style={{textAlign: 'center'}}>🌚</h1>
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
After Width: | Height: | Size: 8.3 KiB |