@etsoo/react 1.2.11 → 1.2.15
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.
- package/__tests__/mu/NotifierMUTests.tsx +1 -2
- package/lib/app/InputDialogProps.d.ts +2 -14
- package/lib/app/ReactApp.d.ts +19 -3
- package/lib/app/ReactApp.js +2 -7
- package/lib/mu/AutocompleteExtendedProps.d.ts +1 -1
- package/lib/mu/ComboBox.d.ts +8 -0
- package/lib/mu/ComboBox.js +18 -3
- package/lib/mu/CountdownButton.d.ts +1 -1
- package/lib/mu/NotifierMU.d.ts +4 -5
- package/lib/mu/NotifierMU.js +36 -28
- package/lib/mu/SelectEx.d.ts +4 -0
- package/lib/mu/SelectEx.js +23 -9
- package/lib/mu/TextFieldEx.d.ts +3 -3
- package/lib/mu/Tiplist.d.ts +1 -1
- package/lib/notifier/Notifier.d.ts +41 -8
- package/lib/notifier/Notifier.js +3 -6
- package/package.json +4 -4
- package/src/app/InputDialogProps.ts +2 -16
- package/src/app/ReactApp.ts +23 -11
- package/src/mu/AutocompleteExtendedProps.ts +4 -1
- package/src/mu/ComboBox.tsx +32 -4
- package/src/mu/NotifierMU.tsx +62 -56
- package/src/mu/NotifierPromptProps.ts +2 -0
- package/src/mu/SelectEx.tsx +29 -7
- package/src/mu/Tiplist.tsx +1 -1
- package/src/notifier/Notifier.ts +68 -16
package/src/mu/SelectEx.tsx
CHANGED
|
@@ -28,6 +28,11 @@ export interface SelectExProps<T = any>
|
|
|
28
28
|
*/
|
|
29
29
|
labelField?: ((option: T) => string) | string;
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Load data callback
|
|
33
|
+
*/
|
|
34
|
+
loadData?: () => PromiseLike<T[] | null | undefined>;
|
|
35
|
+
|
|
31
36
|
/**
|
|
32
37
|
* Array of options.
|
|
33
38
|
*/
|
|
@@ -51,6 +56,7 @@ export function SelectEx<T = any>(props: SelectExProps<T>) {
|
|
|
51
56
|
idField = 'id',
|
|
52
57
|
label,
|
|
53
58
|
labelField = 'label',
|
|
59
|
+
loadData,
|
|
54
60
|
multiple = false,
|
|
55
61
|
name,
|
|
56
62
|
options = [],
|
|
@@ -59,6 +65,10 @@ export function SelectEx<T = any>(props: SelectExProps<T>) {
|
|
|
59
65
|
...rest
|
|
60
66
|
} = props;
|
|
61
67
|
|
|
68
|
+
// Options state
|
|
69
|
+
const [localOptions, setOptions] = React.useState(options);
|
|
70
|
+
const isMounted = React.useRef(true);
|
|
71
|
+
|
|
62
72
|
// Local value
|
|
63
73
|
const valueSource = defaultValue ?? value ?? '';
|
|
64
74
|
let localValue: unknown | unknown[];
|
|
@@ -69,7 +79,7 @@ export function SelectEx<T = any>(props: SelectExProps<T>) {
|
|
|
69
79
|
localValue = valueSource;
|
|
70
80
|
}
|
|
71
81
|
|
|
72
|
-
//
|
|
82
|
+
// Value state
|
|
73
83
|
const [valueState, setValueState] = React.useState(localValue);
|
|
74
84
|
|
|
75
85
|
// Label id
|
|
@@ -107,11 +117,23 @@ export function SelectEx<T = any>(props: SelectExProps<T>) {
|
|
|
107
117
|
// When layout ready
|
|
108
118
|
React.useEffect(() => {
|
|
109
119
|
const input = divRef.current?.querySelector('input');
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
const inputChange = (event: Event) => {
|
|
121
|
+
// Reset case
|
|
122
|
+
if (event.cancelable) setValueState(multiple ? [] : '');
|
|
123
|
+
};
|
|
124
|
+
input?.addEventListener('change', inputChange);
|
|
125
|
+
|
|
126
|
+
if (loadData) {
|
|
127
|
+
loadData().then((result) => {
|
|
128
|
+
if (result == null || !isMounted.current) return;
|
|
129
|
+
setOptions(result);
|
|
114
130
|
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return () => {
|
|
134
|
+
isMounted.current = false;
|
|
135
|
+
input?.removeEventListener('change', inputChange);
|
|
136
|
+
};
|
|
115
137
|
}, []);
|
|
116
138
|
|
|
117
139
|
// Layout
|
|
@@ -139,7 +161,7 @@ export function SelectEx<T = any>(props: SelectExProps<T>) {
|
|
|
139
161
|
onChange={multiple ? handleChange : undefined}
|
|
140
162
|
renderValue={(selected) => {
|
|
141
163
|
// The text shows up
|
|
142
|
-
return
|
|
164
|
+
return localOptions
|
|
143
165
|
.filter((option: any) =>
|
|
144
166
|
Array.isArray(selected)
|
|
145
167
|
? selected.indexOf(option.id) !== -1
|
|
@@ -151,7 +173,7 @@ export function SelectEx<T = any>(props: SelectExProps<T>) {
|
|
|
151
173
|
sx={{ minWidth: '150px' }}
|
|
152
174
|
{...rest}
|
|
153
175
|
>
|
|
154
|
-
{
|
|
176
|
+
{localOptions.map((option: any) => {
|
|
155
177
|
// Option id
|
|
156
178
|
const id = option[idField];
|
|
157
179
|
|
package/src/mu/Tiplist.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import { SearchField } from './SearchField';
|
|
|
10
10
|
* Tiplist props
|
|
11
11
|
*/
|
|
12
12
|
export interface TiplistProps<T extends Record<string, any>>
|
|
13
|
-
extends Omit<AutocompleteExtendedProps<T>, '
|
|
13
|
+
extends Omit<AutocompleteExtendedProps<T>, 'open'> {
|
|
14
14
|
/**
|
|
15
15
|
* Load data callback
|
|
16
16
|
*/
|
package/src/notifier/Notifier.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
INotifier,
|
|
5
5
|
Notification,
|
|
6
6
|
NotificationAlign,
|
|
7
|
+
NotificationCallProps,
|
|
7
8
|
NotificationContainer,
|
|
8
9
|
NotificationDictionary,
|
|
9
10
|
NotificationRenderProps
|
|
@@ -11,13 +12,59 @@ import {
|
|
|
11
12
|
import { IAction } from '@etsoo/appscript';
|
|
12
13
|
import { State } from '../states/State';
|
|
13
14
|
import { IProviderProps, IUpdate } from '../states/IState';
|
|
15
|
+
import { Breakpoint } from '@mui/material';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React notification call props
|
|
19
|
+
*/
|
|
20
|
+
export interface NotificationReactCallProps extends NotificationCallProps {
|
|
21
|
+
/**
|
|
22
|
+
* Full width
|
|
23
|
+
*/
|
|
24
|
+
fullWidth?: boolean;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Full screen
|
|
28
|
+
*/
|
|
29
|
+
fullScreen?: boolean;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Inputs layout
|
|
33
|
+
*/
|
|
34
|
+
inputs?: React.ReactNode;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Max width
|
|
38
|
+
*/
|
|
39
|
+
maxWidth?: Breakpoint | false;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* OK label
|
|
43
|
+
*/
|
|
44
|
+
okLabel?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Cancel label
|
|
48
|
+
*/
|
|
49
|
+
cancelLabel?: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Type
|
|
53
|
+
*/
|
|
54
|
+
type?: string;
|
|
55
|
+
}
|
|
14
56
|
|
|
15
57
|
/**
|
|
16
58
|
* React notification interface
|
|
17
59
|
*/
|
|
18
|
-
export interface INotificationReact
|
|
60
|
+
export interface INotificationReact
|
|
61
|
+
extends INotification<React.ReactNode, NotificationReactCallProps> {}
|
|
19
62
|
|
|
20
|
-
interface ReactNotifications
|
|
63
|
+
interface ReactNotifications
|
|
64
|
+
extends NotificationDictionary<
|
|
65
|
+
React.ReactNode,
|
|
66
|
+
NotificationReactCallProps
|
|
67
|
+
> {}
|
|
21
68
|
|
|
22
69
|
/**
|
|
23
70
|
* Action to manage the notifier
|
|
@@ -37,7 +84,10 @@ interface INotifierAction extends IAction {
|
|
|
37
84
|
/**
|
|
38
85
|
* React notification
|
|
39
86
|
*/
|
|
40
|
-
export abstract class NotificationReact extends Notification<
|
|
87
|
+
export abstract class NotificationReact extends Notification<
|
|
88
|
+
React.ReactNode,
|
|
89
|
+
NotificationReactCallProps
|
|
90
|
+
> {}
|
|
41
91
|
|
|
42
92
|
/**
|
|
43
93
|
* React notification render props
|
|
@@ -49,7 +99,8 @@ export interface NotificationReactRenderProps
|
|
|
49
99
|
/**
|
|
50
100
|
* Notifier interface
|
|
51
101
|
*/
|
|
52
|
-
export interface INotifierReact
|
|
102
|
+
export interface INotifierReact
|
|
103
|
+
extends INotifier<React.ReactNode, NotificationReactCallProps> {
|
|
53
104
|
/**
|
|
54
105
|
* Create state provider
|
|
55
106
|
* @param className Style class name
|
|
@@ -73,7 +124,7 @@ export interface INotifierOptions {
|
|
|
73
124
|
* Notifier for React
|
|
74
125
|
*/
|
|
75
126
|
export abstract class NotifierReact
|
|
76
|
-
extends NotificationContainer<React.ReactNode>
|
|
127
|
+
extends NotificationContainer<React.ReactNode, NotificationReactCallProps>
|
|
77
128
|
implements INotifierReact
|
|
78
129
|
{
|
|
79
130
|
// Instance
|
|
@@ -117,17 +168,15 @@ export abstract class NotifierReact
|
|
|
117
168
|
*/
|
|
118
169
|
protected abstract createContainer(
|
|
119
170
|
align: NotificationAlign,
|
|
120
|
-
children: React.ReactNode[]
|
|
121
|
-
options: any
|
|
171
|
+
children: React.ReactNode[]
|
|
122
172
|
): React.ReactElement;
|
|
123
173
|
|
|
124
174
|
/**
|
|
125
175
|
* Create state provider
|
|
126
176
|
* @param className Style class name
|
|
127
|
-
* @param optionGenerator Options generator
|
|
128
177
|
* @returns Provider
|
|
129
178
|
*/
|
|
130
|
-
createProvider(className?: string
|
|
179
|
+
createProvider(className?: string) {
|
|
131
180
|
// Custom creator
|
|
132
181
|
const creator = (
|
|
133
182
|
state: ReactNotifications,
|
|
@@ -137,9 +186,6 @@ export abstract class NotifierReact
|
|
|
137
186
|
// Hold the current state update
|
|
138
187
|
this.stateUpdate = update;
|
|
139
188
|
|
|
140
|
-
// Options
|
|
141
|
-
const options = optionGenerator ? optionGenerator() : {};
|
|
142
|
-
|
|
143
189
|
// Aligns collection
|
|
144
190
|
const aligns: React.ReactNode[] = [];
|
|
145
191
|
for (const align in state) {
|
|
@@ -148,11 +194,11 @@ export abstract class NotifierReact
|
|
|
148
194
|
|
|
149
195
|
// UI collections
|
|
150
196
|
const ui = notifications.map((notification) =>
|
|
151
|
-
notification.render(props, className + '-item'
|
|
197
|
+
notification.render(props, className + '-item')
|
|
152
198
|
);
|
|
153
199
|
|
|
154
200
|
// Add to the collection
|
|
155
|
-
aligns.push(this.createContainer(Number(align), ui
|
|
201
|
+
aligns.push(this.createContainer(Number(align), ui));
|
|
156
202
|
}
|
|
157
203
|
|
|
158
204
|
// Generate the component
|
|
@@ -162,7 +208,10 @@ export abstract class NotifierReact
|
|
|
162
208
|
// Create state
|
|
163
209
|
const { provider } = State.create(
|
|
164
210
|
(
|
|
165
|
-
state: NotificationDictionary<
|
|
211
|
+
state: NotificationDictionary<
|
|
212
|
+
React.ReactNode,
|
|
213
|
+
NotificationReactCallProps
|
|
214
|
+
>,
|
|
166
215
|
_action: INotifierAction
|
|
167
216
|
) => {
|
|
168
217
|
// Collection update is done with NotificationContainer
|
|
@@ -170,7 +219,10 @@ export abstract class NotifierReact
|
|
|
170
219
|
},
|
|
171
220
|
this.notifications,
|
|
172
221
|
{} as IUpdate<
|
|
173
|
-
NotificationDictionary<
|
|
222
|
+
NotificationDictionary<
|
|
223
|
+
React.ReactNode,
|
|
224
|
+
NotificationReactCallProps
|
|
225
|
+
>,
|
|
174
226
|
INotifierAction
|
|
175
227
|
>,
|
|
176
228
|
creator
|