aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ErrorMessage.tsx
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2022-07-01 23:27:40 +0400
committerGravatar GitHub <[email protected]>2022-07-01 23:27:40 +0400
commite0f9989b56501693289ffeae505b2b36eb4d6273 (patch)
tree575f538151a79060991071c8017f837e827fddee /src/components/ErrorMessage.tsx
parentCleanup Code Owners Comments (#475) (diff)
parentCodify Question State Type (diff)
Merge pull request #474 from python-discord/display-test-failures
Display Test Failures & Refactor Formpage
Diffstat (limited to 'src/components/ErrorMessage.tsx')
-rw-r--r--src/components/ErrorMessage.tsx18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/components/ErrorMessage.tsx b/src/components/ErrorMessage.tsx
index 650100d..6151603 100644
--- a/src/components/ErrorMessage.tsx
+++ b/src/components/ErrorMessage.tsx
@@ -1,10 +1,11 @@
/** @jsx jsx */
-import { jsx, css } from "@emotion/react";
+import {jsx, css} from "@emotion/react";
import colors from "../colors";
+import {selectable} from "../commonStyles";
interface ErrorMessageProps {
show: boolean,
- message: string
+ content: string | JSX.Element,
}
export default function ErrorMessage(props: ErrorMessageProps): JSX.Element | null {
@@ -13,12 +14,23 @@ export default function ErrorMessage(props: ErrorMessageProps): JSX.Element | nu
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 (
- <p css={styles}>{props.message}</p>
+ <div tabIndex={-1} css={[styles, selectable, isString ? floatingStyles : null]}>
+ {props.content}
+ </div>
);
}