Adds a slim top bar above the packages and centres the last row of cards
The CMS serves a second banner at /api/v1/offerings/banner?position=top. The site bakes it into the HTML at build time and replaces it live after hydration, like the banner under the cards, and both may show at once. The cards now sit in a wrapping flex row so an incomplete last row is centred for any number of cards on desktop; phone and tablet stay one column. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { Box, chakra, Text } from '@chakra-ui/react';
|
||||
import type { PricingTopBanner } from '@/content/types';
|
||||
|
||||
type PriceTopBarProps = {
|
||||
banner: PricingTopBanner;
|
||||
};
|
||||
|
||||
// The slim bar above the price cards: one line with a short announcement
|
||||
// from the CMS, made to go with the white banner under the cards (same white,
|
||||
// hairline border and thin heidegroen rule on top). The title is small
|
||||
// spaced capitals in the heading font, the text is quiet ink, and a link is a
|
||||
// small underlined deep-green text link, not a button. The title may be left
|
||||
// out; the text may be too, but not both (mapTopBanner guarantees that). On
|
||||
// a phone a long line wraps, which is the only time it is more than one.
|
||||
export default function PriceTopBar({ banner }: PriceTopBarProps) {
|
||||
const { title, text, link } = banner;
|
||||
|
||||
return (
|
||||
<Box
|
||||
as="aside"
|
||||
aria-label={title ?? 'Mededeling'}
|
||||
data-testid="price-top-bar"
|
||||
display="flex"
|
||||
flexWrap="wrap"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
columnGap={3}
|
||||
rowGap={1}
|
||||
mb="gridGap"
|
||||
mx="auto"
|
||||
px="clamp(1rem, 3vw, 2rem)"
|
||||
py={3}
|
||||
bg="white"
|
||||
borderWidth="1px"
|
||||
borderColor="line"
|
||||
borderTopWidth="3px"
|
||||
borderTopColor="accent"
|
||||
textAlign="center"
|
||||
>
|
||||
{title && (
|
||||
<Text
|
||||
as="strong"
|
||||
fontFamily="heading"
|
||||
fontWeight="normal"
|
||||
fontSize="0.8125rem"
|
||||
letterSpacing="0.14em"
|
||||
textTransform="uppercase"
|
||||
color="ink"
|
||||
>
|
||||
{title}
|
||||
</Text>
|
||||
)}
|
||||
{title && text && (
|
||||
<Box
|
||||
aria-hidden="true"
|
||||
w="5px"
|
||||
h="5px"
|
||||
bg="accent"
|
||||
transform="rotate(45deg)"
|
||||
/>
|
||||
)}
|
||||
{text && (
|
||||
<Text fontSize="0.9375rem" color="ink.soft">
|
||||
{text}
|
||||
</Text>
|
||||
)}
|
||||
{link && (
|
||||
<chakra.a
|
||||
href={link.url}
|
||||
data-testid="price-top-bar-link"
|
||||
fontSize="0.875rem"
|
||||
color="accent.deep"
|
||||
textDecoration="underline"
|
||||
textUnderlineOffset="3px"
|
||||
_hover={{ color: 'ink' }}
|
||||
{...(link.url.startsWith('https://')
|
||||
? { rel: 'noopener' }
|
||||
: {})}
|
||||
>
|
||||
{link.label}
|
||||
</chakra.a>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -94,6 +94,75 @@ describe('Pricing', () => {
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('shows a slim bar above the cards next to the banner under them', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Pricing
|
||||
content={content}
|
||||
packages={packages}
|
||||
banner={{ title: 'Onder' }}
|
||||
topBanner={{
|
||||
title: 'Nieuw',
|
||||
text: 'Nog twee plekken',
|
||||
link: { label: 'Boek nu', url: 'https://example.nl/x' },
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
const bar = screen.getByTestId('price-top-bar');
|
||||
expect(within(bar).getByText('Nieuw')).toBeInTheDocument();
|
||||
expect(within(bar).getByText('Nog twee plekken')).toBeInTheDocument();
|
||||
expect(
|
||||
within(bar).getByRole('link', { name: 'Boek nu' }),
|
||||
).toHaveAttribute('rel', 'noopener');
|
||||
// The bar comes before the first card, the banner after the last
|
||||
const first = screen.getByTestId('price-card-zwangerschap');
|
||||
expect(
|
||||
bar.compareDocumentPosition(first) &
|
||||
Node.DOCUMENT_POSITION_FOLLOWING,
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
first.compareDocumentPosition(screen.getByTestId('price-banner')) &
|
||||
Node.DOCUMENT_POSITION_FOLLOWING,
|
||||
).toBeTruthy();
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('leaves out what the slim bar does not have', async () => {
|
||||
await renderWithProviders(
|
||||
<Pricing
|
||||
content={content}
|
||||
packages={packages}
|
||||
topBanner={{ text: 'Alleen tekst' }}
|
||||
/>,
|
||||
);
|
||||
const bar = screen.getByTestId('price-top-bar');
|
||||
expect(bar).toHaveTextContent('Alleen tekst');
|
||||
expect(within(bar).queryByRole('link')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('price-banner')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows a slim bar with a title only and a site link', async () => {
|
||||
await renderWithProviders(
|
||||
<Pricing
|
||||
content={content}
|
||||
packages={packages}
|
||||
topBanner={{
|
||||
title: 'Alleen titel',
|
||||
link: { label: 'Meer', url: '/contact' },
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
const bar = screen.getByTestId('price-top-bar');
|
||||
expect(bar).toHaveTextContent('Alleen titel');
|
||||
expect(within(bar).getByRole('link')).not.toHaveAttribute('rel');
|
||||
});
|
||||
|
||||
it('shows no slim bar without one', async () => {
|
||||
await renderWithProviders(
|
||||
<Pricing content={content} packages={packages} topBanner={null} />,
|
||||
);
|
||||
expect(screen.queryByTestId('price-top-bar')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows no banner without one', async () => {
|
||||
await renderWithProviders(
|
||||
<Pricing content={content} packages={packages} banner={null} />,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Box, Grid } from '@chakra-ui/react';
|
||||
import { Box, Flex } from '@chakra-ui/react';
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import PageSection from '@/components/PageSection/PageSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
@@ -7,10 +7,12 @@ import type {
|
||||
HomeContent,
|
||||
PricingBanner,
|
||||
PricingPackage,
|
||||
PricingTopBanner,
|
||||
} from '@/content/types';
|
||||
import { visiblePackages } from '@/lib/visiblePackages';
|
||||
import PriceBanner from './PriceBanner';
|
||||
import PriceCard from './PriceCard';
|
||||
import PriceTopBar from './PriceTopBar';
|
||||
|
||||
const TITLE_ID = 'pricing-title';
|
||||
const STAGGER = 0.08;
|
||||
@@ -29,12 +31,20 @@ type PricingProps = {
|
||||
packages: PricingPackage[];
|
||||
// Optional band under the cards; not a package
|
||||
banner?: PricingBanner | null;
|
||||
// Optional slim bar above the cards; both may show at the same time
|
||||
topBanner?: PricingTopBanner | null;
|
||||
};
|
||||
|
||||
// "Prijzen": the shoot packages as cards (design .pricing). One column on
|
||||
// phones and tablets, three from `lg`. Without a valid package the section
|
||||
// phones and tablets, from `lg` rows of three where an incomplete last row is
|
||||
// centred, for any number of cards (4, 5, 7, ...). Without a valid package the section
|
||||
// is left out entirely.
|
||||
export default function Pricing({ content, packages, banner }: PricingProps) {
|
||||
export default function Pricing({
|
||||
content,
|
||||
packages,
|
||||
banner,
|
||||
topBanner,
|
||||
}: PricingProps) {
|
||||
const shown = visiblePackages(packages);
|
||||
if (shown.length === 0) return null;
|
||||
|
||||
@@ -67,18 +77,36 @@ export default function Pricing({ content, packages, banner }: PricingProps) {
|
||||
lead={content.lead}
|
||||
/>
|
||||
</Reveal>
|
||||
<Grid
|
||||
templateColumns={{ base: '1fr', lg: 'repeat(3, 1fr)' }}
|
||||
{topBanner && (
|
||||
<Reveal>
|
||||
<PriceTopBar banner={topBanner} />
|
||||
</Reveal>
|
||||
)}
|
||||
{/* Wrapping flex, not a grid: a grid leaves the last row at
|
||||
the left. Every card is exactly a third of the row minus
|
||||
the gaps, so the cards of a full row line up and an
|
||||
incomplete last row is centred. */}
|
||||
<Flex
|
||||
direction={{ base: 'column', lg: 'row' }}
|
||||
wrap={{ base: 'nowrap', lg: 'wrap' }}
|
||||
justify="center"
|
||||
gap="gridGap"
|
||||
maxW={{ base: '460px', lg: 'none' }}
|
||||
mx="auto"
|
||||
>
|
||||
{shown.map((pkg, index) => (
|
||||
<Reveal key={pkg.id} delay={index * STAGGER} h="100%">
|
||||
<Reveal
|
||||
key={pkg.id}
|
||||
delay={index * STAGGER}
|
||||
w={{
|
||||
base: '100%',
|
||||
lg: 'calc((100% - 2 * {spacing.gridGap}) / 3)',
|
||||
}}
|
||||
>
|
||||
<PriceCard pkg={pkg} />
|
||||
</Reveal>
|
||||
))}
|
||||
</Grid>
|
||||
</Flex>
|
||||
{banner && (
|
||||
<Reveal>
|
||||
<PriceBanner
|
||||
|
||||
Reference in New Issue
Block a user