-
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
a5024c3
commit 3f3b0aa
Showing
7 changed files
with
152 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 @@ | ||
# Learning Username Slot | ||
|
||
### Slot ID: `learning_username_slot` | ||
|
||
## Description | ||
|
||
This slot is used to replace/modify/hide the learning username. | ||
|
||
## Examples | ||
|
||
### Modify Username | ||
|
||
The following `env.config.jsx` will modify the username (in this case replacing it with 🤠) | ||
|
||
![Screenshot of modified username](./images/learning_username_modified.png) | ||
|
||
```jsx | ||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
||
const modifyUsername = ( widget ) => { | ||
widget.content.username = "🤠"; | ||
return widget; | ||
}; | ||
|
||
const config = { | ||
pluginSlots: { | ||
learning_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 learning username entirely (in this case with an svg circle) | ||
|
||
![Screenshot of replaced with custom component](./images/learning_username_custom_component.png) | ||
|
||
```jsx | ||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
||
const config = { | ||
pluginSlots: { | ||
learning_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 learning username (in this case 🖋️ and 🪄). | ||
|
||
![Screenshot of custom components before and after](./images/learning_username_custom_components_before_after.png) | ||
|
||
```jsx | ||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
||
const config = { | ||
pluginSlots: { | ||
learning_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
+4.24 KB
...plugin-slots/LearningUsernameSlot/images/learning_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
+8.66 KB
...earningUsernameSlot/images/learning_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
+5.49 KB
src/plugin-slots/LearningUsernameSlot/images/learning_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,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { PluginSlot } from '@openedx/frontend-plugin-framework'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faUserCircle } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
const LearningUsername = ({ username }) => ( | ||
<> | ||
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" /> | ||
<span data-hj-suppress className="d-none d-md-inline"> | ||
{username} | ||
</span> | ||
</> | ||
); | ||
|
||
const LearningUsernameSlot = ({ username }) => ( | ||
<PluginSlot | ||
id="learning_username_slot" | ||
slotOptions={{ | ||
mergeProps: true, | ||
}} | ||
> | ||
<LearningUsername username={username} /> | ||
</PluginSlot> | ||
); | ||
|
||
LearningUsername.propTypes = { | ||
username: PropTypes.string.isRequired, | ||
}; | ||
|
||
LearningUsernameSlot.propTypes = LearningUsername.propTypes; | ||
|
||
export default LearningUsernameSlot; |
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