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 9 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
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
@@ -1,16 +1,33 @@
import React from 'react';
import React, { useMemo } from 'react';
import type { ReactElement } from 'react';
import Head from 'next/head';
import { StepHeadline } from '../../shared';
import type { FunnelStepFact } from '../../types/funnel';
import { FunnelStepTransitionType } from '../../types/funnel';
import { FunnelStepCtaWrapper } from '../../shared/FunnelStepCtaWrapper';
import { LazyImage } from '../../../../components/LazyImage';
import { ReputationLightningIcon } from '../../../../components/icons';
import { Badge } from '../../../../components/Badge';

export const FunnelFactCentered = ({
parameters,
onTransition,
}: FunnelStepFact): ReactElement => {
const { badge } = parameters;

const badgeComponent = useMemo(() => {
if (!badge?.cta) {
return null;
}
return (
<Badge
label={badge.cta}
icon={<ReputationLightningIcon className="h-6 w-6" secondary />}
variant={badge.variant}
/>
);
}, [badge?.cta, badge?.variant]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think the useMemo is needed for us here. Same goes to the other file.


return (
<FunnelStepCtaWrapper
containerClassName="flex max-h-screen"
Expand Down Expand Up @@ -40,12 +57,16 @@ export const FunnelFactCentered = ({
/>
</>
)}
<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
className="!gap-6"
heading={parameters?.headline}
description={parameters?.explainer}
align={parameters?.align}
/>
{badge?.placement === 'bottom' && badgeComponent}
</div>
</div>
</FunnelStepCtaWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import type { ReactElement } from 'react';
import classNames from 'classnames';
import Head from 'next/head';
Expand All @@ -7,6 +7,8 @@ import type { FunnelStepFact } from '../../types/funnel';
import { FunnelStepTransitionType } from '../../types/funnel';
import { FunnelStepCtaWrapper } from '../../shared/FunnelStepCtaWrapper';
import { LazyImage } from '../../../../components/LazyImage';
import { Badge } from '../../../../components/Badge';
import { ReputationLightningIcon } from '../../../../components/icons';

export const FunnelFactDefault = ({
parameters,
Expand All @@ -15,6 +17,21 @@ export const FunnelFactDefault = ({
const isLayoutReversed =
parameters.layout === 'reversed' || parameters.reverse;

const { badge } = parameters;

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

return (
<FunnelStepCtaWrapper
containerClassName="flex"
Expand All @@ -34,11 +51,15 @@ export const FunnelFactDefault = ({
: 'flex-col justify-between',
)}
>
<StepHeadline
heading={parameters?.headline}
description={parameters?.explainer}
align={parameters?.align}
/>
<div className="flex flex-col items-center gap-4">
{badge?.placement === 'top' && badgeComponent}
<StepHeadline
heading={parameters?.headline}
description={parameters?.explainer}
align={parameters?.align}
/>
{badge?.placement === 'bottom' && badgeComponent}
</div>
{parameters?.visualUrl && (
<>
<Head>
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/features/onboarding/types/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export interface FunnelStepFactParameters {
headline: string;
cta?: string;
reverse?: boolean;
badge?: {
placement?: 'bottom' | 'top';
cta?: string;
variant?: 'primary' | 'onion';
};
explainer: string;
align: StepHeadlineAlign;
visualUrl?: string;
Expand Down