2022-07-02 23:27:22 +01:00
|
|
|
import React, { useContext, useEffect } from 'react';
|
2022-06-12 20:07:52 +01:00
|
|
|
import { CheckIcon, ExclamationIcon, InformationCircleIcon, ShieldExclamationIcon } from '@heroicons/react/outline';
|
|
|
|
import classNames from 'classnames';
|
2022-07-03 18:29:23 +01:00
|
|
|
import { DialogContext, DialogIconProps, styles } from './';
|
2022-06-12 20:07:52 +01:00
|
|
|
|
2022-07-02 22:24:12 +01:00
|
|
|
const icons = {
|
|
|
|
danger: ShieldExclamationIcon,
|
|
|
|
warning: ExclamationIcon,
|
|
|
|
success: CheckIcon,
|
|
|
|
info: InformationCircleIcon,
|
|
|
|
};
|
|
|
|
|
2022-07-03 18:29:23 +01:00
|
|
|
export default ({ type, position, className }: DialogIconProps) => {
|
2022-07-02 23:27:22 +01:00
|
|
|
const { setIcon, setIconPosition } = useContext(DialogContext);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const Icon = icons[type];
|
2022-06-12 20:07:52 +01:00
|
|
|
|
2022-07-02 23:27:22 +01:00
|
|
|
setIcon(
|
|
|
|
<div className={classNames(styles.dialog_icon, styles[type], className)}>
|
|
|
|
<Icon className={'w-6 h-6'} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}, [type, className]);
|
2022-07-02 22:24:12 +01:00
|
|
|
|
2022-07-02 23:27:22 +01:00
|
|
|
useEffect(() => {
|
|
|
|
setIconPosition(position);
|
|
|
|
}, [position]);
|
2022-07-02 22:24:12 +01:00
|
|
|
|
2022-07-02 23:27:22 +01:00
|
|
|
return null;
|
2022-06-12 20:07:52 +01:00
|
|
|
};
|