@etsoo/materialui 1.4.61 → 1.4.63

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,29 @@
1
+ import React from "react";
2
+ /**
3
+ * Button popover props
4
+ */
5
+ export type ButtonPopoverProps<T> = {
6
+ /**
7
+ * Button component
8
+ * @param callback Button click callback
9
+ * @returns Layout
10
+ */
11
+ button: (callback: (handler: HTMLElement | null) => void) => React.ReactNode;
12
+ /**
13
+ * Children component
14
+ * @param data Data
15
+ * @returns Layout
16
+ */
17
+ children: (data: T | null) => React.ReactNode;
18
+ /**
19
+ * Load data
20
+ * @returns Data promise
21
+ */
22
+ loadData?: () => Promise<T | undefined>;
23
+ };
24
+ /**
25
+ * Button popover component
26
+ * @param props Props
27
+ * @returns Component
28
+ */
29
+ export declare function ButtonPopover<T>(props: ButtonPopoverProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,57 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Popover } from "@mui/material";
3
+ import React from "react";
4
+ /**
5
+ * Button popover component
6
+ * @param props Props
7
+ * @returns Component
8
+ */
9
+ export function ButtonPopover(props) {
10
+ // Destruct
11
+ const { button, children, loadData } = props;
12
+ // States
13
+ const [anchorEl, setAnchorEl] = React.useState(null);
14
+ const [data, setData] = React.useState(null);
15
+ const isLoadded = React.useRef(false);
16
+ const open = Boolean(anchorEl);
17
+ // Load data
18
+ React.useEffect(() => {
19
+ if (loadData && (!isLoadded.current || open)) {
20
+ // First time or when open
21
+ loadData().then((d) => {
22
+ if (d == null)
23
+ return;
24
+ setData(d);
25
+ isLoadded.current = true;
26
+ });
27
+ }
28
+ }, [loadData, open]);
29
+ // Children
30
+ const currentChildren = React.useMemo(() => children(data), [children, data]);
31
+ const handleClose = () => {
32
+ setAnchorEl(null);
33
+ };
34
+ // Layout
35
+ return (_jsxs(React.Fragment, { children: [button((handler) => setAnchorEl(handler)), _jsx(Popover, { anchorEl: anchorEl, open: open, onClose: handleClose, onClick: handleClose, transformOrigin: { horizontal: "right", vertical: "top" }, anchorOrigin: { horizontal: "right", vertical: "bottom" }, slotProps: {
36
+ paper: {
37
+ elevation: 0,
38
+ sx: {
39
+ overflow: "visible",
40
+ filter: "drop-shadow(0px 2px 8px rgba(0,0,0,0.32))",
41
+ mt: 1,
42
+ "&::before": {
43
+ content: '""',
44
+ display: "block",
45
+ position: "absolute",
46
+ top: 0,
47
+ right: 14,
48
+ width: 10,
49
+ height: 10,
50
+ bgcolor: "background.paper",
51
+ transform: "translateY(-50%) rotate(45deg)",
52
+ zIndex: 0
53
+ }
54
+ }
55
+ }
56
+ }, children: currentChildren })] }));
57
+ }
package/lib/NotifierMU.js CHANGED
@@ -63,7 +63,7 @@ export class NotificationMU extends NotificationReact {
63
63
  await this.returnValue(undefined);
64
64
  return true;
65
65
  };
66
- return (_jsxs(Dialog, { open: this.open, PaperComponent: draggable ? DraggablePaperComponent : undefined, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen, ...options, children: [_jsxs(IconDialogTitle, { draggable: draggable, className: "dialog-title", children: [icon, _jsx("span", { className: "dialogTitle", children: title }), closable && (_jsx(IconButton, { className: "MuiDialogContent-root-close-button", size: "small", onClick: () => this.returnValue("CLOSE"), children: _jsx(CloseIcon, {}) }))] }), _jsxs(DialogContent, { children: [typeof this.content === "string" ? (_jsx(DialogContentText, { children: this.content })) : (this.content), inputs] }), _jsx(DialogActions, { children: buttons
66
+ return (_jsxs(Dialog, { open: this.open, PaperComponent: draggable ? DraggablePaperComponent : undefined, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen, ...options, children: [_jsxs(IconDialogTitle, { draggable: draggable, className: draggable ? "dialog-title draggable-dialog-title" : "dialog-title", children: [icon, _jsx("span", { className: "dialogTitle", children: title }), closable && (_jsx(IconButton, { className: "MuiDialogContent-root-close-button", size: "small", onClick: () => this.returnValue("CLOSE"), children: _jsx(CloseIcon, {}) }))] }), _jsxs(DialogContent, { children: [typeof this.content === "string" ? (_jsx(DialogContentText, { children: this.content })) : (this.content), inputs] }), _jsx(DialogActions, { children: buttons
67
67
  ? buttons(this, callback)
68
68
  : primaryButton && (_jsx(LoadingButton, { ...setupProps, onClick: callback, autoFocus: true, ...primaryButtonProps, children: okLabel })) })] }, this.id));
69
69
  }
@@ -78,7 +78,7 @@ export class NotificationMU extends NotificationReact {
78
78
  await this.returnValue(value);
79
79
  return true;
80
80
  };
81
- return (_jsxs(Dialog, { open: this.open, PaperComponent: draggable ? DraggablePaperComponent : undefined, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen, ...options, children: [_jsxs(IconDialogTitle, { draggable: draggable, className: "dialog-title", children: [_jsx(Help, { color: "action" }), _jsx("span", { className: "dialogTitle", children: title }), closable && (_jsx(IconButton, { className: "MuiDialogContent-root-close-button", size: "small", onClick: () => this.returnValue("CLOSE"), children: _jsx(CloseIcon, {}) }))] }), _jsxs(DialogContent, { children: [typeof this.content === "string" ? (_jsx(DialogContentText, { children: this.content })) : (this.content), inputs] }), _jsx(DialogActions, { children: buttons ? (buttons(this, callback)) : (_jsxs(React.Fragment, { children: [cancelButton && (_jsx(LoadingButton, { color: "secondary", onClick: async (event) => await callback(event, false), children: cancelLabel })), primaryButton && (_jsx(LoadingButton, { color: "primary", onClick: async (event) => await callback(event, true), autoFocus: true, ...primaryButtonProps, children: okLabel }))] })) })] }, this.id));
81
+ return (_jsxs(Dialog, { open: this.open, PaperComponent: draggable ? DraggablePaperComponent : undefined, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen, ...options, children: [_jsxs(IconDialogTitle, { draggable: draggable, className: draggable ? "dialog-title draggable-dialog-title" : "dialog-title", children: [_jsx(Help, { color: "action" }), _jsx("span", { className: "dialogTitle", children: title }), closable && (_jsx(IconButton, { className: "MuiDialogContent-root-close-button", size: "small", onClick: () => this.returnValue("CLOSE"), children: _jsx(CloseIcon, {}) }))] }), _jsxs(DialogContent, { children: [typeof this.content === "string" ? (_jsx(DialogContentText, { children: this.content })) : (this.content), inputs] }), _jsx(DialogActions, { children: buttons ? (buttons(this, callback)) : (_jsxs(React.Fragment, { children: [cancelButton && (_jsx(LoadingButton, { color: "secondary", onClick: async (event) => await callback(event, false), children: cancelLabel })), primaryButton && (_jsx(LoadingButton, { color: "primary", onClick: async (event) => await callback(event, true), autoFocus: true, ...primaryButtonProps, children: okLabel }))] })) })] }, this.id));
82
82
  }
83
83
  createMessageColor() {
84
84
  if (this.type === NotificationMessageType.Danger)
@@ -177,7 +177,7 @@ export class NotificationMU extends NotificationReact {
177
177
  event.preventDefault();
178
178
  event.currentTarget.elements.namedItem("okButton")?.click();
179
179
  return false;
180
- }, children: [_jsxs(IconDialogTitle, { draggable: draggable, className: "dialog-title", children: [_jsx(Info, { color: "primary" }), _jsx("span", { className: "dialogTitle", children: title }), closable && (_jsx(IconButton, { className: "MuiDialogContent-root-close-button", size: "small", onClick: () => this.returnValue("CLOSE"), children: _jsx(CloseIcon, {}) }))] }), _jsxs(DialogContent, { children: [typeof this.content === "string" ? (_jsx(DialogContentText, { children: this.content })) : (this.content), localInputs, _jsx(Typography, { variant: "caption", display: "block", ref: errorRef, color: "error" })] }), _jsx(DialogActions, { children: buttons ? (buttons(this, handleSubmit)) : (_jsxs(React.Fragment, { children: [cancelButton && (_jsx(Button, { color: "secondary", onClick: () => {
180
+ }, children: [_jsxs(IconDialogTitle, { draggable: draggable, className: draggable ? "dialog-title draggable-dialog-title" : "dialog-title", children: [_jsx(Info, { color: "primary" }), _jsx("span", { className: "dialogTitle", children: title }), closable && (_jsx(IconButton, { className: "MuiDialogContent-root-close-button", size: "small", onClick: () => this.returnValue("CLOSE"), children: _jsx(CloseIcon, {}) }))] }), _jsxs(DialogContent, { children: [typeof this.content === "string" ? (_jsx(DialogContentText, { children: this.content })) : (this.content), localInputs, _jsx(Typography, { variant: "caption", display: "block", ref: errorRef, color: "error" })] }), _jsx(DialogActions, { children: buttons ? (buttons(this, handleSubmit)) : (_jsxs(React.Fragment, { children: [cancelButton && (_jsx(Button, { color: "secondary", onClick: () => {
181
181
  if (this.onReturn)
182
182
  this.onReturn(undefined);
183
183
  this.dismiss();
@@ -1,6 +1,7 @@
1
- import { ApiRefreshTokenDto, IApi } from "@etsoo/appscript";
1
+ import { ApiRefreshTokenDto, IApi, IApiPayload } from "@etsoo/appscript";
2
2
  import { ReactAppType } from "./ReactApp";
3
3
  import { IServiceUser, ServiceUserToken } from "./IServiceUser";
4
+ import { IActionResult } from "@etsoo/shared";
4
5
  /**
5
6
  * Service application interface
6
7
  */
@@ -15,14 +16,21 @@ export interface IServiceApp extends ReactAppType {
15
16
  readonly coreOrigin: string;
16
17
  /**
17
18
  * Load core system UI
19
+ * @param tryLogin Try login or not
18
20
  */
19
- loadCore(): void;
21
+ loadCore(tryLogin?: boolean): void;
22
+ /**
23
+ * Switch organization
24
+ * @param organizationId Organization ID
25
+ * @param fromOrganizationId From organization ID
26
+ * @param payload Payload
27
+ */
28
+ switchOrg(organizationId: number, fromOrganizationId?: number, payload?: IApiPayload<IActionResult<IServiceUser & ServiceUserToken>>): Promise<IActionResult<IServiceUser & ServiceUserToken> | undefined>;
20
29
  /**
21
30
  *
22
31
  * @param user Current user
23
32
  * @param core Core system API token data
24
- * @param keep Keep in local storage or not
25
33
  * @param dispatch User state dispatch
26
34
  */
27
- userLoginEx(user: IServiceUser & ServiceUserToken, core?: ApiRefreshTokenDto, keep?: boolean, dispatch?: boolean): void;
35
+ userLoginEx(user: IServiceUser & ServiceUserToken, core?: ApiRefreshTokenDto, dispatch?: boolean): void;
28
36
  }
package/lib/index.d.ts CHANGED
@@ -38,6 +38,7 @@ export * from "./AutocompleteExtendedProps";
38
38
  export * from "./BackButton";
39
39
  export * from "./BridgeCloseButton";
40
40
  export * from "./ButtonLink";
41
+ export * from "./ButtonPopover";
41
42
  export * from "./ComboBox";
42
43
  export * from "./ComboBoxMultiple";
43
44
  export * from "./ComboBoxPro";
package/lib/index.js CHANGED
@@ -38,6 +38,7 @@ export * from "./AutocompleteExtendedProps";
38
38
  export * from "./BackButton";
39
39
  export * from "./BridgeCloseButton";
40
40
  export * from "./ButtonLink";
41
+ export * from "./ButtonPopover";
41
42
  export * from "./ComboBox";
42
43
  export * from "./ComboBoxMultiple";
43
44
  export * from "./ComboBoxPro";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.4.61",
3
+ "version": "1.4.63",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -0,0 +1,102 @@
1
+ import { Popover } from "@mui/material";
2
+ import React from "react";
3
+
4
+ /**
5
+ * Button popover props
6
+ */
7
+ export type ButtonPopoverProps<T> = {
8
+ /**
9
+ * Button component
10
+ * @param callback Button click callback
11
+ * @returns Layout
12
+ */
13
+ button: (callback: (handler: HTMLElement | null) => void) => React.ReactNode;
14
+
15
+ /**
16
+ * Children component
17
+ * @param data Data
18
+ * @returns Layout
19
+ */
20
+ children: (data: T | null) => React.ReactNode;
21
+
22
+ /**
23
+ * Load data
24
+ * @returns Data promise
25
+ */
26
+ loadData?: () => Promise<T | undefined>;
27
+ };
28
+
29
+ /**
30
+ * Button popover component
31
+ * @param props Props
32
+ * @returns Component
33
+ */
34
+ export function ButtonPopover<T>(props: ButtonPopoverProps<T>) {
35
+ // Destruct
36
+ const { button, children, loadData } = props;
37
+
38
+ // States
39
+ const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null);
40
+ const [data, setData] = React.useState<T | null>(null);
41
+ const isLoadded = React.useRef(false);
42
+
43
+ const open = Boolean(anchorEl);
44
+
45
+ // Load data
46
+ React.useEffect(() => {
47
+ if (loadData && (!isLoadded.current || open)) {
48
+ // First time or when open
49
+ loadData().then((d) => {
50
+ if (d == null) return;
51
+ setData(d);
52
+ isLoadded.current = true;
53
+ });
54
+ }
55
+ }, [loadData, open]);
56
+
57
+ // Children
58
+ const currentChildren = React.useMemo(() => children(data), [children, data]);
59
+
60
+ const handleClose = () => {
61
+ setAnchorEl(null);
62
+ };
63
+
64
+ // Layout
65
+ return (
66
+ <React.Fragment>
67
+ {button((handler) => setAnchorEl(handler))}
68
+ <Popover
69
+ anchorEl={anchorEl}
70
+ open={open}
71
+ onClose={handleClose}
72
+ onClick={handleClose}
73
+ transformOrigin={{ horizontal: "right", vertical: "top" }}
74
+ anchorOrigin={{ horizontal: "right", vertical: "bottom" }}
75
+ slotProps={{
76
+ paper: {
77
+ elevation: 0,
78
+ sx: {
79
+ overflow: "visible",
80
+ filter: "drop-shadow(0px 2px 8px rgba(0,0,0,0.32))",
81
+ mt: 1,
82
+ "&::before": {
83
+ content: '""',
84
+ display: "block",
85
+ position: "absolute",
86
+ top: 0,
87
+ right: 14,
88
+ width: 10,
89
+ height: 10,
90
+ bgcolor: "background.paper",
91
+ transform: "translateY(-50%) rotate(45deg)",
92
+ zIndex: 0
93
+ }
94
+ }
95
+ }
96
+ }}
97
+ >
98
+ {currentChildren}
99
+ </Popover>
100
+ </React.Fragment>
101
+ );
102
+ }
@@ -123,7 +123,12 @@ export class NotificationMU extends NotificationReact {
123
123
  fullScreen={fullScreen}
124
124
  {...options}
125
125
  >
126
- <IconDialogTitle draggable={draggable} className="dialog-title">
126
+ <IconDialogTitle
127
+ draggable={draggable}
128
+ className={
129
+ draggable ? "dialog-title draggable-dialog-title" : "dialog-title"
130
+ }
131
+ >
127
132
  {icon}
128
133
  <span className="dialogTitle">{title}</span>
129
134
  {closable && (
@@ -204,7 +209,12 @@ export class NotificationMU extends NotificationReact {
204
209
  fullScreen={fullScreen}
205
210
  {...options}
206
211
  >
207
- <IconDialogTitle draggable={draggable} className="dialog-title">
212
+ <IconDialogTitle
213
+ draggable={draggable}
214
+ className={
215
+ draggable ? "dialog-title draggable-dialog-title" : "dialog-title"
216
+ }
217
+ >
208
218
  <Help color="action" />
209
219
  <span className="dialogTitle">{title}</span>
210
220
  {closable && (
@@ -438,7 +448,12 @@ export class NotificationMU extends NotificationReact {
438
448
  return false;
439
449
  }}
440
450
  >
441
- <IconDialogTitle draggable={draggable} className="dialog-title">
451
+ <IconDialogTitle
452
+ draggable={draggable}
453
+ className={
454
+ draggable ? "dialog-title draggable-dialog-title" : "dialog-title"
455
+ }
456
+ >
442
457
  <Info color="primary" />
443
458
  <span className="dialogTitle">{title}</span>
444
459
  {closable && (
@@ -1,6 +1,7 @@
1
- import { ApiRefreshTokenDto, IApi } from "@etsoo/appscript";
1
+ import { ApiRefreshTokenDto, IApi, IApiPayload } from "@etsoo/appscript";
2
2
  import { ReactAppType } from "./ReactApp";
3
3
  import { IServiceUser, ServiceUserToken } from "./IServiceUser";
4
+ import { IActionResult } from "@etsoo/shared";
4
5
 
5
6
  /**
6
7
  * Service application interface
@@ -18,20 +19,31 @@ export interface IServiceApp extends ReactAppType {
18
19
 
19
20
  /**
20
21
  * Load core system UI
22
+ * @param tryLogin Try login or not
21
23
  */
22
- loadCore(): void;
24
+ loadCore(tryLogin?: boolean): void;
25
+
26
+ /**
27
+ * Switch organization
28
+ * @param organizationId Organization ID
29
+ * @param fromOrganizationId From organization ID
30
+ * @param payload Payload
31
+ */
32
+ switchOrg(
33
+ organizationId: number,
34
+ fromOrganizationId?: number,
35
+ payload?: IApiPayload<IActionResult<IServiceUser & ServiceUserToken>>
36
+ ): Promise<IActionResult<IServiceUser & ServiceUserToken> | undefined>;
23
37
 
24
38
  /**
25
39
  *
26
40
  * @param user Current user
27
41
  * @param core Core system API token data
28
- * @param keep Keep in local storage or not
29
42
  * @param dispatch User state dispatch
30
43
  */
31
44
  userLoginEx(
32
45
  user: IServiceUser & ServiceUserToken,
33
46
  core?: ApiRefreshTokenDto,
34
- keep?: boolean,
35
47
  dispatch?: boolean
36
48
  ): void;
37
49
  }
package/src/index.ts CHANGED
@@ -43,6 +43,7 @@ export * from "./AutocompleteExtendedProps";
43
43
  export * from "./BackButton";
44
44
  export * from "./BridgeCloseButton";
45
45
  export * from "./ButtonLink";
46
+ export * from "./ButtonPopover";
46
47
  export * from "./ComboBox";
47
48
  export * from "./ComboBoxMultiple";
48
49
  export * from "./ComboBoxPro";