From 55ea00ca3637bc9588d87d5491ff466a8abe1855 Mon Sep 17 00:00:00 2001 From: Owen Yamauchi Date: Mon, 22 Jul 2024 13:51:42 -0400 Subject: [PATCH] Move incentive card code into its own file state-incentive-details.tsx was getting very long (it still is kinda longer than I'd like) so factor out a self-contained subtree of it. This is just cut-and-paste, no substantive changes. --- src/incentive-card.tsx | 130 +++++++++++++++++++++++++++++++ src/state-incentive-details.tsx | 131 +------------------------------- 2 files changed, 132 insertions(+), 129 deletions(-) create mode 100644 src/incentive-card.tsx diff --git a/src/incentive-card.tsx b/src/incentive-card.tsx new file mode 100644 index 0000000..e1d386a --- /dev/null +++ b/src/incentive-card.tsx @@ -0,0 +1,130 @@ +import clsx from 'clsx'; +import { FC, PropsWithChildren } from 'react'; +import { Card } from './card'; +import { ExclamationPoint, ExternalLink, UpRightArrow } from './icons'; + +const Chip: FC> = ({ + isWarning, + children, +}) => ( +
+ {isWarning ? : null} + {children} +
+); + +/** Rendered as a button, with a border. Narrow layout only. */ +const BorderedLinkButton: FC> = ({ + href, + children, +}) => ( + + {children} + +); + +/** Rendered as a pseudo-link, without a border. Med and wide layouts only */ +const BorderlessLinkButton: FC> = ({ + href, + children, +}) => ( + + {children} + +); + +export const IncentiveCard: FC<{ + typeChip: string; + headline: string; + subHeadline: string; + body: string; + warningChip: string | null; + buttonUrl: string; + buttonText: string; +}> = ({ + typeChip, + headline, + subHeadline, + body, + warningChip, + buttonUrl, + buttonText, +}) => ( + +
+
+ {headline} +
+ {/* Only appears on medium and wide layout */} + + {buttonText} + +
+
+ {subHeadline} +
+
{body}
+
+ {typeChip} + {warningChip && {warningChip}} +
+ {/* Only appears on narrow layout */} + + {buttonText} + +
+); diff --git a/src/state-incentive-details.tsx b/src/state-incentive-details.tsx index d151acb..7f212db 100644 --- a/src/state-incentive-details.tsx +++ b/src/state-incentive-details.tsx @@ -1,5 +1,4 @@ -import clsx from 'clsx'; -import { FC, PropsWithChildren, forwardRef, useState } from 'react'; +import { FC, forwardRef, useState } from 'react'; import scrollIntoView from 'scroll-into-view-if-needed'; import { APIResponse, @@ -15,7 +14,7 @@ import { TextInput } from './components/text-input'; import { wasEmailSubmitted } from './email-signup'; import { str } from './i18n/str'; import { MsgFn, useTranslated } from './i18n/use-translated'; -import { ExclamationPoint, ExternalLink, UpRightArrow } from './icons'; +import { IncentiveCard } from './incentive-card'; import { IRARebate, getRebatesFor } from './ira-rebates'; import { itemName } from './item-name'; import { PartnerLogos } from './partner-logos'; @@ -108,132 +107,6 @@ const getStartYearIfInFuture = (incentive: Incentive) => ? getYear(incentive.start_date) : null; -const Chip: FC> = ({ - isWarning, - children, -}) => ( -
- {isWarning ? : null} - {children} -
-); - -/** Rendered as a button, with a border. */ -const BorderedLinkButton: FC> = ({ - href, - children, -}) => ( - - {children} - -); - -/** Rendered as a pseudo-link, without a border */ -const BorderlessLinkButton: FC> = ({ - href, - children, -}) => ( - - {children} - -); - -const IncentiveCard: FC<{ - typeChip: string; - headline: string; - subHeadline: string; - body: string; - warningChip: string | null; - buttonUrl: string; - buttonText: string; -}> = ({ - typeChip, - headline, - subHeadline, - body, - warningChip, - buttonUrl, - buttonText, -}) => ( - -
-
- {headline} -
- {/* Only appears on medium and wide layout */} - - {buttonText} - -
-
- {subHeadline} -
-
{body}
-
- {typeChip} - {warningChip && {warningChip}} -
- {/* Only appears on narrow layout */} - - {buttonText} - -
-); - function scrollToForm(event: React.MouseEvent) { const calculator = ( event.currentTarget.getRootNode() as ShadowRoot