@linzjs/step-ag-grid 2.3.0 → 2.4.0
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/dist/index.js +48 -23
- package/dist/index.js.map +1 -1
- package/dist/src/components/GridSubComponentTextArea.d.ts +4 -4
- package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -1
- package/dist/src/contexts/GridSubComponentContext.d.ts +8 -0
- package/dist/step-ag-grid.esm.js +48 -23
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridPopoverHook.tsx +0 -1
- package/src/components/GridSubComponentTextArea.tsx +22 -10
- package/src/components/gridForm/GridFormMultiSelect.tsx +19 -15
- package/src/components/gridForm/GridFormTextArea.tsx +3 -3
- package/src/components/gridForm/GridFormTextInput.tsx +3 -3
- package/src/contexts/GridSubComponentContext.ts +21 -0
- package/src/react-menu3/components/ControlledMenu.tsx +13 -9
- package/src/stories/components/ActionButton.stories.tsx +1 -1
- package/src/stories/grid/FormTest.tsx +5 -6
- package/src/stories/grid/GridPopoutBearing.stories.tsx +1 -1
- package/src/stories/grid/GridPopoutEditDropDown.stories.tsx +1 -1
- package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +1 -1
- package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +3 -3
- package/src/stories/grid/GridPopoutEditMultiSelect.stories.tsx +2 -2
- package/src/stories/grid/GridReadOnly.stories.tsx +1 -1
- package/dist/src/components/gridForm/GridSubComponentProps.d.ts +0 -6
- package/src/components/gridForm/GridSubComponentProps.ts +0 -6
package/package.json
CHANGED
|
@@ -47,7 +47,6 @@ export const useGridPopoverHook = <RowType extends GridBaseRow>(props: GridPopov
|
|
|
47
47
|
saveButtonRef={saveButtonRef}
|
|
48
48
|
menuClassName={"step-ag-grid-react-menu"}
|
|
49
49
|
onClose={(event: MenuCloseEvent) => {
|
|
50
|
-
if (event.reason === "blur") return;
|
|
51
50
|
triggerSave(event.reason).then();
|
|
52
51
|
}}
|
|
53
52
|
viewScroll={"auto"}
|
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
import { useCallback, useEffect } from "react";
|
|
2
|
-
import { GridSubComponentProps } from "./gridForm/GridSubComponentProps";
|
|
1
|
+
import { useCallback, useContext, useEffect } from "react";
|
|
3
2
|
import { TextInputFormatted } from "../lui/TextInputFormatted";
|
|
3
|
+
import { GridSubComponentContext } from "../contexts/GridSubComponentContext";
|
|
4
4
|
|
|
5
|
-
export interface GridSubComponentTextAreaProps
|
|
5
|
+
export interface GridSubComponentTextAreaProps {
|
|
6
6
|
placeholder?: string;
|
|
7
7
|
required?: boolean;
|
|
8
|
-
|
|
8
|
+
maxLength?: number;
|
|
9
9
|
width?: string | number;
|
|
10
|
-
validate
|
|
10
|
+
validate?: (value: string) => string | null;
|
|
11
|
+
defaultValue: string;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export const GridSubComponentTextArea = (props: GridSubComponentTextAreaProps): JSX.Element => {
|
|
14
|
-
const { value, setValue, setValid, triggerSave } =
|
|
15
|
+
const { value, setValue, setValid, triggerSave } = useContext(GridSubComponentContext);
|
|
16
|
+
|
|
17
|
+
// If is not initialised yet as it's just been created then set the default value
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (value == null) setValue(props.defaultValue);
|
|
20
|
+
}, [props.defaultValue, setValue, value]);
|
|
21
|
+
|
|
15
22
|
const validate = useCallback(
|
|
16
|
-
(value: string) => {
|
|
23
|
+
(value: string | null) => {
|
|
24
|
+
if (value == null) return null;
|
|
25
|
+
// This can happen because subcomponent is invoked without type safety
|
|
26
|
+
if (typeof value !== "string") {
|
|
27
|
+
console.error("Value is not a string", value);
|
|
28
|
+
}
|
|
17
29
|
if (props.required && value.length === 0) {
|
|
18
30
|
return `Some text is required`;
|
|
19
31
|
}
|
|
20
|
-
if (props.
|
|
21
|
-
return `Text must be no longer than ${props.
|
|
32
|
+
if (props.maxLength && value.length > props.maxLength) {
|
|
33
|
+
return `Text must be no longer than ${props.maxLength} characters`;
|
|
22
34
|
}
|
|
23
35
|
if (props.validate) {
|
|
24
36
|
return props.validate(value);
|
|
@@ -29,7 +41,7 @@ export const GridSubComponentTextArea = (props: GridSubComponentTextAreaProps):
|
|
|
29
41
|
);
|
|
30
42
|
|
|
31
43
|
useEffect(() => {
|
|
32
|
-
setValid(validate(value) == null);
|
|
44
|
+
setValid(value != null && validate(value) == null);
|
|
33
45
|
}, [setValid, validate, value]);
|
|
34
46
|
|
|
35
47
|
return (
|
|
@@ -10,7 +10,7 @@ import { useGridPopoverHook } from "../GridPopoverHook";
|
|
|
10
10
|
import { MenuSeparatorString } from "./GridFormDropDown";
|
|
11
11
|
import { CellEditorCommon, CellParams } from "../GridCell";
|
|
12
12
|
import { ClickEvent } from "../../react-menu3/types";
|
|
13
|
-
import {
|
|
13
|
+
import { GridSubComponentContext } from "contexts/GridSubComponentContext";
|
|
14
14
|
|
|
15
15
|
interface MultiFinalSelectOption<ValueType> {
|
|
16
16
|
value: ValueType;
|
|
@@ -208,20 +208,24 @@ export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
|
|
|
208
208
|
|
|
209
209
|
{selectedValues.includes(item.value) && item.subComponent && (
|
|
210
210
|
<FocusableItem className={"LuiDeprecatedForms"} key={`${item.value}_subcomponent`}>
|
|
211
|
-
{(
|
|
212
|
-
item.subComponent &&
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
211
|
+
{(_: any) =>
|
|
212
|
+
item.subComponent && (
|
|
213
|
+
<GridSubComponentContext.Provider
|
|
214
|
+
value={{
|
|
215
|
+
value: subSelectedValues[`${item.value}`],
|
|
216
|
+
setValue: (value: any) => {
|
|
217
|
+
subSelectedValues[`${item.value}`] = value;
|
|
218
|
+
setSubSelectedValues({ ...subSelectedValues });
|
|
219
|
+
},
|
|
220
|
+
setValid: (valid: boolean) => {
|
|
221
|
+
subComponentIsValid.current[`${item.value}`] = valid;
|
|
222
|
+
},
|
|
223
|
+
triggerSave,
|
|
224
|
+
}}
|
|
225
|
+
>
|
|
226
|
+
<item.subComponent />
|
|
227
|
+
</GridSubComponentContext.Provider>
|
|
228
|
+
)
|
|
225
229
|
}
|
|
226
230
|
</FocusableItem>
|
|
227
231
|
)}
|
|
@@ -7,7 +7,7 @@ import { CellEditorCommon, CellParams } from "../GridCell";
|
|
|
7
7
|
export interface GridFormTextAreaProps<RowType extends GridBaseRow> extends CellEditorCommon {
|
|
8
8
|
placeholder?: string;
|
|
9
9
|
required?: boolean;
|
|
10
|
-
|
|
10
|
+
maxLength?: number;
|
|
11
11
|
width?: string | number;
|
|
12
12
|
validate?: (value: string) => string | null;
|
|
13
13
|
onSave?: (selectedRows: RowType[], value: string) => Promise<boolean>;
|
|
@@ -21,8 +21,8 @@ export const GridFormTextArea = <RowType extends GridBaseRow>(_props: GridFormTe
|
|
|
21
21
|
if (props.required && value.length == 0) {
|
|
22
22
|
return `Some text is required`;
|
|
23
23
|
}
|
|
24
|
-
if (props.
|
|
25
|
-
return `Text must be no longer than ${props.
|
|
24
|
+
if (props.maxLength && value.length > props.maxLength) {
|
|
25
|
+
return `Text must be no longer than ${props.maxLength} characters`;
|
|
26
26
|
}
|
|
27
27
|
if (props.validate) {
|
|
28
28
|
return props.validate(value);
|
|
@@ -8,7 +8,7 @@ export interface GridFormTextInputProps<RowType extends GridBaseRow> extends Cel
|
|
|
8
8
|
placeholder?: string;
|
|
9
9
|
units?: string;
|
|
10
10
|
required?: boolean;
|
|
11
|
-
|
|
11
|
+
maxLength?: number;
|
|
12
12
|
width?: string | number;
|
|
13
13
|
// Return null for ok, otherwise an error string
|
|
14
14
|
validate?: (value: string, data: RowType) => string | null;
|
|
@@ -25,8 +25,8 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(_props: GridFormT
|
|
|
25
25
|
if (props.required && trimmedValue.length == 0) {
|
|
26
26
|
return `Some text is required`;
|
|
27
27
|
}
|
|
28
|
-
if (props.
|
|
29
|
-
return `Text must be no longer than ${props.
|
|
28
|
+
if (props.maxLength && trimmedValue.length > props.maxLength) {
|
|
29
|
+
return `Text must be no longer than ${props.maxLength} characters`;
|
|
30
30
|
}
|
|
31
31
|
if (props.validate) {
|
|
32
32
|
return props.validate(trimmedValue, props.data);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
|
|
3
|
+
export interface GridSubComponentContextType {
|
|
4
|
+
value: any;
|
|
5
|
+
setValue: (value: string) => void;
|
|
6
|
+
setValid: (valid: boolean) => void;
|
|
7
|
+
triggerSave: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const GridSubComponentContext = createContext<GridSubComponentContextType>({
|
|
11
|
+
value: "GridSubComponentContext value no context",
|
|
12
|
+
setValue: () => {
|
|
13
|
+
console.error("GridSubComponentContext setValue no context");
|
|
14
|
+
},
|
|
15
|
+
setValid: () => {
|
|
16
|
+
console.error("GridSubComponentContext setValid no context");
|
|
17
|
+
},
|
|
18
|
+
triggerSave: async () => {
|
|
19
|
+
console.error("GridSubComponentContext triggerSave no context");
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -76,16 +76,16 @@ export const ControlledMenuFr = (
|
|
|
76
76
|
],
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
-
const
|
|
80
|
-
(
|
|
81
|
-
hasParentClass("szh-menu--state-open",
|
|
82
|
-
(closeMenuExclusionClassName && hasParentClass(closeMenuExclusionClassName,
|
|
79
|
+
const isWithinMenu = useCallback(
|
|
80
|
+
(target: EventTarget | null) =>
|
|
81
|
+
hasParentClass("szh-menu--state-open", target as Node) ||
|
|
82
|
+
(closeMenuExclusionClassName && hasParentClass(closeMenuExclusionClassName, target as Node)),
|
|
83
83
|
[closeMenuExclusionClassName],
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
const handleScreenEventForSave = useCallback(
|
|
87
87
|
(ev: MouseEvent) => {
|
|
88
|
-
if (!
|
|
88
|
+
if (!isWithinMenu(ev.target)) {
|
|
89
89
|
ev.preventDefault();
|
|
90
90
|
ev.stopPropagation();
|
|
91
91
|
// FIXME There's an issue in React17
|
|
@@ -107,17 +107,17 @@ export const ControlledMenuFr = (
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
|
-
[
|
|
110
|
+
[isWithinMenu, onClose, saveButtonRef, skipOpen],
|
|
111
111
|
);
|
|
112
112
|
|
|
113
113
|
const handleScreenEventForCancel = useCallback(
|
|
114
114
|
(ev: MouseEvent) => {
|
|
115
|
-
if (!
|
|
115
|
+
if (!isWithinMenu(ev.target)) {
|
|
116
116
|
ev.preventDefault();
|
|
117
117
|
ev.stopPropagation();
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
|
-
[
|
|
120
|
+
[isWithinMenu],
|
|
121
121
|
);
|
|
122
122
|
|
|
123
123
|
useEffect(() => {
|
|
@@ -183,7 +183,11 @@ export const ControlledMenuFr = (
|
|
|
183
183
|
};
|
|
184
184
|
|
|
185
185
|
const onBlur = (e: FocusEvent) => {
|
|
186
|
-
if (
|
|
186
|
+
if (
|
|
187
|
+
isMenuOpen(state) &&
|
|
188
|
+
!e.currentTarget.contains(e.relatedTarget || document.activeElement) &&
|
|
189
|
+
!isWithinMenu(e.relatedTarget)
|
|
190
|
+
) {
|
|
187
191
|
safeCall(onClose, { reason: CloseReason.BLUR });
|
|
188
192
|
|
|
189
193
|
// If a user clicks on the menu button when a menu is open, we need to close the menu.
|
|
@@ -7,7 +7,7 @@ import { useCallback, useState } from "react";
|
|
|
7
7
|
import { wait } from "../../utils/util";
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
title: "Components /
|
|
10
|
+
title: "Components / ActionButton",
|
|
11
11
|
component: ActionButton,
|
|
12
12
|
args: {},
|
|
13
13
|
} as ComponentMeta<typeof ActionButton>;
|
|
@@ -18,23 +18,22 @@ export interface IFormTestRow {
|
|
|
18
18
|
|
|
19
19
|
export const FormTest = <RowType extends GridBaseRow>(_props: CellEditorCommon): JSX.Element => {
|
|
20
20
|
const props = _props as CellParams<RowType>;
|
|
21
|
-
const [v1, v2
|
|
21
|
+
const [v1, ...v2] = props.value.split(" ");
|
|
22
22
|
|
|
23
23
|
const [nameType, setNameType] = useState(v1);
|
|
24
|
-
const [numba, setNumba] = useState(v2);
|
|
25
|
-
const [plan, setPlan] = useState(v3.join(" "));
|
|
24
|
+
const [numba, setNumba] = useState(v2.join(" "));
|
|
26
25
|
|
|
27
26
|
const save = useCallback(async (): Promise<boolean> => {
|
|
28
27
|
// eslint-disable-next-line no-console
|
|
29
|
-
console.log("onSave", props.selectedRows, nameType, numba
|
|
28
|
+
console.log("onSave", props.selectedRows, nameType, numba);
|
|
30
29
|
|
|
31
30
|
// @ts-ignore
|
|
32
|
-
props.selectedRows.forEach((row) => (row["name"] = [nameType, numba
|
|
31
|
+
props.selectedRows.forEach((row) => (row["name"] = [nameType, numba].join(" ")));
|
|
33
32
|
await wait(1000);
|
|
34
33
|
|
|
35
34
|
// Close form
|
|
36
35
|
return true;
|
|
37
|
-
}, [nameType, numba,
|
|
36
|
+
}, [nameType, numba, props.selectedRows]);
|
|
38
37
|
|
|
39
38
|
const [showModal, setShowModal] = useState<boolean>(false);
|
|
40
39
|
|
|
@@ -83,7 +83,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
83
83
|
[],
|
|
84
84
|
);
|
|
85
85
|
|
|
86
|
-
const [rowData
|
|
86
|
+
const [rowData] = useState([
|
|
87
87
|
{ id: 1000, bearing1: 1.234, bearingCorrection: 90 },
|
|
88
88
|
{ id: 1001, bearing1: 1.565, bearingCorrection: 240 },
|
|
89
89
|
{ id: 1002, bearing1: null, bearingCorrection: 355.1 },
|
|
@@ -57,7 +57,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
|
|
|
57
57
|
[],
|
|
58
58
|
);
|
|
59
59
|
|
|
60
|
-
const [rowData
|
|
60
|
+
const [rowData] = useState([
|
|
61
61
|
{ id: 1000, name: "IS IS DP12345", nameType: "IS", numba: "IX", plan: "DP 12345" },
|
|
62
62
|
{ id: 1001, name: "PEG V SD523", nameType: "PEG", numba: "V", plan: "SD 523" },
|
|
63
63
|
] as IFormTestRow[]);
|
|
@@ -61,7 +61,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
|
|
|
61
61
|
multiEdit: true,
|
|
62
62
|
editorParams: {
|
|
63
63
|
required: true,
|
|
64
|
-
|
|
64
|
+
maxLength: 12,
|
|
65
65
|
placeholder: "Enter some text...",
|
|
66
66
|
validate: (value: string) => {
|
|
67
67
|
if (value === "never") return "The value 'never' is not allowed";
|
|
@@ -88,7 +88,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
|
|
|
88
88
|
{
|
|
89
89
|
multiEdit: true,
|
|
90
90
|
editorParams: {
|
|
91
|
-
|
|
91
|
+
maxLength: 12,
|
|
92
92
|
placeholder: "Enter distance...",
|
|
93
93
|
units: "m",
|
|
94
94
|
validate: (value: string) => {
|
|
@@ -115,7 +115,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
|
|
|
115
115
|
multiEdit: true,
|
|
116
116
|
editorParams: {
|
|
117
117
|
required: true,
|
|
118
|
-
|
|
118
|
+
maxLength: 32,
|
|
119
119
|
placeholder: "Enter some text...",
|
|
120
120
|
|
|
121
121
|
validate: (value: string) => {
|
|
@@ -80,7 +80,7 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
|
|
|
80
80
|
{
|
|
81
81
|
value: "other",
|
|
82
82
|
label: "Other",
|
|
83
|
-
subComponent: (
|
|
83
|
+
subComponent: () => <GridSubComponentTextArea maxLength={2} defaultValue={""} />,
|
|
84
84
|
},
|
|
85
85
|
],
|
|
86
86
|
initialSelectedValues: () => ({
|
|
@@ -128,7 +128,7 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
|
|
|
128
128
|
];
|
|
129
129
|
}, []);
|
|
130
130
|
|
|
131
|
-
const [rowData
|
|
131
|
+
const [rowData] = useState([
|
|
132
132
|
{ id: 1000, position: "Tester", position2: "1", position3: "Tester" },
|
|
133
133
|
{ id: 1001, position: "Developer", position2: "2", position3: "Developer" },
|
|
134
134
|
] as ITestRow[]);
|
|
@@ -151,7 +151,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
151
151
|
[],
|
|
152
152
|
);
|
|
153
153
|
|
|
154
|
-
const [rowData
|
|
154
|
+
const [rowData] = useState([
|
|
155
155
|
{ id: 1000, position: "Tester", age: 30, desc: "Tests application", dd: "1" },
|
|
156
156
|
{ id: 1001, position: "Developer", age: 12, desc: "Develops application", dd: "2" },
|
|
157
157
|
]);
|