ag-common 0.0.266 → 0.0.269
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.
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export declare const CheckboxEdit: ({ defaultValue, onSubmit, noGrow, }: {
|
|
1
|
+
export declare const CheckboxEdit: ({ defaultValue, onSubmit, noGrow, allowUndo, }: {
|
|
2
2
|
defaultValue: boolean;
|
|
3
3
|
onSubmit: (val: boolean) => void;
|
|
4
4
|
noGrow?: boolean | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* if true, will add undo button after changes. if false, will submit after every keypress. default true
|
|
7
|
+
*/
|
|
8
|
+
allowUndo?: boolean | undefined;
|
|
5
9
|
}) => JSX.Element;
|
|
@@ -39,7 +39,7 @@ const Icons = (0, styled_components_1.default)(FlexRow_1.FlexRow) `
|
|
|
39
39
|
top: 0;
|
|
40
40
|
right: -2rem;
|
|
41
41
|
`;
|
|
42
|
-
const CheckboxEdit = ({ defaultValue, onSubmit, noGrow = false, }) => {
|
|
42
|
+
const CheckboxEdit = ({ defaultValue, onSubmit, noGrow = false, allowUndo = true, }) => {
|
|
43
43
|
const ref = (0, react_1.useRef)(null);
|
|
44
44
|
const [value, setValue] = (0, react_1.useState)(defaultValue);
|
|
45
45
|
(0, react_1.useEffect)(() => {
|
|
@@ -52,11 +52,18 @@ const CheckboxEdit = ({ defaultValue, onSubmit, noGrow = false, }) => {
|
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { ref: ref, "data-nogrow": noGrow }),
|
|
55
|
-
react_1.default.createElement(common_1.ValueInputCB, { type: "checkbox", "data-type": "checkbox", checked: value, onChange: () =>
|
|
56
|
-
|
|
55
|
+
react_1.default.createElement(common_1.ValueInputCB, { type: "checkbox", "data-type": "checkbox", checked: value, onChange: () => {
|
|
56
|
+
if (allowUndo) {
|
|
57
|
+
setValue(!value);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
onSubmit(!value);
|
|
61
|
+
}
|
|
62
|
+
}, onKeyPress: (e) => e.key === 'Enter' && value !== defaultValue && onSubmit(value) }),
|
|
63
|
+
allowUndo && (react_1.default.createElement(Icons, { center: true, enableOverflow: true },
|
|
57
64
|
value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconLeft, onClick: () => value !== defaultValue && onSubmit(value) },
|
|
58
65
|
react_1.default.createElement(images_1.SaveIcon, null))),
|
|
59
66
|
value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconRight, onClick: () => setValue(defaultValue) },
|
|
60
|
-
react_1.default.createElement(images_1.UndoIcon, null))))));
|
|
67
|
+
react_1.default.createElement(images_1.UndoIcon, null)))))));
|
|
61
68
|
};
|
|
62
69
|
exports.CheckboxEdit = CheckboxEdit;
|
|
@@ -38,13 +38,17 @@ renderLabel = (e) => e.toString(), }) => {
|
|
|
38
38
|
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag),
|
|
39
39
|
react_1.default.createElement("select", { size: 5,
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
value: value.toString(), onChange: (v) =>
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
value: value.toString(), onChange: (v) => {
|
|
42
|
+
const selected = values[v.target.selectedIndex];
|
|
43
|
+
if (!selected) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
return canEdit ? setValue(selected) : onSubmit(selected);
|
|
47
|
+
} }, values.map((v) => (react_1.default.createElement("option", {
|
|
44
48
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
-
key:
|
|
49
|
+
key: v.toString(),
|
|
46
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
value:
|
|
51
|
+
value: v.toString() }, renderLabel(v))))),
|
|
48
52
|
canEdit && value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconLeft, onClick: () => value !== defaultValue && onSubmit(value) },
|
|
49
53
|
react_1.default.createElement(images_1.SaveIcon, null))),
|
|
50
54
|
canEdit && value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconRight, onClick: () => setValue(defaultValue) },
|
|
@@ -94,14 +94,15 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
|
|
|
94
94
|
}, () => {
|
|
95
95
|
if (valueChange) {
|
|
96
96
|
onSubmit(value, false);
|
|
97
|
+
return;
|
|
97
98
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
if (!disableEdit && onClickOutsideWithNoValue) {
|
|
100
|
+
onClickOutsideWithNoValue();
|
|
101
|
+
}
|
|
102
|
+
if (!disableEdit && editing && defaultEditing) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (editing) {
|
|
105
106
|
setEditingRaw(false);
|
|
106
107
|
}
|
|
107
108
|
});
|