generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ensure default_contents widgets support merging props with Plug…
…inOperations.Modify
- Loading branch information
1 parent
bf8705b
commit f8aca45
Showing
19 changed files
with
525 additions
and
75 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,74 @@ | ||
import React from 'react'; | ||
import { | ||
Container, Row, Col, Stack, | ||
} from '@openedx/paragon'; | ||
|
||
import PluginSlotWithModifyDefaultContents from './pluginSlots/PluginSlotWithModifyDefaultContents'; | ||
import PluginSlotWithInsert from './pluginSlots/PluginSlotWithInsert'; | ||
import PluginSlotWithModifyWrapHide from './pluginSlots/PluginSlotWithModifyWrapHide'; | ||
import PluginSlotWithModularPlugins from './pluginSlots/PluginSlotWithModularPlugins'; | ||
import PluginSlotWithoutDefault from './pluginSlots/PluginSlotWithoutDefault'; | ||
|
||
const pluginExamples = [ | ||
{ | ||
id: 'plugin-operation-insert', | ||
label: 'Plugin Operation: Insert', | ||
Component: PluginSlotWithInsert, | ||
}, | ||
{ | ||
id: 'plugin-operation-modify-wrap-hide', | ||
label: 'Plugin Operation: Modify, Wrap, and Hide', | ||
Component: PluginSlotWithModifyWrapHide, | ||
}, | ||
{ | ||
id: 'plugin-operation-modify-default-content', | ||
label: 'Plugin Operation: Modify Default Content', | ||
Component: PluginSlotWithModifyDefaultContents, | ||
}, | ||
{ | ||
id: 'direct-plugins-modular-components', | ||
label: 'Direct Plugins Using Modular Components', | ||
Component: PluginSlotWithModularPlugins, | ||
}, | ||
{ | ||
id: 'no-default-content', | ||
label: 'Default Content Set to False', | ||
Component: PluginSlotWithoutDefault, | ||
}, | ||
]; | ||
|
||
export default function ExamplePage() { | ||
return ( | ||
<main className="center m-5"> | ||
<h1>Plugins Page</h1> | ||
|
||
<p> | ||
This page is here to help test the plugins module. A plugin configuration can be added in | ||
index.jsx and this page will display that plugin. | ||
</p> | ||
<p> | ||
To do this, a plugin MFE must be running on some other port. | ||
To make it a more realistic test, you may also want to edit your | ||
/etc/hosts file (or your system's equivalent) to provide an alternate domain for | ||
127.0.0.1 at which you can load the plugin. | ||
</p> | ||
<div className="d-flex flex-column"> | ||
<PluginSlotWithInsert /> | ||
<PluginSlotWithModifyWrapHide /> | ||
<PluginSlotWithModularPlugins /> | ||
<PluginSlotWithoutDefault /> | ||
</div> | ||
<main> | ||
<Container size="lg" className="py-3"> | ||
<Row> | ||
<Col> | ||
<h1>Plugins Page</h1> | ||
<p> | ||
This page is here to help test the plugins module. A plugin configuration can be added in | ||
index.jsx and this page will display that plugin. | ||
</p> | ||
<p> | ||
To do this, a plugin MFE must be running on some other port. | ||
To make it a more realistic test, you may also want to edit your | ||
/etc/hosts file (or your system's equivalent) to provide an alternate domain for | ||
127.0.0.1 at which you can load the plugin. | ||
</p> | ||
<h2>Examples</h2> | ||
<Stack gap={3}> | ||
<ul> | ||
{pluginExamples.map(({ id, label }) => ( | ||
<li key={id}> | ||
<a href={`#${id}`}>{label}</a> | ||
</li> | ||
))} | ||
</ul> | ||
<Stack gap={5}> | ||
{pluginExamples.map(({ id, label, Component }) => <Component key={id} label={label} />)} | ||
</Stack> | ||
</Stack> | ||
</Col> | ||
</Row> | ||
</Container> | ||
</main> | ||
); | ||
} |
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
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
46 changes: 46 additions & 0 deletions
46
example/src/pluginSlots/PluginSlotWithModifyDefaultContents.jsx
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,46 @@ | ||
import React from 'react'; | ||
|
||
import { PluginSlot } from '@openedx/frontend-plugin-framework'; | ||
import classNames from 'classnames'; | ||
|
||
|
||
// Example component used as the default child(ren) within a PluginSlot | ||
const Username = ({ className, ...rest }) => { | ||
const authenticatedUser = { username: 'testuser' }; | ||
const { username } = authenticatedUser; | ||
return ( | ||
<span | ||
className={classNames('default-classname', className)} | ||
{...rest} | ||
> | ||
{username} | ||
</span> | ||
); | ||
}; | ||
|
||
function PluginSlotWithModifyDefaultContents({ label }) { | ||
return ( | ||
<div className="border border-primary mb-2 px-3"> | ||
<h3 id="plugin-operation-modify-default-content">{label}</h3> | ||
<p> | ||
The following <code>PluginSlot</code> examples demonstrate the <code>PLUGIN_OPERATIONS.Modify</code> operation, when | ||
the <code>widgetId</code> is <code>default_contents</code>. Any configured, custom plugin <code>content</code> is | ||
merged with any existing props passed to the component(s) represented by <code>default_contents</code>. | ||
</p> | ||
<ul> | ||
<li>Custom <code>className</code> overrides are concatenated with the <code>className</code> prop passed to the <code>default_contents</code> component(s), if any.</li> | ||
<li>Custom <code>style</code> overrides are shallow merged with the <code>style</code> prop passed to the <code>default_contents</code> component(s), if any.</li> | ||
<li>Custom event handlers (e.g., <code>onClick</code>) are executed in sequence, after any event handlers passed to the <code>default_contents</code> component(s), if any.</li> | ||
</ul> | ||
<PluginSlot id="slot_with_username_pii" as="div"> | ||
<Username className="d-block" /> | ||
<Username className="abc123" /> | ||
</PluginSlot> | ||
<PluginSlot id="slot_with_username_pii" as="div"> | ||
<Username className="def456" /> | ||
</PluginSlot> | ||
</div> | ||
); | ||
} | ||
|
||
export default PluginSlotWithModifyDefaultContents; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Oops, something went wrong.