@linzjs/step-ag-grid 1.5.2 → 1.5.3
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.d.ts +1 -1
- package/dist/index.js +24 -16
- package/dist/index.js.map +1 -1
- package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -0
- package/dist/src/lui/TextInputFormatted.d.ts +1 -2
- package/dist/src/stories/components/FormTest.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +22 -17
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridCell.tsx +4 -2
- package/src/components/gridForm/GridFormTextInput.tsx +13 -10
- package/src/lui/TextInputFormatted.tsx +1 -3
- package/src/stories/components/FormTest.tsx +1 -0
- package/src/stories/components/GridPopoutEditGenericTextArea.stories.tsx +27 -3
package/package.json
CHANGED
|
@@ -72,8 +72,9 @@ export const GridCell = <RowType extends GridBaseRow, FormProps extends GenericC
|
|
|
72
72
|
}),
|
|
73
73
|
// Default value formatter, otherwise react freaks out on objects
|
|
74
74
|
valueFormatter: (params: ValueFormatterParams) => {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
if (params.value == null) return "-";
|
|
76
|
+
const types = ["number", "boolean", "string"];
|
|
77
|
+
if (types.includes(typeof params.value)) return `${params.value}`;
|
|
77
78
|
else return JSON.stringify(params.value);
|
|
78
79
|
},
|
|
79
80
|
...props,
|
|
@@ -130,6 +131,7 @@ export const GenericCellEditorComponentFr = <RowType extends GridBaseRow, FormPr
|
|
|
130
131
|
updateValue={updateValue}
|
|
131
132
|
saving={saving}
|
|
132
133
|
formProps={formProps}
|
|
134
|
+
data={data}
|
|
133
135
|
value={value}
|
|
134
136
|
field={field}
|
|
135
137
|
selectedRows={selectedRows}
|
|
@@ -6,6 +6,7 @@ import { GridBaseRow } from "../Grid";
|
|
|
6
6
|
|
|
7
7
|
export interface GridFormTextInputProps<RowType extends GridBaseRow> extends GenericCellEditorParams<RowType> {
|
|
8
8
|
placeholder?: string;
|
|
9
|
+
units?: string;
|
|
9
10
|
required?: boolean;
|
|
10
11
|
maxlength?: number;
|
|
11
12
|
width?: string | number;
|
|
@@ -15,17 +16,19 @@ export interface GridFormTextInputProps<RowType extends GridBaseRow> extends Gen
|
|
|
15
16
|
|
|
16
17
|
export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormProps<RowType>) => {
|
|
17
18
|
const formProps = props.formProps as GridFormTextInputProps<RowType>;
|
|
18
|
-
const
|
|
19
|
+
const initValue = props.value == null ? "" : `${props.value}`;
|
|
20
|
+
const [value, setValue] = useState(initValue);
|
|
19
21
|
|
|
20
22
|
const invalid = useCallback(() => {
|
|
21
|
-
|
|
23
|
+
const trimmedValue = value.trim();
|
|
24
|
+
if (formProps.required && trimmedValue.length == 0) {
|
|
22
25
|
return `Some text is required`;
|
|
23
26
|
}
|
|
24
|
-
if (formProps.maxlength &&
|
|
27
|
+
if (formProps.maxlength && trimmedValue.length > formProps.maxlength) {
|
|
25
28
|
return `Text must be no longer than ${formProps.maxlength} characters`;
|
|
26
29
|
}
|
|
27
30
|
if (formProps.validate) {
|
|
28
|
-
return formProps.validate(
|
|
31
|
+
return formProps.validate(trimmedValue);
|
|
29
32
|
}
|
|
30
33
|
return null;
|
|
31
34
|
}, [formProps, value]);
|
|
@@ -33,11 +36,11 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormPr
|
|
|
33
36
|
const save = useCallback(
|
|
34
37
|
async (selectedRows: any[]): Promise<boolean> => {
|
|
35
38
|
if (invalid()) return false;
|
|
36
|
-
|
|
37
|
-
if (
|
|
39
|
+
const trimmedValue = value.trim();
|
|
40
|
+
if (initValue === trimmedValue) return true;
|
|
38
41
|
|
|
39
42
|
if (formProps.onSave) {
|
|
40
|
-
return await formProps.onSave(selectedRows,
|
|
43
|
+
return await formProps.onSave(selectedRows, trimmedValue);
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
const field = props.field;
|
|
@@ -45,10 +48,10 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormPr
|
|
|
45
48
|
console.error("ColDef has no field set");
|
|
46
49
|
return false;
|
|
47
50
|
}
|
|
48
|
-
selectedRows.forEach((row) => (row[field] =
|
|
51
|
+
selectedRows.forEach((row) => (row[field] = trimmedValue));
|
|
49
52
|
return true;
|
|
50
53
|
},
|
|
51
|
-
[invalid,
|
|
54
|
+
[invalid, value, initValue, formProps, props.field],
|
|
52
55
|
);
|
|
53
56
|
const { popoverWrapper, triggerSave } = useGridPopoverHook(props, save);
|
|
54
57
|
|
|
@@ -58,7 +61,7 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormPr
|
|
|
58
61
|
value={value}
|
|
59
62
|
onChange={(e) => setValue(e.target.value)}
|
|
60
63
|
error={invalid()}
|
|
61
|
-
formatted={
|
|
64
|
+
formatted={formProps.units}
|
|
62
65
|
inputProps={{
|
|
63
66
|
style: { width: "100%" },
|
|
64
67
|
placeholder: formProps.placeholder,
|
|
@@ -14,9 +14,8 @@ export interface LuiTextInputProps {
|
|
|
14
14
|
className?: string;
|
|
15
15
|
value: string;
|
|
16
16
|
|
|
17
|
-
icon?: JSX.Element;
|
|
18
17
|
placeholder?: string;
|
|
19
|
-
formatted
|
|
18
|
+
formatted?: string;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export const TextInputFormatted = (props: LuiTextInputProps): JSX.Element => {
|
|
@@ -39,7 +38,6 @@ export const TextInputFormatted = (props: LuiTextInputProps): JSX.Element => {
|
|
|
39
38
|
{...props.inputProps}
|
|
40
39
|
/>
|
|
41
40
|
<span className={"LuiTextInput-formatted"}>{props.formatted}</span>
|
|
42
|
-
{props.icon}
|
|
43
41
|
</span>
|
|
44
42
|
|
|
45
43
|
{props.error && (
|
|
@@ -9,7 +9,7 @@ import { Grid, GridProps } from "@components/Grid";
|
|
|
9
9
|
import { useMemo, useState } from "react";
|
|
10
10
|
import { GridCell } from "@components/GridCell";
|
|
11
11
|
import { IFormTestRow } from "./FormTest";
|
|
12
|
-
import { wait } from "@utils/util";
|
|
12
|
+
import { isFloat, wait } from "@utils/util";
|
|
13
13
|
import { GridPopoverTextArea } from "@components/gridPopoverEdit/GridPopoverTextArea";
|
|
14
14
|
import { GridPopoverTextInput } from "@components/gridPopoverEdit/GridPopoverTextInput";
|
|
15
15
|
|
|
@@ -63,6 +63,30 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
|
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
65
|
}),
|
|
66
|
+
GridPopoverTextInput<IFormTestRow>({
|
|
67
|
+
field: "distance",
|
|
68
|
+
headerName: "Number input",
|
|
69
|
+
maxWidth: 140,
|
|
70
|
+
valueFormatter: (params) => {
|
|
71
|
+
const v = params.data.distance;
|
|
72
|
+
return v != null ? `${v}${params.colDef.cellEditorParams.units}` : v;
|
|
73
|
+
},
|
|
74
|
+
cellEditorParams: {
|
|
75
|
+
maxlength: 12,
|
|
76
|
+
placeholder: "Enter distance...",
|
|
77
|
+
units: "m",
|
|
78
|
+
validate: (value: string) => {
|
|
79
|
+
if (value.length && !isFloat(value)) return "Value must be a number";
|
|
80
|
+
return null;
|
|
81
|
+
},
|
|
82
|
+
multiEdit: false,
|
|
83
|
+
onSave: async (selectedRows, value) => {
|
|
84
|
+
await wait(1000);
|
|
85
|
+
selectedRows.forEach((selectedRow) => (selectedRow["distance"] = value.length ? parseFloat(value) : null));
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
66
90
|
GridPopoverTextArea<IFormTestRow>({
|
|
67
91
|
field: "plan",
|
|
68
92
|
headerName: "Text area",
|
|
@@ -90,8 +114,8 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
|
|
|
90
114
|
const rowData = useMemo(
|
|
91
115
|
() =>
|
|
92
116
|
[
|
|
93
|
-
{ id: 1000, name: "IS IS DP12345", nameType: "IS", numba: "IX", plan: "DP 12345" },
|
|
94
|
-
{ id: 1001, name: "PEG V SD523", nameType: "PEG", numba: "V", plan: "SD 523" },
|
|
117
|
+
{ id: 1000, name: "IS IS DP12345", nameType: "IS", numba: "IX", plan: "DP 12345", distance: 10 },
|
|
118
|
+
{ id: 1001, name: "PEG V SD523", nameType: "PEG", numba: "V", plan: "SD 523", distance: null },
|
|
95
119
|
] as IFormTestRow[],
|
|
96
120
|
[],
|
|
97
121
|
);
|