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

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-07-02 22:27:22 +00:00
import React, { useContext, useEffect } 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 styles from './style.module.css';
2022-06-12 19:07:52 +00:00
2022-07-02 22:27:22 +00:00
export type IconPosition = 'title' | 'container' | undefined;
2022-06-12 19:07:52 +00:00
interface Props {
type: 'danger' | 'info' | 'success' | 'warning';
2022-07-02 22:27:22 +00:00
position?: IconPosition;
2022-06-12 19:07:52 +00:00
className?: string;
}
const icons = {
danger: ShieldExclamationIcon,
warning: ExclamationIcon,
success: CheckIcon,
info: InformationCircleIcon,
};
2022-07-02 22:27:22 +00:00
export default ({ type, position, className }: Props) => {
const { setIcon, setIconPosition } = useContext(DialogContext);
useEffect(() => {
const Icon = icons[type];
2022-06-12 19:07:52 +00:00
2022-07-02 22:27:22 +00:00
setIcon(
<div className={classNames(styles.dialog_icon, styles[type], className)}>
<Icon className={'w-6 h-6'} />
</div>
);
}, [type, className]);
2022-07-02 22:27:22 +00:00
useEffect(() => {
setIconPosition(position);
}, [position]);
2022-07-02 22:27:22 +00:00
return null;
2022-06-12 19:07:52 +00:00
};