-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f3b0aa
commit 6136b88
Showing
7 changed files
with
157 additions
and
6 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
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,116 @@ | ||
# Desktop Username Slot | ||
|
||
### Slot ID: `desktop_username_slot` | ||
|
||
## Description | ||
|
||
This slot is used to replace/modify/hide the desktop username. | ||
|
||
## Examples | ||
|
||
### Modify Username | ||
|
||
The following `env.config.jsx` will modify the username (in this case replacing it with 🤠) | ||
|
||
![Screenshot of modified username](./images/desktop_username_modified.png) | ||
|
||
```jsx | ||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
||
const modifyUsername = ( widget ) => { | ||
widget.content.username = "🤠"; | ||
return widget; | ||
}; | ||
|
||
const config = { | ||
pluginSlots: { | ||
desktop_username_slot: { | ||
keepDefault: true, | ||
plugins: [ | ||
{ | ||
op: PLUGIN_OPERATIONS.Modify, | ||
widgetId: 'default_contents', | ||
fn: modifyUsername, | ||
}, | ||
] | ||
}, | ||
}, | ||
} | ||
|
||
export default config; | ||
``` | ||
|
||
|
||
### Replace Username with Custom Component | ||
|
||
The following `env.config.jsx` will replace the items in the desktop username entirely (in this case with an svg circle) | ||
|
||
![Screenshot of replaced with custom component](./images/desktop_username_custom_component.png) | ||
|
||
```jsx | ||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
||
const config = { | ||
pluginSlots: { | ||
desktop_username_slot: { | ||
keepDefault: false, | ||
plugins: [ | ||
{ | ||
op: PLUGIN_OPERATIONS.Insert, | ||
widget: { | ||
id: 'custom_username_component', | ||
type: DIRECT_PLUGIN, | ||
RenderWidget: () => ( | ||
<svg height="30" width="30"> | ||
<circle r="15" cx="15" cy="15" fill="purple" /> | ||
</svg> | ||
), | ||
}, | ||
}, | ||
] | ||
}, | ||
}, | ||
} | ||
|
||
export default config; | ||
``` | ||
|
||
### Add Custom Components before and after Username | ||
|
||
The following `env.config.jsx` will place custom components before and after the desktop username (in this case 🖋️ and 🪄). | ||
|
||
![Screenshot of custom components before and after](./images/desktop_username_custom_components_before_after.png) | ||
|
||
```jsx | ||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
||
const config = { | ||
pluginSlots: { | ||
desktop_username_slot: { | ||
keepDefault: true, | ||
plugins: [ | ||
{ | ||
op: PLUGIN_OPERATIONS.Insert, | ||
widget: { | ||
id: 'custom_before_username_component', | ||
type: DIRECT_PLUGIN, | ||
priority: 10, | ||
RenderWidget: () => "🖋️", | ||
}, | ||
}, | ||
{ | ||
op: PLUGIN_OPERATIONS.Insert, | ||
widget: { | ||
id: 'custom_after_username_component', | ||
type: DIRECT_PLUGIN, | ||
priority: 90, | ||
RenderWidget: () => "🪄", | ||
}, | ||
}, | ||
] | ||
}, | ||
}, | ||
} | ||
|
||
export default config; | ||
``` |
Binary file added
BIN
+2.48 KB
src/plugin-slots/DesktopUsernameSlot/images/desktop_username_custom_component.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.2 KB
.../DesktopUsernameSlot/images/desktop_username_custom_components_before_after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.08 KB
src/plugin-slots/DesktopUsernameSlot/images/desktop_username_modified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,38 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { PluginSlot } from '@openedx/frontend-plugin-framework'; | ||
|
||
import Avatar from '../../Avatar'; | ||
import { CaretIcon } from '../../Icons'; | ||
|
||
const DesktopUsername = ({ username, avatar }) => ( | ||
<> | ||
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" /> | ||
{username} <CaretIcon role="img" aria-hidden focusable="false" /> | ||
</> | ||
); | ||
|
||
const DesktopUsernameSlot = ({ username, avatar }) => ( | ||
<PluginSlot | ||
id="desktop_username_slot" | ||
slotOptions={{ | ||
mergeProps: true, | ||
}} | ||
> | ||
<DesktopUsername username={username} avatar={avatar} /> | ||
</PluginSlot> | ||
); | ||
|
||
DesktopUsername.propTypes = { | ||
avatar: PropTypes.string, | ||
username: PropTypes.string.isRequired, | ||
}; | ||
|
||
DesktopUsername.defaultProps = { | ||
avatar: null, | ||
}; | ||
|
||
DesktopUsernameSlot.propTypes = DesktopUsername.propTypes; | ||
DesktopUsernameSlot.defaultProps = DesktopUsername.defaultProps; | ||
|
||
export default DesktopUsernameSlot; |
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