@dilicorp/ui 1.3.1 → 1.3.3
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.
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export function useMergedRefs(...refs) {
|
|
3
|
+
return React.useCallback((value) => {
|
|
4
|
+
refs.forEach(ref => {
|
|
5
|
+
if (!ref)
|
|
6
|
+
return;
|
|
7
|
+
if (typeof ref === 'function') {
|
|
8
|
+
ref(value);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
ref.current = value;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}, [refs]);
|
|
15
|
+
}
|
package/dist/molecules/alert.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import React, { forwardRef, useImperativeHandle, useState } from 'react';
|
|
1
|
+
import React, { forwardRef, useCallback, useImperativeHandle, useState } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { Button } from '../atoms/button';
|
|
5
5
|
export const Alert = forwardRef((props, ref) => {
|
|
6
6
|
const { children, className, showButton, buttonText = 'Ok', color, onClose } = props;
|
|
7
7
|
const [display, setDisplay] = useState(false);
|
|
8
|
-
const open = () =>
|
|
9
|
-
|
|
8
|
+
const open = useCallback(() => {
|
|
9
|
+
setDisplay(true);
|
|
10
|
+
}, []);
|
|
11
|
+
const close = useCallback(() => {
|
|
10
12
|
setDisplay(false);
|
|
11
13
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
12
|
-
};
|
|
14
|
+
}, [onClose]);
|
|
13
15
|
useImperativeHandle(ref, () => ({
|
|
14
|
-
open
|
|
15
|
-
close
|
|
16
|
-
}));
|
|
16
|
+
open,
|
|
17
|
+
close
|
|
18
|
+
}), [open, close]);
|
|
17
19
|
const classes = classNames(className, 'alert-content', color);
|
|
18
20
|
if (!display)
|
|
19
|
-
return
|
|
21
|
+
return null;
|
|
20
22
|
return ReactDOM.createPortal(React.createElement(React.Fragment, null,
|
|
21
23
|
React.createElement("div", { className: "alert-overlay", onClick: close }),
|
|
22
24
|
React.createElement("div", { className: classes },
|
|
@@ -2,10 +2,12 @@ import React, { forwardRef } from 'react';
|
|
|
2
2
|
import { Button } from '../../atoms/button';
|
|
3
3
|
import { Alert } from '../../molecules/alert';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
|
+
import { useMergedRefs } from '../../hooks/use-merge-ref';
|
|
5
6
|
export const Modal = forwardRef((props, ref) => {
|
|
6
7
|
const { children, title, closeFn, className, innerRef } = props;
|
|
8
|
+
const mergedRef = useMergedRefs(ref, innerRef);
|
|
7
9
|
const classes = classNames(className !== null && className !== void 0 ? className : 'alert-small');
|
|
8
|
-
return (React.createElement(Alert, { ref:
|
|
10
|
+
return (React.createElement(Alert, { ref: mergedRef, className: classes, onClose: closeFn },
|
|
9
11
|
React.createElement("div", { className: "modal modal-sm" },
|
|
10
12
|
React.createElement("div", { className: "modal-header" },
|
|
11
13
|
React.createElement("div", { className: "title" }, title),
|