Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dzole0311 committed Dec 18, 2024
1 parent bb4682a commit 04b81e7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 58 deletions.
101 changes: 48 additions & 53 deletions app/scripts/components/common/banner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ import {
USWDSMediaBlockBody
} from '$components/common/uswds/banner';

interface Guidance {
left?: GuidanceContent;
right?: GuidanceContent;
}

interface GuidanceContent {
icon: string;
icon?: string;
iconAlt?: string;
title: string;
text: string;
title?: string;
text?: string;
}

interface BannerProps {
Expand All @@ -30,7 +35,12 @@ interface BannerProps {
contentId?: string;
}

const defaultGuidance = {
const DEFAULT_HEADER_TEXT =
'An official website of the United States government';

const DEFAULT_HEADER_ACTION_TEXT = "Here's how you know";

const DEFAULT_GUIDANCE: Guidance = {
left: {
title: 'Official websites use .gov',
text: 'A .gov website belongs to an official government organization in the United States.',
Expand All @@ -39,19 +49,40 @@ const defaultGuidance = {
},
right: {
title: 'Secure .gov websites use HTTPS',
text: `<>
text: `
A <strong>lock</strong> or <strong>https://</strong> means you've safely
connected to the .gov website. Share sensitive information only on
official, secure websites.
</>`,
`,
iconAlt: 'HTTPS icon',
icon: '/img/icon-https.svg'
}
};

const GuidanceBlock = ({
content,
className
}: {
content: GuidanceContent;
className?: string;
}) => (
<USWDSBannerGuidance className={className}>
<USWDSBannerIcon src={content.icon} alt={content.iconAlt ?? ''} />
<USWDSMediaBlockBody>
<p>
<strong>{content.title}</strong>
<br />
<span
dangerouslySetInnerHTML={{ __html: decode(content.text ?? '') }}
/>
</p>
</USWDSMediaBlockBody>
</USWDSBannerGuidance>
);

export default function Banner({
headerText,
headerActionText = "Here's how you know",
headerActionText,
ariaLabel,
flagImgAlt = '',
leftGuidance,
Expand All @@ -62,78 +93,42 @@ export default function Banner({
}: BannerProps) {
const [isOpen, setIsOpen] = useState(defaultIsOpen);

const defaultHeaderText =
'An official website of the United States government';

const leftContent = {
...defaultGuidance.left,
...DEFAULT_GUIDANCE.left,
...leftGuidance
};
} as GuidanceContent;

const rightContent = {
...defaultGuidance.right,
...DEFAULT_GUIDANCE.right,
...rightGuidance
};
} as GuidanceContent;

return (
<USWDSBanner
aria-label={ariaLabel ?? defaultHeaderText}
aria-label={ariaLabel ?? DEFAULT_HEADER_TEXT}
className={className}
>
<USWDSBannerHeader
isOpen={isOpen}
flagImg={
<USWDSBannerFlag src='/img/us_flag_small.png' alt={flagImgAlt} />
}
headerText={headerText ?? defaultHeaderText}
headerActionText={headerActionText}
headerText={headerText ?? DEFAULT_HEADER_TEXT}
headerActionText={headerActionText ?? DEFAULT_HEADER_ACTION_TEXT}
>
<USWDSBannerButton
isOpen={isOpen}
onClick={() => setIsOpen((prev) => !prev)}
aria-controls={contentId}
>
{headerActionText}
{headerActionText ?? DEFAULT_HEADER_ACTION_TEXT}
</USWDSBannerButton>
</USWDSBannerHeader>

<USWDSBannerContent id={contentId} isOpen={isOpen}>
<div className='grid-row grid-gap-lg'>
<USWDSBannerGuidance className='tablet:grid-col-6'>
<USWDSBannerIcon
src={leftContent.icon}
alt={leftContent.iconAlt || ''}
/>
<USWDSMediaBlockBody>
<p>
<strong>{leftContent.title}</strong>
<br />
<span
dangerouslySetInnerHTML={{
__html: decode(leftContent.text)
}}
/>
</p>
</USWDSMediaBlockBody>
</USWDSBannerGuidance>

<USWDSBannerGuidance className='tablet:grid-col-6'>
<USWDSBannerIcon
src={rightContent.icon}
alt={rightContent.iconAlt || ''}
/>
<USWDSMediaBlockBody>
<p>
<strong>{rightContent.title}</strong>
<br />
<span
dangerouslySetInnerHTML={{
__html: decode(rightContent.text)
}}
/>
</p>
</USWDSMediaBlockBody>
</USWDSBannerGuidance>
<GuidanceBlock content={leftContent} className='tablet:grid-col-6' />
<GuidanceBlock content={rightContent} className='tablet:grid-col-6' />
</div>
</USWDSBannerContent>
</USWDSBanner>
Expand Down
5 changes: 2 additions & 3 deletions app/scripts/components/common/site-alert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ export default function SiteAlert({
slim = false,
className = ''
}: SiteAlertProps) {
const alertId = content;
const showAlert = localStorage.getItem(ALERT_KEY) !== alertId;
const showAlert = localStorage.getItem(ALERT_KEY) !== content;
const [isOpen, setIsOpen] = useState(showAlert && !hasExpired(expires));

function onClose() {
localStorage.setItem(ALERT_KEY, alertId);
localStorage.setItem(ALERT_KEY, content);
setIsOpen(false);
}

Expand Down
6 changes: 4 additions & 2 deletions mock/veda.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ module.exports = {
contentId: 'gov-banner-content'
},
siteAlert: {
content:
'<p class="usa-alert__text"><a target="_blank" rel="noreferrer" href="stories/emit-and-aviris-3">Read the new data insight</a> on using EMIT and AVIRIS-3 for monitoring large methane emission events.</p>',
content: `<p class="usa-alert__text">
<a target="_blank" rel="noreferrer" href="stories/life-of-water">
Discover insights on how the COVID-19 pandemic
</a> impacted air quality worldwide, observed through NASA's satellite data.</p>`,
expires: '2026-08-03T12:00:00-04:00',
type: 'info',
slim: true,
Expand Down

0 comments on commit 04b81e7

Please sign in to comment.