Adds src/i18n (t, tList, tPlural over typed Dutch JSON, key and parameter checks), the first text (back to top) as proof, a baseline tool for the prerendered pages (pnpm baseline:save and baseline:check), a lint warning for text typed straight into JSX, and docs/translations.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
64 lines
2.5 KiB
TypeScript
64 lines
2.5 KiB
TypeScript
import { chakra } from '@chakra-ui/react';
|
|
import { Icon } from '@iconify/react/offline';
|
|
import upOutlined from '@iconify-icons/ant-design/up-outlined';
|
|
import { t } from '@/i18n';
|
|
import useScrolledPast from '@/hooks/useScrolledPast';
|
|
import { backToTopThreshold } from '@/lib/backToTopThreshold';
|
|
|
|
// Buiten het component, zodat de functie stabiel is voor useScrolledPast
|
|
const threshold = () => backToTopThreshold(window.innerHeight);
|
|
|
|
// Afstand tot de rand zoals in het design. Op hele brede schermen lijnt de
|
|
// knop uit met de rand van de content in plaats van de hoek van het scherm.
|
|
const EDGE = 'clamp(1rem, 3vw, 2rem)';
|
|
|
|
// Vaste knop rechtsonder om terug naar boven te gaan (FR-06, BR-TOP-*)
|
|
export default function BackToTop() {
|
|
const visible = useScrolledPast(threshold);
|
|
|
|
const scrollToTop = () => {
|
|
const reduced = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)',
|
|
).matches;
|
|
window.scrollTo({ top: 0, behavior: reduced ? 'instant' : 'smooth' });
|
|
// De knop verdwijnt bovenaan; de focus gaat naar de inhoud
|
|
document.getElementById('main')?.focus({ preventScroll: true });
|
|
};
|
|
|
|
return (
|
|
<chakra.button
|
|
type="button"
|
|
onClick={scrollToTop}
|
|
aria-label={t('common.aria.backToTop')}
|
|
data-testid="back-to-top-button"
|
|
position="fixed"
|
|
bottom={EDGE}
|
|
right={`max(${EDGE}, calc((100vw - {sizes.content}) / 2 + {spacing.gutter}))`}
|
|
zIndex="backToTop"
|
|
display="inline-flex"
|
|
alignItems="center"
|
|
justifyContent="center"
|
|
w="46px"
|
|
h="46px"
|
|
bg="ink"
|
|
color="white"
|
|
fontSize="1.1rem"
|
|
cursor="pointer"
|
|
// Verborgen = niet zichtbaar, niet focusbaar, niet klikbaar en
|
|
// niet voorgelezen (BR-TOP-03); inert dekt dat ook zonder CSS af
|
|
inert={!visible}
|
|
visibility={visible ? 'visible' : 'hidden'}
|
|
opacity={visible ? 1 : 0}
|
|
transform={visible ? 'none' : 'translateY(8px)'}
|
|
transitionProperty="opacity, transform, visibility, background-color"
|
|
transitionDuration="interaction"
|
|
transitionTimingFunction="smooth"
|
|
_hover={{ bg: 'accent.deep' }}
|
|
_focusVisible={{ bg: 'accent.deep' }}
|
|
_motionReduce={{ transitionDuration: '0s', transform: 'none' }}
|
|
>
|
|
<Icon icon={upOutlined} aria-hidden />
|
|
</chakra.button>
|
|
);
|
|
}
|