es-grid-template 1.6.0 → 1.6.1
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/es/grid-component/EditForm/EditForm.d.ts +27 -0
- package/es/grid-component/EditForm/EditForm.js +391 -0
- package/es/grid-component/EditForm/index.d.ts +1 -0
- package/es/grid-component/EditForm/index.js +1 -0
- package/es/grid-component/EditableCell.js +46 -43
- package/es/grid-component/control/InputControl/InputControl.d.ts +26 -0
- package/es/grid-component/control/InputControl/InputControl.js +121 -0
- package/es/grid-component/control/InputControl/index.d.ts +1 -0
- package/es/grid-component/control/InputControl/index.js +1 -0
- package/es/grid-component/table/GridEdit.js +5 -5
- package/es/grid-component/type.d.ts +27 -0
- package/es/grid-component/useContext.d.ts +0 -1
- package/lib/grid-component/EditForm/EditForm.d.ts +27 -0
- package/lib/grid-component/EditForm/EditForm.js +401 -0
- package/lib/grid-component/EditForm/index.d.ts +1 -0
- package/lib/grid-component/EditForm/index.js +16 -0
- package/lib/grid-component/EditableCell.js +46 -43
- package/lib/grid-component/control/InputControl/InputControl.d.ts +26 -0
- package/lib/grid-component/control/InputControl/InputControl.js +131 -0
- package/lib/grid-component/control/InputControl/index.d.ts +1 -0
- package/lib/grid-component/control/InputControl/index.js +16 -0
- package/lib/grid-component/table/GridEdit.js +5 -4
- package/lib/grid-component/type.d.ts +27 -0
- package/lib/grid-component/useContext.d.ts +0 -1
- package/package.json +2 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
id?: string;
|
|
4
|
+
externalClick?: any;
|
|
5
|
+
menuPortalTarget?: any;
|
|
6
|
+
value: any;
|
|
7
|
+
onChange: (props: any) => void;
|
|
8
|
+
filterKey?: string;
|
|
9
|
+
customRender?: any;
|
|
10
|
+
filterHeaderKey?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
invalid?: any;
|
|
13
|
+
menuHeight?: number;
|
|
14
|
+
menuWidth?: number;
|
|
15
|
+
classNamePrefix?: string;
|
|
16
|
+
cellFocus?: boolean;
|
|
17
|
+
t?: any;
|
|
18
|
+
column: any;
|
|
19
|
+
fieldKey?: any;
|
|
20
|
+
rowData: any;
|
|
21
|
+
indexRow: any;
|
|
22
|
+
template?: any;
|
|
23
|
+
onKeyDown?: (event: any) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const SelectStyle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
26
|
+
export declare const EditForm: (props: Props) => React.JSX.Element;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import React, { Fragment, useRef } from "react";
|
|
2
|
+
import styled from "styled-components";
|
|
3
|
+
import { useForm } from "react-hook-form";
|
|
4
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
5
|
+
import { Col, Row } from "rc-master-ui/es/grid";
|
|
6
|
+
import InputControl from "../control/InputControl/InputControl";
|
|
7
|
+
import { isNullOrUndefined, isObjEmpty } from "../hooks";
|
|
8
|
+
import { Input } from "rc-master-ui";
|
|
9
|
+
import { Dropdown } from "antd";
|
|
10
|
+
import Divider from "rc-master-ui/es/divider";
|
|
11
|
+
import Button from "rc-master-ui/es/button";
|
|
12
|
+
export const SelectStyle = styled.div.withConfig({
|
|
13
|
+
displayName: "SelectStyle",
|
|
14
|
+
componentId: "es-grid-template__sc-7ba05m-0"
|
|
15
|
+
})(["width:100%;&.be-select{.input-group-merge{flex-wrap:nowrap;}}"]);
|
|
16
|
+
export const EditForm = props => {
|
|
17
|
+
const {
|
|
18
|
+
id,
|
|
19
|
+
// menuPortalTarget,
|
|
20
|
+
value,
|
|
21
|
+
fieldKey,
|
|
22
|
+
placeholder,
|
|
23
|
+
// invalid,
|
|
24
|
+
menuHeight,
|
|
25
|
+
menuWidth,
|
|
26
|
+
// classNamePrefix,
|
|
27
|
+
onChange,
|
|
28
|
+
// onKeyDown,
|
|
29
|
+
t,
|
|
30
|
+
cellFocus,
|
|
31
|
+
column
|
|
32
|
+
} = props;
|
|
33
|
+
const formRef = useRef();
|
|
34
|
+
const divRef = useRef(null);
|
|
35
|
+
const inputRef = useRef(null);
|
|
36
|
+
const defaultValue = !isNullOrUndefined(value) ? column?.editFromSettings?.formatLabel ? column?.editFromSettings?.formatLabel(value) : value[fieldKey] : '';
|
|
37
|
+
const {
|
|
38
|
+
control,
|
|
39
|
+
handleSubmit,
|
|
40
|
+
getValues,
|
|
41
|
+
reset,
|
|
42
|
+
setValue,
|
|
43
|
+
setError,
|
|
44
|
+
formState: {
|
|
45
|
+
errors
|
|
46
|
+
}
|
|
47
|
+
} = useForm({
|
|
48
|
+
mode: 'onChange',
|
|
49
|
+
defaultValues: column.editFromSettings?.defaultValues,
|
|
50
|
+
resolver: column.editFromSettings?.schema ? yupResolver(column.editFromSettings?.schema) : undefined
|
|
51
|
+
});
|
|
52
|
+
const handleToggle = () => {
|
|
53
|
+
divRef?.current?.click(); // Giả lập click vào nút để mở dropdown
|
|
54
|
+
};
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
if (cellFocus) {
|
|
57
|
+
handleToggle();
|
|
58
|
+
}
|
|
59
|
+
}, [cellFocus]);
|
|
60
|
+
const handleOnSubmit = val => {
|
|
61
|
+
handleToggle();
|
|
62
|
+
onChange(val);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// const handleOnKeyDown = (e: any) => {
|
|
66
|
+
//
|
|
67
|
+
// if (dropdownOpen) {
|
|
68
|
+
// e.preventDefault()
|
|
69
|
+
//
|
|
70
|
+
// if (e.code === 'Tab') {
|
|
71
|
+
// e.stopPropagation()
|
|
72
|
+
// const formElement = document.getElementById('edit-form')
|
|
73
|
+
//
|
|
74
|
+
// if (formElement) {
|
|
75
|
+
//
|
|
76
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
77
|
+
//
|
|
78
|
+
// }
|
|
79
|
+
//
|
|
80
|
+
// }
|
|
81
|
+
//
|
|
82
|
+
// if (e.code === "Escape") {
|
|
83
|
+
// e.preventDefault()
|
|
84
|
+
// e.stopPropagation()
|
|
85
|
+
// return e
|
|
86
|
+
// }
|
|
87
|
+
//
|
|
88
|
+
// const formElement = document.getElementById('edit-form')
|
|
89
|
+
//
|
|
90
|
+
// if (formElement) {
|
|
91
|
+
//
|
|
92
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
93
|
+
//
|
|
94
|
+
// }
|
|
95
|
+
// return e.code
|
|
96
|
+
//
|
|
97
|
+
//
|
|
98
|
+
// } else {
|
|
99
|
+
// if (e.code === 'ArrowDown') {
|
|
100
|
+
// e.preventDefault()
|
|
101
|
+
//
|
|
102
|
+
// setTimeout(() => {
|
|
103
|
+
// const formElement = document.getElementById('edit-form')
|
|
104
|
+
// if (formElement) {
|
|
105
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
106
|
+
//
|
|
107
|
+
// }
|
|
108
|
+
//
|
|
109
|
+
// }, 100)
|
|
110
|
+
//
|
|
111
|
+
//
|
|
112
|
+
// }
|
|
113
|
+
// }
|
|
114
|
+
//
|
|
115
|
+
// if (onKeyDown) {
|
|
116
|
+
// onKeyDown(e)
|
|
117
|
+
// }
|
|
118
|
+
//
|
|
119
|
+
//
|
|
120
|
+
// }
|
|
121
|
+
//
|
|
122
|
+
|
|
123
|
+
const handleOnFocus = e => {
|
|
124
|
+
e.target.setSelectionRange(0, e.target.innerText.length - 1);
|
|
125
|
+
};
|
|
126
|
+
const formItemKeyDown = (e, index, length) => {
|
|
127
|
+
if (e.code === 'Tab' || e.code === 'ArrowDown') {
|
|
128
|
+
const itemElement = document.getElementById(`edit-form-${index + 1}`);
|
|
129
|
+
if (itemElement && index < length) {
|
|
130
|
+
if (itemElement.className.includes('be-select')) {
|
|
131
|
+
itemElement.getElementsByTagName('input')[0]?.focus();
|
|
132
|
+
} else {
|
|
133
|
+
itemElement.focus();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
}
|
|
138
|
+
if (e.code === 'ArrowUp') {
|
|
139
|
+
const itemElement = document.getElementById(`edit-form-${index - 1}`);
|
|
140
|
+
if (itemElement && index !== 0) {
|
|
141
|
+
if (itemElement.className.includes('be-select')) {
|
|
142
|
+
itemElement.getElementsByTagName('input')[0]?.focus();
|
|
143
|
+
} else {
|
|
144
|
+
itemElement.focus();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
}
|
|
149
|
+
if (e.code === 'Enter') {
|
|
150
|
+
if (isObjEmpty(errors)) {
|
|
151
|
+
const rs = getValues();
|
|
152
|
+
if (column.editFromSettings?.schema) {
|
|
153
|
+
column.editFromSettings?.schema.validate(rs, {
|
|
154
|
+
abortEarly: false
|
|
155
|
+
}).then(() => {
|
|
156
|
+
handleToggle();
|
|
157
|
+
onChange(rs);
|
|
158
|
+
if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
159
|
+
column?.editFromSettings?.formClose({
|
|
160
|
+
value,
|
|
161
|
+
setValue,
|
|
162
|
+
getValues,
|
|
163
|
+
reset
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (inputRef) {
|
|
167
|
+
inputRef.current.focus();
|
|
168
|
+
}
|
|
169
|
+
}).catch(err => {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
e.stopPropagation();
|
|
172
|
+
err.inner.forEach(error => {
|
|
173
|
+
setError(error.path ? error.path : '', {
|
|
174
|
+
type: "manual",
|
|
175
|
+
message: error.message
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
e.stopPropagation();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// const checkErrors = () => {
|
|
188
|
+
//
|
|
189
|
+
//
|
|
190
|
+
// if (isObjEmpty(errors)) {
|
|
191
|
+
// const rs = getValues()
|
|
192
|
+
// if (column.editFromSettings?.schema) {
|
|
193
|
+
// column.editFromSettings?.schema.validate(rs, { abortEarly: false })
|
|
194
|
+
// .then(() => {
|
|
195
|
+
// handleToggle()
|
|
196
|
+
// onChange(rs)
|
|
197
|
+
//
|
|
198
|
+
// if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
199
|
+
// column?.editFromSettings?.formClose({value, setValue, getValues, reset})
|
|
200
|
+
// }
|
|
201
|
+
// if (inputRef) {
|
|
202
|
+
// inputRef.current.focus()
|
|
203
|
+
// }
|
|
204
|
+
// })
|
|
205
|
+
// .catch((err: ValidationError) => {
|
|
206
|
+
//
|
|
207
|
+
// err.inner.forEach((error: ValidationError) => {
|
|
208
|
+
//
|
|
209
|
+
// setError(error.path ? error.path : '', {
|
|
210
|
+
// type: "manual",
|
|
211
|
+
// message: error.message
|
|
212
|
+
// })
|
|
213
|
+
// })
|
|
214
|
+
// })
|
|
215
|
+
// }
|
|
216
|
+
//
|
|
217
|
+
//
|
|
218
|
+
// } else {
|
|
219
|
+
//
|
|
220
|
+
// }
|
|
221
|
+
// }
|
|
222
|
+
|
|
223
|
+
const handleFormKeydown = e => {
|
|
224
|
+
// if (dropdownOpen) {
|
|
225
|
+
|
|
226
|
+
if (e.code === 'Tab' || e.code === 'ArrowUp' || e.code === 'ArrowDown') {
|
|
227
|
+
e.preventDefault();
|
|
228
|
+
e.stopPropagation();
|
|
229
|
+
// if (formElement && indexRowForm <= totalRowFrom) {
|
|
230
|
+
// setIndexRowForm((prevState) => prevState + 1)
|
|
231
|
+
// formElement.getElementsByTagName('input')[indexRowForm + 1]?.focus()
|
|
232
|
+
// }
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// if (e.code === 'Enter') {
|
|
236
|
+
// const rs = getValues()
|
|
237
|
+
//
|
|
238
|
+
//
|
|
239
|
+
// onChange(rs)
|
|
240
|
+
//
|
|
241
|
+
// if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
242
|
+
// column?.editFromSettings?.formClose({value, setValue, getValues, reset})
|
|
243
|
+
// }
|
|
244
|
+
// if (inputRef) {
|
|
245
|
+
// inputRef.current.focus()
|
|
246
|
+
// }
|
|
247
|
+
//
|
|
248
|
+
// e.preventDefault()
|
|
249
|
+
// e.stopPropagation()
|
|
250
|
+
// }
|
|
251
|
+
|
|
252
|
+
if (e.code === "Escape") {
|
|
253
|
+
handleToggle();
|
|
254
|
+
if (inputRef) {
|
|
255
|
+
inputRef.current.focus();
|
|
256
|
+
}
|
|
257
|
+
e.preventDefault();
|
|
258
|
+
e.stopPropagation();
|
|
259
|
+
}
|
|
260
|
+
return e.code;
|
|
261
|
+
// }
|
|
262
|
+
};
|
|
263
|
+
const renderForm = rows => {
|
|
264
|
+
return /*#__PURE__*/React.createElement(Row, {
|
|
265
|
+
gutter: [0, 10]
|
|
266
|
+
}, rows.map((item, index) => {
|
|
267
|
+
return /*#__PURE__*/React.createElement(Col, {
|
|
268
|
+
key: `${index}`,
|
|
269
|
+
xl: column.editFromSettings?.layout?.xl ? column.editFromSettings?.layout?.xl : 24,
|
|
270
|
+
lg: column.editFromSettings?.layout?.lg ? column.editFromSettings?.layout?.lg : 24,
|
|
271
|
+
md: column.editFromSettings?.layout?.md ? column.editFromSettings?.layout?.md : 24,
|
|
272
|
+
sm: column.editFromSettings?.layout?.sm ? column.editFromSettings?.layout?.sm : 24,
|
|
273
|
+
xs: column.editFromSettings?.layout?.xs ? column.editFromSettings?.layout?.xs : 24,
|
|
274
|
+
className: 'mb-1'
|
|
275
|
+
}, /*#__PURE__*/React.createElement(InputControl, {
|
|
276
|
+
id: `edit-form-${index}`,
|
|
277
|
+
t: t,
|
|
278
|
+
control: control
|
|
279
|
+
// name={`specificationCode${index + 1}`}
|
|
280
|
+
,
|
|
281
|
+
name: item.name,
|
|
282
|
+
label: item.label ? item.label : '',
|
|
283
|
+
labelSize: "label-medium",
|
|
284
|
+
errors: errors[item.name],
|
|
285
|
+
onKeyDown: e => formItemKeyDown(e, index, column.editFromSettings?.items ? column.editFromSettings?.items.length : 0)
|
|
286
|
+
}));
|
|
287
|
+
}));
|
|
288
|
+
};
|
|
289
|
+
const contentStyle = {
|
|
290
|
+
padding: 6,
|
|
291
|
+
width: menuWidth,
|
|
292
|
+
backgroundColor: '#fff',
|
|
293
|
+
borderRadius: '6px',
|
|
294
|
+
boxShadow: '0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05)'
|
|
295
|
+
};
|
|
296
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(SelectStyle, {
|
|
297
|
+
ref: formRef,
|
|
298
|
+
id: id ? id : ''
|
|
299
|
+
}, /*#__PURE__*/React.createElement(Dropdown, {
|
|
300
|
+
menu: {
|
|
301
|
+
items: []
|
|
302
|
+
},
|
|
303
|
+
autoFocus: true,
|
|
304
|
+
onOpenChange: open => {
|
|
305
|
+
if (open) {
|
|
306
|
+
setTimeout(() => {
|
|
307
|
+
const formElement = document.getElementById('edit-form-0');
|
|
308
|
+
if (formElement) {
|
|
309
|
+
formElement.focus();
|
|
310
|
+
}
|
|
311
|
+
}, 10);
|
|
312
|
+
if (column.editFromSettings && column?.editFromSettings?.formOpen) {
|
|
313
|
+
column?.editFromSettings?.formOpen({
|
|
314
|
+
value,
|
|
315
|
+
setValue,
|
|
316
|
+
getValues,
|
|
317
|
+
reset
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
322
|
+
column?.editFromSettings?.formClose({
|
|
323
|
+
value,
|
|
324
|
+
setValue,
|
|
325
|
+
getValues,
|
|
326
|
+
reset
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
trigger: ['click'],
|
|
332
|
+
destroyPopupOnHide: true,
|
|
333
|
+
rootClassName: 'be-popup-container',
|
|
334
|
+
dropdownRender: () => /*#__PURE__*/React.createElement("div", {
|
|
335
|
+
style: contentStyle,
|
|
336
|
+
onKeyDown: e => handleFormKeydown(e),
|
|
337
|
+
onClick: e => {
|
|
338
|
+
e.preventDefault();
|
|
339
|
+
e.stopPropagation();
|
|
340
|
+
}
|
|
341
|
+
}, /*#__PURE__*/React.createElement("form", {
|
|
342
|
+
className: "todo-modal",
|
|
343
|
+
onSubmit: handleSubmit(handleOnSubmit)
|
|
344
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
345
|
+
className: 'p-1',
|
|
346
|
+
style: {
|
|
347
|
+
maxHeight: menuHeight ? menuHeight : 300,
|
|
348
|
+
overflow: "auto"
|
|
349
|
+
}
|
|
350
|
+
}, column.editFromSettings?.items ? renderForm(column.editFromSettings?.items) : ''), /*#__PURE__*/React.createElement(Divider, {
|
|
351
|
+
style: {
|
|
352
|
+
margin: 0
|
|
353
|
+
}
|
|
354
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
355
|
+
className: "d-flex justify-content-end p-1"
|
|
356
|
+
// style={{ boxShadow: "0 4px 24px 0 rgb(34 41 47 / 10%)" }}
|
|
357
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
358
|
+
variant: "solid",
|
|
359
|
+
className: ""
|
|
360
|
+
// onSubmit={handleSubmit(handleOnSubmit)}
|
|
361
|
+
,
|
|
362
|
+
onClick: handleSubmit(handleOnSubmit),
|
|
363
|
+
color: "primary",
|
|
364
|
+
style: {}
|
|
365
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
366
|
+
className: "d-flex "
|
|
367
|
+
}, t ? t('Save') : 'Save'))))))
|
|
368
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
369
|
+
ref: divRef,
|
|
370
|
+
style: {
|
|
371
|
+
height: '100%'
|
|
372
|
+
}
|
|
373
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
374
|
+
style: {
|
|
375
|
+
borderRadius: 0,
|
|
376
|
+
height: '100%'
|
|
377
|
+
},
|
|
378
|
+
ref: inputRef,
|
|
379
|
+
defaultValue: defaultValue,
|
|
380
|
+
value: defaultValue,
|
|
381
|
+
placeholder: placeholder,
|
|
382
|
+
className: 'be-select__input'
|
|
383
|
+
// onChange={handleOnChange}
|
|
384
|
+
,
|
|
385
|
+
onFocus: handleOnFocus
|
|
386
|
+
// onClick={handleOnClick}
|
|
387
|
+
// onKeyDown={handleOnKeyDown}
|
|
388
|
+
,
|
|
389
|
+
readOnly: true
|
|
390
|
+
})))));
|
|
391
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EditForm';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./EditForm";
|
|
@@ -22,6 +22,7 @@ import { Checkbox, Select, TreeSelect } from "rc-master-ui";
|
|
|
22
22
|
import { AsyncSelect } from "./async-select";
|
|
23
23
|
import { AsyncTableSelect } from "./async-table-select";
|
|
24
24
|
import { cyan, green, red, blue } from '@ant-design/colors';
|
|
25
|
+
import { EditForm } from "./EditForm";
|
|
25
26
|
|
|
26
27
|
// import moment from "moment";
|
|
27
28
|
|
|
@@ -148,16 +149,7 @@ const EditableCell = props => {
|
|
|
148
149
|
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
149
150
|
disabled: isDisable(column, record) ?? false,
|
|
150
151
|
maxDate: maxDate,
|
|
151
|
-
minDate: minDate
|
|
152
|
-
|
|
153
|
-
// onOpenChange={(open) => {
|
|
154
|
-
// console.log(open)
|
|
155
|
-
// if (open) {
|
|
156
|
-
// handleSubmit(onSubmit)
|
|
157
|
-
// }
|
|
158
|
-
// }}
|
|
159
|
-
,
|
|
160
|
-
|
|
152
|
+
minDate: minDate,
|
|
161
153
|
onChange: (newDate, dateString) => {
|
|
162
154
|
const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
|
|
163
155
|
onChange(newDateValue);
|
|
@@ -196,7 +188,6 @@ const EditableCell = props => {
|
|
|
196
188
|
minDate: minDate,
|
|
197
189
|
onChange: (newDate, dateString) => {
|
|
198
190
|
const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
|
|
199
|
-
// console.log('newDateValue', newDateValue)
|
|
200
191
|
onChange(newDateValue);
|
|
201
192
|
setTimeout(() => {
|
|
202
193
|
// @ts-ignore
|
|
@@ -746,36 +737,51 @@ const EditableCell = props => {
|
|
|
746
737
|
},
|
|
747
738
|
disabled: isDisable(column, record) ?? false
|
|
748
739
|
}));
|
|
740
|
+
case 'form':
|
|
741
|
+
const valueForm = value;
|
|
742
|
+
return /*#__PURE__*/React.createElement(EditForm, {
|
|
743
|
+
rowData: record,
|
|
744
|
+
column: column,
|
|
745
|
+
t: t,
|
|
746
|
+
id: `col${indexCol}-record${indexRow}`,
|
|
747
|
+
value: valueForm
|
|
748
|
+
// fieldKey={'name'}
|
|
749
|
+
,
|
|
750
|
+
fieldKey: column.editFromSettings?.fieldKey
|
|
751
|
+
// recordData={record}
|
|
752
|
+
,
|
|
753
|
+
indexRow: indexRow,
|
|
754
|
+
cellFocus: column.field === cellEditing?.column.field,
|
|
755
|
+
onChange: val => {
|
|
756
|
+
const formState = getValues();
|
|
749
757
|
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
// />
|
|
778
|
-
// )
|
|
758
|
+
// @ts-ignore
|
|
759
|
+
const prevState = record[dataIndex];
|
|
760
|
+
const newState = val;
|
|
761
|
+
handleCellChange?.({
|
|
762
|
+
key: getRowKey?.(record, index),
|
|
763
|
+
field: column.field ?? column.dataIndex,
|
|
764
|
+
record: {
|
|
765
|
+
...formState,
|
|
766
|
+
[column.field ?? '']: val
|
|
767
|
+
},
|
|
768
|
+
prevState,
|
|
769
|
+
newState,
|
|
770
|
+
option: val,
|
|
771
|
+
indexCol,
|
|
772
|
+
indexRow,
|
|
773
|
+
type: 'blur'
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
// cellEditing={cellEditing}
|
|
777
|
+
|
|
778
|
+
// menuPortalTarget={tableContainerRef}
|
|
779
|
+
// classNamePrefix={column.classElement ?? 'select'}
|
|
780
|
+
,
|
|
781
|
+
placeholder: t ? t(column.placeholder ? column.placeholder : '') : column.placeholder ? column.placeholder : '',
|
|
782
|
+
menuWidth: column.editFromSettings?.menuWidth,
|
|
783
|
+
menuHeight: column.editFromSettings?.menuHeight
|
|
784
|
+
});
|
|
779
785
|
|
|
780
786
|
// case 'file':
|
|
781
787
|
// const valueFile = record[column.dataIndex]
|
|
@@ -960,9 +966,6 @@ const EditableCell = props => {
|
|
|
960
966
|
// @ts-ignore
|
|
961
967
|
const prevState = record[dataIndex];
|
|
962
968
|
const newState = value;
|
|
963
|
-
//
|
|
964
|
-
// console.log('newState', newState)
|
|
965
|
-
// console.log('prevState', prevState)
|
|
966
969
|
const key = getRowKey?.(record, index);
|
|
967
970
|
// @ts-ignore
|
|
968
971
|
if (newState !== prevState) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { HTMLInputTypeAttribute } from "react";
|
|
2
|
+
interface IFFormInput {
|
|
3
|
+
id?: any;
|
|
4
|
+
control: any;
|
|
5
|
+
name: string;
|
|
6
|
+
type?: HTMLInputTypeAttribute;
|
|
7
|
+
label: string;
|
|
8
|
+
labelSize?: string;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
errors?: any;
|
|
11
|
+
height?: number | string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
row?: number;
|
|
14
|
+
isLabel?: boolean;
|
|
15
|
+
inLine?: boolean;
|
|
16
|
+
autoFocus?: boolean;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
classes?: string;
|
|
19
|
+
callback?: any;
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
isView?: boolean;
|
|
22
|
+
t?: any;
|
|
23
|
+
onKeyDown?: (event: any) => void;
|
|
24
|
+
}
|
|
25
|
+
declare const InputControl: (props: IFFormInput) => React.JSX.Element;
|
|
26
|
+
export default InputControl;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { Controller } from "react-hook-form";
|
|
3
|
+
import { Input } from "rc-master-ui";
|
|
4
|
+
import { Typography } from "antd";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
import React, { Fragment } from "react";
|
|
7
|
+
// import type { InputType } from "reactstrap/types/lib/Input"
|
|
8
|
+
import { isNullOrUndefined } from "../../hooks";
|
|
9
|
+
import { Col, Row } from "rc-master-ui/es/grid";
|
|
10
|
+
// import {isNullOrUndefined} from "../../../hooks"
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
Text
|
|
14
|
+
} = Typography;
|
|
15
|
+
const InputControl = props => {
|
|
16
|
+
const {
|
|
17
|
+
id,
|
|
18
|
+
control,
|
|
19
|
+
name,
|
|
20
|
+
type,
|
|
21
|
+
label,
|
|
22
|
+
labelSize,
|
|
23
|
+
required,
|
|
24
|
+
errors,
|
|
25
|
+
height,
|
|
26
|
+
disabled,
|
|
27
|
+
row,
|
|
28
|
+
isLabel,
|
|
29
|
+
placeholder,
|
|
30
|
+
autoFocus,
|
|
31
|
+
inLine,
|
|
32
|
+
callback,
|
|
33
|
+
readOnly,
|
|
34
|
+
classes,
|
|
35
|
+
isView,
|
|
36
|
+
t,
|
|
37
|
+
onKeyDown,
|
|
38
|
+
...rest
|
|
39
|
+
} = props;
|
|
40
|
+
const renderLabel = () => {
|
|
41
|
+
return /*#__PURE__*/React.createElement(Col, {
|
|
42
|
+
span: 8
|
|
43
|
+
}, isLabel === false ? '' : /*#__PURE__*/React.createElement("label", {
|
|
44
|
+
className: "form-label"
|
|
45
|
+
}, t ? t(label ? label : '') : label ? label : '', " ", required ? /*#__PURE__*/React.createElement("span", {
|
|
46
|
+
className: "text-danger"
|
|
47
|
+
}, "*") : '', " "));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// const renderText = () => {
|
|
51
|
+
// return (
|
|
52
|
+
// <Fragment>
|
|
53
|
+
// <Controller
|
|
54
|
+
// name={name}
|
|
55
|
+
// control={control}
|
|
56
|
+
// render={({ field: { value } }) => (
|
|
57
|
+
// <span>{value}</span>
|
|
58
|
+
// )}
|
|
59
|
+
// />
|
|
60
|
+
// </Fragment>
|
|
61
|
+
// )
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
const renderInput = () => {
|
|
65
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
style: {
|
|
67
|
+
display: 'flex',
|
|
68
|
+
flexDirection: 'column'
|
|
69
|
+
}
|
|
70
|
+
}, /*#__PURE__*/React.createElement(Controller, {
|
|
71
|
+
name: name,
|
|
72
|
+
control: control,
|
|
73
|
+
render: ({
|
|
74
|
+
field: {
|
|
75
|
+
value,
|
|
76
|
+
onChange
|
|
77
|
+
}
|
|
78
|
+
}) => /*#__PURE__*/React.createElement(Input, _extends({}, rest, {
|
|
79
|
+
id: id,
|
|
80
|
+
value: !isNullOrUndefined(value) ? value : '',
|
|
81
|
+
onChange: val => {
|
|
82
|
+
onChange(val.target.value);
|
|
83
|
+
if (callback) {
|
|
84
|
+
callback(val);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
style: {
|
|
88
|
+
height: `${height}px`
|
|
89
|
+
},
|
|
90
|
+
autoFocus: autoFocus,
|
|
91
|
+
disabled: disabled,
|
|
92
|
+
placeholder: placeholder,
|
|
93
|
+
type: type ? type : 'text'
|
|
94
|
+
// invalid={errors && true}
|
|
95
|
+
,
|
|
96
|
+
status: errors && true ? 'error' : undefined
|
|
97
|
+
// rows={row}
|
|
98
|
+
,
|
|
99
|
+
readOnly: readOnly,
|
|
100
|
+
onKeyDown: onKeyDown
|
|
101
|
+
}))
|
|
102
|
+
}), errors && /*#__PURE__*/React.createElement(Text, {
|
|
103
|
+
type: "danger"
|
|
104
|
+
}, errors?.message));
|
|
105
|
+
};
|
|
106
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Row, {
|
|
107
|
+
gutter: [4, 4]
|
|
108
|
+
// className={classnames(' align', {
|
|
109
|
+
// [labelSize ? labelSize : '']: labelSize,
|
|
110
|
+
// [classes ? classes : '']: classes,
|
|
111
|
+
// 'form-row-inline-error': errors
|
|
112
|
+
// }, inLine === false ? 'form-group ' : 'form-row-inline d-flex'
|
|
113
|
+
// )}
|
|
114
|
+
}, renderLabel(), /*#__PURE__*/React.createElement(Col, {
|
|
115
|
+
span: 16,
|
|
116
|
+
className: classnames('', {
|
|
117
|
+
'hidden-label': isLabel === false
|
|
118
|
+
})
|
|
119
|
+
}, renderInput())));
|
|
120
|
+
};
|
|
121
|
+
export default InputControl;
|