Code coverage report for js/components/SlideDialog.tsx

# All files / js/components SlideDialog.tsx

11.76% Statements 2/17
0% Branches 0/4
0% Functions 0/5
14.29% Lines 2/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
    491x
    1x

     import React, { ReactNode, useEffect } from "react";
    import { trans } from "../i18n";

    export default function SlideDialog({
      title,
      hasCloseButton,
      dismiss,
      children,
    }: {
      title: string;
      hasCloseButton: boolean;
      dismiss: () => void;
      children: ReactNode;
    }): JSX.Element {
      useEffect(() => {
        const handler = (ev: KeyboardEvent) => {
          if (ev.key === "Escape") {
            ev.preventDefault();
            dismiss();
          }
        };
        window.addEventListener("keydown", handler);
        return () => {
          window.removeEventListener("keydown", handler);
        };
      }, [dismiss]);

      return (
        <div className="sliding-panel container">
          <div className="col-md-6 offset-md-3">
            {hasCloseButton && (
              <a
                href="#"
                className="close-btn"
                onClick={(ev) => {
                  ev.preventDefault();
                  dismiss();
                }}
              >
                {trans("CLOSE")}
              </a>
            )}
            <h3>{title}</h3>
            {children}
          </div>
        </div>
      );
    }