-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add frontend-plugin-framework
LogoSlot
(#528)
- Loading branch information
1 parent
8a7d6ee
commit 8213ee7
Showing
10 changed files
with
510 additions
and
1,598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
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 = { | ||
Logo.propTypes = { | ||
href: PropTypes.string.isRequired, | ||
src: PropTypes.string.isRequired, | ||
alt: PropTypes.string.isRequired, | ||
}; | ||
|
||
export { LinkedLogo, Logo }; | ||
export default Logo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Logo Slot | ||
|
||
### Slot ID: `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: { | ||
logo_slot: { | ||
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: { | ||
logo_slot: { | ||
keepDefault: false, | ||
plugins: [ | ||
{ | ||
op: PLUGIN_OPERATIONS.Insert, | ||
widget: { | ||
id: 'custom_logo_component', | ||
type: DIRECT_PLUGIN, | ||
RenderWidget: () => ( | ||
<h1 style={{textAlign: 'center'}}>🗺️</h1> | ||
), | ||
}, | ||
}, | ||
] | ||
} | ||
}, | ||
} | ||
|
||
export default config; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { PluginSlot } from '@openedx/frontend-plugin-framework'; | ||
import Logo from '../../Logo'; | ||
|
||
const LogoSlot = ({ | ||
href, src, alt, ...attributes | ||
}) => ( | ||
<PluginSlot | ||
id="logo_slot" | ||
slotOptions={{ | ||
mergeProps: true, | ||
}} | ||
> | ||
<Logo href={href} src={src} alt={alt} {...attributes} /> | ||
</PluginSlot> | ||
); | ||
|
||
LogoSlot.propTypes = { | ||
href: PropTypes.string.isRequired, | ||
src: PropTypes.string.isRequired, | ||
alt: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default LogoSlot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `frontend-component-header` Plugin Slots | ||
|
||
* [`logo_slot`](./LogoSlot/) |