Skip to content

Commit bee173a

Browse files
feat: add frontend-plugin-framework LogoSlot
1 parent a0d7fd7 commit bee173a

File tree

9 files changed

+370
-1597
lines changed

9 files changed

+370
-1597
lines changed

package-lock.json

Lines changed: 265 additions & 1561 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@fortawesome/free-regular-svg-icons": "6.6.0",
6161
"@fortawesome/free-solid-svg-icons": "6.6.0",
6262
"@fortawesome/react-fontawesome": "^0.2.0",
63+
"@openedx/frontend-plugin-framework": "github:brian-smith-tcril/frontend-plugin-framework#f9461d2f3b2f5b2cc68c62b3c0c6a9805c138b64",
6364
"axios-mock-adapter": "1.22.0",
6465
"babel-polyfill": "6.26.0",
6566
"jest-environment-jsdom": "^29.7.0",

src/DesktopHeader.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getConfig } from '@edx/frontend-platform';
66
// Local Components
77
import { Menu, MenuTrigger, MenuContent } from './Menu';
88
import Avatar from './Avatar';
9-
import { LinkedLogo, Logo } from './Logo';
9+
import LogoSlot from './plugin-slots/LogoSlot';
1010

1111
// i18n
1212
import messages from './Header.messages';
@@ -145,7 +145,7 @@ class DesktopHeader extends React.Component {
145145
<a className="nav-skip sr-only sr-only-focusable" href="#main">{intl.formatMessage(messages['header.label.skip.nav'])}</a>
146146
<div className={`container-fluid ${logoClasses}`}>
147147
<div className="nav-container position-relative d-flex align-items-center">
148-
{logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} />}
148+
<LogoSlot {...logoProps} />
149149
<nav
150150
aria-label={intl.formatMessage(messages['header.label.main.nav'])}
151151
className="nav main-nav"

src/Logo.jsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const Logo = ({ src, alt, ...attributes }) => (
5-
<img src={src} alt={alt} {...attributes} />
6-
);
7-
8-
Logo.propTypes = {
9-
src: PropTypes.string.isRequired,
10-
alt: PropTypes.string.isRequired,
11-
};
12-
13-
const LinkedLogo = ({
4+
const Logo = ({
145
href,
156
src,
167
alt,
178
...attributes
189
}) => (
19-
<a href={href} {...attributes}>
10+
<a href={href} className="logo" {...attributes}>
2011
<img className="d-block" src={src} alt={alt} />
2112
</a>
2213
);
2314

24-
LinkedLogo.propTypes = {
15+
Logo.propTypes = {
2516
href: PropTypes.string.isRequired,
2617
src: PropTypes.string.isRequired,
2718
alt: PropTypes.string.isRequired,
2819
};
2920

30-
export { LinkedLogo, Logo };
3121
export default Logo;

src/MobileHeader.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getConfig } from '@edx/frontend-platform';
66
// Local Components
77
import { Menu, MenuTrigger, MenuContent } from './Menu';
88
import Avatar from './Avatar';
9-
import { LinkedLogo, Logo } from './Logo';
9+
import LogoSlot from './plugin-slots/LogoSlot';
1010

1111
// i18n
1212
import messages from './Header.messages';
@@ -155,7 +155,7 @@ class MobileHeader extends React.Component {
155155
</div>
156156
) : null}
157157
<div className={`w-100 d-flex ${logoClasses}`}>
158-
{ logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} itemType="http://schema.org/Organization" />}
158+
<LogoSlot {...logoProps} itemType="http://schema.org/Organization" />
159159
</div>
160160
{userMenu.length > 0 || loggedOutItems.length > 0 ? (
161161
<div className="w-100 d-flex justify-content-end align-items-center">

src/learning-header/LearningHeader.jsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,16 @@ import { AppContext } from '@edx/frontend-platform/react';
66

77
import AnonymousUserMenu from './AnonymousUserMenu';
88
import AuthenticatedUserDropdown from './AuthenticatedUserDropdown';
9+
import LogoSlot from '../plugin-slots/LogoSlot';
910
import messages from './messages';
1011

11-
const LinkedLogo = ({
12-
href,
13-
src,
14-
alt,
15-
...attributes
16-
}) => (
17-
<a href={href} {...attributes}>
18-
<img className="d-block" src={src} alt={alt} />
19-
</a>
20-
);
21-
22-
LinkedLogo.propTypes = {
23-
href: PropTypes.string.isRequired,
24-
src: PropTypes.string.isRequired,
25-
alt: PropTypes.string.isRequired,
26-
};
27-
2812
const LearningHeader = ({
2913
courseOrg, courseNumber, courseTitle, intl, showUserDropdown,
3014
}) => {
3115
const { authenticatedUser } = useContext(AppContext);
3216

3317
const headerLogo = (
34-
<LinkedLogo
35-
className="logo"
18+
<LogoSlot
3619
href={`${getConfig().LMS_BASE_URL}/dashboard`}
3720
src={getConfig().LOGO_URL}
3821
alt={getConfig().SITE_NAME}

src/plugin-slots/LogoSlot/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Logo Slot
2+
3+
### Slot ID: `logo_slot`
4+
5+
## Description
6+
7+
This slot is used to replace/modify/hide the logo.
8+
9+
## Examples
10+
11+
### Modify URL
12+
13+
The following `env.config.jsx` will modify the link href for the logo.
14+
15+
```jsx
16+
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
17+
18+
const modifyLogoHref = ( logo ) => {
19+
logo.content.href = "https://openedx.org/";
20+
return logo;
21+
};
22+
23+
const config = {
24+
pluginSlots: {
25+
logo_slot: {
26+
keepDefault: true,
27+
plugins: [
28+
{
29+
op: PLUGIN_OPERATIONS.Modify,
30+
widgetId: 'default_contents',
31+
fn: modifyLogoHref,
32+
},
33+
]
34+
},
35+
},
36+
}
37+
38+
export default config;
39+
```
40+
41+
### Custom Component
42+
43+
The following `env.config.jsx` will replace the logo entirely (in this case with a centered 🗺️ `h1`)
44+
45+
```jsx
46+
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
47+
48+
const config = {
49+
pluginSlots: {
50+
logo_slot: {
51+
keepDefault: false,
52+
plugins: [
53+
{
54+
op: PLUGIN_OPERATIONS.Insert,
55+
widget: {
56+
id: 'custom_logo_component',
57+
type: DIRECT_PLUGIN,
58+
RenderWidget: () => (
59+
<h1 style={{textAlign: 'center'}}>🗺️</h1>
60+
),
61+
},
62+
},
63+
]
64+
}
65+
},
66+
}
67+
68+
export default config;
69+
```

src/plugin-slots/LogoSlot/index.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { PluginSlot } from '@openedx/frontend-plugin-framework';
4+
import Logo from '../../Logo';
5+
6+
const LogoSlot = ({ href, src, alt, ...attributes }) => (
7+
<PluginSlot
8+
id="logo_slot"
9+
slotOptions={{
10+
mergeProps: true,
11+
}}
12+
>
13+
<Logo href={href} src={src} alt={alt} {...attributes} />
14+
</PluginSlot>
15+
);
16+
17+
LogoSlot.propTypes = {
18+
href: PropTypes.string.isRequired,
19+
src: PropTypes.string.isRequired,
20+
alt: PropTypes.string.isRequired,
21+
};
22+
23+
export default LogoSlot;

src/plugin-slots/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `frontend-component-header` Plugin Slots
2+
3+
* [`logo_slot`](./LogoSlot/)

0 commit comments

Comments
 (0)