@linzjs/step-ag-grid 4.0.1 → 4.0.2
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 +23 -19
- package/dist/index.js.map +1 -1
- package/dist/src/components/gridForm/GridFormSubComponentTextArea.d.ts +3 -2
- package/dist/src/components/gridForm/GridFormSubComponentTextInput.d.ts +3 -2
- 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 +1 -0
- package/dist/src/utils/textValidator.d.ts +4 -3
- package/dist/step-ag-grid.esm.js +23 -19
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/gridForm/GridFormDropDown.tsx +2 -1
- package/src/components/gridForm/GridFormMultiSelect.tsx +2 -1
- package/src/components/gridForm/GridFormPopoverMenu.tsx +2 -1
- package/src/components/gridForm/GridFormSubComponentTextArea.tsx +9 -4
- package/src/components/gridForm/GridFormSubComponentTextInput.tsx +9 -4
- package/src/components/gridForm/GridFormTextArea.tsx +5 -3
- package/src/components/gridForm/GridFormTextInput.tsx +5 -3
- package/src/contexts/GridSubComponentContext.ts +2 -0
- package/src/utils/textValidator.ts +10 -4
package/package.json
CHANGED
|
@@ -64,7 +64,7 @@ const fieldToString = (field: any) => {
|
|
|
64
64
|
export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
|
|
65
65
|
props: GridFormPopoutDropDownProps<RowType, ValueType>,
|
|
66
66
|
) => {
|
|
67
|
-
const { selectedRows, field, updateValue } = useGridPopoverContext<RowType>();
|
|
67
|
+
const { selectedRows, field, updateValue, data } = useGridPopoverContext<RowType>();
|
|
68
68
|
const { stopEditing } = useContext(GridContext);
|
|
69
69
|
|
|
70
70
|
const [filter, setFilter] = useState("");
|
|
@@ -266,6 +266,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
|
|
|
266
266
|
{(ref: MenuInstance) => (
|
|
267
267
|
<GridSubComponentContext.Provider
|
|
268
268
|
value={{
|
|
269
|
+
data,
|
|
269
270
|
value: subSelectedValue,
|
|
270
271
|
setValue: (value: any) => {
|
|
271
272
|
setSubSelectedValue(value);
|
|
@@ -45,7 +45,7 @@ export interface GridFormMultiSelectProps<RowType extends GridBaseRow, ValueType
|
|
|
45
45
|
export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
|
|
46
46
|
props: GridFormMultiSelectProps<RowType, ValueType>,
|
|
47
47
|
) => {
|
|
48
|
-
const { selectedRows } = useGridPopoverContext<RowType>();
|
|
48
|
+
const { selectedRows, data } = useGridPopoverContext<RowType>();
|
|
49
49
|
|
|
50
50
|
const initialiseValues = useMemo(() => {
|
|
51
51
|
const r = props.initialSelectedValues && props.initialSelectedValues(selectedRows);
|
|
@@ -214,6 +214,7 @@ export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
|
|
|
214
214
|
item.subComponent && (
|
|
215
215
|
<GridSubComponentContext.Provider
|
|
216
216
|
value={{
|
|
217
|
+
data,
|
|
217
218
|
value: selectedValues[`${item.value}`],
|
|
218
219
|
setValue: (value: any) => {
|
|
219
220
|
setSelectedValues({
|
|
@@ -38,7 +38,7 @@ export interface MenuOption<RowType extends GridBaseRow> {
|
|
|
38
38
|
* you need a useMemo around your columnDefs
|
|
39
39
|
*/
|
|
40
40
|
export const GridFormPopoverMenu = <RowType extends GridBaseRow>(props: GridFormPopoutMenuProps<RowType>) => {
|
|
41
|
-
const { selectedRows, updateValue } = useGridPopoverContext<RowType>();
|
|
41
|
+
const { selectedRows, updateValue, data } = useGridPopoverContext<RowType>();
|
|
42
42
|
|
|
43
43
|
const optionsInitialising = useRef(false);
|
|
44
44
|
const [options, setOptions] = useState<MenuOption<RowType>[]>();
|
|
@@ -148,6 +148,7 @@ export const GridFormPopoverMenu = <RowType extends GridBaseRow>(props: GridForm
|
|
|
148
148
|
item.subComponent && (
|
|
149
149
|
<GridSubComponentContext.Provider
|
|
150
150
|
value={{
|
|
151
|
+
data,
|
|
151
152
|
value: subSelectedValue,
|
|
152
153
|
setValue: (value: any) => {
|
|
153
154
|
setSubSelectedValue(value);
|
|
@@ -4,8 +4,11 @@ import { CellEditorCommon } from "../GridCell";
|
|
|
4
4
|
import clsx from "clsx";
|
|
5
5
|
import { TextAreaInput } from "../../lui/TextAreaInput";
|
|
6
6
|
import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
|
|
7
|
+
import { GridBaseRow } from "../Grid";
|
|
7
8
|
|
|
8
|
-
export interface GridSubComponentTextAreaProps extends
|
|
9
|
+
export interface GridSubComponentTextAreaProps<RowType extends GridBaseRow>
|
|
10
|
+
extends TextInputValidatorProps<RowType>,
|
|
11
|
+
CellEditorCommon {
|
|
9
12
|
placeholder?: string;
|
|
10
13
|
width?: string | number;
|
|
11
14
|
defaultValue: string;
|
|
@@ -13,8 +16,10 @@ export interface GridSubComponentTextAreaProps extends TextInputValidatorProps,
|
|
|
13
16
|
helpText?: string;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
export const GridFormSubComponentTextArea =
|
|
17
|
-
|
|
19
|
+
export const GridFormSubComponentTextArea = <RowType extends GridBaseRow>(
|
|
20
|
+
props: GridSubComponentTextAreaProps<RowType>,
|
|
21
|
+
): JSX.Element => {
|
|
22
|
+
const { value, data, setValue, setValid, triggerSave } = useContext(GridSubComponentContext);
|
|
18
23
|
|
|
19
24
|
const helpText = props.helpText ?? "Press tab to save";
|
|
20
25
|
|
|
@@ -23,7 +28,7 @@ export const GridFormSubComponentTextArea = (props: GridSubComponentTextAreaProp
|
|
|
23
28
|
if (value == null) setValue(props.defaultValue);
|
|
24
29
|
}, [props.defaultValue, setValue, value]);
|
|
25
30
|
|
|
26
|
-
const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
|
|
31
|
+
const invalid = useCallback(() => TextInputValidator(props, value, data), [data, props, value]);
|
|
27
32
|
|
|
28
33
|
useEffect(() => {
|
|
29
34
|
setValid(value != null && invalid() == null);
|
|
@@ -3,16 +3,21 @@ import { GridSubComponentContext } from "../../contexts/GridSubComponentContext"
|
|
|
3
3
|
import { TextInputFormatted } from "../../lui/TextInputFormatted";
|
|
4
4
|
import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
|
|
5
5
|
import { CellEditorCommon } from "../GridCell";
|
|
6
|
+
import { GridBaseRow } from "../Grid";
|
|
6
7
|
|
|
7
|
-
export interface GridFormSubComponentTextInputProps extends
|
|
8
|
+
export interface GridFormSubComponentTextInputProps<RowType extends GridBaseRow>
|
|
9
|
+
extends TextInputValidatorProps<RowType>,
|
|
10
|
+
CellEditorCommon {
|
|
8
11
|
placeholder?: string;
|
|
9
12
|
width?: string | number;
|
|
10
13
|
defaultValue: string;
|
|
11
14
|
helpText?: string;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
export const GridFormSubComponentTextInput =
|
|
15
|
-
|
|
17
|
+
export const GridFormSubComponentTextInput = <RowType extends GridBaseRow>(
|
|
18
|
+
props: GridFormSubComponentTextInputProps<RowType>,
|
|
19
|
+
): JSX.Element => {
|
|
20
|
+
const { value, setValue, setValid, triggerSave, data } = useContext(GridSubComponentContext);
|
|
16
21
|
|
|
17
22
|
const helpText = props.helpText ?? "Press enter or tab to save";
|
|
18
23
|
|
|
@@ -21,7 +26,7 @@ export const GridFormSubComponentTextInput = (props: GridFormSubComponentTextInp
|
|
|
21
26
|
if (value == null) setValue(props.defaultValue);
|
|
22
27
|
}, [props.defaultValue, setValue, value]);
|
|
23
28
|
|
|
24
|
-
const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
|
|
29
|
+
const invalid = useCallback(() => TextInputValidator(props, value, data), [data, props, value]);
|
|
25
30
|
|
|
26
31
|
useEffect(() => {
|
|
27
32
|
setValid(value != null && invalid() == null);
|
|
@@ -6,7 +6,9 @@ import { CellEditorCommon } from "../GridCell";
|
|
|
6
6
|
import { useGridPopoverContext } from "../../contexts/GridPopoverContext";
|
|
7
7
|
import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
|
|
8
8
|
|
|
9
|
-
export interface GridFormTextAreaProps<RowType extends GridBaseRow>
|
|
9
|
+
export interface GridFormTextAreaProps<RowType extends GridBaseRow>
|
|
10
|
+
extends TextInputValidatorProps<RowType>,
|
|
11
|
+
CellEditorCommon {
|
|
10
12
|
placeholder?: string;
|
|
11
13
|
width?: string | number;
|
|
12
14
|
onSave?: (selectedRows: RowType[], value: string) => Promise<boolean>;
|
|
@@ -14,12 +16,12 @@ export interface GridFormTextAreaProps<RowType extends GridBaseRow> extends Text
|
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export const GridFormTextArea = <RowType extends GridBaseRow>(props: GridFormTextAreaProps<RowType>) => {
|
|
17
|
-
const { field, value: initialVale } = useGridPopoverContext<RowType>();
|
|
19
|
+
const { field, value: initialVale, data } = useGridPopoverContext<RowType>();
|
|
18
20
|
const [value, setValue] = useState(initialVale != null ? `${initialVale}` : "");
|
|
19
21
|
|
|
20
22
|
const helpText = props.helpText ?? "Press tab to save";
|
|
21
23
|
|
|
22
|
-
const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
|
|
24
|
+
const invalid = useCallback(() => TextInputValidator(props, value, data), [props, value, data]);
|
|
23
25
|
|
|
24
26
|
const save = useCallback(
|
|
25
27
|
async (selectedRows: RowType[]): Promise<boolean> => {
|
|
@@ -6,7 +6,9 @@ import { CellEditorCommon } from "../GridCell";
|
|
|
6
6
|
import { useGridPopoverContext } from "../../contexts/GridPopoverContext";
|
|
7
7
|
import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
|
|
8
8
|
|
|
9
|
-
export interface GridFormTextInputProps<RowType extends GridBaseRow>
|
|
9
|
+
export interface GridFormTextInputProps<RowType extends GridBaseRow>
|
|
10
|
+
extends TextInputValidatorProps<RowType>,
|
|
11
|
+
CellEditorCommon {
|
|
10
12
|
placeholder?: string;
|
|
11
13
|
units?: string;
|
|
12
14
|
width?: string | number;
|
|
@@ -15,14 +17,14 @@ export interface GridFormTextInputProps<RowType extends GridBaseRow> extends Tex
|
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormTextInputProps<RowType>) => {
|
|
18
|
-
const { field, value: initialVale } = useGridPopoverContext<RowType>();
|
|
20
|
+
const { field, value: initialVale, data } = useGridPopoverContext<RowType>();
|
|
19
21
|
|
|
20
22
|
const helpText = props.helpText ?? "Press enter or tab to save";
|
|
21
23
|
|
|
22
24
|
const initValue = initialVale == null ? "" : `${initialVale}`;
|
|
23
25
|
const [value, setValue] = useState(initValue);
|
|
24
26
|
|
|
25
|
-
const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
|
|
27
|
+
const invalid = useCallback(() => TextInputValidator<RowType>(props, value, data), [data, props, value]);
|
|
26
28
|
|
|
27
29
|
const save = useCallback(
|
|
28
30
|
async (selectedRows: RowType[]): Promise<boolean> => {
|
|
@@ -2,6 +2,7 @@ import { createContext } from "react";
|
|
|
2
2
|
|
|
3
3
|
export interface GridSubComponentContextType {
|
|
4
4
|
value: any;
|
|
5
|
+
data: any;
|
|
5
6
|
setValue: (value: string) => void;
|
|
6
7
|
setValid: (valid: boolean) => void;
|
|
7
8
|
triggerSave: () => Promise<void>;
|
|
@@ -9,6 +10,7 @@ export interface GridSubComponentContextType {
|
|
|
9
10
|
|
|
10
11
|
export const GridSubComponentContext = createContext<GridSubComponentContextType>({
|
|
11
12
|
value: "GridSubComponentContext value no context",
|
|
13
|
+
data: {},
|
|
12
14
|
setValue: () => {
|
|
13
15
|
console.error("GridSubComponentContext setValue no context");
|
|
14
16
|
},
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { GridBaseRow } from "../components/Grid";
|
|
2
|
+
|
|
3
|
+
export interface TextInputValidatorProps<RowType extends GridBaseRow> {
|
|
2
4
|
required?: boolean;
|
|
3
5
|
maxLength?: number;
|
|
4
|
-
validate?: (value: string) => string | null;
|
|
6
|
+
validate?: (value: string, data: RowType) => string | null;
|
|
5
7
|
}
|
|
6
8
|
|
|
7
|
-
export const TextInputValidator =
|
|
9
|
+
export const TextInputValidator = <RowType extends GridBaseRow>(
|
|
10
|
+
props: TextInputValidatorProps<RowType>,
|
|
11
|
+
value: string | null,
|
|
12
|
+
data: RowType,
|
|
13
|
+
) => {
|
|
8
14
|
if (value == null) return null;
|
|
9
15
|
|
|
10
16
|
// This can happen because subcomponent is invoked without type safety
|
|
@@ -18,7 +24,7 @@ export const TextInputValidator = (props: TextInputValidatorProps, value: string
|
|
|
18
24
|
return `Text must be no longer than ${props.maxLength} characters`;
|
|
19
25
|
}
|
|
20
26
|
if (props.validate) {
|
|
21
|
-
return props.validate(value);
|
|
27
|
+
return props.validate(value, data);
|
|
22
28
|
}
|
|
23
29
|
return null;
|
|
24
30
|
};
|