Better dialog setting logic
This commit is contained in:
parent
7a6440988b
commit
e49e6ee802
4 changed files with 87 additions and 43 deletions
|
@ -1,17 +1,15 @@
|
|||
import React, { useContext } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import DialogContext from '@/components/elements/dialog/context';
|
||||
import { useDeepCompareEffect } from '@/plugins/useDeepCompareEffect';
|
||||
|
||||
export default ({ children }: { children: React.ReactNode }) => {
|
||||
const { buttons } = useContext(DialogContext);
|
||||
const { setFooter } = useContext(DialogContext);
|
||||
|
||||
if (!buttons.current) {
|
||||
return null;
|
||||
}
|
||||
useDeepCompareEffect(() => {
|
||||
setFooter(
|
||||
<div className={'px-6 py-3 bg-gray-700 flex items-center justify-end space-x-3 rounded-b'}>{children}</div>
|
||||
);
|
||||
}, [children]);
|
||||
|
||||
const element = (
|
||||
<div className={'px-6 py-3 bg-gray-700 flex items-center justify-end space-x-3 rounded-b'}>{children}</div>
|
||||
);
|
||||
|
||||
return createPortal(element, buttons.current);
|
||||
return null;
|
||||
};
|
||||
|
|
Reference in a new issue