@soul-refiner/design-system 0.2.49 → 0.2.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,9 +5,10 @@ export interface ModalProps extends React.PropsWithChildren {
|
|
|
5
5
|
* instead of it managing its own state
|
|
6
6
|
*/
|
|
7
7
|
controlledOpen?: boolean;
|
|
8
|
+
onChange?: (open?: boolean) => void;
|
|
8
9
|
}
|
|
9
10
|
declare const Modal: {
|
|
10
|
-
({ controlledOpen, ...props }: ModalProps): React.JSX.Element;
|
|
11
|
+
({ controlledOpen, onChange, ...props }: ModalProps): React.JSX.Element;
|
|
11
12
|
Trigger: {
|
|
12
13
|
({ children: child, }: {
|
|
13
14
|
children: React.ReactElement;
|
|
@@ -5,13 +5,16 @@ import { Button } from '../../';
|
|
|
5
5
|
import { Close } from '../../../icons';
|
|
6
6
|
import { callAll } from '../../../utils';
|
|
7
7
|
const ModalContext = React.createContext([false, (() => undefined)]);
|
|
8
|
-
const Modal = ({ controlledOpen, ...props }) => {
|
|
8
|
+
const Modal = ({ controlledOpen, onChange, ...props }) => {
|
|
9
9
|
const [open, setOpen] = React.useState(controlledOpen || false);
|
|
10
10
|
React.useEffect(() => {
|
|
11
11
|
if (controlledOpen !== undefined) {
|
|
12
12
|
setOpen(controlledOpen);
|
|
13
13
|
}
|
|
14
14
|
}, [controlledOpen]);
|
|
15
|
+
React.useEffect(() => {
|
|
16
|
+
onChange && onChange(open);
|
|
17
|
+
}, [open]);
|
|
15
18
|
return React.createElement(ModalContext.Provider, { value: [open, setOpen], ...props });
|
|
16
19
|
};
|
|
17
20
|
const ModalTrigger = ({ children: child, }) => {
|