-
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
#526
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,18 @@ | ||
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, | ||
}; | ||
Comment on lines
-4
to
-11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I combed through the codebase and couldn't find any time where we are using a logo without a link. I have some previous commits on a WIP branch that add slots and don't remove this, but I figured I might as well take the opportunity to clean up unused code. |
||
|
||
const LinkedLogo = ({ | ||
href, | ||
src, | ||
alt, | ||
...attributes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could only find 2 attributes being added to the logo throughout the codebase. One was The other attribute was less straightforward. In |
||
}) => ( | ||
<a href={href} {...attributes}> | ||
<img className="d-block" src={src} alt={alt} /> | ||
const Logo = ({ content }) => ( | ||
<a href={content.href} className="logo"> | ||
<img className="d-block" src={content.src} alt={content.alt} /> | ||
</a> | ||
); | ||
|
||
LinkedLogo.propTypes = { | ||
href: PropTypes.string.isRequired, | ||
src: PropTypes.string.isRequired, | ||
alt: PropTypes.string.isRequired, | ||
Logo.propTypes = { | ||
content: PropTypes.shape({ | ||
href: PropTypes.string.isRequired, | ||
src: PropTypes.string.isRequired, | ||
alt: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export { LinkedLogo, Logo }; | ||
export default Logo; |
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 = ( logo ) => { | ||
logo.RenderWidget.props.content.href = "https://openedx.org/"; | ||
return logo; | ||
}; | ||
|
||
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; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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 }) => ( | ||
<PluginSlot id="logo_slot"> | ||
<Logo content={{ href, src, alt }} /> | ||
</PluginSlot> | ||
); | ||
|
||
LogoSlot.propTypes = { | ||
href: PropTypes.string.isRequired, | ||
src: PropTypes.string.isRequired, | ||
alt: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default LogoSlot; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `frontend-component-header` Plugin Slots | ||
|
||
* [`logo_slot`](./LogoSlot/) |
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.
I'm not sure if it makes more sense to have this as a direct dependency here or to make it a peer dependency. I went with direct but I'd like to hear what others think.