All files / client/src/components BackButton.tsx

78.57% Statements 11/14
0% Branches 0/2
80% Functions 4/5
78.57% Lines 11/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51              356x 77x 77x 77x   77x 3x                                       1x       77x 77x         1x       1x      
import { ReactElement } from "react";
import { useNavigate, useNavigationType } from "react-router";
import { useTranslation } from "react-i18next";
import styled from "styled-components";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { navigateToPreviousOrRoot } from "client/utils/navigation";
 
export const BackButton = (): ReactElement => {
  const navigate = useNavigate();
  const navigationType = useNavigationType();
  const { t } = useTranslation();
 
  const goBack = async (): Promise<void> => {
    await navigateToPreviousOrRoot(navigationType, navigate);
  };
 
  return (
    <Container
      role="link"
      tabIndex={0}
      onClick={goBack}
      onKeyDown={async (event) => {
        if (event.key === "Enter") {
          await goBack();
        }
      }}
    >
      <Icon icon="circle-chevron-left" aria-hidden={true} />
      <Text>{t("button.back")}</Text>
    </Container>
  );
};
 
const Container = styled.div`
  background: none;
  border: none;
  padding: 8px 0 8px 4px;
  color: ${(props) => props.theme.textLink};
  font-size: ${(props) => props.theme.linkFontSize};
  cursor: pointer;
  width: fit-content;
`;
 
const Text = styled.span`
  text-decoration: underline;
`;
 
const Icon = styled(FontAwesomeIcon)`
  padding-right: 4px;
`;