Skip to content
Merged
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
32 changes: 24 additions & 8 deletions src/js/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Props = {
disabled?: boolean;
},
onCrossIconClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
onLinkClick?: () => void;
/** Open the link in this tab instead of a new one. */
sameTab?: boolean;
}

const Banner = (props: Props) => {
Expand All @@ -34,14 +37,27 @@ const Banner = (props: Props) => {
</div>
{props.banner.label &&
<button className={`banner-link-button type-${props.banner.type}`}>
<Link
className="banner-link-button-text"
to={{ pathname: `https://${props.banner.link}` }}
target="_blank"
rel="noopener noreferrer"
>
{props.banner.label}
</Link>
{props.sameTab ? (
// A plain <a>: react-router's <Link> would treat an external URL
// opened in the same tab as an in-app route.
<a
className="banner-link-button-text"
href={`https://${props.banner.link}`}
onClick={props.onLinkClick}
>
{props.banner.label}
</a>
) : (
<Link
className="banner-link-button-text"
to={{ pathname: `https://${props.banner.link}` }}
target="_blank"
rel="noopener noreferrer"
onClick={props.onLinkClick}
>
{props.banner.label}
</Link>
)}
</button>}
</div>
<button className="banner-cross-bg" onClick={(e) => handleBannerCrossClick(e)}>
Expand Down
5 changes: 5 additions & 0 deletions src/js/components/Banner/NewDesignBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import Banner from './Banner';
import { rememberNewDesign } from '../../util/design-preference';

const SESSION_STORAGE_KEY = 'newDesignBannerDismissed';

Expand Down Expand Up @@ -35,6 +36,10 @@ const NewDesignBanner = () => {
classes: { notification: 'notification-new-design' },
}}
onCrossIconClick={handleDismiss}
// Opting in here must remember the choice too, or the old site never
// redirects. Same tab, like the home page's "Try it now" link (#151).
onLinkClick={rememberNewDesign}
sameTab
/>
);
};
Expand Down
Loading