2026-10-05 18:10:18 -04:00
|
|
|
import { use, useEffect } from 'react';
|
|
|
|
|
import { DialogContext } from './context';
|
|
|
|
|
import type { DialogIconProps } from './types';
|
2022-06-12 15:07:52 -04:00
|
|
|
|
2026-10-12 09:04:03 -04:00
|
|
|
/** Places a type icon beside the dialog title, or beside the whole content with `position="container"`. */
|
2026-10-05 18:10:18 -04:00
|
|
|
const DialogIcon = ({ type, position, className }: DialogIconProps) => {
|
|
|
|
|
const { setIcon, setIconPosition } = use(DialogContext);
|
2022-07-02 18:27:22 -04:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-10-12 09:04:03 -04:00
|
|
|
setIcon({ type, className });
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
return () => setIcon(undefined);
|
|
|
|
|
}, [className, setIcon, type]);
|
2022-07-02 17:24:12 -04:00
|
|
|
|
2022-07-02 18:27:22 -04:00
|
|
|
useEffect(() => {
|
|
|
|
|
setIconPosition(position);
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
return () => setIconPosition('title');
|
|
|
|
|
}, [position, setIconPosition]);
|
2022-07-02 17:24:12 -04:00
|
|
|
|
2022-07-02 18:27:22 -04:00
|
|
|
return null;
|
2022-06-12 15:07:52 -04:00
|
|
|
};
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
export default DialogIcon;
|