@etsoo/materialui 1.1.41 → 1.1.43

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.
@@ -0,0 +1,33 @@
1
+ import { GridCellModesModel, GridRowId, GridValidRowModel } from "@mui/x-data-grid";
2
+ import { DataGridProps } from "@mui/x-data-grid/models/props/DataGridProps";
3
+ import React from "react";
4
+ /**
5
+ * Data table selected cell params
6
+ */
7
+ export interface DataTableSelectedCellParams {
8
+ id: GridRowId;
9
+ field: string;
10
+ index: number;
11
+ }
12
+ /**
13
+ * Data table props
14
+ */
15
+ export type DataTableProps<R extends GridValidRowModel = any> = Omit<DataGridProps<R>, "disableColumnMenu"> & {
16
+ /**
17
+ * Cell selection handler
18
+ * @param params Params
19
+ * @returns Result
20
+ */
21
+ onCellSelection?: (params: DataTableSelectedCellParams) => void | false;
22
+ /**
23
+ * Toolbar creator
24
+ * @returns Toolbar
25
+ */
26
+ toolbarCreator?: (selectedCellParams: DataTableSelectedCellParams | null, setCellModesModel: React.Dispatch<React.SetStateAction<GridCellModesModel>>, cellModesModel: GridCellModesModel) => React.ReactElement;
27
+ };
28
+ /**
29
+ * Data table
30
+ * @param props Props
31
+ * @returns Component
32
+ */
33
+ export declare function DataTable<R extends GridValidRowModel = any>(props: DataTableProps<R>): JSX.Element;
@@ -0,0 +1,56 @@
1
+ import { DataGrid } from "@mui/x-data-grid";
2
+ import React from "react";
3
+ import { globalApp } from "./app/ReactApp";
4
+ /**
5
+ * Data table
6
+ * @param props Props
7
+ * @returns Component
8
+ */
9
+ export function DataTable(props) {
10
+ var _a;
11
+ // Destructor
12
+ const { localeText = {}, onCellSelection, toolbarCreator, ...rest } = props;
13
+ // Labels
14
+ const { noRows } = (_a = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("noRows")) !== null && _a !== void 0 ? _a : {};
15
+ if (noRows && !localeText.noRowsLabel)
16
+ localeText.noRowsLabel = noRows;
17
+ const [selectedCellParams, setSelectedCellParams] = React.useState(null);
18
+ const [cellModesModel, setCellModesModel] = React.useState({});
19
+ const handleCellFocus = React.useCallback((event) => {
20
+ // event.target is the element that triggered the event
21
+ // event.currentTarget is the element that the event listener is attached to
22
+ const cell = event.currentTarget;
23
+ const row = cell.parentElement;
24
+ if (row == null)
25
+ return;
26
+ const id = row.dataset.id;
27
+ const index = row.dataset.rowindex;
28
+ const field = cell.dataset.field;
29
+ if (id == null || index == null || field == null)
30
+ return;
31
+ const params = {
32
+ id,
33
+ field,
34
+ index: parseInt(index)
35
+ };
36
+ if (onCellSelection) {
37
+ if (onCellSelection(params) === false)
38
+ return;
39
+ }
40
+ setSelectedCellParams(params);
41
+ }, []);
42
+ return (React.createElement(DataGrid, { disableColumnMenu: true, hideFooter: true, localeText: localeText, cellModesModel: cellModesModel, onCellModesModelChange: (model) => setCellModesModel(model), components: {
43
+ Toolbar: toolbarCreator
44
+ ? ({ selectedCellParams, setCellModesModel, cellModesModel }) => toolbarCreator(selectedCellParams, setCellModesModel, cellModesModel)
45
+ : undefined
46
+ }, componentsProps: {
47
+ toolbar: {
48
+ selectedCellParams,
49
+ setCellModesModel,
50
+ cellModesModel
51
+ },
52
+ cell: {
53
+ onFocus: handleCellFocus
54
+ }
55
+ }, ...rest }));
56
+ }
@@ -11,11 +11,11 @@ export interface SwitchAntProps extends SwitchProps {
11
11
  /**
12
12
  * Start label
13
13
  */
14
- startLabel: string;
14
+ startLabel?: string;
15
15
  /**
16
16
  * End label
17
17
  */
18
- endLabel: string;
18
+ endLabel?: string;
19
19
  }
20
20
  /**
21
21
  * Ant style switch
@@ -0,0 +1,45 @@
1
+ import { FormControlProps } from "@mui/material";
2
+ import React from "react";
3
+ /**
4
+ * SwitchField props
5
+ */
6
+ export type SwitchFieldProps = Omit<FormControlProps<"fieldset">, "defaultValue"> & {
7
+ /**
8
+ * Helper text
9
+ */
10
+ helperText?: React.ReactNode;
11
+ /**
12
+ * Label
13
+ */
14
+ label?: string;
15
+ /**
16
+ * Checked
17
+ */
18
+ checked?: boolean;
19
+ /**
20
+ * Active color
21
+ */
22
+ activeColor?: string;
23
+ /**
24
+ * Start label
25
+ */
26
+ startLabel?: string;
27
+ /**
28
+ * End label
29
+ */
30
+ endLabel?: string;
31
+ /**
32
+ * Height in px
33
+ */
34
+ height?: number;
35
+ /**
36
+ * Value, default is true
37
+ */
38
+ value?: unknown;
39
+ };
40
+ /**
41
+ * SwitchField
42
+ * @param props Props
43
+ * @returns Component
44
+ */
45
+ export declare function SwitchField(props: SwitchFieldProps): JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { Box, FormControl, FormHelperText, InputLabel } from "@mui/material";
2
+ import NotchedOutline from "@mui/material/OutlinedInput";
3
+ import React from "react";
4
+ import { SwitchAnt } from "./SwitchAnt";
5
+ /**
6
+ * SwitchField
7
+ * @param props Props
8
+ * @returns Component
9
+ */
10
+ export function SwitchField(props) {
11
+ // Destruct
12
+ const { activeColor, startLabel, endLabel, value = true, fullWidth, height = 56, helperText, label, name, required, sx = {}, checked, variant = "outlined", ...rest } = props;
13
+ // Outlined
14
+ const outlined = variant === "outlined";
15
+ if (sx) {
16
+ Object.assign(sx, { height: outlined ? `${height}px` : undefined });
17
+ }
18
+ // Layout
19
+ return (React.createElement(React.Fragment, null,
20
+ React.createElement(FormControl, { component: "fieldset", fullWidth: fullWidth, sx: sx, ...rest },
21
+ label && (React.createElement(InputLabel, { required: required, variant: variant, shrink: true }, label)),
22
+ outlined && (React.createElement(NotchedOutline, { label: label && required ? label + " *" : label, notched: true, sx: {
23
+ cursor: "default",
24
+ position: "absolute",
25
+ width: fullWidth ? "100%" : "auto",
26
+ "& input": {
27
+ visibility: "hidden"
28
+ }
29
+ } })),
30
+ React.createElement(Box, { paddingLeft: 2, paddingY: "7px", position: outlined ? "absolute" : undefined },
31
+ React.createElement(SwitchAnt, { activeColor: activeColor, name: name, startLabel: startLabel, endLabel: endLabel, value: value, checked: checked }))),
32
+ helperText && React.createElement(FormHelperText, null, helperText)));
33
+ }
package/lib/index.d.ts CHANGED
@@ -38,6 +38,7 @@ export * from "./CustomFabProps";
38
38
  export * from "./DataGridEx";
39
39
  export * from "./DataGridRenderers";
40
40
  export * from "./DataSteps";
41
+ export * from "./DataTable";
41
42
  export * from "./DialogButton";
42
43
  export * from "./DnDList";
43
44
  export * from "./DraggablePaperComponent";
@@ -77,6 +78,7 @@ export * from "./SelectEx";
77
78
  export * from "./ShowDataComparison";
78
79
  export * from "./Switch";
79
80
  export * from "./SwitchAnt";
81
+ export * from "./SwitchField";
80
82
  export * from "./TabBox";
81
83
  export * from "./TableEx";
82
84
  export * from "./TextFieldEx";
package/lib/index.js CHANGED
@@ -38,6 +38,7 @@ export * from "./CustomFabProps";
38
38
  export * from "./DataGridEx";
39
39
  export * from "./DataGridRenderers";
40
40
  export * from "./DataSteps";
41
+ export * from "./DataTable";
41
42
  export * from "./DialogButton";
42
43
  export * from "./DnDList";
43
44
  export * from "./DraggablePaperComponent";
@@ -77,6 +78,7 @@ export * from "./SelectEx";
77
78
  export * from "./ShowDataComparison";
78
79
  export * from "./Switch";
79
80
  export * from "./SwitchAnt";
81
+ export * from "./SwitchField";
80
82
  export * from "./TabBox";
81
83
  export * from "./TableEx";
82
84
  export * from "./TextFieldEx";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.41",
3
+ "version": "1.1.43",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -56,6 +56,7 @@
56
56
  "@etsoo/shared": "^1.1.89",
57
57
  "@mui/icons-material": "^5.11.9",
58
58
  "@mui/material": "^5.11.10",
59
+ "@mui/x-data-grid": "^6.0.0-beta.5",
59
60
  "@types/pica": "^9.0.1",
60
61
  "@types/pulltorefreshjs": "^0.1.5",
61
62
  "@types/react": "^18.0.28",
@@ -0,0 +1,124 @@
1
+ import {
2
+ DataGrid,
3
+ GridCellModesModel,
4
+ GridRowId,
5
+ GridValidRowModel
6
+ } from "@mui/x-data-grid";
7
+ import { DataGridProps } from "@mui/x-data-grid/models/props/DataGridProps";
8
+ import React from "react";
9
+ import { globalApp } from "./app/ReactApp";
10
+
11
+ /**
12
+ * Data table selected cell params
13
+ */
14
+ export interface DataTableSelectedCellParams {
15
+ id: GridRowId;
16
+ field: string;
17
+ index: number;
18
+ }
19
+
20
+ /**
21
+ * Data table props
22
+ */
23
+ export type DataTableProps<R extends GridValidRowModel = any> = Omit<
24
+ DataGridProps<R>,
25
+ "disableColumnMenu"
26
+ > & {
27
+ /**
28
+ * Cell selection handler
29
+ * @param params Params
30
+ * @returns Result
31
+ */
32
+ onCellSelection?: (params: DataTableSelectedCellParams) => void | false;
33
+
34
+ /**
35
+ * Toolbar creator
36
+ * @returns Toolbar
37
+ */
38
+ toolbarCreator?: (
39
+ selectedCellParams: DataTableSelectedCellParams | null,
40
+ setCellModesModel: React.Dispatch<React.SetStateAction<GridCellModesModel>>,
41
+ cellModesModel: GridCellModesModel
42
+ ) => React.ReactElement;
43
+ };
44
+
45
+ /**
46
+ * Data table
47
+ * @param props Props
48
+ * @returns Component
49
+ */
50
+ export function DataTable<R extends GridValidRowModel = any>(
51
+ props: DataTableProps<R>
52
+ ) {
53
+ // Destructor
54
+ const { localeText = {}, onCellSelection, toolbarCreator, ...rest } = props;
55
+
56
+ // Labels
57
+ const { noRows } = globalApp?.getLabels("noRows") ?? {};
58
+ if (noRows && !localeText.noRowsLabel) localeText.noRowsLabel = noRows;
59
+
60
+ const [selectedCellParams, setSelectedCellParams] =
61
+ React.useState<DataTableSelectedCellParams | null>(null);
62
+
63
+ const [cellModesModel, setCellModesModel] =
64
+ React.useState<GridCellModesModel>({});
65
+
66
+ const handleCellFocus = React.useCallback(
67
+ (event: React.FocusEvent<HTMLDivElement>) => {
68
+ // event.target is the element that triggered the event
69
+ // event.currentTarget is the element that the event listener is attached to
70
+ const cell = event.currentTarget;
71
+ const row = cell.parentElement;
72
+ if (row == null) return;
73
+
74
+ const id = row.dataset.id;
75
+ const index = row.dataset.rowindex;
76
+ const field = cell.dataset.field;
77
+ if (id == null || index == null || field == null) return;
78
+
79
+ const params: DataTableSelectedCellParams = {
80
+ id,
81
+ field,
82
+ index: parseInt(index)
83
+ };
84
+
85
+ if (onCellSelection) {
86
+ if (onCellSelection(params) === false) return;
87
+ }
88
+
89
+ setSelectedCellParams(params);
90
+ },
91
+ []
92
+ );
93
+
94
+ return (
95
+ <DataGrid
96
+ disableColumnMenu
97
+ hideFooter
98
+ localeText={localeText}
99
+ cellModesModel={cellModesModel}
100
+ onCellModesModelChange={(model) => setCellModesModel(model)}
101
+ components={{
102
+ Toolbar: toolbarCreator
103
+ ? ({ selectedCellParams, setCellModesModel, cellModesModel }) =>
104
+ toolbarCreator(
105
+ selectedCellParams,
106
+ setCellModesModel,
107
+ cellModesModel
108
+ )
109
+ : undefined
110
+ }}
111
+ componentsProps={{
112
+ toolbar: {
113
+ selectedCellParams,
114
+ setCellModesModel,
115
+ cellModesModel
116
+ },
117
+ cell: {
118
+ onFocus: handleCellFocus
119
+ }
120
+ }}
121
+ {...rest}
122
+ />
123
+ );
124
+ }
package/src/SwitchAnt.tsx CHANGED
@@ -15,12 +15,12 @@ export interface SwitchAntProps extends SwitchProps {
15
15
  /**
16
16
  * Start label
17
17
  */
18
- startLabel: string;
18
+ startLabel?: string;
19
19
 
20
20
  /**
21
21
  * End label
22
22
  */
23
- endLabel: string;
23
+ endLabel?: string;
24
24
  }
25
25
 
26
26
  /**
@@ -0,0 +1,133 @@
1
+ import {
2
+ Box,
3
+ FormControl,
4
+ FormControlProps,
5
+ FormHelperText,
6
+ InputLabel
7
+ } from "@mui/material";
8
+ import NotchedOutline from "@mui/material/OutlinedInput";
9
+ import React from "react";
10
+ import { SwitchAnt } from "./SwitchAnt";
11
+
12
+ /**
13
+ * SwitchField props
14
+ */
15
+ export type SwitchFieldProps = Omit<
16
+ FormControlProps<"fieldset">,
17
+ "defaultValue"
18
+ > & {
19
+ /**
20
+ * Helper text
21
+ */
22
+ helperText?: React.ReactNode;
23
+
24
+ /**
25
+ * Label
26
+ */
27
+ label?: string;
28
+
29
+ /**
30
+ * Checked
31
+ */
32
+ checked?: boolean;
33
+
34
+ /**
35
+ * Active color
36
+ */
37
+ activeColor?: string;
38
+
39
+ /**
40
+ * Start label
41
+ */
42
+ startLabel?: string;
43
+
44
+ /**
45
+ * End label
46
+ */
47
+ endLabel?: string;
48
+
49
+ /**
50
+ * Height in px
51
+ */
52
+ height?: number;
53
+
54
+ /**
55
+ * Value, default is true
56
+ */
57
+ value?: unknown;
58
+ };
59
+
60
+ /**
61
+ * SwitchField
62
+ * @param props Props
63
+ * @returns Component
64
+ */
65
+ export function SwitchField(props: SwitchFieldProps) {
66
+ // Destruct
67
+ const {
68
+ activeColor,
69
+ startLabel,
70
+ endLabel,
71
+ value = true,
72
+
73
+ fullWidth,
74
+ height = 56,
75
+ helperText,
76
+ label,
77
+ name,
78
+ required,
79
+ sx = {},
80
+ checked,
81
+ variant = "outlined",
82
+ ...rest
83
+ } = props;
84
+
85
+ // Outlined
86
+ const outlined = variant === "outlined";
87
+
88
+ if (sx) {
89
+ Object.assign(sx, { height: outlined ? `${height}px` : undefined });
90
+ }
91
+
92
+ // Layout
93
+ return (
94
+ <React.Fragment>
95
+ <FormControl component="fieldset" fullWidth={fullWidth} sx={sx} {...rest}>
96
+ {label && (
97
+ <InputLabel required={required} variant={variant} shrink>
98
+ {label}
99
+ </InputLabel>
100
+ )}
101
+ {outlined && (
102
+ <NotchedOutline
103
+ label={label && required ? label + " *" : label}
104
+ notched
105
+ sx={{
106
+ cursor: "default",
107
+ position: "absolute",
108
+ width: fullWidth ? "100%" : "auto",
109
+ "& input": {
110
+ visibility: "hidden"
111
+ }
112
+ }}
113
+ />
114
+ )}
115
+ <Box
116
+ paddingLeft={2}
117
+ paddingY="7px"
118
+ position={outlined ? "absolute" : undefined}
119
+ >
120
+ <SwitchAnt
121
+ activeColor={activeColor}
122
+ name={name}
123
+ startLabel={startLabel}
124
+ endLabel={endLabel}
125
+ value={value}
126
+ checked={checked}
127
+ />
128
+ </Box>
129
+ </FormControl>
130
+ {helperText && <FormHelperText>{helperText}</FormHelperText>}
131
+ </React.Fragment>
132
+ );
133
+ }
package/src/index.ts CHANGED
@@ -41,6 +41,7 @@ export * from "./CustomFabProps";
41
41
  export * from "./DataGridEx";
42
42
  export * from "./DataGridRenderers";
43
43
  export * from "./DataSteps";
44
+ export * from "./DataTable";
44
45
  export * from "./DialogButton";
45
46
  export * from "./DnDList";
46
47
  export * from "./DraggablePaperComponent";
@@ -80,6 +81,7 @@ export * from "./SelectEx";
80
81
  export * from "./ShowDataComparison";
81
82
  export * from "./Switch";
82
83
  export * from "./SwitchAnt";
84
+ export * from "./SwitchField";
83
85
  export * from "./TabBox";
84
86
  export * from "./TableEx";
85
87
  export * from "./TextFieldEx";