Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/plugin-slots/PageBannerSlot/Readme.md
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.

![Screenshot of Custom Page Banner](./screenshot_custom_banner_msg.png)

```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;
```
45 changes: 45 additions & 0 deletions src/plugin-slots/PageBannerSlot/index.tsx
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think dismissable should 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.

onDismiss: () => void;
className: string;
Copy link
Contributor

Choose a reason for hiding this comment

The 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 className on the div in the default contents, or move that wrapper div outside of the slot. This className won't necessarily apply to custom plugins that put different content in this slot.

children: ReactNode;
variant?: string;
dismissAltText?: string;
Comment on lines +11 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The 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',
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/schedule-and-details/basic-section/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
import {
PageBanner, Button, Card, MailtoLink, Hyperlink,
Button, Card, MailtoLink, Hyperlink,
} from '@openedx/paragon';
import PageBannerSlot from '@src/plugin-slots/PageBannerSlot';
import { Email as EmailIcon } from '@openedx/paragon/icons';

import SectionSubHeader from '../../generic/section-sub-header';
Expand Down Expand Up @@ -78,7 +79,7 @@ const BasicSection = ({
);

const renderPageBanner = () => (
<PageBanner
<PageBannerSlot
show={showPageBanner}
dismissible
onDismiss={() => setShowPageBanner(false)}
Expand All @@ -88,7 +89,7 @@ const BasicSection = ({
<span className="text text-gray-700 text-left">
{intl.formatMessage(messages.basicBannerText)}
</span>
</PageBanner>
</PageBannerSlot>
);

const renderCoursePromotion = () => (
Expand Down