@linzjs/step-ag-grid 1.2.0 → 1.3.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "1.2.0",
5
+ "version": "1.3.0",
6
6
  "main": "dist/index.js",
7
7
  "typings": "dist/index.d.ts",
8
8
  "module": "dist/step-ag-grid.esm.js",
@@ -9,6 +9,7 @@ export interface GridFormTextAreaProps<RowType extends GridBaseRow> extends Gene
9
9
  required?: boolean;
10
10
  maxlength?: number;
11
11
  width?: string | number;
12
+ validate?: (value: string) => string | null;
12
13
  onSave?: (selectedRows: RowType[], value: string) => Promise<boolean>;
13
14
  }
14
15
 
@@ -23,6 +24,9 @@ export const GridFormTextArea = <RowType extends GridBaseRow>(props: GridFormPro
23
24
  if (formProps.maxlength && value.length > formProps.maxlength) {
24
25
  return `Text must be no longer than ${formProps.maxlength} characters`;
25
26
  }
27
+ if (formProps.validate) {
28
+ return formProps.validate(value);
29
+ }
26
30
  return null;
27
31
  }, [formProps.maxlength, formProps.required, value.length]);
28
32
 
@@ -9,6 +9,7 @@ export interface GridFormTextInputProps<RowType extends GridBaseRow> extends Gen
9
9
  required?: boolean;
10
10
  maxlength?: number;
11
11
  width?: string | number;
12
+ validate?: (value: string) => string | null;
12
13
  onSave?: (selectedRows: RowType[], value: string) => Promise<boolean>;
13
14
  }
14
15
 
@@ -23,6 +24,9 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormPr
23
24
  if (formProps.maxlength && value.length > formProps.maxlength) {
24
25
  return `Text must be no longer than ${formProps.maxlength} characters`;
25
26
  }
27
+ if (formProps.validate) {
28
+ return formProps.validate(value);
29
+ }
26
30
  return null;
27
31
  }, [formProps.maxlength, formProps.required, value.length]);
28
32
 
@@ -0,0 +1,20 @@
1
+ import { GridCell } from "../GridCell";
2
+ import { GridBaseRow } from "../Grid";
3
+ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
4
+ import { GridFormTextArea, GridFormTextAreaProps } from "../gridForm/GridFormTextArea";
5
+
6
+ export const GridPopoverTextArea = <RowType extends GridBaseRow>(
7
+ colDef: GenericCellColDef<RowType, GridFormTextAreaProps<RowType>>,
8
+ ) => {
9
+ return GridCell<RowType, GridFormTextAreaProps<RowType>>({
10
+ maxWidth: 260,
11
+ ...colDef,
12
+ ...(colDef?.cellEditorParams && {
13
+ cellEditorParams: {
14
+ width: 260,
15
+ ...colDef.cellEditorParams,
16
+ form: GridFormTextArea,
17
+ },
18
+ }),
19
+ });
20
+ };
@@ -0,0 +1,20 @@
1
+ import { GridCell } from "../GridCell";
2
+ import { GridBaseRow } from "../Grid";
3
+ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
4
+ import { GridFormTextInput, GridFormTextInputProps } from "../gridForm/GridFormTextInput";
5
+
6
+ export const GridPopoverTextInput = <RowType extends GridBaseRow>(
7
+ colDef: GenericCellColDef<RowType, GridFormTextInputProps<RowType>>,
8
+ ) => {
9
+ return GridCell<RowType, GridFormTextInputProps<RowType>>({
10
+ maxWidth: 140,
11
+ ...colDef,
12
+ ...(colDef?.cellEditorParams && {
13
+ cellEditorParams: {
14
+ width: 240,
15
+ ...colDef.cellEditorParams,
16
+ form: GridFormTextInput,
17
+ },
18
+ }),
19
+ });
20
+ };
@@ -12,6 +12,8 @@ import { IFormTestRow } from "./FormTest";
12
12
  import { GridFormTextArea, GridFormTextAreaProps } from "../../components/gridForm/GridFormTextArea";
13
13
  import { GridFormTextInput, GridFormTextInputProps } from "../../components/gridForm/GridFormTextInput";
14
14
  import { wait } from "../../utils/util";
15
+ import { GridPopoverTextArea } from "../../components/gridPopoverEdit/GridPopoverTextArea";
16
+ import { GridPopoverTextInput } from "../../components/gridPopoverEdit/GridPopoverTextInput";
15
17
 
16
18
  export default {
17
19
  title: "Components / Grids",
@@ -43,16 +45,18 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
43
45
  initialWidth: 65,
44
46
  maxWidth: 85,
45
47
  }),
46
- GridCell<IFormTestRow, GridFormTextInputProps<IFormTestRow>>({
48
+ GridPopoverTextInput<IFormTestRow>({
47
49
  field: "name",
48
50
  headerName: "Text input",
49
51
  maxWidth: 140,
50
52
  cellEditorParams: {
51
- form: GridFormTextInput,
52
53
  required: true,
53
54
  maxlength: 12,
54
55
  placeholder: "Enter some text...",
55
- width: 240,
56
+ validate: (value: string) => {
57
+ if (value === "never") return "The value 'never' is not allowed";
58
+ return null;
59
+ },
56
60
  multiEdit: false,
57
61
  onSave: async (selectedRows, value) => {
58
62
  await wait(1000);
@@ -61,17 +65,19 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
61
65
  },
62
66
  },
63
67
  }),
64
- GridCell<IFormTestRow, GridFormTextAreaProps<IFormTestRow>>({
68
+ GridPopoverTextArea<IFormTestRow>({
65
69
  field: "plan",
66
70
  headerName: "Text area",
67
71
  maxWidth: 140,
68
72
  cellEditorParams: {
69
- form: GridFormTextArea,
70
73
  required: true,
71
74
  maxlength: 32,
72
75
  placeholder: "Enter some text...",
73
- width: 260,
74
76
  multiEdit: true,
77
+ validate: (value: string) => {
78
+ if (value === "never") return "The value 'never' is not allowed";
79
+ return null;
80
+ },
75
81
  onSave: async (selectedRows, value) => {
76
82
  await wait(1000);
77
83
  selectedRows.forEach((selectedRow) => (selectedRow["plan"] = value));