-
Notifications
You must be signed in to change notification settings - Fork 175
feat: add Page Banner Slot for Schedule and Details Page #2748
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
base: master
Are you sure you want to change the base?
Changes from all commits
ff6283f
903df9b
8c8ae72
1842699
324d1fc
1e9edb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Page Banner Slot | ||
|
|
||
| ### Slot ID: `org.openedx.frontend.authoring.page_banner.v1` | ||
|
|
||
| ### Slot ID Aliases | ||
| * `page_banner_slot` | ||
|
|
||
| ## Description | ||
|
|
||
| This slot wraps the Paragon `PageBanner` component to allow plugins to replace, modify, or hide the banner shown on pages like Schedule & Details. By default, it renders the standard `PageBanner` with the provided props and children. | ||
|
|
||
| ## Example | ||
|
|
||
| The following `env.config.jsx` example replaces the default banner message with a custom message. | ||
|
|
||
|  | ||
|
|
||
| ```jsx | ||
| import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
|
||
| const config = { | ||
| pluginSlots: { | ||
| 'org.openedx.frontend.authoring.page_banner.v1': { | ||
| plugins: [ | ||
| { | ||
| // Hide the default banner contents | ||
| op: PLUGIN_OPERATIONS.Hide, | ||
| widgetId: 'default_contents', | ||
| }, | ||
| { | ||
| // Insert a custom banner contents | ||
| op: PLUGIN_OPERATIONS.Insert, | ||
| widget: { | ||
| id: 'custom_page_banner_contents', | ||
| type: DIRECT_PLUGIN, | ||
| RenderWidget: () => ( | ||
| <> | ||
| <h4 className="text-black">Custom Banner Title</h4> | ||
| <span className="text text-gray-700 text-left"> | ||
| This message was injected via the PageBanner plugin slot. | ||
| </span> | ||
| </> | ||
| ), | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default config; | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import React, { ReactNode } from 'react'; | ||
| import { PluginSlot } from '@openedx/frontend-plugin-framework'; | ||
| import { PageBanner } from '@openedx/paragon'; | ||
|
|
||
| export interface PageBannerSlotProps { | ||
| show: boolean; | ||
| dismissible: boolean; | ||
| onDismiss: () => void; | ||
| className: string; | ||
|
Contributor
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 don't think this makes sense as a prop either. Just hard-code the default |
||
| children: ReactNode; | ||
| variant?: string; | ||
| dismissAltText?: string; | ||
|
Comment on lines
+11
to
+12
Contributor
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. These two props don't seem to be used, so I think you can just use them on the default contents only; they don't have to be a plugin prop. The plugin prop API needs to be stable so it's best to keep it as simple as possible and only include necessary properties. |
||
| } | ||
|
|
||
| const PageBannerSlot: React.FC<PageBannerSlotProps> = ({ | ||
| show, | ||
| dismissible, | ||
| onDismiss, | ||
| className, | ||
| children, | ||
| variant = 'info', | ||
| dismissAltText = 'Dismiss', | ||
|
Contributor
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. This word "Dismiss" won't be translated, so we need another way of specifying it. |
||
| }) => ( | ||
| <PluginSlot | ||
| id="org.openedx.frontend.authoring.page_banner.v1" | ||
| idAliases={['page_banner_slot']} | ||
| pluginProps={{ | ||
| show, dismissible, onDismiss, className, variant, dismissAltText, | ||
| }} | ||
| > | ||
| <div className={className}> | ||
| <PageBanner | ||
| show={show} | ||
| dismissible={dismissible} | ||
| onDismiss={onDismiss} | ||
| variant={variant as any} | ||
| dismissAltText={dismissAltText} | ||
| > | ||
| {children} | ||
| </PageBanner> | ||
| </div> | ||
| </PluginSlot> | ||
| ); | ||
|
|
||
| export default PageBannerSlot; | ||
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 don't think
dismissableshould be a prop for the plugin slot. First of all, it's never false, and second of all, it should be up to the plugin contents to decide whether to show a dismiss button or not.