@dilicorp/ui 1.3.3 → 1.3.5

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.
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
2
  export function useMergedRefs(...refs) {
3
+ const syncedRefs = React.useRef(refs);
4
+ syncedRefs.current = refs;
3
5
  return React.useCallback((value) => {
4
- refs.forEach(ref => {
6
+ syncedRefs.current.forEach(ref => {
5
7
  if (!ref)
6
8
  return;
7
9
  if (typeof ref === 'function') {
@@ -11,5 +13,5 @@ export function useMergedRefs(...refs) {
11
13
  ref.current = value;
12
14
  }
13
15
  });
14
- }, [refs]);
16
+ }, []);
15
17
  }
@@ -1,16 +1,26 @@
1
- import React, { forwardRef, useCallback, useImperativeHandle, useState } from 'react';
1
+ import React, { forwardRef, useCallback, useImperativeHandle, useRef, 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 closingInternallyRef = useRef(false);
6
7
  const { children, className, showButton, buttonText = 'Ok', color, onClose } = props;
7
8
  const [display, setDisplay] = useState(false);
8
9
  const open = useCallback(() => {
9
10
  setDisplay(true);
10
11
  }, []);
11
12
  const close = useCallback(() => {
13
+ if (closingInternallyRef.current) {
14
+ return;
15
+ }
16
+ closingInternallyRef.current = true;
12
17
  setDisplay(false);
13
- onClose === null || onClose === void 0 ? void 0 : onClose();
18
+ try {
19
+ onClose === null || onClose === void 0 ? void 0 : onClose();
20
+ }
21
+ finally {
22
+ closingInternallyRef.current = false;
23
+ }
14
24
  }, [onClose]);
15
25
  useImperativeHandle(ref, () => ({
16
26
  open,
@@ -1,11 +1,12 @@
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
5
  import { useMergedRefs } from '../../hooks/use-merge-ref';
6
6
  export const Modal = forwardRef((props, ref) => {
7
7
  const { children, title, closeFn, className, innerRef } = props;
8
- const mergedRef = useMergedRefs(ref, innerRef);
8
+ const refsArray = useMemo(() => [ref, innerRef], [ref, innerRef]);
9
+ const mergedRef = useMergedRefs(...refsArray);
9
10
  const classes = classNames(className !== null && className !== void 0 ? className : 'alert-small');
10
11
  return (React.createElement(Alert, { ref: mergedRef, className: classes, onClose: closeFn },
11
12
  React.createElement("div", { className: "modal modal-sm" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dilicorp/ui",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "A simple UI design for Dilicorp",
5
5
  "repository": {
6
6
  "type": "git",