@codezee/sixtify-brahma 0.2.175 → 0.2.177
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/package.json +2 -1
- package/packages/shared-components/dist/FormFields/Autocomplete/Autocomplete.d.ts +6 -1
- package/packages/shared-components/dist/FormFields/Autocomplete/Autocomplete.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/Autocomplete/Autocomplete.js +146 -11
- package/packages/shared-components/dist/FormFields/CheckBox/CheckBox.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/CheckBox/CheckBox.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/CheckBox/CheckBox.js +23 -6
- package/packages/shared-components/dist/FormFields/DatePicker/DatePicker.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/DatePicker/DatePicker.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/DatePicker/DatePicker.js +14 -5
- package/packages/shared-components/dist/FormFields/DateTimePicker/DateTimePicker.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/DateTimePicker/DateTimePicker.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/DateTimePicker/DateTimePicker.js +14 -5
- package/packages/shared-components/dist/FormFields/DecimalTextField/DecimalTextField.d.ts +18 -0
- package/packages/shared-components/dist/FormFields/DecimalTextField/DecimalTextField.d.ts.map +1 -0
- package/packages/shared-components/dist/FormFields/DecimalTextField/DecimalTextField.js +227 -0
- package/packages/shared-components/dist/FormFields/DecimalTextField/index.d.ts +2 -0
- package/packages/shared-components/dist/FormFields/DecimalTextField/index.d.ts.map +1 -0
- package/packages/shared-components/dist/FormFields/DecimalTextField/index.js +17 -0
- package/packages/shared-components/dist/FormFields/FileUpload/FileUpload.js +1 -1
- package/packages/shared-components/dist/FormFields/ImageUpload/ImageUpload.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/ImageUpload/ImageUpload.js +3 -1
- package/packages/shared-components/dist/FormFields/PhoneInputField/PhoneInputField.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/PhoneInputField/PhoneInputField.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/PhoneInputField/PhoneInputField.js +7 -3
- package/packages/shared-components/dist/FormFields/RadioGroupField/RadioGroupField.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/RadioGroupField/RadioGroupField.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/RadioGroupField/RadioGroupField.js +34 -14
- package/packages/shared-components/dist/FormFields/Rating/Ratting.js +1 -1
- package/packages/shared-components/dist/FormFields/Select/Select.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/Select/Select.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/Select/Select.js +12 -6
- package/packages/shared-components/dist/FormFields/SwitchField/SwitchField.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/SwitchField/SwitchField.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/SwitchField/SwitchField.js +10 -4
- package/packages/shared-components/dist/FormFields/TextField/TextField.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/TextField/TextField.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/TextField/TextField.js +7 -6
- package/packages/shared-components/dist/FormFields/TimeField/TimeField.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/TimeField/TimeField.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/TimeField/TimeField.js +6 -3
- package/packages/shared-components/dist/FormFields/TimePicker/TimePicker.d.ts +3 -1
- package/packages/shared-components/dist/FormFields/TimePicker/TimePicker.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/TimePicker/TimePicker.js +51 -3
- package/packages/shared-components/dist/FormFields/index.d.ts +1 -0
- package/packages/shared-components/dist/FormFields/index.d.ts.map +1 -1
- package/packages/shared-components/dist/FormFields/index.js +1 -0
- package/packages/shared-components/dist/RichTextEditor/RichTextEditor.d.ts +1 -1
- package/packages/shared-components/dist/SmartGrid/Components/TableRowComponent.js +2 -2
- package/packages/shared-components/dist/utils/context/NavigationKeyContext.d.ts +13 -0
- package/packages/shared-components/dist/utils/context/NavigationKeyContext.d.ts.map +1 -0
- package/packages/shared-components/dist/utils/context/NavigationKeyContext.js +15 -0
- package/packages/shared-components/dist/utils/context/index.d.ts +2 -0
- package/packages/shared-components/dist/utils/context/index.d.ts.map +1 -0
- package/packages/shared-components/dist/utils/context/index.js +6 -0
- package/packages/shared-components/dist/utils/hooks/useFormFieldFocus.d.ts +8 -1
- package/packages/shared-components/dist/utils/hooks/useFormFieldFocus.d.ts.map +1 -1
- package/packages/shared-components/dist/utils/hooks/useFormFieldFocus.js +94 -2
- package/packages/shared-components/dist/utils/index.d.ts +3 -2
- package/packages/shared-components/dist/utils/index.d.ts.map +1 -1
- package/packages/shared-components/dist/utils/index.js +3 -2
- package/packages/shared-components/dist/utils/regex.d.ts +1 -0
- package/packages/shared-components/dist/utils/regex.d.ts.map +1 -1
- package/packages/shared-components/dist/utils/regex.js +2 -1
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DecimalTextField = DecimalTextField;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
9
|
+
const react_number_format_1 = require("react-number-format");
|
|
10
|
+
const Tooltip_1 = require("../../Tooltip");
|
|
11
|
+
const useFormFieldFocus_1 = require("../../utils/hooks/useFormFieldFocus");
|
|
12
|
+
const commonStyles_1 = require("../commonStyles");
|
|
13
|
+
const Skeleton_1 = require("../TextField/Skeleton");
|
|
14
|
+
function DecimalTextField({ control, name, decimalScale, defaultFallbackValue = 0, min, max, defaultValue, label = "", required, disabled, loading = false, placeholder = "", containerProps, styling = "custom", infoMessage, customOnChange, navigationKey = "tab", ...restProps }) {
|
|
15
|
+
const { field: { value, onChange: formOnChange, onBlur: formOnBlur, ref }, fieldState: { error }, } = (0, react_hook_form_1.useController)({ name, control, defaultValue });
|
|
16
|
+
const { inputRef: navigationInputRef, maintainFocus, handleKeyDown: handleNavigationKeyDown, } = (0, useFormFieldFocus_1.useFormFieldFocus)({ navigationKey });
|
|
17
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
18
|
+
const isInitializedRef = (0, react_1.useRef)(false);
|
|
19
|
+
const formatNumber = (0, react_1.useCallback)((num) => {
|
|
20
|
+
return num.toFixed(decimalScale);
|
|
21
|
+
}, [decimalScale]);
|
|
22
|
+
const parseValue = (0, react_1.useCallback)((val) => {
|
|
23
|
+
if (typeof val === "string") {
|
|
24
|
+
const parsed = parseFloat(val);
|
|
25
|
+
return isNaN(parsed) ? null : parsed;
|
|
26
|
+
}
|
|
27
|
+
if (typeof val === "number" && !isNaN(val)) {
|
|
28
|
+
return val;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}, []);
|
|
32
|
+
const getValidInitialValue = (0, react_1.useMemo)(() => {
|
|
33
|
+
return (fallback) => {
|
|
34
|
+
let candidateValue = fallback ?? 0;
|
|
35
|
+
if (min !== undefined && candidateValue < min) {
|
|
36
|
+
candidateValue = min;
|
|
37
|
+
}
|
|
38
|
+
if (max !== undefined && candidateValue > max) {
|
|
39
|
+
candidateValue = max;
|
|
40
|
+
}
|
|
41
|
+
return candidateValue;
|
|
42
|
+
};
|
|
43
|
+
}, [min, max]);
|
|
44
|
+
const isValidValue = (0, react_1.useCallback)((val) => {
|
|
45
|
+
return (!isNaN(val) &&
|
|
46
|
+
(min === undefined || val >= min) &&
|
|
47
|
+
(max === undefined || val <= max));
|
|
48
|
+
}, [min, max]);
|
|
49
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
50
|
+
(0, react_1.useEffect)(() => {
|
|
51
|
+
if (isInitializedRef.current) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const currentNumericValue = parseValue(value);
|
|
55
|
+
let initialValue = null;
|
|
56
|
+
const isDefaultZero = currentNumericValue === 0 &&
|
|
57
|
+
(defaultValue === undefined ||
|
|
58
|
+
defaultValue === null ||
|
|
59
|
+
defaultValue === "");
|
|
60
|
+
if (currentNumericValue !== null &&
|
|
61
|
+
isValidValue(currentNumericValue) &&
|
|
62
|
+
!isDefaultZero) {
|
|
63
|
+
initialValue = currentNumericValue;
|
|
64
|
+
}
|
|
65
|
+
else if (defaultValue !== undefined &&
|
|
66
|
+
defaultValue !== null &&
|
|
67
|
+
defaultValue !== "") {
|
|
68
|
+
const parsedDefault = typeof defaultValue === "number"
|
|
69
|
+
? defaultValue
|
|
70
|
+
: parseValue(defaultValue);
|
|
71
|
+
if (parsedDefault !== null) {
|
|
72
|
+
initialValue = getValidInitialValue(parsedDefault);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (initialValue === null) {
|
|
76
|
+
if (defaultFallbackValue != undefined && defaultFallbackValue != null) {
|
|
77
|
+
initialValue = getValidInitialValue(defaultFallbackValue);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (initialValue !== null) {
|
|
81
|
+
const formattedValue = formatNumber(initialValue);
|
|
82
|
+
if (value !== formattedValue) {
|
|
83
|
+
formOnChange(formattedValue);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
isInitializedRef.current = true;
|
|
87
|
+
}, []);
|
|
88
|
+
const handleValueChange = (0, react_1.useCallback)((values) => {
|
|
89
|
+
const numericValue = values.floatValue;
|
|
90
|
+
formOnChange(values.value);
|
|
91
|
+
if (customOnChange && numericValue !== undefined) {
|
|
92
|
+
customOnChange(numericValue);
|
|
93
|
+
}
|
|
94
|
+
maintainFocus();
|
|
95
|
+
}, [formOnChange, customOnChange, maintainFocus]);
|
|
96
|
+
const handleBlur = (0, react_1.useCallback)((event) => {
|
|
97
|
+
const currentValue = parseValue(value);
|
|
98
|
+
if (currentValue === null || !isValidValue(currentValue)) {
|
|
99
|
+
let resetValue;
|
|
100
|
+
if (defaultFallbackValue != undefined &&
|
|
101
|
+
isValidValue(defaultFallbackValue)) {
|
|
102
|
+
resetValue = defaultFallbackValue;
|
|
103
|
+
}
|
|
104
|
+
else if (min !== undefined) {
|
|
105
|
+
resetValue = min;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
resetValue = 0;
|
|
109
|
+
}
|
|
110
|
+
const formattedValue = formatNumber(resetValue);
|
|
111
|
+
formOnChange(formattedValue);
|
|
112
|
+
if (customOnChange) {
|
|
113
|
+
customOnChange(resetValue);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const formattedValue = formatNumber(currentValue);
|
|
118
|
+
formOnChange(formattedValue);
|
|
119
|
+
}
|
|
120
|
+
formOnBlur();
|
|
121
|
+
if (restProps.onBlur) {
|
|
122
|
+
restProps.onBlur(event);
|
|
123
|
+
}
|
|
124
|
+
}, [
|
|
125
|
+
value,
|
|
126
|
+
isValidValue,
|
|
127
|
+
min,
|
|
128
|
+
defaultFallbackValue,
|
|
129
|
+
formOnChange,
|
|
130
|
+
formOnBlur,
|
|
131
|
+
customOnChange,
|
|
132
|
+
formatNumber,
|
|
133
|
+
parseValue,
|
|
134
|
+
restProps,
|
|
135
|
+
]);
|
|
136
|
+
const handleFocus = (0, react_1.useCallback)((event) => {
|
|
137
|
+
if (restProps.onFocus) {
|
|
138
|
+
restProps.onFocus(event);
|
|
139
|
+
}
|
|
140
|
+
}, [value, isValidValue, parseValue, restProps]);
|
|
141
|
+
const handleKeyDown = (0, react_1.useCallback)(
|
|
142
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
143
|
+
(event) => {
|
|
144
|
+
// Handle arrow keys for increment/decrement
|
|
145
|
+
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
const currentValue = parseValue(value) ?? getValidInitialValue(defaultFallbackValue);
|
|
148
|
+
const step = 1 / Math.pow(10, decimalScale);
|
|
149
|
+
let newValue;
|
|
150
|
+
if (event.key === "ArrowUp") {
|
|
151
|
+
newValue = currentValue + step;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
newValue = currentValue - step;
|
|
155
|
+
}
|
|
156
|
+
if (min !== undefined && newValue < min) {
|
|
157
|
+
newValue = min;
|
|
158
|
+
}
|
|
159
|
+
if (max !== undefined && newValue > max) {
|
|
160
|
+
newValue = max;
|
|
161
|
+
}
|
|
162
|
+
if (isValidValue(newValue)) {
|
|
163
|
+
const formattedValue = formatNumber(newValue);
|
|
164
|
+
formOnChange(formattedValue);
|
|
165
|
+
if (customOnChange) {
|
|
166
|
+
customOnChange(newValue);
|
|
167
|
+
}
|
|
168
|
+
maintainFocus();
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Handle navigation keys (Tab/Enter)
|
|
173
|
+
handleNavigationKeyDown(event, undefined, false);
|
|
174
|
+
if (restProps.onKeyDown) {
|
|
175
|
+
restProps.onKeyDown(event);
|
|
176
|
+
}
|
|
177
|
+
}, [
|
|
178
|
+
value,
|
|
179
|
+
parseValue,
|
|
180
|
+
getValidInitialValue,
|
|
181
|
+
defaultFallbackValue,
|
|
182
|
+
decimalScale,
|
|
183
|
+
min,
|
|
184
|
+
max,
|
|
185
|
+
isValidValue,
|
|
186
|
+
formatNumber,
|
|
187
|
+
formOnChange,
|
|
188
|
+
customOnChange,
|
|
189
|
+
maintainFocus,
|
|
190
|
+
handleNavigationKeyDown,
|
|
191
|
+
restProps,
|
|
192
|
+
]);
|
|
193
|
+
const handleInputRef = (0, react_1.useCallback)((el) => {
|
|
194
|
+
inputRef.current = el;
|
|
195
|
+
navigationInputRef.current = el;
|
|
196
|
+
if (ref) {
|
|
197
|
+
if (typeof ref === "function") {
|
|
198
|
+
ref(el);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
ref.current = el;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}, [ref, navigationInputRef]);
|
|
205
|
+
// eslint-disable-next-line sonarjs/function-return-type
|
|
206
|
+
const displayValue = (0, react_1.useMemo)(() => {
|
|
207
|
+
const numericValue = parseValue(value);
|
|
208
|
+
if (numericValue !== null) {
|
|
209
|
+
if (typeof value === "string" && value.includes(".")) {
|
|
210
|
+
const parts = value.split(".");
|
|
211
|
+
if (parts[1] && parts[1].length <= decimalScale) {
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return numericValue;
|
|
216
|
+
}
|
|
217
|
+
return "";
|
|
218
|
+
}, [value, parseValue, decimalScale]);
|
|
219
|
+
if (loading) {
|
|
220
|
+
return (0, jsx_runtime_1.jsx)(Skeleton_1.Skeleton, { label: label, styling: styling });
|
|
221
|
+
}
|
|
222
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { ...containerProps, gap: "5px", children: [label && styling === "custom" && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", alignItems: "center", gap: "4px", children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { required: required, disabled: disabled, children: label }), infoMessage && ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { toolTipLabel: infoMessage, children: (0, jsx_runtime_1.jsx)(icons_material_1.InfoOutlined, { sx: {
|
|
223
|
+
fontSize: 13,
|
|
224
|
+
} }) }))] })), (0, jsx_runtime_1.jsx)(react_number_format_1.NumericFormat, { customInput: material_1.TextField, ...restProps, disabled: disabled, required: required, fullWidth: true, placeholder: styling === "default" ? placeholder : placeholder || label, label: styling === "default" ? label : undefined, sx: (0, commonStyles_1.getDefaultTextFieldSx)(styling), InputLabelProps: (0, commonStyles_1.getDefaultInputLabelProps)(styling), inputProps: {
|
|
225
|
+
...restProps.inputProps,
|
|
226
|
+
}, error: Boolean(error), helperText: error?.message, name: name, decimalScale: decimalScale, fixedDecimalScale: true, allowNegative: false, thousandSeparator: false, value: displayValue, onValueChange: handleValueChange, onBlur: handleBlur, onFocus: handleFocus, onKeyDown: handleKeyDown, inputMode: "decimal", getInputRef: handleInputRef })] }));
|
|
227
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/FormFields/DecimalTextField/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./DecimalTextField"), exports);
|
|
@@ -22,7 +22,7 @@ function FileUpload({ loading = false, onChange, isDisabled, multiple = false, r
|
|
|
22
22
|
const theme = (0, material_1.useTheme)();
|
|
23
23
|
const { red, iron, black, butterflyBlue } = theme.palette.app.color;
|
|
24
24
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
25
|
-
const { inputRef, setInputRef } = (0, useFormFieldFocus_1.useFormFieldFocus)();
|
|
25
|
+
const { inputRef, setInputRef } = (0, useFormFieldFocus_1.useFormFieldFocus)({ navigationKey: "tab" });
|
|
26
26
|
const dragCounter = (0, react_1.useRef)(0);
|
|
27
27
|
const rafRef = (0, react_1.useRef)(null);
|
|
28
28
|
const animStartRef = (0, react_1.useRef)(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageUpload.d.ts","sourceRoot":"","sources":["../../../src/FormFields/ImageUpload/ImageUpload.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAKlD,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AASH,wBAAgB,WAAW,CAAC,EAC1B,OAAkB,EAClB,WAAmB,EACnB,YAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,SAAiB,EACjB,OAAe,EACf,IAAQ,EACR,QAAiC,GAClC,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"ImageUpload.d.ts","sourceRoot":"","sources":["../../../src/FormFields/ImageUpload/ImageUpload.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAKlD,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AASH,wBAAgB,WAAW,CAAC,EAC1B,OAAkB,EAClB,WAAmB,EACnB,YAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,SAAiB,EACjB,OAAe,EACf,IAAQ,EACR,QAAiC,GAClC,EAAE,gBAAgB,2CAwMlB"}
|
|
@@ -24,7 +24,9 @@ function ImageUpload({ variant = "square", isUploading = false, defaultValue = "
|
|
|
24
24
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
25
25
|
const [hover, setHover] = (0, react_1.useState)(false);
|
|
26
26
|
const [isOpenCaptureModal, setIsOpenCaptureModal] = (0, react_1.useState)(false);
|
|
27
|
-
const { inputRef, setInputRef, maintainFocusAfterClose } = (0, useFormFieldFocus_1.useFormFieldFocus)(
|
|
27
|
+
const { inputRef, setInputRef, maintainFocusAfterClose } = (0, useFormFieldFocus_1.useFormFieldFocus)({
|
|
28
|
+
isOpen: isOpenCaptureModal,
|
|
29
|
+
});
|
|
28
30
|
const theme = (0, material_1.useTheme)();
|
|
29
31
|
const { butterflyBlue, iron } = theme.palette.app.color;
|
|
30
32
|
const handleFileChange = (event) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ControllerRenderProps, type FieldValues, type UseControllerProps } from "react-hook-form";
|
|
2
2
|
import type { PhoneInputProps } from "react-phone-input-2";
|
|
3
|
+
import { type NavigationKey } from "../../utils/hooks/useFormFieldFocus";
|
|
3
4
|
export type PhoneInputFieldProps<P extends FieldValues> = UseControllerProps<P> & Omit<PhoneInputProps, keyof ControllerRenderProps<P>> & {
|
|
4
5
|
label?: string;
|
|
5
6
|
loading?: boolean;
|
|
@@ -7,6 +8,7 @@ export type PhoneInputFieldProps<P extends FieldValues> = UseControllerProps<P>
|
|
|
7
8
|
required?: boolean;
|
|
8
9
|
error?: boolean;
|
|
9
10
|
helperText?: string;
|
|
11
|
+
navigationKey?: NavigationKey;
|
|
10
12
|
};
|
|
11
|
-
export declare function PhoneInputField<P extends FieldValues>({ control, name, defaultValue, rules, label, disabled, required, rows, loading, placeholder, error, helperText, ...phoneInputProps }: PhoneInputFieldProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function PhoneInputField<P extends FieldValues>({ control, name, defaultValue, rules, label, disabled, required, rows, loading, placeholder, error, helperText, navigationKey, ...phoneInputProps }: PhoneInputFieldProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
12
14
|
//# sourceMappingURL=PhoneInputField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInputField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/PhoneInputField/PhoneInputField.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"PhoneInputField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/PhoneInputField/PhoneInputField.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAC;AAG7C,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,WAAW,IACpD,kBAAkB,CAAC,CAAC,CAAC,GACnB,IAAI,CAAC,eAAe,EAAE,MAAM,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAAG;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEN,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,EAAE,EACrD,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,KAAK,EACL,QAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,OAAe,EACf,WAAgB,EAChB,KAAK,EACL,UAAU,EACV,aAAqB,EACrB,GAAG,eAAe,EACnB,EAAE,oBAAoB,CAAC,CAAC,CAAC,2CAuNzB"}
|
|
@@ -10,9 +10,9 @@ const material_1 = require("@mui/material");
|
|
|
10
10
|
const react_1 = require("react");
|
|
11
11
|
const react_hook_form_1 = require("react-hook-form");
|
|
12
12
|
const react_phone_input_2_1 = __importDefault(require("react-phone-input-2"));
|
|
13
|
-
const
|
|
13
|
+
const useFormFieldFocus_1 = require("../../utils/hooks/useFormFieldFocus");
|
|
14
14
|
const Skeleton_1 = require("./Skeleton");
|
|
15
|
-
function PhoneInputField({ control, name, defaultValue, rules, label, disabled = false, required, rows, loading = false, placeholder = "", error, helperText, ...phoneInputProps }) {
|
|
15
|
+
function PhoneInputField({ control, name, defaultValue, rules, label, disabled = false, required, rows, loading = false, placeholder = "", error, helperText, navigationKey = "tab", ...phoneInputProps }) {
|
|
16
16
|
const theme = (0, material_1.useTheme)();
|
|
17
17
|
const { iron, red, butterflyBlue, slate } = theme.palette.app.color;
|
|
18
18
|
const { field: { value, onChange, ...restField }, } = (0, react_hook_form_1.useController)({
|
|
@@ -22,7 +22,7 @@ function PhoneInputField({ control, name, defaultValue, rules, label, disabled =
|
|
|
22
22
|
rules,
|
|
23
23
|
});
|
|
24
24
|
const [dropdownOpen, setDropdownOpen] = (0, react_1.useState)(false);
|
|
25
|
-
const { setInputRef, maintainFocusAfterClose } = (0,
|
|
25
|
+
const { setInputRef, maintainFocusAfterClose, handleKeyDown } = (0, useFormFieldFocus_1.useFormFieldFocus)({ isOpen: dropdownOpen, navigationKey });
|
|
26
26
|
const containerRef = (0, react_1.useRef)(null);
|
|
27
27
|
(0, react_1.useEffect)(() => {
|
|
28
28
|
const container = containerRef.current;
|
|
@@ -119,6 +119,10 @@ function PhoneInputField({ control, name, defaultValue, rules, label, disabled =
|
|
|
119
119
|
if (!dropdownOpen) {
|
|
120
120
|
maintainFocusAfterClose();
|
|
121
121
|
}
|
|
122
|
+
}, onKeyDown: (event) => {
|
|
123
|
+
if (!dropdownOpen) {
|
|
124
|
+
handleKeyDown(event, undefined, false);
|
|
125
|
+
}
|
|
122
126
|
}, containerStyle: {
|
|
123
127
|
width: "100%",
|
|
124
128
|
border: error
|
|
@@ -2,6 +2,7 @@ import { type StackOwnProps, type StackProps, type SxProps } from "@mui/material
|
|
|
2
2
|
import { type RadioProps as MuiRadioProps } from "@mui/material/Radio";
|
|
3
3
|
import type { ReactNode } from "react";
|
|
4
4
|
import { type ControllerRenderProps, type FieldValues, type UseControllerProps } from "react-hook-form";
|
|
5
|
+
import { type NavigationKey } from "../../utils/hooks/useFormFieldFocus";
|
|
5
6
|
type Options = {
|
|
6
7
|
values: boolean | string;
|
|
7
8
|
label?: ReactNode;
|
|
@@ -17,7 +18,8 @@ export type RadioGroupFieldProps<P extends FieldValues> = UseControllerProps<P>
|
|
|
17
18
|
sx?: SxProps;
|
|
18
19
|
isHorizontal?: boolean;
|
|
19
20
|
containerProps?: StackProps;
|
|
21
|
+
navigationKey?: NavigationKey;
|
|
20
22
|
};
|
|
21
|
-
export declare function RadioGroupField<P extends FieldValues>({ name, rules, label, control, options, defaultValue, size, color, loading, required, direction, sx, containerProps, isHorizontal, ...restRadioButtonProps }: RadioGroupFieldProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export declare function RadioGroupField<P extends FieldValues>({ name, rules, label, control, options, defaultValue, size, color, loading, required, direction, sx, containerProps, isHorizontal, navigationKey, ...restRadioButtonProps }: RadioGroupFieldProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
22
24
|
export {};
|
|
23
25
|
//# sourceMappingURL=RadioGroupField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioGroupField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/RadioGroupField/RadioGroupField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,OAAO,EACb,MAAM,eAAe,CAAC;AACvB,OAAc,EAAE,KAAK,UAAU,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"RadioGroupField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/RadioGroupField/RadioGroupField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,OAAO,EACb,MAAM,eAAe,CAAC;AACvB,OAAc,EAAE,KAAK,UAAU,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAC;AAG7C,KAAK,OAAO,GAAG;IACb,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,WAAW,IACpD,kBAAkB,CAAC,CAAC,CAAC,GACnB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,MAAM,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAAG;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IACvC,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,UAAU,CAAC;IAC5B,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEN,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,EAAE,EACrD,IAAI,EACJ,KAAK,EACL,KAAK,EACL,OAAO,EACP,OAAO,EACP,YAAY,EACZ,IAAc,EACd,KAAmB,EACnB,OAAe,EACf,QAAgB,EAChB,SAAiB,EACjB,EAAO,EACP,cAAc,EACd,YAAoB,EACpB,aAAqB,EACrB,GAAG,oBAAoB,EACxB,EAAE,oBAAoB,CAAC,CAAC,CAAC,2CAwGzB"}
|
|
@@ -8,9 +8,27 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
8
8
|
const material_1 = require("@mui/material");
|
|
9
9
|
const Radio_1 = __importDefault(require("@mui/material/Radio"));
|
|
10
10
|
const react_hook_form_1 = require("react-hook-form");
|
|
11
|
+
const useFormFieldFocus_1 = require("../../utils/hooks/useFormFieldFocus");
|
|
11
12
|
const Skeleton_1 = require("./Skeleton");
|
|
12
|
-
function RadioGroupField({ name, rules, label, control, options, defaultValue, size = "small", color = "secondary", loading = false, required = false, direction = "row", sx = {}, containerProps, isHorizontal = false, ...restRadioButtonProps }) {
|
|
13
|
-
const { field: { value, onChange, ...restField }, } = (0, react_hook_form_1.useController)({ name, control, defaultValue, rules });
|
|
13
|
+
function RadioGroupField({ name, rules, label, control, options, defaultValue, size = "small", color = "secondary", loading = false, required = false, direction = "row", sx = {}, containerProps, isHorizontal = false, navigationKey = "tab", ...restRadioButtonProps }) {
|
|
14
|
+
const { field: { value, onChange, ref, ...restField }, } = (0, react_hook_form_1.useController)({ name, control, defaultValue, rules });
|
|
15
|
+
const { inputRef, handleKeyDown: handleNavigationKeyDown, maintainFocus, } = (0, useFormFieldFocus_1.useFormFieldFocus)({ navigationKey });
|
|
16
|
+
const handleKeyDown = (event) => {
|
|
17
|
+
handleNavigationKeyDown(event, undefined, false);
|
|
18
|
+
};
|
|
19
|
+
const handleRadioChange = (event) => {
|
|
20
|
+
const newValue = event.target.value;
|
|
21
|
+
if (newValue === "true") {
|
|
22
|
+
onChange(true);
|
|
23
|
+
}
|
|
24
|
+
else if (newValue === "false") {
|
|
25
|
+
onChange(false);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
onChange(newValue);
|
|
29
|
+
}
|
|
30
|
+
maintainFocus();
|
|
31
|
+
};
|
|
14
32
|
if (loading) {
|
|
15
33
|
return (0, jsx_runtime_1.jsx)(Skeleton_1.Skeleton, {});
|
|
16
34
|
}
|
|
@@ -18,19 +36,21 @@ function RadioGroupField({ name, rules, label, control, options, defaultValue, s
|
|
|
18
36
|
whiteSpace: "normal",
|
|
19
37
|
overflow: "visible",
|
|
20
38
|
textOverflow: "unset",
|
|
21
|
-
}, required: required, disabled: restRadioButtonProps.disabled, children: label })), (0, jsx_runtime_1.jsx)(material_1.RadioGroup, { name: name, value: value, onChange: (
|
|
22
|
-
if (event === "true") {
|
|
23
|
-
onChange(true);
|
|
24
|
-
}
|
|
25
|
-
else if (event === "false") {
|
|
26
|
-
onChange(false);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
onChange(event);
|
|
30
|
-
}
|
|
31
|
-
}, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: direction === "column" ? "5px" : "10px", direction: direction, ...containerProps, children: options?.map(({ label, values, disabled }, index) => {
|
|
39
|
+
}, required: required, disabled: restRadioButtonProps.disabled, children: label })), (0, jsx_runtime_1.jsx)(material_1.RadioGroup, { name: name, value: value, onChange: handleRadioChange, onKeyDown: handleKeyDown, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: direction === "column" ? "5px" : "10px", direction: direction, ...containerProps, children: options?.map(({ label, values, disabled }, index) => {
|
|
32
40
|
return (
|
|
33
41
|
// eslint-disable-next-line sonarjs/no-array-index-key
|
|
34
|
-
(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { value: values, control: (0, jsx_runtime_1.jsx)(Radio_1.default, { ...restField, ...restRadioButtonProps, color: color, size: size
|
|
42
|
+
(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { value: values, control: (0, jsx_runtime_1.jsx)(Radio_1.default, { ...restField, ...restRadioButtonProps, color: color, size: size, inputRef: (el) => {
|
|
43
|
+
if (el && !inputRef.current) {
|
|
44
|
+
inputRef.current = el;
|
|
45
|
+
if (ref) {
|
|
46
|
+
if (typeof ref === "function") {
|
|
47
|
+
ref(el);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
ref.current = el;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} }), disabled: disabled, label: label, sx: sx }) }, index));
|
|
35
55
|
}) }) })] }));
|
|
36
56
|
}
|
|
@@ -8,7 +8,7 @@ const utils_1 = require("../../utils");
|
|
|
8
8
|
const Skeleton_1 = require("./Skeleton");
|
|
9
9
|
function Rating({ control, name, defaultValue, label = "", rules, disabled, loading = false, direction = "column", required = false, ...ratingProps }) {
|
|
10
10
|
const { field: { value, onChange, ...restField }, fieldState: { error }, } = (0, react_hook_form_1.useController)({ name, control, defaultValue, rules });
|
|
11
|
-
const { maintainFocus } = (0, utils_1.useFormFieldFocus)();
|
|
11
|
+
const { maintainFocus } = (0, utils_1.useFormFieldFocus)({});
|
|
12
12
|
if (loading) {
|
|
13
13
|
return (0, jsx_runtime_1.jsx)(Skeleton_1.RatingSkeleton, { label: label });
|
|
14
14
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SelectProps as MuiSelectProps } from "@mui/material";
|
|
2
2
|
import { type ControllerRenderProps, type FieldValues, type UseControllerProps } from "react-hook-form";
|
|
3
|
+
import { type NavigationKey } from "../../utils/hooks/useFormFieldFocus";
|
|
3
4
|
import type { OnAction } from "../../utils/types";
|
|
4
5
|
export type SelectOption = {
|
|
5
6
|
heading?: string;
|
|
@@ -28,6 +29,7 @@ export type SelectProps<P extends FieldValues> = UseControllerProps<P> & Omit<Mu
|
|
|
28
29
|
disableClearable?: boolean;
|
|
29
30
|
setOnFinalChange?: boolean;
|
|
30
31
|
styling?: "custom" | "default";
|
|
32
|
+
navigationKey?: NavigationKey;
|
|
31
33
|
};
|
|
32
|
-
export declare function Select<P extends FieldValues>({ control, defaultValue, name, required, label, multiple, disabled, options, rules, loading, helperText, error, placeholder, isShowSelectAll, isShowAvatar, onAction, renderOption, maxLimit, maxDisplayItems, disableClearable, setOnFinalChange, styling, ...restProps }: SelectProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export declare function Select<P extends FieldValues>({ control, defaultValue, name, required, label, multiple, disabled, options, rules, loading, helperText, error, placeholder, isShowSelectAll, isShowAvatar, onAction, renderOption, maxLimit, maxDisplayItems, disableClearable, setOnFinalChange, styling, navigationKey, ...restProps }: SelectProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
33
35
|
//# sourceMappingURL=Select.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../src/FormFields/Select/Select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AAmBnE,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../src/FormFields/Select/Select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AAmBnE,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAQlD,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,CAAC,GACpE,IAAI,CACF,cAAc,EACd,MAAM,qBAAqB,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CACnE,GAAG;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,KAAK,GAAG,CAAC,OAAO,CAAC;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEJ,wBAAgB,MAAM,CAAC,CAAC,SAAS,WAAW,EAAE,EAC5C,OAAO,EACP,YAAY,EACZ,IAAI,EACJ,QAAgB,EAChB,KAAK,EACL,QAAgB,EAChB,QAAgB,EAChB,OAAY,EACZ,KAAK,EACL,OAAe,EACf,UAAU,EACV,KAAK,EACL,WAAgB,EAChB,eAAsB,EACtB,YAAoB,EACpB,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,eAAmB,EACnB,gBAA0C,EAC1C,gBAAwB,EACxB,OAAkB,EAClB,aAAqB,EACrB,GAAG,SAAS,EACb,EAAE,WAAW,CAAC,CAAC,CAAC,2CAkfhB"}
|
|
@@ -9,11 +9,11 @@ const react_hook_form_1 = require("react-hook-form");
|
|
|
9
9
|
const react_i18next_1 = require("react-i18next");
|
|
10
10
|
const Actions_1 = require("../../Actions");
|
|
11
11
|
const Toast_1 = require("../../Toast");
|
|
12
|
-
const
|
|
12
|
+
const useFormFieldFocus_1 = require("../../utils/hooks/useFormFieldFocus");
|
|
13
13
|
const CheckBox_styled_1 = require("../CheckBox/CheckBox.styled");
|
|
14
14
|
const commonStyles_1 = require("../commonStyles");
|
|
15
15
|
const Select_styled_1 = require("./Select.styled");
|
|
16
|
-
function Select({ control, defaultValue, name, required = false, label, multiple = false, disabled = false, options = [], rules, loading = false, helperText, error, placeholder = "", isShowSelectAll = true, isShowAvatar = false, onAction, renderOption, maxLimit, maxDisplayItems = 2, disableClearable = required ? true : false, setOnFinalChange = false, styling = "custom", ...restProps }) {
|
|
16
|
+
function Select({ control, defaultValue, name, required = false, label, multiple = false, disabled = false, options = [], rules, loading = false, helperText, error, placeholder = "", isShowSelectAll = true, isShowAvatar = false, onAction, renderOption, maxLimit, maxDisplayItems = 2, disableClearable = required ? true : false, setOnFinalChange = false, styling = "custom", navigationKey = "tab", ...restProps }) {
|
|
17
17
|
const { field: { onChange, value, ...restField }, } = (0, react_hook_form_1.useController)({
|
|
18
18
|
name,
|
|
19
19
|
control,
|
|
@@ -27,7 +27,7 @@ function Select({ control, defaultValue, name, required = false, label, multiple
|
|
|
27
27
|
const [pendingValue, setPendingValue] = (0, react_1.useState)(null);
|
|
28
28
|
const hasPendingChange = (0, react_1.useRef)(false);
|
|
29
29
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
30
|
-
const { setInputRef, maintainFocusAfterClose, handleKeyDown } = (0,
|
|
30
|
+
const { setInputRef, maintainFocusAfterClose, handleKeyDown, handleEnterNavigation, } = (0, useFormFieldFocus_1.useFormFieldFocus)({ isOpen: open, navigationKey });
|
|
31
31
|
const handleSelectAll = (isSelected) => {
|
|
32
32
|
if (isSelected) {
|
|
33
33
|
const allValues = options
|
|
@@ -65,13 +65,13 @@ function Select({ control, defaultValue, name, required = false, label, multiple
|
|
|
65
65
|
return placeholder;
|
|
66
66
|
};
|
|
67
67
|
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [isShowAvatar && selectedOption?.avatar && ((0, jsx_runtime_1.jsx)(material_1.Avatar, { src: selectedOption.avatar ?? "", sx: { width: 20, height: 20 } })), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: disabledColor, sx: {
|
|
68
|
-
|
|
68
|
+
WebkitTextFillColor: disabledColor,
|
|
69
69
|
}, noWrap: true, children: placeholderText() })] }));
|
|
70
70
|
}
|
|
71
71
|
if (!Array.isArray(selected) || selected.length === 0) {
|
|
72
72
|
const shouldShowPlaceholder = styling !== "default" || !label || placeholder;
|
|
73
73
|
return ((0, jsx_runtime_1.jsx)(material_1.Typography, { sx: {
|
|
74
|
-
|
|
74
|
+
WebkitTextFillColor: disabledColor,
|
|
75
75
|
}, color: disabledColor, variant: "body2", noWrap: true, children: shouldShowPlaceholder ? placeholder : "" }));
|
|
76
76
|
}
|
|
77
77
|
const visibleItems = selectedOptions.slice(0, maxDisplayItems);
|
|
@@ -89,7 +89,7 @@ function Select({ control, defaultValue, name, required = false, label, multiple
|
|
|
89
89
|
fontSize: "12px",
|
|
90
90
|
maxWidth: "120px",
|
|
91
91
|
}, children: option.label }, option.value))), overflowCount > 0 && ((0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", color: disabledColor, sx: {
|
|
92
|
-
|
|
92
|
+
WebkitTextFillColor: disabledColor,
|
|
93
93
|
backgroundColor: slate[300],
|
|
94
94
|
padding: "2px 5px",
|
|
95
95
|
borderRadius: "12px",
|
|
@@ -224,6 +224,12 @@ function Select({ control, defaultValue, name, required = false, label, multiple
|
|
|
224
224
|
!disableClearable && ((0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "small", onClick: (e) => {
|
|
225
225
|
e.stopPropagation();
|
|
226
226
|
onChange(multiple ? [] : "");
|
|
227
|
+
}, onKeyDown: (event) => {
|
|
228
|
+
if (navigationKey === "enter" &&
|
|
229
|
+
event.key === "Enter") {
|
|
230
|
+
event.stopPropagation();
|
|
231
|
+
handleEnterNavigation(event);
|
|
232
|
+
}
|
|
227
233
|
}, children: (0, jsx_runtime_1.jsx)(x_date_pickers_1.ClearIcon, { sx: { fontSize: "14px" } }) })), (0, jsx_runtime_1.jsx)(x_date_pickers_1.ArrowDropDownIcon, { ...props })] })), displayEmpty: true, MenuProps: {
|
|
228
234
|
PaperProps: {
|
|
229
235
|
sx: {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type SwitchProps } from "@mui/material";
|
|
2
2
|
import { type ControllerRenderProps, type FieldValues, type UseControllerProps } from "react-hook-form";
|
|
3
|
+
import { type NavigationKey } from "../../utils/hooks/useFormFieldFocus";
|
|
3
4
|
export type SwitchFieldProps<P extends FieldValues> = UseControllerProps<P> & Omit<Omit<SwitchProps, "checked">, keyof ControllerRenderProps<P>> & {
|
|
4
5
|
loading?: boolean;
|
|
6
|
+
navigationKey?: NavigationKey;
|
|
5
7
|
};
|
|
6
|
-
export declare function SwitchField<P extends FieldValues>({ name, rules, control, defaultValue, loading, ...restSwitchProps }: SwitchFieldProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function SwitchField<P extends FieldValues>({ name, rules, control, defaultValue, loading, navigationKey, ...restSwitchProps }: SwitchFieldProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
7
9
|
//# sourceMappingURL=SwitchField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/SwitchField/SwitchField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"SwitchField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/SwitchField/SwitchField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAC;AAG7C,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,CAAC,GACzE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAAG;IACnE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEJ,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,EAAE,EACjD,IAAI,EACJ,KAAK,EACL,OAAO,EACP,YAAY,EACZ,OAAe,EACf,aAAqB,EACrB,GAAG,eAAe,EACnB,EAAE,gBAAgB,CAAC,CAAC,CAAC,2CAgFrB"}
|
|
@@ -4,17 +4,23 @@ exports.SwitchField = SwitchField;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const material_1 = require("@mui/material");
|
|
6
6
|
const react_hook_form_1 = require("react-hook-form");
|
|
7
|
-
const
|
|
7
|
+
const useFormFieldFocus_1 = require("../../utils/hooks/useFormFieldFocus");
|
|
8
8
|
const Skeleton_1 = require("./Skeleton");
|
|
9
|
-
function SwitchField({ name, rules, control, defaultValue, loading = false, ...restSwitchProps }) {
|
|
9
|
+
function SwitchField({ name, rules, control, defaultValue, loading = false, navigationKey = "tab", ...restSwitchProps }) {
|
|
10
10
|
const theme = (0, material_1.useTheme)();
|
|
11
11
|
const { butterflyBlue, iron } = theme.palette.app.color;
|
|
12
12
|
const { field: { value = false, ...restField }, } = (0, react_hook_form_1.useController)({ name, control, defaultValue, rules });
|
|
13
|
-
const { setInputRef, maintainFocus } = (0,
|
|
13
|
+
const { setInputRef, maintainFocus, handleKeyDown: handleNavigationKeyDown, } = (0, useFormFieldFocus_1.useFormFieldFocus)({ navigationKey });
|
|
14
14
|
if (loading) {
|
|
15
15
|
return (0, jsx_runtime_1.jsx)(Skeleton_1.Skeleton, {});
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
const handleKeyDown = (event) => {
|
|
18
|
+
handleNavigationKeyDown(event, undefined, false);
|
|
19
|
+
if (restSwitchProps.onKeyDown) {
|
|
20
|
+
restSwitchProps.onKeyDown(event);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Switch, { checked: value, ...restField, ...restSwitchProps, inputRef: setInputRef, onKeyDown: handleKeyDown, onChange: (event) => {
|
|
18
24
|
restField.onChange(event);
|
|
19
25
|
maintainFocus();
|
|
20
26
|
}, sx: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TextFieldProps as MuiTextFieldProps, type StackProps } from "@mui/material";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
import { type ControllerRenderProps, type FieldError, type FieldValues, type UseControllerProps } from "react-hook-form";
|
|
4
|
+
import { type NavigationKey } from "../../utils/hooks/useFormFieldFocus";
|
|
4
5
|
export type AllowedCharacterType = "string" | "string-number" | "string-number-special" | "string-special" | "string-special-all" | "custom";
|
|
5
6
|
export type LetterCase = "uppercase" | "lowercase" | "mixed";
|
|
6
7
|
export type TextFieldProps<P extends FieldValues> = UseControllerProps<P> & Omit<MuiTextFieldProps, keyof ControllerRenderProps<P>> & {
|
|
@@ -23,6 +24,7 @@ export type TextFieldProps<P extends FieldValues> = UseControllerProps<P> & Omit
|
|
|
23
24
|
regex: RegExp;
|
|
24
25
|
};
|
|
25
26
|
customOnChange?: (value: string | null | number) => void;
|
|
27
|
+
navigationKey?: NavigationKey;
|
|
26
28
|
};
|
|
27
|
-
export declare function TextField<P extends FieldValues>({ control, name, defaultValue, label, rules, type, required, disabled, loading, placeholder, isCapitalize, isTrimStartDisabled, rows, characterType, letterCase, setError, containerProps, styling, infoMessage, regexExpression,
|
|
29
|
+
export declare function TextField<P extends FieldValues>({ control, name, defaultValue, label, rules, type, required, disabled, loading, placeholder, isCapitalize, isTrimStartDisabled, rows, characterType, letterCase, setError, containerProps, styling, infoMessage, regexExpression, navigationKey, customOnChange, ...inputFieldProps }: TextFieldProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
28
30
|
//# sourceMappingURL=TextField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/TextField/TextField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,IAAI,iBAAiB,EACxC,KAAK,UAAU,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/TextField/TextField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,IAAI,iBAAiB,EACxC,KAAK,UAAU,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAC;AAO7C,MAAM,MAAM,oBAAoB,GAC5B,QAAQ,GACR,eAAe,GACf,uBAAuB,GACvB,gBAAgB,GAChB,oBAAoB,GACpB,QAAQ,CAAC;AAEb,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,WAAW,GAAG,OAAO,CAAC;AAY7D,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,CAAC,GACvE,IAAI,CAAC,iBAAiB,EAAE,MAAM,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAAG;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,CACT,IAAI,EAAE,MAAM,CAAC,EACb,KAAK,EAAE,UAAU,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KACnD,IAAI,CAAC;IACV,cAAc,CAAC,EAAE,UAAU,CAAC;IAC5B,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,eAAe,CAAC,EAAE;QAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,KAAK,IAAI,CAAC;IACzD,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEJ,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,EAAE,EAC/C,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,KAAU,EACV,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,OAAe,EACf,WAAgB,EAChB,YAAoB,EACpB,mBAA2B,EAC3B,IAAI,EACJ,aAAuC,EACvC,UAAoB,EACpB,QAAQ,EACR,cAAc,EACd,OAAkB,EAClB,WAAW,EACX,eAGC,EACD,aAAqB,EACrB,cAAc,EACd,GAAG,eAAe,EACnB,EAAE,cAAc,CAAC,CAAC,CAAC,2CAsKnB"}
|