Skip to content

Commit

Permalink
feat: making banner more composable (#6540)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Mar 13, 2024
1 parent 9438400 commit f7062e2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions frontend/src/component/App.tsx
Expand Up @@ -22,6 +22,7 @@ import { ExternalBanners } from './banners/externalBanners/ExternalBanners';
import { EdgeUpgradeBanner } from './banners/EdgeUpgradeBanner/EdgeUpgradeBanner';
import { LicenseBanner } from './banners/internalBanners/LicenseBanner';
import { Demo } from './demo/Demo';
import { OutdatedSdksBanner } from './banners/OutdatedSdksBanner/OutdatedSdksBanner';

const StyledContainer = styled('div')(() => ({
'& ul': {
Expand Down Expand Up @@ -67,6 +68,7 @@ export const App = () => {
<ExternalBanners />
<InternalBanners />
<EdgeUpgradeBanner />
<OutdatedSdksBanner />
<StyledContainer>
<ToastRenderer />
<Routes>
Expand Down
Expand Up @@ -61,7 +61,7 @@ export const BannerModal = ({ banner, open, setOpen }: IBannerModalProps) => {
setLink(banner?.link || '');
setLinkText(banner?.linkText || '');
setDialogTitle(banner?.dialogTitle || '');
setDialog(banner?.dialog || '');
setDialog(typeof banner?.dialog === 'string' ? banner?.dialog : '');
}, [open, banner]);

const editing = banner !== undefined;
Expand Down
@@ -1,6 +1,7 @@
import { styled } from '@mui/material';
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { Markdown } from 'component/common/Markdown/Markdown';
import { ReactNode } from 'react';

const StyledMarkdown = styled(Markdown)(({ theme }) => ({
'h1, h2, h3': {
Expand All @@ -12,7 +13,7 @@ interface IBannerDialogProps {
title: string;
open: boolean;
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
children: string;
children: ReactNode;
}

export const BannerDialog = ({
Expand All @@ -30,7 +31,11 @@ export const BannerDialog = ({
setOpen(false);
}}
>
<StyledMarkdown>{children}</StyledMarkdown>
{typeof children === 'string' ? (
<StyledMarkdown>{children}</StyledMarkdown>
) : (
children
)}
</Dialogue>
);
};
@@ -0,0 +1,23 @@
import { ConditionallyRender } from '../../common/ConditionallyRender/ConditionallyRender';
import { Banner } from '../Banner/Banner';
import { IBanner } from '../../../interfaces/banner';

export const OutdatedSdksBanner = () => {
const displayOutdatedSdksBanner = false;
const outdatedSdksBanner: IBanner = {
message: `We noticed that you're using outdated SDKs. `,
variant: 'warning',
link: 'dialog',
linkText: 'Please update those versions',
dialogTitle: 'Outdated SDKs',
dialog: <h1>Outdated SDKs</h1>,
};
return (
<>
<ConditionallyRender
condition={displayOutdatedSdksBanner}
show={<Banner banner={outdatedSdksBanner} />}
/>
</>
);
};
4 changes: 3 additions & 1 deletion frontend/src/interfaces/banner.ts
@@ -1,3 +1,5 @@
import { ReactNode } from 'react';

export type BannerVariant = 'info' | 'warning' | 'error' | 'success';

export interface IBanner {
Expand All @@ -9,7 +11,7 @@ export interface IBanner {
linkText?: string;
plausibleEvent?: string;
dialogTitle?: string;
dialog?: string;
dialog?: ReactNode;
}

export interface IInternalBanner extends Omit<IBanner, 'plausibleEvent'> {
Expand Down

0 comments on commit f7062e2

Please sign in to comment.