@etsoo/materialui 1.1.19 → 1.1.21

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,3 +1,4 @@
1
+ import { EventWatcher } from "@etsoo/react";
1
2
  import React from "react";
2
3
  /**
3
4
  * User menu props
@@ -27,6 +28,10 @@ export interface UserMenuLocalProps extends Omit<UserMenuProps, "children"> {
27
28
  */
28
29
  smDown: boolean;
29
30
  }
31
+ /**
32
+ * Event watcher
33
+ */
34
+ export declare const eventWatcher: EventWatcher;
30
35
  /**
31
36
  * User menu
32
37
  * @param props Props
@@ -1,6 +1,13 @@
1
+ import { EventWatcher } from "@etsoo/react";
1
2
  import { IconButton, Menu } from "@mui/material";
2
3
  import React from "react";
4
+ import { useNavigate } from "react-router-dom";
3
5
  import { UserAvatar } from "../UserAvatar";
6
+ /**
7
+ * Event watcher
8
+ */
9
+ export const eventWatcher = new EventWatcher();
10
+ const eventWatcherAction = "usermenu.href.transitionend";
4
11
  /**
5
12
  * User menu
6
13
  * @param props Props
@@ -13,6 +20,8 @@ export function UserMenu(props) {
13
20
  const [anchorEl, setAnchorEl] = React.useState();
14
21
  // User menu open or not
15
22
  const isMenuOpen = Boolean(anchorEl);
23
+ // Route
24
+ const navigate = useNavigate();
16
25
  // User menu
17
26
  const handleUserMenuOpen = (event) => {
18
27
  setAnchorEl(event.currentTarget);
@@ -20,6 +29,24 @@ export function UserMenu(props) {
20
29
  const handleMenuClose = () => {
21
30
  setAnchorEl(undefined);
22
31
  };
32
+ const handleClick = async (event) => {
33
+ var _a;
34
+ handleMenuClose();
35
+ const item = (_a = event.target) === null || _a === void 0 ? void 0 : _a.closest("li[href]");
36
+ if (item != null) {
37
+ const href = item.getAttribute("href");
38
+ if (href) {
39
+ // Even set transitionDuration = 0, still need to wait a little bit
40
+ eventWatcher.add({
41
+ type: eventWatcherAction,
42
+ action: () => {
43
+ navigate(href);
44
+ },
45
+ once: true
46
+ });
47
+ }
48
+ }
49
+ };
23
50
  return (React.createElement(React.Fragment, null,
24
51
  React.createElement(IconButton, { edge: "end", "aria-haspopup": "true", onClick: handleUserMenuOpen, color: "inherit" },
25
52
  React.createElement(UserAvatar, { title: name, src: avatar })),
@@ -54,5 +81,5 @@ export function UserMenu(props) {
54
81
  }, keepMounted: true, transformOrigin: {
55
82
  vertical: "top",
56
83
  horizontal: "right"
57
- }, open: isMenuOpen, onClick: handleMenuClose, onClose: handleMenuClose }, children(handleMenuClose))));
84
+ }, open: isMenuOpen, onTransitionEnd: () => eventWatcher.do(eventWatcherAction), onClick: handleClick, onClose: handleMenuClose }, children(handleMenuClose))));
58
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -70,7 +70,7 @@
70
70
  "react-dom": "^18.2.0",
71
71
  "react-draggable": "^4.4.5",
72
72
  "react-imask": "^6.4.3",
73
- "react-router-dom": "^6.7.0",
73
+ "react-router-dom": "^6.8.0",
74
74
  "react-window": "^1.8.8"
75
75
  },
76
76
  "devDependencies": {
@@ -86,8 +86,8 @@
86
86
  "@types/jest": "^29.4.0",
87
87
  "@typescript-eslint/eslint-plugin": "^5.49.0",
88
88
  "@typescript-eslint/parser": "^5.49.0",
89
- "jest": "^29.4.0",
90
- "jest-environment-jsdom": "^29.4.0",
89
+ "jest": "^29.4.1",
90
+ "jest-environment-jsdom": "^29.4.1",
91
91
  "typescript": "^4.9.4"
92
92
  }
93
93
  }
@@ -1,5 +1,7 @@
1
+ import { EventWatcher } from "@etsoo/react";
1
2
  import { IconButton, Menu } from "@mui/material";
2
3
  import React from "react";
4
+ import { useNavigate } from "react-router-dom";
3
5
  import { UserAvatar } from "../UserAvatar";
4
6
 
5
7
  /**
@@ -35,6 +37,13 @@ export interface UserMenuLocalProps extends Omit<UserMenuProps, "children"> {
35
37
  smDown: boolean;
36
38
  }
37
39
 
40
+ /**
41
+ * Event watcher
42
+ */
43
+ export const eventWatcher = new EventWatcher();
44
+
45
+ const eventWatcherAction = "usermenu.href.transitionend";
46
+
38
47
  /**
39
48
  * User menu
40
49
  * @param props Props
@@ -50,6 +59,9 @@ export function UserMenu(props: UserMenuProps) {
50
59
  // User menu open or not
51
60
  const isMenuOpen = Boolean(anchorEl);
52
61
 
62
+ // Route
63
+ const navigate = useNavigate();
64
+
53
65
  // User menu
54
66
  const handleUserMenuOpen = (event: React.MouseEvent<HTMLButtonElement>) => {
55
67
  setAnchorEl(event.currentTarget);
@@ -59,6 +71,25 @@ export function UserMenu(props: UserMenuProps) {
59
71
  setAnchorEl(undefined);
60
72
  };
61
73
 
74
+ const handleClick = async (event: React.MouseEvent<HTMLDivElement>) => {
75
+ handleMenuClose();
76
+
77
+ const item = (event.target as HTMLElement)?.closest("li[href]");
78
+ if (item != null) {
79
+ const href = item.getAttribute("href");
80
+ if (href) {
81
+ // Even set transitionDuration = 0, still need to wait a little bit
82
+ eventWatcher.add({
83
+ type: eventWatcherAction,
84
+ action: () => {
85
+ navigate(href!);
86
+ },
87
+ once: true
88
+ });
89
+ }
90
+ }
91
+ };
92
+
62
93
  return (
63
94
  <React.Fragment>
64
95
  <IconButton
@@ -108,7 +139,8 @@ export function UserMenu(props: UserMenuProps) {
108
139
  horizontal: "right"
109
140
  }}
110
141
  open={isMenuOpen}
111
- onClick={handleMenuClose}
142
+ onTransitionEnd={() => eventWatcher.do(eventWatcherAction)}
143
+ onClick={handleClick}
112
144
  onClose={handleMenuClose}
113
145
  >
114
146
  {children(handleMenuClose)}