mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
303838f63d
* Use CSS modules * Fix tests * Feedback
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { h } from 'preact';
|
|
import { useCallback } from 'preact/hooks';
|
|
import { Modal, ModalContent, ModalFooter } from './Modal';
|
|
|
|
import styles from './css/ErrorModal.module.css';
|
|
|
|
export interface ErrorProps {
|
|
error: unknown | undefined;
|
|
setError: (error: string | undefined) => void;
|
|
}
|
|
|
|
export const ErrorModal = ({ error, setError }: ErrorProps) => {
|
|
const onClose = useCallback(() => setError(undefined), [setError]);
|
|
let errorStr = null;
|
|
if (error) {
|
|
if (error instanceof Error) {
|
|
errorStr = error.message;
|
|
} else if (typeof error === 'string') {
|
|
errorStr = error;
|
|
} else {
|
|
errorStr = 'Unknown Error';
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
if (errorStr) {
|
|
return (
|
|
<Modal
|
|
title="Error"
|
|
icon="triangle-exclamation"
|
|
isOpen={true}
|
|
onClose={onClose}
|
|
>
|
|
<ModalContent>
|
|
<div className={styles.errorModal}>
|
|
{errorStr}
|
|
</div>
|
|
</ModalContent>
|
|
<ModalFooter>
|
|
<button onClick={onClose}>OK</button>
|
|
</ModalFooter>
|
|
</Modal>
|
|
);
|
|
} else {
|
|
return null;
|
|
}
|
|
};
|