misc_pterodactyl-panel/resources/scripts/components/elements/dialog/DialogIcon.tsx

35 lines
989 B
TypeScript
Raw Normal View History

import React, { useContext } from 'react';
2022-06-12 19:07:52 +00:00
import { CheckIcon, ExclamationIcon, InformationCircleIcon, ShieldExclamationIcon } from '@heroicons/react/outline';
import classNames from 'classnames';
import DialogContext from '@/components/elements/dialog/context';
import { createPortal } from 'react-dom';
import styles from './style.module.css';
2022-06-12 19:07:52 +00:00
interface Props {
type: 'danger' | 'info' | 'success' | 'warning';
className?: string;
}
const icons = {
danger: ShieldExclamationIcon,
warning: ExclamationIcon,
success: CheckIcon,
info: InformationCircleIcon,
};
2022-06-12 19:07:52 +00:00
export default ({ type, className }: Props) => {
const { icon } = useContext(DialogContext);
2022-06-12 19:07:52 +00:00
if (!icon.current) {
return null;
}
const element = (
<div className={classNames(styles.dialog_icon, styles[type], className)}>
{React.createElement(icons[type], { className: 'w-6 h-6' })}
2022-06-12 19:07:52 +00:00
</div>
);
return createPortal(element, icon.current);
2022-06-12 19:07:52 +00:00
};