aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ErrorMessage.tsx
blob: 6151603776861f5b1083abfb75e51554175b8b72 (plain) (blame)
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
/** @jsx jsx */
import {jsx, css} from "@emotion/react";
import colors from "../colors";
import {selectable} from "../commonStyles";

interface ErrorMessageProps {
    show: boolean,
    content: string | JSX.Element,
}

export default function ErrorMessage(props: ErrorMessageProps): JSX.Element | null {
    const styles = css`
      color: ${colors.error};
      font-size: 1.15rem;
      line-height: 1.1rem;
      margin: 1rem 0 0;

      visibility: ${props.show ? "visible" : "hidden"};
      opacity: ${props.show ? 1 : 0};
      transition: opacity 200ms, visibility 200ms;
    `;

    // These styles are not applied when content is an element;
    const floatingStyles = css`
      position: absolute;
      z-index: -1;
    `;

    const isString = typeof props.content === "string";

    return (
        <div tabIndex={-1} css={[styles, selectable, isString ? floatingStyles : null]}>
            {props.content}
        </div>
    );
}