Lets the price banner work with empty fields
Only the banner title is required; description, price, price note, features and the button label are left out when empty (the button then says Neem contact op). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,8 @@ type PriceBannerProps = {
|
||||
// layout=banner in the CMS), for an offer or an announcement. It is not a
|
||||
// bookable package: the button only leads to the contact form, without a
|
||||
// chosen package. The price is free text from the CMS ("€ 99 i.p.v. € 150").
|
||||
// Only the title is required; whatever is empty is left out. Without a button
|
||||
// label the button says "Neem contact op".
|
||||
export default function PriceBanner({ banner }: PriceBannerProps) {
|
||||
const linkButton = useRecipe({ key: 'linkButton' });
|
||||
|
||||
@@ -60,23 +62,25 @@ export default function PriceBanner({ banner }: PriceBannerProps) {
|
||||
)}
|
||||
</Box>
|
||||
<Box textAlign={{ base: 'start', md: 'center' }}>
|
||||
<Text
|
||||
fontFamily="heading"
|
||||
fontSize="1.75rem"
|
||||
lineHeight="1.1"
|
||||
color="white"
|
||||
>
|
||||
{banner.priceText}
|
||||
</Text>
|
||||
{banner.priceText && (
|
||||
<Text
|
||||
fontFamily="heading"
|
||||
fontSize="1.75rem"
|
||||
lineHeight="1.1"
|
||||
color="white"
|
||||
>
|
||||
{banner.priceText}
|
||||
</Text>
|
||||
)}
|
||||
{banner.priceNote && (
|
||||
<Text fontSize="sm" opacity={0.85} mb={4}>
|
||||
<Text fontSize="sm" opacity={0.85}>
|
||||
{banner.priceNote}
|
||||
</Text>
|
||||
)}
|
||||
<Box
|
||||
asChild
|
||||
css={linkButton({ variant: 'light', size: 'fit' })}
|
||||
mt={banner.priceNote ? 0 : 4}
|
||||
mt={banner.priceText || banner.priceNote ? 4 : 0}
|
||||
>
|
||||
<Link to="/" hash="contact" data-testid="price-banner-cta">
|
||||
{banner.ctaLabel ?? 'Neem contact op'}
|
||||
|
||||
@@ -63,6 +63,27 @@ describe('Pricing', () => {
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('hides every empty field of the banner', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Pricing
|
||||
content={content}
|
||||
packages={packages}
|
||||
banner={{ title: 'Past er niets bij?', features: [] }}
|
||||
/>,
|
||||
);
|
||||
const shown = screen.getByTestId('price-banner');
|
||||
expect(
|
||||
within(shown).getByRole('heading', { level: 3 }),
|
||||
).toHaveTextContent('Past er niets bij?');
|
||||
expect(shown.querySelectorAll('ul, li')).toHaveLength(0);
|
||||
// Only the heading and the button have text
|
||||
expect(shown.querySelectorAll('p')).toHaveLength(0);
|
||||
expect(
|
||||
within(shown).getByRole('link', { name: 'Neem contact op' }),
|
||||
).toBeInTheDocument();
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('shows no banner without one', async () => {
|
||||
await renderWithProviders(
|
||||
<Pricing content={content} packages={packages} banner={null} />,
|
||||
|
||||
@@ -103,11 +103,12 @@ export interface PricingPackage {
|
||||
|
||||
// The one optional banner under the price cards (an offering with
|
||||
// layout=banner in the CMS). It is not a bookable package: it is not in the
|
||||
// form's choices and not in the package count. The price is free text.
|
||||
// form's choices and not in the package count. The price is free text. Only
|
||||
// the title is required; the banner hides what is empty.
|
||||
export interface PricingBanner {
|
||||
title: string;
|
||||
description: string;
|
||||
priceText: string;
|
||||
description?: string;
|
||||
priceText?: string;
|
||||
priceNote?: string;
|
||||
features: string[];
|
||||
ctaLabel?: string;
|
||||
|
||||
Reference in New Issue
Block a user