@dilicorp/ui 1.3.2 → 1.3.4
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,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export function useMergedRefs(...refs) {
|
|
3
|
+
const syncedRefs = React.useRef(refs);
|
|
4
|
+
syncedRefs.current = refs;
|
|
5
|
+
return React.useCallback((value) => {
|
|
6
|
+
syncedRefs.current.forEach(ref => {
|
|
7
|
+
if (!ref)
|
|
8
|
+
return;
|
|
9
|
+
if (typeof ref === 'function') {
|
|
10
|
+
ref(value);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
ref.current = value;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}, []);
|
|
17
|
+
}
|
|
@@ -7,10 +7,12 @@ export declare type AlertProps = {
|
|
|
7
7
|
color?: 'default' | 'success' | 'info' | 'warning' | 'error';
|
|
8
8
|
showButton?: boolean;
|
|
9
9
|
buttonText?: string;
|
|
10
|
+
onClose?: () => void;
|
|
10
11
|
} & React.HTMLAttributes<HTMLDivElement>;
|
|
11
12
|
export declare const Alert: React.ForwardRefExoticComponent<{
|
|
12
13
|
color?: "success" | "info" | "warning" | "default" | "error" | undefined;
|
|
13
14
|
showButton?: boolean | undefined;
|
|
14
15
|
buttonText?: string | undefined;
|
|
16
|
+
onClose?: (() => void) | undefined;
|
|
15
17
|
} & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<AlertRef>>;
|
|
16
18
|
//# sourceMappingURL=alert.d.ts.map
|
package/dist/molecules/alert.js
CHANGED
|
@@ -1,19 +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
|
-
const { children, className, showButton, buttonText = 'Ok', color } = props;
|
|
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(() => {
|
|
12
|
+
setDisplay(false);
|
|
13
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
14
|
+
}, [onClose]);
|
|
10
15
|
useImperativeHandle(ref, () => ({
|
|
11
|
-
open
|
|
12
|
-
close
|
|
13
|
-
}));
|
|
16
|
+
open,
|
|
17
|
+
close
|
|
18
|
+
}), [open, close]);
|
|
14
19
|
const classes = classNames(className, 'alert-content', color);
|
|
15
20
|
if (!display)
|
|
16
|
-
return
|
|
21
|
+
return null;
|
|
17
22
|
return ReactDOM.createPortal(React.createElement(React.Fragment, null,
|
|
18
23
|
React.createElement("div", { className: "alert-overlay", onClick: close }),
|
|
19
24
|
React.createElement("div", { className: classes },
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react';
|
|
1
|
+
import React, { forwardRef, useMemo } 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 refsArray = useMemo(() => [ref, innerRef], [ref, innerRef]);
|
|
9
|
+
const mergedRef = useMergedRefs(...refsArray);
|
|
7
10
|
const classes = classNames(className !== null && className !== void 0 ? className : 'alert-small');
|
|
8
|
-
return (React.createElement(Alert, { ref:
|
|
11
|
+
return (React.createElement(Alert, { ref: mergedRef, className: classes, onClose: closeFn },
|
|
9
12
|
React.createElement("div", { className: "modal modal-sm" },
|
|
10
13
|
React.createElement("div", { className: "modal-header" },
|
|
11
14
|
React.createElement("div", { className: "title" }, title),
|