Skip to content

feat(funnels): CTA micro-liners to fact screen #4502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 22, 2025
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
35 changes: 35 additions & 0 deletions packages/shared/src/components/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import classNames from 'classnames';
import type { ReactNode } from 'react';
import React from 'react';
import {
Typography,
TypographyTag,
TypographyType,
} from './typography/Typography';

type BadgeProps = {
icon?: ReactNode;
label: string;
variant: 'primary' | 'onion';
};

const variantToClassName: Record<BadgeProps['variant'], string> = {
primary: 'border-border-subtlest-secondary text-surface-primary',
onion: 'border-overlay-secondary-onion text-accent-onion-subtler',
};

export const Badge = ({ label, icon, variant }: BadgeProps) => {
return (
<div
className={classNames(
variantToClassName[variant],
'flex items-center gap-1 rounded-20 border px-3 py-2',
)}
>
{icon}
<Typography type={TypographyType.Body} bold tag={TypographyTag.P}>
{label}
</Typography>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactElement } from 'react';
import React from 'react';
import React, { useMemo } from 'react';
import classNames from 'classnames';
import type { ButtonProps } from '../../../components/buttons/Button';
import {
Expand All @@ -10,10 +10,17 @@ import {
} from '../../../components/buttons/Button';
import { FunnelTargetId } from '../types/funnelEvents';
import { MoveToIcon } from '../../../components/icons';
import {
Typography,
TypographyColor,
TypographyType,
} from '../../../components/typography/Typography';
import { sanitizeMessage } from './utils';

export type FunnelStepCtaWrapperProps = ButtonProps<'button'> & {
cta?: {
label?: string;
note?: string;
};
containerClassName?: string;
skip?: ButtonProps<'button'> & {
Expand All @@ -29,10 +36,28 @@ export function FunnelStepCtaWrapper({
containerClassName,
...props
}: FunnelStepCtaWrapperProps): ReactElement {
const note = useMemo(() => {
if (!cta?.note) {
return null;
}

const sanitized = sanitizeMessage(cta.note);

return (
<Typography
className="text-center"
type={TypographyType.Title3}
color={TypographyColor.Primary}
dangerouslySetInnerHTML={{ __html: sanitized }}
/>
);
}, [cta?.note]);

return (
<div className="relative flex flex-1 flex-col gap-4">
<div className={classNames('flex-1', containerClassName)}>{children}</div>
<div className="sticky bottom-2 m-4 flex flex-col gap-4">
{note}
<Button
className={classNames(className, 'w-full')}
data-funnel-track={FunnelTargetId.StepCta}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const StepHeadline = ({
return (
<div
data-testid="step-headline-container"
className={classNames('flex flex-col gap-2', className, {
className={classNames('flex flex-col gap-4', className, {
'text-left': align === StepHeadlineAlign.Left,
'text-center': align === StepHeadlineAlign.Center,
'text-right': align === StepHeadlineAlign.Right,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render, screen, fireEvent } from '@testing-library/react';
import { FunnelFact } from '.';
import { FunnelStepType } from '../../types/funnel';
import type { FunnelStepFact } from '../../types/funnel';
import { StepHeadlineAlign } from '../../shared';

const mockOnTransition = jest.fn();

Expand All @@ -13,7 +14,7 @@ const defaultProps: FunnelStepFact = {
parameters: {
headline: 'Test Headline',
explainer: 'Test explanation text',
align: 'center',
align: StepHeadlineAlign.Center,
cta: 'Continue',
},
onTransition: mockOnTransition,
Expand All @@ -36,6 +37,21 @@ describe('FunnelFact', () => {
).toBeInTheDocument();
});

it('should render badge when provided', async () => {
renderComponent({
parameters: {
...defaultProps.parameters,
badge: {
cta: 'Badge CTA',
variant: 'primary',
placement: 'top',
},
},
});

expect(await screen.findByText('Badge CTA')).toBeInTheDocument();
});

it('should call onTransition when button is clicked', async () => {
renderComponent();
const button = await screen.findByText('Continue');
Expand Down Expand Up @@ -85,7 +101,7 @@ describe('FunnelFact', () => {
renderComponent({
parameters: {
...defaultProps.parameters,
align: 'left',
align: StepHeadlineAlign.Left,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,27 @@ import {
ButtonVariant,
ButtonIconPosition,
} from '../../../../components/buttons/common';
import { MoveToIcon } from '../../../../components/icons';
import {
MoveToIcon,
ReputationLightningIcon,
} from '../../../../components/icons';
import { FunnelTargetId } from '../../types/funnelEvents';
import { Badge } from '../../../../components/Badge';

export const FunnelFactCentered = (props: FunnelStepFact): ReactElement => {
const { parameters, transitions, onTransition } = props;
const { badge, headline, explainer, align, visualUrl } = parameters;
const skip = useMemo(
() => transitions.find((t) => t.on === FunnelStepTransitionType.Skip),
[transitions],
);
const badgeComponent = !badge?.cta ? null : (
<Badge
label={badge.cta}
icon={<ReputationLightningIcon className="h-6 w-6" secondary />}
variant={badge.variant}
/>
);

return (
<FunnelFactWrapper {...props}>
Expand All @@ -42,27 +54,30 @@ export const FunnelFactCentered = (props: FunnelStepFact): ReactElement => {
{skip?.cta ?? 'Skip'}
</Button>
)}
{parameters?.visualUrl && (
{visualUrl && (
<>
<Head>
<link rel="preload" as="image" href={parameters.visualUrl} />
<link rel="preload" as="image" href={visualUrl} />
</Head>
<LazyImage
aria-hidden
eager
imgSrc={parameters?.visualUrl}
imgSrc={visualUrl}
className="max-h-[25rem] w-full flex-1"
imgAlt="Supportive illustration for the information"
fit="contain"
/>
</>
)}
<StepHeadline
className="!gap-6"
heading={parameters?.headline}
description={parameters?.explainer}
align={parameters?.align}
/>
<div className="flex flex-col items-center gap-4">
{badge?.placement === 'top' && badgeComponent}
<StepHeadline
heading={headline}
description={explainer}
align={align}
/>
{badge?.placement === 'bottom' && badgeComponent}
</div>
</div>
</FunnelFactWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ import { StepHeadline } from '../../shared';
import type { FunnelStepFact } from '../../types/funnel';
import { FunnelStepTransitionType } from '../../types/funnel';
import { LazyImage } from '../../../../components/LazyImage';
import { Badge } from '../../../../components/Badge';
import {
ReputationLightningIcon,
MoveToIcon,
} from '../../../../components/icons';
import { FunnelFactWrapper } from './FunnelFactWrapper';
import { Button } from '../../../../components/buttons/Button';
import {
ButtonVariant,
ButtonIconPosition,
} from '../../../../components/buttons/common';
import { MoveToIcon } from '../../../../components/icons';
import { FunnelTargetId } from '../../types/funnelEvents';

export const FunnelFactDefault = (props: FunnelStepFact): ReactElement => {
const { parameters, transitions, onTransition } = props;
const isLayoutReversed =
parameters.layout === 'reversed' || parameters.reverse;
const { badge, headline, explainer, align, reverse, layout, visualUrl } =
parameters;
const isLayoutReversed = layout === 'reversed' || reverse;
const skip = useMemo(
() => transitions.find((t) => t.on === FunnelStepTransitionType.Skip),
[transitions],
Expand All @@ -37,6 +42,14 @@ export const FunnelFactDefault = (props: FunnelStepFact): ReactElement => {
</Button>
);

const badgeComponent = !badge?.cta ? null : (
<Badge
label={badge.cta}
icon={<ReputationLightningIcon className="h-6 w-6" secondary />}
variant={badge.variant}
/>
);

return (
<FunnelFactWrapper {...props}>
<div
Expand All @@ -48,21 +61,25 @@ export const FunnelFactDefault = (props: FunnelStepFact): ReactElement => {
: 'flex-col justify-between',
)}
>
{skip?.placement === 'top' && !isLayoutReversed && skipButton}
<StepHeadline
heading={parameters?.headline}
description={parameters?.explainer}
align={parameters?.align}
/>
{parameters?.visualUrl && (
<div className="flex flex-col items-center gap-4">
{badge?.placement === 'top' && badgeComponent}
{skip?.placement === 'top' && !isLayoutReversed && skipButton}
<StepHeadline
heading={headline}
description={explainer}
align={align}
/>
{badge?.placement === 'bottom' && badgeComponent}
</div>
{visualUrl && (
<>
<Head>
<link rel="preload" as="image" href={parameters.visualUrl} />
<link rel="preload" as="image" href={visualUrl} />
</Head>
<LazyImage
aria-hidden
eager
imgSrc={parameters?.visualUrl}
imgSrc={visualUrl}
className="h-auto w-full object-cover"
ratio="64%"
imgAlt="Supportive illustration for the information"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const FunnelFactWrapper = ({
...props
}: PropsWithChildren<FunnelStepFact>) => {
const { parameters, onTransition, transitions } = props;
const { cta, ctaNote } = parameters;
const skip = useMemo(
() => transitions.find((t) => t.on === FunnelStepTransitionType.Skip),
[transitions],
Expand All @@ -25,7 +26,7 @@ export const FunnelFactWrapper = ({
return (
<FunnelStepCtaWrapper
containerClassName="flex"
cta={{ label: parameters?.cta ?? 'Next' }}
cta={{ label: cta ?? 'Next', note: ctaNote }}
onClick={() =>
onTransition({
type: FunnelStepTransitionType.Complete,
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/src/features/onboarding/types/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ export interface FunnelStepLoading
export interface FunnelStepFactParameters {
headline: string;
cta?: string;
ctaNote?: string;
reverse?: boolean;
badge?: {
placement?: 'bottom' | 'top';
cta?: string;
variant?: 'primary' | 'onion';
};
explainer: string;
align: StepHeadlineAlign;
visualUrl?: string;
Expand Down
Loading