@etsoo/materialui 1.5.50 → 1.5.52

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.
@@ -20,6 +20,7 @@ const TextField_1 = __importDefault(require("@mui/material/TextField"));
20
20
  const DnDList_1 = require("./DnDList");
21
21
  const FlexBox_1 = require("./FlexBox");
22
22
  const ReactApp_1 = require("./app/ReactApp");
23
+ const FormLabel_1 = __importDefault(require("@mui/material/FormLabel"));
23
24
  function ButtonPopupList(props) {
24
25
  // Destruct
25
26
  const { addSplitter = /\s*[,;]\s*/, ids = [], items, labelField, labelFormatter, labels, onAdd, onValueChange } = props;
@@ -72,12 +73,12 @@ function ButtonPopupCheckbox(props) {
72
73
  // App
73
74
  const app = (0, ReactApp_1.useRequiredAppContext)();
74
75
  // Destruct
75
- const { addSplitter, ids, inputName, label, labelEnd, labelFormatter = (data) => {
76
+ const { addSplitter, ids = [], inputName, label, labelEnd, labelFormatter = (data) => {
76
77
  if (labelField in data) {
77
78
  return data[labelField];
78
79
  }
79
80
  return data.id.toString();
80
- }, labelField, labels = {}, loadData, onAdd, onValueChange, popupTitle = label, popupMessage, required = false, sx = { gap: 1, justifyContent: "flex-start" }, variant = "outlined", ...rest } = props;
81
+ }, labelField, labels = {}, loadData, onAdd, onValueChange, popupTitle = label, popupMessage, required = false, sx = { gap: 1, justifyContent: "flex-start", minHeight: "56px" }, variant = "outlined", ...rest } = props;
81
82
  // Default labels
82
83
  if (!labels.add)
83
84
  labels.add = app.get("add");
@@ -120,7 +121,7 @@ function ButtonPopupCheckbox(props) {
120
121
  fullScreen: app.smDown
121
122
  });
122
123
  };
123
- return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { type: "text", style: { position: "absolute", opacity: 0, width: 0 }, name: inputName, required: required, defaultValue: selectedIds?.join(",") }), (0, jsx_runtime_1.jsxs)(Button_1.default, { variant: variant, sx: sx, onClick: () => clickHandler(), ...rest, disabled: !items || items.length === 0, children: [label && (0, jsx_runtime_1.jsxs)(Typography_1.default, { variant: "body2", children: [label, ":"] }), selectedIds?.map((id) => {
124
+ return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { type: "text", style: { position: "absolute", opacity: 0, width: 0 }, name: inputName, required: required, defaultValue: selectedIds?.join(",") }), (0, jsx_runtime_1.jsxs)(Button_1.default, { variant: variant, sx: sx, onClick: () => clickHandler(), ...rest, disabled: !items || items.length === 0, children: [label && ((0, jsx_runtime_1.jsx)(FormLabel_1.default, { required: required, sx: { fontSize: (theme) => theme.typography.body2.fontSize }, children: label })), selectedIds?.map((id) => {
124
125
  const item = items.find((item) => item.id === id);
125
126
  if (item == null)
126
127
  return null;
@@ -1,6 +1,13 @@
1
1
  import React from "react";
2
2
  import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from "@etsoo/shared";
3
3
  import { SelectProps, SelectVariants } from "@mui/material/Select";
4
+ export type SelectExMethods = {
5
+ /**
6
+ * Set open state
7
+ * @param isOpen Open state
8
+ */
9
+ setOpen: (isOpen: boolean) => void;
10
+ };
4
11
  /**
5
12
  * Extended select component props
6
13
  */
@@ -37,6 +44,10 @@ export type SelectExProps<T extends object, D extends DataTypes.Keys<T> = IdDefa
37
44
  * Load data callback
38
45
  */
39
46
  loadData?: () => PromiseLike<T[] | null | undefined>;
47
+ /**
48
+ * Methods
49
+ */
50
+ mRef?: React.Ref<SelectExMethods>;
40
51
  /**
41
52
  * Item change callback
42
53
  */
@@ -28,7 +28,7 @@ const Refresh_1 = __importDefault(require("@mui/icons-material/Refresh"));
28
28
  */
29
29
  function SelectEx(props) {
30
30
  // Destruct
31
- const { defaultValue, idField = "id", error, helperText, inputReset, itemIconRenderer, itemStyle, label, labelField = "label", loadData, onItemChange, onItemClick, onLoadData, multiple = false, name, options, refresh, search = false, autoAddBlankItem = search, value, onChange, fullWidth, required, variant = "outlined", ...rest } = props;
31
+ const { defaultValue, idField = "id", error, helperText, inputReset, itemIconRenderer, itemStyle, label, labelField = "label", loadData, mRef, onItemChange, onItemClick, onLoadData, multiple = false, name, options, refresh, search = false, autoAddBlankItem = search, value, onChange, fullWidth, required, variant = "outlined", ...rest } = props;
32
32
  // Options state
33
33
  const [localOptions, setOptions] = react_1.default.useState([]);
34
34
  const isMounted = react_1.default.useRef(false);
@@ -74,6 +74,12 @@ function SelectEx(props) {
74
74
  valueRef.current = newValue;
75
75
  setValueStateBase(newValue);
76
76
  };
77
+ const [open, setOpen] = react_1.default.useState(false);
78
+ react_1.default.useImperativeHandle(mRef, () => ({
79
+ setOpen: (isOpen) => {
80
+ setOpen(isOpen);
81
+ }
82
+ }), []);
77
83
  react_1.default.useEffect(() => {
78
84
  if (valueSource != null)
79
85
  setValueState(valueSource);
@@ -145,7 +151,10 @@ function SelectEx(props) {
145
151
  ? valueState
146
152
  : localOptions.some((o) => o[idField] === valueState)
147
153
  ? valueState
148
- : "", input: (0, jsx_runtime_1.jsx)(OutlinedInput_1.default, { notched: true, label: label, required: required, inputProps: { "data-reset": inputReset } }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
154
+ : "", input: (0, jsx_runtime_1.jsx)(OutlinedInput_1.default, { notched: true, label: label, required: required, inputProps: {
155
+ "aria-hidden": false,
156
+ "data-reset": inputReset
157
+ } }), open: open, onClose: () => setOpen(false), onOpen: () => setOpen(true), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
149
158
  if (onChange) {
150
159
  onChange(event, child);
151
160
  // event.preventDefault() will block executing
@@ -14,6 +14,7 @@ import TextField from "@mui/material/TextField";
14
14
  import { DnDList } from "./DnDList";
15
15
  import { HBox, VBox } from "./FlexBox";
16
16
  import { useRequiredAppContext } from "./app/ReactApp";
17
+ import FormLabel from "@mui/material/FormLabel";
17
18
  function ButtonPopupList(props) {
18
19
  // Destruct
19
20
  const { addSplitter = /\s*[,;]\s*/, ids = [], items, labelField, labelFormatter, labels, onAdd, onValueChange } = props;
@@ -66,12 +67,12 @@ export function ButtonPopupCheckbox(props) {
66
67
  // App
67
68
  const app = useRequiredAppContext();
68
69
  // Destruct
69
- const { addSplitter, ids, inputName, label, labelEnd, labelFormatter = (data) => {
70
+ const { addSplitter, ids = [], inputName, label, labelEnd, labelFormatter = (data) => {
70
71
  if (labelField in data) {
71
72
  return data[labelField];
72
73
  }
73
74
  return data.id.toString();
74
- }, labelField, labels = {}, loadData, onAdd, onValueChange, popupTitle = label, popupMessage, required = false, sx = { gap: 1, justifyContent: "flex-start" }, variant = "outlined", ...rest } = props;
75
+ }, labelField, labels = {}, loadData, onAdd, onValueChange, popupTitle = label, popupMessage, required = false, sx = { gap: 1, justifyContent: "flex-start", minHeight: "56px" }, variant = "outlined", ...rest } = props;
75
76
  // Default labels
76
77
  if (!labels.add)
77
78
  labels.add = app.get("add");
@@ -114,7 +115,7 @@ export function ButtonPopupCheckbox(props) {
114
115
  fullScreen: app.smDown
115
116
  });
116
117
  };
117
- return (_jsxs(React.Fragment, { children: [_jsx("input", { type: "text", style: { position: "absolute", opacity: 0, width: 0 }, name: inputName, required: required, defaultValue: selectedIds?.join(",") }), _jsxs(Button, { variant: variant, sx: sx, onClick: () => clickHandler(), ...rest, disabled: !items || items.length === 0, children: [label && _jsxs(Typography, { variant: "body2", children: [label, ":"] }), selectedIds?.map((id) => {
118
+ return (_jsxs(React.Fragment, { children: [_jsx("input", { type: "text", style: { position: "absolute", opacity: 0, width: 0 }, name: inputName, required: required, defaultValue: selectedIds?.join(",") }), _jsxs(Button, { variant: variant, sx: sx, onClick: () => clickHandler(), ...rest, disabled: !items || items.length === 0, children: [label && (_jsx(FormLabel, { required: required, sx: { fontSize: (theme) => theme.typography.body2.fontSize }, children: label })), selectedIds?.map((id) => {
118
119
  const item = items.find((item) => item.id === id);
119
120
  if (item == null)
120
121
  return null;
@@ -1,6 +1,13 @@
1
1
  import React from "react";
2
2
  import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from "@etsoo/shared";
3
3
  import { SelectProps, SelectVariants } from "@mui/material/Select";
4
+ export type SelectExMethods = {
5
+ /**
6
+ * Set open state
7
+ * @param isOpen Open state
8
+ */
9
+ setOpen: (isOpen: boolean) => void;
10
+ };
4
11
  /**
5
12
  * Extended select component props
6
13
  */
@@ -37,6 +44,10 @@ export type SelectExProps<T extends object, D extends DataTypes.Keys<T> = IdDefa
37
44
  * Load data callback
38
45
  */
39
46
  loadData?: () => PromiseLike<T[] | null | undefined>;
47
+ /**
48
+ * Methods
49
+ */
50
+ mRef?: React.Ref<SelectExMethods>;
40
51
  /**
41
52
  * Item change callback
42
53
  */
@@ -22,7 +22,7 @@ import RefreshIcon from "@mui/icons-material/Refresh";
22
22
  */
23
23
  export function SelectEx(props) {
24
24
  // Destruct
25
- const { defaultValue, idField = "id", error, helperText, inputReset, itemIconRenderer, itemStyle, label, labelField = "label", loadData, onItemChange, onItemClick, onLoadData, multiple = false, name, options, refresh, search = false, autoAddBlankItem = search, value, onChange, fullWidth, required, variant = "outlined", ...rest } = props;
25
+ const { defaultValue, idField = "id", error, helperText, inputReset, itemIconRenderer, itemStyle, label, labelField = "label", loadData, mRef, onItemChange, onItemClick, onLoadData, multiple = false, name, options, refresh, search = false, autoAddBlankItem = search, value, onChange, fullWidth, required, variant = "outlined", ...rest } = props;
26
26
  // Options state
27
27
  const [localOptions, setOptions] = React.useState([]);
28
28
  const isMounted = React.useRef(false);
@@ -68,6 +68,12 @@ export function SelectEx(props) {
68
68
  valueRef.current = newValue;
69
69
  setValueStateBase(newValue);
70
70
  };
71
+ const [open, setOpen] = React.useState(false);
72
+ React.useImperativeHandle(mRef, () => ({
73
+ setOpen: (isOpen) => {
74
+ setOpen(isOpen);
75
+ }
76
+ }), []);
71
77
  React.useEffect(() => {
72
78
  if (valueSource != null)
73
79
  setValueState(valueSource);
@@ -139,7 +145,10 @@ export function SelectEx(props) {
139
145
  ? valueState
140
146
  : localOptions.some((o) => o[idField] === valueState)
141
147
  ? valueState
142
- : "", input: _jsx(OutlinedInput, { notched: true, label: label, required: required, inputProps: { "data-reset": inputReset } }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
148
+ : "", input: _jsx(OutlinedInput, { notched: true, label: label, required: required, inputProps: {
149
+ "aria-hidden": false,
150
+ "data-reset": inputReset
151
+ } }), open: open, onClose: () => setOpen(false), onOpen: () => setOpen(true), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
143
152
  if (onChange) {
144
153
  onChange(event, child);
145
154
  // event.preventDefault() will block executing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.5.50",
3
+ "version": "1.5.52",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -14,6 +14,7 @@ import TextField from "@mui/material/TextField";
14
14
  import { DnDList, DnDListRef } from "./DnDList";
15
15
  import { HBox, VBox } from "./FlexBox";
16
16
  import { useRequiredAppContext } from "./app/ReactApp";
17
+ import FormLabel from "@mui/material/FormLabel";
17
18
 
18
19
  type DnDItemType = {
19
20
  id: IdType;
@@ -261,7 +262,7 @@ export function ButtonPopupCheckbox<D extends DnDItemType>(
261
262
  // Destruct
262
263
  const {
263
264
  addSplitter,
264
- ids,
265
+ ids = [],
265
266
  inputName,
266
267
  label,
267
268
  labelEnd,
@@ -280,7 +281,7 @@ export function ButtonPopupCheckbox<D extends DnDItemType>(
280
281
  popupTitle = label,
281
282
  popupMessage,
282
283
  required = false,
283
- sx = { gap: 1, justifyContent: "flex-start" },
284
+ sx = { gap: 1, justifyContent: "flex-start", minHeight: "56px" },
284
285
  variant = "outlined",
285
286
  ...rest
286
287
  } = props;
@@ -356,7 +357,14 @@ export function ButtonPopupCheckbox<D extends DnDItemType>(
356
357
  {...rest}
357
358
  disabled={!items || items.length === 0}
358
359
  >
359
- {label && <Typography variant="body2">{label}:</Typography>}
360
+ {label && (
361
+ <FormLabel
362
+ required={required}
363
+ sx={{ fontSize: (theme) => theme.typography.body2.fontSize }}
364
+ >
365
+ {label}
366
+ </FormLabel>
367
+ )}
360
368
  {selectedIds?.map((id) => {
361
369
  const item = items.find((item) => item.id === id);
362
370
  if (item == null) return null;
package/src/SelectEx.tsx CHANGED
@@ -22,6 +22,14 @@ import IconButton from "@mui/material/IconButton";
22
22
  import FormHelperText from "@mui/material/FormHelperText";
23
23
  import RefreshIcon from "@mui/icons-material/Refresh";
24
24
 
25
+ export type SelectExMethods = {
26
+ /**
27
+ * Set open state
28
+ * @param isOpen Open state
29
+ */
30
+ setOpen: (isOpen: boolean) => void;
31
+ };
32
+
25
33
  /**
26
34
  * Extended select component props
27
35
  */
@@ -70,6 +78,11 @@ export type SelectExProps<
70
78
  */
71
79
  loadData?: () => PromiseLike<T[] | null | undefined>;
72
80
 
81
+ /**
82
+ * Methods
83
+ */
84
+ mRef?: React.Ref<SelectExMethods>;
85
+
73
86
  /**
74
87
  * Item change callback
75
88
  */
@@ -128,6 +141,7 @@ export function SelectEx<
128
141
  label,
129
142
  labelField = "label" as L,
130
143
  loadData,
144
+ mRef,
131
145
  onItemChange,
132
146
  onItemClick,
133
147
  onLoadData,
@@ -202,6 +216,18 @@ export function SelectEx<
202
216
  setValueStateBase(newValue);
203
217
  };
204
218
 
219
+ const [open, setOpen] = React.useState(false);
220
+
221
+ React.useImperativeHandle(
222
+ mRef,
223
+ () => ({
224
+ setOpen: (isOpen: boolean) => {
225
+ setOpen(isOpen);
226
+ }
227
+ }),
228
+ []
229
+ );
230
+
205
231
  React.useEffect(() => {
206
232
  if (valueSource != null) setValueState(valueSource);
207
233
  }, [valueSource]);
@@ -308,9 +334,15 @@ export function SelectEx<
308
334
  notched
309
335
  label={label}
310
336
  required={required}
311
- inputProps={{ "data-reset": inputReset }}
337
+ inputProps={{
338
+ "aria-hidden": false,
339
+ "data-reset": inputReset
340
+ }}
312
341
  />
313
342
  }
343
+ open={open}
344
+ onClose={() => setOpen(false)}
345
+ onOpen={() => setOpen(true)}
314
346
  labelId={labelId}
315
347
  name={name}
316
348
  multiple={multiple}