-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add frontend-plugin-framework LogoSlot
#528
Merged
brian-smith-tcril
merged 1 commit into
openedx:master
from
brian-smith-tcril:fpf-logo-slot
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as an aside while we're all talking about the syntax for plugins, I have to say... that's a whole lot of code to replace a logo. 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think people generally agree that FPF config feels a bit too verbose (hence the thread https://discuss.openedx.org/t/proposal-simplified-frontend-plugin-api-config/13312)
That being said, just changing the logo image itself is still very much possible via existing config methods - wrapping the Logo component in a PluginSlot doesn't change that