ar-design 0.4.43 → 0.4.44
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.
|
@@ -8,9 +8,9 @@ const Editable = function ({ c, item, trackByValue, onEditable, config }) {
|
|
|
8
8
|
// variables
|
|
9
9
|
const key = c.key;
|
|
10
10
|
const itemValue = item[c.key];
|
|
11
|
-
const selectItem = c.editable?.options?.find((x) => x.value === itemValue);
|
|
11
|
+
const selectItem = c.editable?.(item)?.options?.find((x) => x.value === itemValue);
|
|
12
12
|
const selectItems = Array.isArray(itemValue)
|
|
13
|
-
? c.editable?.options?.filter((x) => itemValue.includes(x.value))
|
|
13
|
+
? c.editable?.(item)?.options?.filter((x) => itemValue.includes(x.value))
|
|
14
14
|
: [];
|
|
15
15
|
const validation = config.validation;
|
|
16
16
|
const _vText = validation?.errors?.[`${c.key}_${trackByValue}`];
|
|
@@ -18,39 +18,39 @@ const Editable = function ({ c, item, trackByValue, onEditable, config }) {
|
|
|
18
18
|
const [_value, setValue] = useState(itemValue);
|
|
19
19
|
// useEffects
|
|
20
20
|
useEffect(() => setValue(itemValue), [item]);
|
|
21
|
-
switch (c.editable?.type) {
|
|
21
|
+
switch (c.editable?.(item)?.type) {
|
|
22
22
|
case "string":
|
|
23
23
|
case "number":
|
|
24
24
|
return (React.createElement(Input, { variant: "borderless", value: _value, onChange: (event) => {
|
|
25
25
|
const { value } = event.target;
|
|
26
26
|
setValue(value);
|
|
27
|
-
onEditable({ ...item, [key]: c.editable?.type === "number" ? Number(value) : value }, trackByValue, ExtractKey(c.key));
|
|
28
|
-
}, validation: { text: _vText }, ...(c.editable.where ? { disabled: c.editable
|
|
27
|
+
onEditable({ ...item, [key]: c.editable?.(item)?.type === "number" ? Number(value) : value }, trackByValue, ExtractKey(c.key));
|
|
28
|
+
}, validation: { text: _vText }, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
|
|
29
29
|
case "decimal":
|
|
30
30
|
return (React.createElement(Input.Decimal, { variant: "borderless", name: c.key, value: _value, onChange: (event) => {
|
|
31
31
|
const { value } = event.target;
|
|
32
32
|
setValue(value);
|
|
33
33
|
onEditable({ ...item, [key]: value }, trackByValue, ExtractKey(c.key));
|
|
34
|
-
}, validation: { text: _vText }, locale: config.locale, ...(c.editable.where ? { disabled: c.editable
|
|
34
|
+
}, validation: { text: _vText }, locale: config.locale, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
|
|
35
35
|
case "input-formatted-decimal":
|
|
36
36
|
return (React.createElement(Input.FormattedDecimal, { variant: "borderless", name: c.key, value: _value, onChange: (event) => {
|
|
37
37
|
const { value } = event.target;
|
|
38
38
|
setValue(value);
|
|
39
39
|
onEditable({ ...item, [key]: value }, trackByValue, ExtractKey(c.key));
|
|
40
|
-
}, validation: { text: _vText }, locale: config.locale, ...(c.editable.where ? { disabled: c.editable
|
|
40
|
+
}, validation: { text: _vText }, locale: config.locale, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
|
|
41
41
|
case "date-picker":
|
|
42
42
|
return (React.createElement(DatePicker, { variant: "borderless", value: _value, onChange: (value) => {
|
|
43
43
|
setValue(value);
|
|
44
44
|
onEditable({ ...item, [key]: value }, trackByValue, ExtractKey(c.key));
|
|
45
|
-
}, validation: { text: _vText }, ...(c.editable.where ? { disabled: c.editable
|
|
45
|
+
}, validation: { text: _vText }, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
|
|
46
46
|
case "single-select":
|
|
47
|
-
return (React.createElement(Select, { variant: "borderless", value: selectItem, options: c.editable.options, onClick: async () => await c.editable?.method?.(), onChange: (option) => {
|
|
47
|
+
return (React.createElement(Select, { variant: "borderless", value: selectItem, options: c.editable?.(item).options, onClick: async () => await c.editable?.(item)?.method?.(), onChange: (option) => {
|
|
48
48
|
onEditable({ ...item, [key]: option?.value }, trackByValue, ExtractKey(c.key));
|
|
49
|
-
}, validation: { text: _vText }, ...(c.editable.where ? { disabled: c.editable
|
|
49
|
+
}, validation: { text: _vText }, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
|
|
50
50
|
case "multiple-select":
|
|
51
|
-
return (React.createElement(Select, { variant: "borderless", value: selectItems, options: c.editable.options, onClick: async () => await c.editable?.method?.(), onChange: (options) => {
|
|
51
|
+
return (React.createElement(Select, { variant: "borderless", value: selectItems, options: c.editable?.(item).options, onClick: async () => await c.editable?.(item)?.method?.(), onChange: (options) => {
|
|
52
52
|
onEditable({ ...item, [key]: options.map((option) => option.value) }, trackByValue, ExtractKey(c.key));
|
|
53
|
-
}, validation: { text: _vText }, multiple: true, ...(c.editable.where ? { disabled: c.editable
|
|
53
|
+
}, validation: { text: _vText }, multiple: true, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
|
|
54
54
|
default:
|
|
55
55
|
return null;
|
|
56
56
|
}
|
|
@@ -35,11 +35,11 @@ export type TableColumnType<T> = {
|
|
|
35
35
|
filters?: Option[];
|
|
36
36
|
filterDataType?: FilterDataType;
|
|
37
37
|
render?: (item: T) => React.ReactNode;
|
|
38
|
-
editable?: {
|
|
38
|
+
editable?: (item: T) => {
|
|
39
39
|
type: "string" | "number" | "decimal" | "input-formatted-decimal" | "date-picker" | "single-select" | "multiple-select";
|
|
40
40
|
options?: Option[];
|
|
41
41
|
method?: () => void | Promise<void>;
|
|
42
|
-
where?:
|
|
42
|
+
where?: boolean;
|
|
43
43
|
};
|
|
44
44
|
config?: {
|
|
45
45
|
width?: number | "auto" | "fit-content" | "max-content" | "min-content";
|