@etsoo/materialui 1.1.5 → 1.1.7
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/lib/DnDList.d.ts +8 -4
- package/lib/DnDList.js +18 -12
- package/lib/OptionGroup.d.ts +5 -5
- package/lib/OptionGroup.js +13 -11
- package/package.json +5 -5
- package/src/DnDList.tsx +304 -300
- package/src/OptionGroup.tsx +275 -274
package/lib/DnDList.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { UniqueIdentifier } from
|
|
2
|
-
import { DataTypes } from
|
|
3
|
-
import { Theme } from
|
|
4
|
-
import React, { CSSProperties } from
|
|
1
|
+
import { UniqueIdentifier } from "@dnd-kit/core";
|
|
2
|
+
import { DataTypes } from "@etsoo/shared";
|
|
3
|
+
import { Theme } from "@mui/material";
|
|
4
|
+
import React, { CSSProperties } from "react";
|
|
5
5
|
/**
|
|
6
6
|
* DnD item default style
|
|
7
7
|
* @param index Item index
|
|
@@ -76,6 +76,10 @@ export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>> {
|
|
|
76
76
|
* Data change handler
|
|
77
77
|
*/
|
|
78
78
|
onChange?: (items: D[]) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Form data change handler
|
|
81
|
+
*/
|
|
82
|
+
onFormChange?: (items: D[]) => void;
|
|
79
83
|
/**
|
|
80
84
|
* Drag end handler
|
|
81
85
|
*/
|
package/lib/DnDList.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DndContext } from
|
|
2
|
-
import { SortableContext, useSortable, verticalListSortingStrategy } from
|
|
3
|
-
import { CSS } from
|
|
4
|
-
import { useTheme } from
|
|
5
|
-
import React from
|
|
1
|
+
import { DndContext } from "@dnd-kit/core";
|
|
2
|
+
import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
3
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
4
|
+
import { useTheme } from "@mui/material";
|
|
5
|
+
import React from "react";
|
|
6
6
|
function SortableItem(props) {
|
|
7
7
|
// Destruct
|
|
8
8
|
const { id, itemRenderer, style = {} } = props;
|
|
@@ -33,7 +33,7 @@ function SortableItem(props) {
|
|
|
33
33
|
*/
|
|
34
34
|
export const DnDItemStyle = (index, isDragging, theme) => ({
|
|
35
35
|
padding: theme.spacing(1),
|
|
36
|
-
zIndex: isDragging ? 1 :
|
|
36
|
+
zIndex: isDragging ? 1 : "auto",
|
|
37
37
|
background: isDragging
|
|
38
38
|
? theme.palette.primary.light
|
|
39
39
|
: index % 2 === 0
|
|
@@ -47,7 +47,7 @@ export const DnDItemStyle = (index, isDragging, theme) => ({
|
|
|
47
47
|
*/
|
|
48
48
|
export function DnDList(props) {
|
|
49
49
|
// Destruct
|
|
50
|
-
const { keyField, itemRenderer, labelField, mRef, onChange, onDragEnd } = props;
|
|
50
|
+
const { keyField, itemRenderer, labelField, mRef, onChange, onFormChange, onDragEnd } = props;
|
|
51
51
|
let getItemStyle = props.getItemStyle;
|
|
52
52
|
if (getItemStyle == null) {
|
|
53
53
|
// Theme
|
|
@@ -61,6 +61,8 @@ export function DnDList(props) {
|
|
|
61
61
|
// Possible to alter items with the handler
|
|
62
62
|
if (onChange)
|
|
63
63
|
onChange(newItems);
|
|
64
|
+
if (onFormChange)
|
|
65
|
+
onFormChange(newItems);
|
|
64
66
|
// Update state
|
|
65
67
|
setItems(newItems);
|
|
66
68
|
};
|
|
@@ -148,9 +150,13 @@ export function DnDList(props) {
|
|
|
148
150
|
React.useEffect(() => {
|
|
149
151
|
setItems(props.items);
|
|
150
152
|
}, [props.items]);
|
|
151
|
-
return (React.createElement(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
153
|
+
return (React.createElement("form", { onChange: () => {
|
|
154
|
+
if (onFormChange)
|
|
155
|
+
onFormChange(items);
|
|
156
|
+
} },
|
|
157
|
+
React.createElement(DndContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd },
|
|
158
|
+
React.createElement(SortableContext, { items: items, strategy: verticalListSortingStrategy }, items.map((item, index) => {
|
|
159
|
+
const id = item[keyField];
|
|
160
|
+
return (React.createElement(SortableItem, { id: id, key: id, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }));
|
|
161
|
+
})))));
|
|
156
162
|
}
|
package/lib/OptionGroup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from
|
|
2
|
-
import { FormControlProps } from
|
|
3
|
-
import React from
|
|
1
|
+
import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from "@etsoo/shared";
|
|
2
|
+
import { FormControlProps } from "@mui/material";
|
|
3
|
+
import React from "react";
|
|
4
4
|
/**
|
|
5
5
|
* OptionGroup methods ref
|
|
6
6
|
*/
|
|
@@ -14,7 +14,7 @@ export interface OptionGroupRef {
|
|
|
14
14
|
/**
|
|
15
15
|
* OptionGroup props
|
|
16
16
|
*/
|
|
17
|
-
export type OptionGroupProps<T extends object, D extends DataTypes.Keys<T>, L extends DataTypes.Keys<T, string>> = Omit<FormControlProps<
|
|
17
|
+
export type OptionGroupProps<T extends object, D extends DataTypes.Keys<T>, L extends DataTypes.Keys<T, string>> = Omit<FormControlProps<"fieldset">, "defaultValue"> & {
|
|
18
18
|
/**
|
|
19
19
|
* Default value
|
|
20
20
|
*/
|
|
@@ -66,7 +66,7 @@ export type OptionGroupProps<T extends object, D extends DataTypes.Keys<T>, L ex
|
|
|
66
66
|
/**
|
|
67
67
|
* Item size
|
|
68
68
|
*/
|
|
69
|
-
itemSize?:
|
|
69
|
+
itemSize?: "small" | "medium";
|
|
70
70
|
/**
|
|
71
71
|
* Helper text
|
|
72
72
|
*/
|
package/lib/OptionGroup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DataTypes, Utils } from
|
|
2
|
-
import { Box, Checkbox, FormControl, FormControlLabel, FormGroup, FormHelperText, InputLabel, Radio, RadioGroup, useTheme } from
|
|
3
|
-
import NotchedOutline from
|
|
4
|
-
import React from
|
|
1
|
+
import { DataTypes, Utils } from "@etsoo/shared";
|
|
2
|
+
import { Box, Checkbox, FormControl, FormControlLabel, FormGroup, FormHelperText, InputLabel, Radio, RadioGroup, useTheme } from "@mui/material";
|
|
3
|
+
import NotchedOutline from "@mui/material/OutlinedInput";
|
|
4
|
+
import React from "react";
|
|
5
5
|
/**
|
|
6
6
|
* OptionGroup
|
|
7
7
|
* @param props Props
|
|
@@ -10,7 +10,7 @@ import React from 'react';
|
|
|
10
10
|
export function OptionGroup(props) {
|
|
11
11
|
var _a;
|
|
12
12
|
// Destruct
|
|
13
|
-
const { getOptionLabel, defaultValue, idField =
|
|
13
|
+
const { getOptionLabel, defaultValue, idField = "id", label, labelField = "label", multiple = false, mRef, name, onValueChange, options, readOnly, row, itemSize, helperText, variant, required, fullWidth, ...rest } = props;
|
|
14
14
|
// Theme
|
|
15
15
|
const theme = useTheme();
|
|
16
16
|
// Get option value
|
|
@@ -75,16 +75,14 @@ export function OptionGroup(props) {
|
|
|
75
75
|
setValues(changedValues);
|
|
76
76
|
} })) : (React.createElement(Radio, { disabled: disabledIds === null || disabledIds === void 0 ? void 0 : disabledIds.includes(ov), size: itemSize, readOnly: readOnly }));
|
|
77
77
|
// Label
|
|
78
|
-
const label = getOptionLabel == null
|
|
79
|
-
? `${option[labelField]}`
|
|
80
|
-
: getOptionLabel(option);
|
|
78
|
+
const label = getOptionLabel == null ? `${option[labelField]}` : getOptionLabel(option);
|
|
81
79
|
// Value, convert to string
|
|
82
80
|
// Will fail when type is number
|
|
83
81
|
const value = getOptionValue(option);
|
|
84
82
|
return (React.createElement(FormControlLabel, { key: value, control: control, value: value, label: label }));
|
|
85
83
|
});
|
|
86
84
|
// Group
|
|
87
|
-
const group = multiple ? (React.createElement(FormGroup, { row: row }, list)) : (React.createElement(RadioGroup, { row: row, name: name, value: (_a = values[0]) !== null && _a !== void 0 ? _a :
|
|
85
|
+
const group = multiple ? (React.createElement(FormGroup, { row: row }, list)) : (React.createElement(RadioGroup, { row: row, name: name, value: (_a = values[0]) !== null && _a !== void 0 ? _a : "", onChange: (_event, value) => {
|
|
88
86
|
if (firstOptionValue == null)
|
|
89
87
|
return;
|
|
90
88
|
const typeValue = Utils.parseString(value, firstOptionValue);
|
|
@@ -94,9 +92,13 @@ export function OptionGroup(props) {
|
|
|
94
92
|
} }, list));
|
|
95
93
|
// Layout
|
|
96
94
|
return (React.createElement(React.Fragment, null,
|
|
97
|
-
React.createElement(FormControl, { component: "fieldset", ...rest },
|
|
95
|
+
React.createElement(FormControl, { component: "fieldset", fullWidth: fullWidth, ...rest },
|
|
98
96
|
label && (React.createElement(InputLabel, { required: required, variant: variant, shrink: true }, label)),
|
|
99
97
|
React.createElement(Box, { paddingLeft: 2, paddingY: "7px" }, group),
|
|
100
|
-
variant ===
|
|
98
|
+
variant === "outlined" && (React.createElement(NotchedOutline, { label: label && required ? label + " *" : label, notched: true, style: {
|
|
99
|
+
position: "absolute",
|
|
100
|
+
borderRadius: theme.shape.borderRadius,
|
|
101
|
+
width: fullWidth ? "100%" : "auto"
|
|
102
|
+
} }))),
|
|
101
103
|
helperText && React.createElement(FormHelperText, null, helperText)));
|
|
102
104
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"@emotion/css": "^11.10.5",
|
|
51
51
|
"@emotion/react": "^11.10.5",
|
|
52
52
|
"@emotion/styled": "^11.10.5",
|
|
53
|
-
"@etsoo/appscript": "^1.3.
|
|
54
|
-
"@etsoo/notificationbase": "^1.1.
|
|
55
|
-
"@etsoo/react": "^1.6.
|
|
56
|
-
"@etsoo/shared": "^1.1.
|
|
53
|
+
"@etsoo/appscript": "^1.3.58",
|
|
54
|
+
"@etsoo/notificationbase": "^1.1.23",
|
|
55
|
+
"@etsoo/react": "^1.6.41",
|
|
56
|
+
"@etsoo/shared": "^1.1.88",
|
|
57
57
|
"@mui/icons-material": "^5.11.0",
|
|
58
58
|
"@mui/material": "^5.11.4",
|
|
59
59
|
"@types/pica": "^9.0.1",
|