Files
AndreaSlopFotografie/web/src/components/Breadcrumb/Breadcrumb.tsx
T

82 lines
3.1 KiB
TypeScript

import { Fragment } from 'react';
import { Box, Flex, Text } from '@chakra-ui/react';
import RouterLink from '@/components/RouterLink';
import { t } from '@/i18n';
import type { BreadcrumbItem } from '@/lib/shootPageView';
type BreadcrumbProps = {
// The name of the navigation landmark, e.g. "Kruimelpad"
label: string;
// The last item is the page itself
items: readonly BreadcrumbItem[];
'data-testid'?: string;
};
// The path to the current page (BR-SP-01..04): links for every item but the
// last, which is plain text marked as the current page. The links match
// exactly, so only the page itself can ever be "current".
export default function Breadcrumb({
label,
items,
'data-testid': testId,
}: BreadcrumbProps) {
if (items.length === 0) return null;
return (
<Box as="nav" aria-label={label} data-testid={testId}>
<Flex
as="ol"
wrap="wrap"
justify="center"
align="center"
gap={2}
fontSize="0.875rem"
color="ink.soft"
listStyle="none"
m={0}
p={0}
>
{items.map((item, index) => {
const last = index === items.length - 1;
// The list is static, so the index is a stable key
return (
<Fragment key={index}>
<Box as="li">
{last ? (
<Text
as="span"
aria-current="page"
color="ink"
minH="2.75rem"
display="inline-flex"
alignItems="center"
>
{item.label}
</Text>
) : (
<RouterLink
to={item.to}
activeOptions={{ exact: true }}
color="accent.deep"
textDecoration="underline"
minH="2.75rem"
display="inline-flex"
alignItems="center"
>
{item.label}
</RouterLink>
)}
</Box>
{!last && (
<Box as="li" aria-hidden="true">
{t('site.breadcrumb.separator')}
</Box>
)}
</Fragment>
);
})}
</Flex>
</Box>
);
}