@react-fabric/core 1.0.0-beta.61 → 1.0.0-beta.62

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.
Files changed (54) hide show
  1. package/css/components/_breadcrumbs.css +2 -0
  2. package/css/components/_button.css +8 -2
  3. package/css/components/_modal.css +2 -2
  4. package/css/core/_theme.css +1 -1
  5. package/css/reset/_reset.css +6 -2
  6. package/dist/cjs/components/button/Button.js +1 -1
  7. package/dist/cjs/components/dropdown/Dropdown.js +13 -1
  8. package/dist/cjs/components/icon/Icon.js +24 -24
  9. package/dist/cjs/components/menu/Menu.js +4 -3
  10. package/dist/cjs/components/menu/MenuItem.js +1 -1
  11. package/dist/cjs/components/navigator/Navigator.js +2 -2
  12. package/dist/cjs/components/tabpanel/TabPanel.js +3 -2
  13. package/dist/cjs/core/theme/ThemeProvider.js +3 -2
  14. package/dist/cjs/hooks/useNavigator.js +9 -8
  15. package/dist/cjs/hooks/useOverlayService.js +34 -13
  16. package/dist/cjs/i18n/index.js +4 -4
  17. package/dist/cjs/index.js +1 -0
  18. package/dist/esm/components/button/Button.js +1 -1
  19. package/dist/esm/components/dropdown/Dropdown.js +14 -2
  20. package/dist/esm/components/icon/Icon.js +24 -24
  21. package/dist/esm/components/menu/Menu.js +4 -3
  22. package/dist/esm/components/menu/MenuItem.js +1 -1
  23. package/dist/esm/components/navigator/Navigator.js +2 -2
  24. package/dist/esm/components/tabpanel/TabPanel.js +3 -2
  25. package/dist/esm/core/theme/ThemeProvider.js +3 -2
  26. package/dist/esm/hooks/useNavigator.js +10 -9
  27. package/dist/esm/hooks/useOverlayService.js +35 -14
  28. package/dist/esm/i18n/index.js +2 -2
  29. package/dist/esm/index.js +1 -1
  30. package/dist/types/components/index.d.ts +2 -2
  31. package/dist/types/components/menu/types.d.ts +6 -1
  32. package/dist/types/components/navigator/Navigator.d.ts +6 -0
  33. package/dist/types/core/theme/ThemeProvider.d.ts +2 -2
  34. package/dist/types/hooks/useOverlayService.d.ts +3 -5
  35. package/package.json +3 -3
  36. package/src/components/button/Button.tsx +3 -1
  37. package/src/components/dropdown/Dropdown.tsx +23 -6
  38. package/src/components/icon/Icon.tsx +22 -22
  39. package/src/components/index.ts +4 -3
  40. package/src/components/menu/Menu.tsx +3 -2
  41. package/src/components/menu/MenuItem.tsx +1 -1
  42. package/src/components/menu/types.ts +6 -1
  43. package/src/components/navigator/Navigator.tsx +9 -2
  44. package/src/components/tabpanel/TabPanel.tsx +2 -1
  45. package/src/core/theme/ThemeProvider.tsx +4 -2
  46. package/src/hooks/useNavigator.tsx +10 -11
  47. package/src/hooks/useOverlayService.tsx +29 -16
  48. package/src/i18n/index.ts +2 -2
  49. /package/dist/cjs/i18n/{ar.json.js → ar/core.json.js} +0 -0
  50. /package/dist/cjs/i18n/{en.json.js → en/core.json.js} +0 -0
  51. /package/dist/esm/i18n/{ar.json.js → ar/core.json.js} +0 -0
  52. /package/dist/esm/i18n/{en.json.js → en/core.json.js} +0 -0
  53. /package/src/i18n/{ar.json → ar/core.json} +0 -0
  54. /package/src/i18n/{en.json → en/core.json} +0 -0
@@ -21,7 +21,7 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import { useCallback, useMemo, useRef, useState } from "react";
24
+ import { useCallback, useMemo, useState } from "react";
25
25
 
26
26
  /**
27
27
  * Custom hook to manage navigation through a list of items.
@@ -43,19 +43,18 @@ import { useCallback, useMemo, useRef, useState } from "react";
43
43
  */
44
44
  export const useNavigator = (totalCount = 0, defaultIndex = 0) => {
45
45
  const [currentIndex, setCurrentIndex] = useState(defaultIndex);
46
- const refCurrent = useRef(defaultIndex);
47
46
 
48
47
  const onNavigate = useCallback(
49
48
  (dir: 1 | -1) => {
50
- if (dir === -1) {
51
- refCurrent.current =
52
- refCurrent.current > 0 ? refCurrent.current - 1 : totalCount - 1;
53
- }
54
- if (dir === 1) {
55
- refCurrent.current =
56
- refCurrent.current + 1 < totalCount ? refCurrent.current + 1 : 0;
57
- }
58
- setCurrentIndex(refCurrent.current);
49
+ setCurrentIndex((prevValue) => {
50
+ if (dir === -1) {
51
+ return prevValue > 0 ? prevValue - 1 : totalCount - 1;
52
+ }
53
+ if (dir === 1) {
54
+ return prevValue + 1 < totalCount ? prevValue + 1 : 0;
55
+ }
56
+ return prevValue;
57
+ });
59
58
  },
60
59
  [totalCount],
61
60
  );
@@ -21,10 +21,11 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import { useState, type ComponentProps, type ElementType } from "react";
24
+ import { useRef, useState } from "react";
25
25
  import { type ModalProps } from "../types";
26
26
 
27
- type OverlayComponent = ElementType<ModalProps<AnyObject>>;
27
+ // return the blank function since state functionality will execute if the value is function
28
+ const EMPTY_FC = () => () => null;
28
29
 
29
30
  /**
30
31
  * Hook to manage overlay components like modals or flyouts.
@@ -36,7 +37,8 @@ type OverlayComponent = ElementType<ModalProps<AnyObject>>;
36
37
  * of the overlay when it is closed, allowing you to handle the result in a controlled manner.
37
38
  *
38
39
  * @param ModalOrFlyout - The component to be used as an overlay.
39
- * @returns An array containing the current overlay and a function to open it.
40
+ * @param toggleOpen - If true, calling `openOverlay` while an overlay is already open will close the existing one instead of opening a new one.
41
+ * @returns An array containing the current overlay, a function to open it, and a boolean indicating if the overlay is open.
40
42
  *
41
43
  * @example
42
44
  * ```jsx
@@ -50,27 +52,38 @@ type OverlayComponent = ElementType<ModalProps<AnyObject>>;
50
52
  * <Overlay />
51
53
  * ```
52
54
  */
53
- export const useOverlayService = (
54
- ModalOrFlyout: OverlayComponent,
55
+ export const useOverlayService = <T extends AnyObject = AnyObject>(
56
+ ModalOrFlyout: React.FunctionComponent<ModalProps<T>>,
55
57
  ): [
56
- Overlay: React.ReactNode | null,
57
- openOverlay: (props?: KeyValue) => Promise<AnyObject>,
58
+ Overlay: React.FunctionComponent<Partial<T>>,
59
+ openOverlay: (props?: Partial<T>) => Promise<AnyObject>,
60
+ closeOverlay: ((args?: AnyObject) => void) | null,
58
61
  ] => {
59
- const [Overlay, setOverlay] = useState<React.ReactNode | null>(null);
62
+ const [Overlay, setOverlay] =
63
+ useState<React.FunctionComponent<Partial<T>>>(EMPTY_FC);
60
64
 
61
- const openOverlay = async ({
62
- onClose,
63
- ...props
64
- }: ComponentProps<typeof ModalOrFlyout> = {}) => {
65
+ const existingOpenPromise = useRef<AnyObject | null>(null);
66
+ const openOverlay = async ({ onClose, ...outerProps }: AnyObject = {}) => {
67
+ if (existingOpenPromise.current) {
68
+ return;
69
+ }
65
70
  return await new Promise((resolve) => {
66
- const handleClose = (args: AnyObject) => {
67
- setOverlay(null);
71
+ existingOpenPromise.current = (args: AnyObject) => {
72
+ setOverlay(EMPTY_FC);
68
73
  resolve(args);
69
74
  onClose?.(args);
75
+ existingOpenPromise.current = null;
70
76
  };
71
- setOverlay(<ModalOrFlyout {...props} onClose={handleClose} />);
77
+ // eslint-disable-next-line react/display-name
78
+ setOverlay(() => (overrideProps: Partial<T>) => (
79
+ <ModalOrFlyout
80
+ {...outerProps}
81
+ {...(overrideProps as any)}
82
+ onClose={existingOpenPromise.current}
83
+ />
84
+ ));
72
85
  });
73
86
  };
74
87
 
75
- return [Overlay, openOverlay];
88
+ return [Overlay, openOverlay, existingOpenPromise.current];
76
89
  };
package/src/i18n/index.ts CHANGED
@@ -23,8 +23,8 @@
23
23
  /* istanbul ignore file */
24
24
 
25
25
  import i18n from "i18next";
26
- import ar from "./ar.json";
27
- import en from "./en.json";
26
+ import ar from "./ar/core.json";
27
+ import en from "./en/core.json";
28
28
 
29
29
  /**
30
30
  * add language bundles using bundle keys as namespaces
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes