@etsoo/materialui 1.3.82 → 1.3.84

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.
@@ -9,9 +9,13 @@ export type TextFieldExProps = TextFieldProps & {
9
9
  */
10
10
  changeDelay?: number;
11
11
  /**
12
- * Click clear button callback, return false to prevent the clear action
12
+ * Clear button label
13
13
  */
14
- onClear?: () => boolean | void;
14
+ clearLabel?: string;
15
+ /**
16
+ * Click clear button callback
17
+ */
18
+ onClear?: (doClear: () => void) => void;
15
19
  /**
16
20
  * On enter click
17
21
  */
@@ -51,9 +55,13 @@ export declare const TextFieldEx: React.ForwardRefExoticComponent<(Omit<import("
51
55
  */
52
56
  changeDelay?: number;
53
57
  /**
54
- * Click clear button callback, return false to prevent the clear action
58
+ * Clear button label
59
+ */
60
+ clearLabel?: string;
61
+ /**
62
+ * Click clear button callback
55
63
  */
56
- onClear?: () => boolean | void;
64
+ onClear?: (doClear: () => void) => void;
57
65
  /**
58
66
  * On enter click
59
67
  */
@@ -82,9 +90,13 @@ export declare const TextFieldEx: React.ForwardRefExoticComponent<(Omit<import("
82
90
  */
83
91
  changeDelay?: number;
84
92
  /**
85
- * Click clear button callback, return false to prevent the clear action
93
+ * Clear button label
86
94
  */
87
- onClear?: () => boolean | void;
95
+ clearLabel?: string;
96
+ /**
97
+ * Click clear button callback
98
+ */
99
+ onClear?: (doClear: () => void) => void;
88
100
  /**
89
101
  * On enter click
90
102
  */
@@ -113,9 +125,13 @@ export declare const TextFieldEx: React.ForwardRefExoticComponent<(Omit<import("
113
125
  */
114
126
  changeDelay?: number;
115
127
  /**
116
- * Click clear button callback, return false to prevent the clear action
128
+ * Clear button label
129
+ */
130
+ clearLabel?: string;
131
+ /**
132
+ * Click clear button callback
117
133
  */
118
- onClear?: () => boolean | void;
134
+ onClear?: (doClear: () => void) => void;
119
135
  /**
120
136
  * On enter click
121
137
  */
@@ -5,9 +5,12 @@ import { MUGlobal } from "./MUGlobal";
5
5
  import { Clear, Visibility } from "@mui/icons-material";
6
6
  import { Keyboard } from "@etsoo/shared";
7
7
  import { ReactUtils, useCombinedRefs, useDelayedExecutor } from "@etsoo/react";
8
+ import { globalApp } from "./app/ReactApp";
8
9
  export const TextFieldEx = React.forwardRef((props, ref) => {
10
+ // Labels
11
+ const { showIt, clearInput } = globalApp?.getLabels("showIt", "clearInput") ?? {};
9
12
  // Destructure
10
- const { changeDelay, error, fullWidth = true, helperText, InputLabelProps = {}, InputProps = {}, onChange, onClear, onKeyDown, onEnter, onVisibility, inputRef, readOnly, showClear, showPassword, type, variant = MUGlobal.textFieldVariant, ...rest } = props;
13
+ const { changeDelay, clearLabel = clearInput, error, fullWidth = true, helperText, InputLabelProps = {}, InputProps = {}, onChange, onClear, onKeyDown, onEnter, onVisibility, inputRef, readOnly, showClear, showPassword, type, variant = MUGlobal.textFieldVariant, ...rest } = props;
11
14
  // Shrink
12
15
  InputLabelProps.shrink ?? (InputLabelProps.shrink = MUGlobal.searchFieldShrink);
13
16
  // State
@@ -31,16 +34,20 @@ export const TextFieldEx = React.forwardRef((props, ref) => {
31
34
  updateEmpty(false);
32
35
  }
33
36
  };
34
- const clearClick = () => {
37
+ const doClear = () => {
35
38
  if (input == null)
36
39
  return;
37
- if (onClear) {
38
- if (onClear() === false)
39
- return;
40
- }
41
40
  ReactUtils.triggerChange(input, "", false);
42
41
  input.focus();
43
42
  };
43
+ const clearClick = () => {
44
+ if (onClear) {
45
+ onClear(doClear);
46
+ }
47
+ else {
48
+ doClear();
49
+ }
50
+ };
44
51
  const preventDefault = (e) => {
45
52
  // Prevent long press
46
53
  if (e.isPropagationStopped())
@@ -72,7 +79,7 @@ export const TextFieldEx = React.forwardRef((props, ref) => {
72
79
  };
73
80
  // Show password and/or clear button
74
81
  if (!empty && (showPassword || showClear)) {
75
- InputProps.endAdornment = (_jsxs(InputAdornment, { position: "end", children: [showPassword && (_jsx(IconButton, { tabIndex: -1, onContextMenu: (event) => event.preventDefault(), onMouseDown: touchStart, onMouseUp: touchEnd, onTouchStart: touchStart, onTouchCancel: touchEnd, onTouchEnd: touchEnd, children: _jsx(Visibility, {}) })), showClear && (_jsx(IconButton, { onClick: clearClick, tabIndex: -1, children: _jsx(Clear, {}) }))] }));
82
+ InputProps.endAdornment = (_jsxs(InputAdornment, { position: "end", children: [showPassword && (_jsx(IconButton, { tabIndex: -1, onContextMenu: (event) => event.preventDefault(), onMouseDown: touchStart, onMouseUp: touchEnd, onTouchStart: touchStart, onTouchCancel: touchEnd, onTouchEnd: touchEnd, title: showIt, children: _jsx(Visibility, {}) })), showClear && (_jsx(IconButton, { onClick: clearClick, tabIndex: -1, title: clearLabel, children: _jsx(Clear, {}) }))] }));
76
83
  }
77
84
  // Extend key precess
78
85
  const onKeyPressEx = onEnter == null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.3.82",
3
+ "version": "1.3.84",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "@emotion/css": "^11.13.0",
51
51
  "@emotion/react": "^11.13.0",
52
52
  "@emotion/styled": "^11.13.0",
53
- "@etsoo/appscript": "^1.5.5",
53
+ "@etsoo/appscript": "^1.5.7",
54
54
  "@etsoo/notificationbase": "^1.1.47",
55
55
  "@etsoo/react": "^1.7.62",
56
56
  "@etsoo/shared": "^1.2.44",
@@ -9,6 +9,7 @@ import { MUGlobal } from "./MUGlobal";
9
9
  import { Clear, Visibility } from "@mui/icons-material";
10
10
  import { Keyboard } from "@etsoo/shared";
11
11
  import { ReactUtils, useCombinedRefs, useDelayedExecutor } from "@etsoo/react";
12
+ import { globalApp } from "./app/ReactApp";
12
13
 
13
14
  /**
14
15
  * Extended text field props
@@ -20,9 +21,14 @@ export type TextFieldExProps = TextFieldProps & {
20
21
  changeDelay?: number;
21
22
 
22
23
  /**
23
- * Click clear button callback, return false to prevent the clear action
24
+ * Clear button label
24
25
  */
25
- onClear?: () => boolean | void;
26
+ clearLabel?: string;
27
+
28
+ /**
29
+ * Click clear button callback
30
+ */
31
+ onClear?: (doClear: () => void) => void;
26
32
 
27
33
  /**
28
34
  * On enter click
@@ -67,9 +73,14 @@ export const TextFieldEx = React.forwardRef<
67
73
  TextFieldExMethods,
68
74
  TextFieldExProps
69
75
  >((props, ref) => {
76
+ // Labels
77
+ const { showIt, clearInput } =
78
+ globalApp?.getLabels("showIt", "clearInput") ?? {};
79
+
70
80
  // Destructure
71
81
  const {
72
82
  changeDelay,
83
+ clearLabel = clearInput,
73
84
  error,
74
85
  fullWidth = true,
75
86
  helperText,
@@ -118,15 +129,18 @@ export const TextFieldEx = React.forwardRef<
118
129
  }
119
130
  };
120
131
 
121
- const clearClick = () => {
132
+ const doClear = () => {
122
133
  if (input == null) return;
134
+ ReactUtils.triggerChange(input, "", false);
135
+ input.focus();
136
+ };
123
137
 
138
+ const clearClick = () => {
124
139
  if (onClear) {
125
- if (onClear() === false) return;
140
+ onClear(doClear);
141
+ } else {
142
+ doClear();
126
143
  }
127
-
128
- ReactUtils.triggerChange(input, "", false);
129
- input.focus();
130
144
  };
131
145
 
132
146
  const preventDefault = (e: React.TouchEvent | React.MouseEvent) => {
@@ -173,12 +187,13 @@ export const TextFieldEx = React.forwardRef<
173
187
  onTouchStart={touchStart}
174
188
  onTouchCancel={touchEnd}
175
189
  onTouchEnd={touchEnd}
190
+ title={showIt}
176
191
  >
177
192
  <Visibility />
178
193
  </IconButton>
179
194
  )}
180
195
  {showClear && (
181
- <IconButton onClick={clearClick} tabIndex={-1}>
196
+ <IconButton onClick={clearClick} tabIndex={-1} title={clearLabel}>
182
197
  <Clear />
183
198
  </IconButton>
184
199
  )}