@etsoo/materialui 1.5.27 → 1.5.29

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.
@@ -29,6 +29,11 @@ export interface TabBoxProps extends Omit<TabsProps, "value"> {
29
29
  * Current index
30
30
  */
31
31
  index?: number;
32
+ /**
33
+ * Index field of the search params
34
+ * @default 'index'
35
+ */
36
+ indexField?: string;
32
37
  /**
33
38
  * Add a hidden input and its name
34
39
  */
package/lib/cjs/TabBox.js CHANGED
@@ -5,11 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.TabBox = TabBox;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = require("@etsoo/react");
8
9
  const shared_1 = require("@etsoo/shared");
9
10
  const Box_1 = __importDefault(require("@mui/material/Box"));
10
11
  const Tab_1 = __importDefault(require("@mui/material/Tab"));
11
12
  const Tabs_1 = __importDefault(require("@mui/material/Tabs"));
12
- const react_1 = __importDefault(require("react"));
13
+ const react_2 = __importDefault(require("react"));
13
14
  function isActionTab(children) {
14
15
  return typeof children === "function" && children.length === 0;
15
16
  }
@@ -20,16 +21,26 @@ function isActionTab(children) {
20
21
  */
21
22
  function TabBox(props) {
22
23
  // Destruct
23
- const { index, inputName, root, defaultIndex = 0, onChange, tabProps, tabs, ...rest } = props;
24
+ const { index, indexField = "index", inputName, root, defaultIndex = 0, onChange, tabProps, tabs, ...rest } = props;
24
25
  // State
25
- const [value, setValue] = react_1.default.useState(defaultIndex);
26
- react_1.default.useEffect(() => {
26
+ const [params, setSearchParams] = (0, react_1.useSearchParamsEx1)({
27
+ [indexField]: "number"
28
+ });
29
+ const [value, setValue] = react_2.default.useState(params[indexField] ?? defaultIndex);
30
+ react_2.default.useEffect(() => {
27
31
  if (index == null)
28
32
  return;
29
33
  setValue(index);
30
34
  }, [index]);
31
35
  // Layout
32
- return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [inputName && (0, jsx_runtime_1.jsx)("input", { type: "hidden", name: inputName, value: value }), (0, jsx_runtime_1.jsx)(Box_1.default, { ...root, children: (0, jsx_runtime_1.jsx)(Tabs_1.default, { value: value, onChange: (event, newValue) => {
36
+ return ((0, jsx_runtime_1.jsxs)(react_2.default.Fragment, { children: [inputName && (0, jsx_runtime_1.jsx)("input", { type: "hidden", name: inputName, value: value }), (0, jsx_runtime_1.jsx)(Box_1.default, { ...root, children: (0, jsx_runtime_1.jsx)(Tabs_1.default, { value: value, onChange: (event, newValue) => {
37
+ setSearchParams((prev) => {
38
+ if (newValue == defaultIndex)
39
+ prev.delete(indexField);
40
+ else
41
+ prev.set(indexField, newValue);
42
+ return prev;
43
+ });
33
44
  const { children } = tabs[newValue];
34
45
  if (isActionTab(children)) {
35
46
  children();
@@ -39,5 +50,5 @@ function TabBox(props) {
39
50
  if (onChange)
40
51
  onChange(event, newValue);
41
52
  }
42
- }, ...rest, children: tabs.map(({ children, panelProps, ...tabRest }, index) => ((0, jsx_runtime_1.jsx)(Tab_1.default, { value: index, ...tabRest }, index))) }) }), tabs.map(({ children, panelProps }, index) => ((0, jsx_runtime_1.jsx)(Box_1.default, { hidden: value !== index, ...tabProps, ...panelProps, children: isActionTab(children) ? ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, {})) : (shared_1.Utils.getResult(children, value === index)) }, index)))] }));
53
+ }, ...rest, children: tabs.map(({ children, panelProps, ...tabRest }, index) => ((0, jsx_runtime_1.jsx)(Tab_1.default, { value: index, ...tabRest }, index))) }) }), tabs.map(({ children, panelProps }, index) => ((0, jsx_runtime_1.jsx)(Box_1.default, { hidden: value !== index, ...tabProps, ...panelProps, children: isActionTab(children) ? ((0, jsx_runtime_1.jsx)(react_2.default.Fragment, {})) : (shared_1.Utils.getResult(children, value === index)) }, index)))] }));
43
54
  }
@@ -29,6 +29,10 @@ export interface CommonPageProps extends Omit<ContainerProps, "id"> {
29
29
  * Add panel to the Fab
30
30
  */
31
31
  fabPanel?: boolean;
32
+ /**
33
+ * Fab refresh button is supported or not
34
+ */
35
+ fabRefresh?: boolean;
32
36
  /**
33
37
  * Fab lays in the top
34
38
  */
@@ -25,7 +25,7 @@ function CommonPage(props) {
25
25
  // Global app
26
26
  const app = (0, ReactApp_1.useAppContext)();
27
27
  // Destruct
28
- const { children, disableGutters = true, fabTop, fabButtons, fabColumnDirection, fabPanel, fabPaddingAdjust = 1.5, fabSize = "small", maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal_1.MUGlobal.pagePaddings, scrollContainer, supportBack = false, targetFields, sx = {}, ...rest } = props;
28
+ const { children, disableGutters = true, fabTop, fabButtons, fabColumnDirection, fabPanel, fabPaddingAdjust = 1.5, fabSize = "small", maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal_1.MUGlobal.pagePaddings, scrollContainer, supportBack = false, targetFields, fabRefresh = onRefresh != null, sx = {}, ...rest } = props;
29
29
  // Fab padding
30
30
  const fabPadding = MUGlobal_1.MUGlobal.increase(MUGlobal_1.MUGlobal.pagePaddings, fabPaddingAdjust);
31
31
  if (typeof sx === "object" && sx != null && !Reflect.has(sx, "padding")) {
@@ -74,5 +74,5 @@ function CommonPage(props) {
74
74
  bottom: distance,
75
75
  right: distance
76
76
  })
77
- }, columnDirection: fabColumnDirection, fabPanel: fabPanel, children: [scrollContainer && ((0, jsx_runtime_1.jsx)(ScrollTopFab_1.ScrollTopFab, { size: fabSize, target: scrollContainer, title: labels.scrollTop })), fabButtons, onRefresh != null && ((0, jsx_runtime_1.jsx)(Fab_1.default, { title: labels.refresh, size: fabSize, onClick: onRefresh, sx: { display: { xs: "none", md: "inherit" } }, children: (0, jsx_runtime_1.jsx)(Refresh_1.default, {}) })), (0, jsx_runtime_1.jsx)(MoreFab_1.MoreFab, { size: fabSize, title: labels.more, actions: moreActions }), supportBack && (0, jsx_runtime_1.jsx)(BackButton_1.BackButton, { title: labels.back, size: fabSize })] }), children] })] }));
77
+ }, columnDirection: fabColumnDirection, fabPanel: fabPanel, children: [scrollContainer && ((0, jsx_runtime_1.jsx)(ScrollTopFab_1.ScrollTopFab, { size: fabSize, target: scrollContainer, title: labels.scrollTop })), fabButtons, fabRefresh && ((0, jsx_runtime_1.jsx)(Fab_1.default, { title: labels.refresh, size: fabSize, onClick: onRefresh, sx: { display: { xs: "none", md: "inherit" } }, children: (0, jsx_runtime_1.jsx)(Refresh_1.default, {}) })), (0, jsx_runtime_1.jsx)(MoreFab_1.MoreFab, { size: fabSize, title: labels.more, actions: moreActions }), supportBack && (0, jsx_runtime_1.jsx)(BackButton_1.BackButton, { title: labels.back, size: fabSize })] }), children] })] }));
78
78
  }
@@ -29,6 +29,11 @@ export interface TabBoxProps extends Omit<TabsProps, "value"> {
29
29
  * Current index
30
30
  */
31
31
  index?: number;
32
+ /**
33
+ * Index field of the search params
34
+ * @default 'index'
35
+ */
36
+ indexField?: string;
32
37
  /**
33
38
  * Add a hidden input and its name
34
39
  */
package/lib/mjs/TabBox.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useSearchParamsEx1 } from "@etsoo/react";
2
3
  import { Utils } from "@etsoo/shared";
3
4
  import Box from "@mui/material/Box";
4
5
  import Tab from "@mui/material/Tab";
@@ -14,9 +15,12 @@ function isActionTab(children) {
14
15
  */
15
16
  export function TabBox(props) {
16
17
  // Destruct
17
- const { index, inputName, root, defaultIndex = 0, onChange, tabProps, tabs, ...rest } = props;
18
+ const { index, indexField = "index", inputName, root, defaultIndex = 0, onChange, tabProps, tabs, ...rest } = props;
18
19
  // State
19
- const [value, setValue] = React.useState(defaultIndex);
20
+ const [params, setSearchParams] = useSearchParamsEx1({
21
+ [indexField]: "number"
22
+ });
23
+ const [value, setValue] = React.useState(params[indexField] ?? defaultIndex);
20
24
  React.useEffect(() => {
21
25
  if (index == null)
22
26
  return;
@@ -24,6 +28,13 @@ export function TabBox(props) {
24
28
  }, [index]);
25
29
  // Layout
26
30
  return (_jsxs(React.Fragment, { children: [inputName && _jsx("input", { type: "hidden", name: inputName, value: value }), _jsx(Box, { ...root, children: _jsx(Tabs, { value: value, onChange: (event, newValue) => {
31
+ setSearchParams((prev) => {
32
+ if (newValue == defaultIndex)
33
+ prev.delete(indexField);
34
+ else
35
+ prev.set(indexField, newValue);
36
+ return prev;
37
+ });
27
38
  const { children } = tabs[newValue];
28
39
  if (isActionTab(children)) {
29
40
  children();
@@ -29,6 +29,10 @@ export interface CommonPageProps extends Omit<ContainerProps, "id"> {
29
29
  * Add panel to the Fab
30
30
  */
31
31
  fabPanel?: boolean;
32
+ /**
33
+ * Fab refresh button is supported or not
34
+ */
35
+ fabRefresh?: boolean;
32
36
  /**
33
37
  * Fab lays in the top
34
38
  */
@@ -19,7 +19,7 @@ export function CommonPage(props) {
19
19
  // Global app
20
20
  const app = useAppContext();
21
21
  // Destruct
22
- const { children, disableGutters = true, fabTop, fabButtons, fabColumnDirection, fabPanel, fabPaddingAdjust = 1.5, fabSize = "small", maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal.pagePaddings, scrollContainer, supportBack = false, targetFields, sx = {}, ...rest } = props;
22
+ const { children, disableGutters = true, fabTop, fabButtons, fabColumnDirection, fabPanel, fabPaddingAdjust = 1.5, fabSize = "small", maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal.pagePaddings, scrollContainer, supportBack = false, targetFields, fabRefresh = onRefresh != null, sx = {}, ...rest } = props;
23
23
  // Fab padding
24
24
  const fabPadding = MUGlobal.increase(MUGlobal.pagePaddings, fabPaddingAdjust);
25
25
  if (typeof sx === "object" && sx != null && !Reflect.has(sx, "padding")) {
@@ -68,5 +68,5 @@ export function CommonPage(props) {
68
68
  bottom: distance,
69
69
  right: distance
70
70
  })
71
- }, columnDirection: fabColumnDirection, fabPanel: fabPanel, children: [scrollContainer && (_jsx(ScrollTopFab, { size: fabSize, target: scrollContainer, title: labels.scrollTop })), fabButtons, onRefresh != null && (_jsx(Fab, { title: labels.refresh, size: fabSize, onClick: onRefresh, sx: { display: { xs: "none", md: "inherit" } }, children: _jsx(RefreshIcon, {}) })), _jsx(MoreFab, { size: fabSize, title: labels.more, actions: moreActions }), supportBack && _jsx(BackButton, { title: labels.back, size: fabSize })] }), children] })] }));
71
+ }, columnDirection: fabColumnDirection, fabPanel: fabPanel, children: [scrollContainer && (_jsx(ScrollTopFab, { size: fabSize, target: scrollContainer, title: labels.scrollTop })), fabButtons, fabRefresh && (_jsx(Fab, { title: labels.refresh, size: fabSize, onClick: onRefresh, sx: { display: { xs: "none", md: "inherit" } }, children: _jsx(RefreshIcon, {}) })), _jsx(MoreFab, { size: fabSize, title: labels.more, actions: moreActions }), supportBack && _jsx(BackButton, { title: labels.back, size: fabSize })] }), children] })] }));
72
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.5.27",
3
+ "version": "1.5.29",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -42,7 +42,7 @@
42
42
  "@emotion/styled": "^11.14.0",
43
43
  "@etsoo/appscript": "^1.6.22",
44
44
  "@etsoo/notificationbase": "^1.1.60",
45
- "@etsoo/react": "^1.8.38",
45
+ "@etsoo/react": "^1.8.39",
46
46
  "@etsoo/shared": "^1.2.68",
47
47
  "@mui/icons-material": "^7.0.2",
48
48
  "@mui/material": "^7.0.2",
package/src/TabBox.tsx CHANGED
@@ -1,3 +1,4 @@
1
+ import { useSearchParamsEx1 } from "@etsoo/react";
1
2
  import { Utils } from "@etsoo/shared";
2
3
  import Box, { BoxProps } from "@mui/material/Box";
3
4
  import Tab, { TabProps } from "@mui/material/Tab";
@@ -46,6 +47,12 @@ export interface TabBoxProps extends Omit<TabsProps, "value"> {
46
47
  */
47
48
  index?: number;
48
49
 
50
+ /**
51
+ * Index field of the search params
52
+ * @default 'index'
53
+ */
54
+ indexField?: string;
55
+
49
56
  /**
50
57
  * Add a hidden input and its name
51
58
  */
@@ -76,6 +83,7 @@ export function TabBox(props: TabBoxProps) {
76
83
  // Destruct
77
84
  const {
78
85
  index,
86
+ indexField = "index",
79
87
  inputName,
80
88
  root,
81
89
  defaultIndex = 0,
@@ -86,7 +94,10 @@ export function TabBox(props: TabBoxProps) {
86
94
  } = props;
87
95
 
88
96
  // State
89
- const [value, setValue] = React.useState(defaultIndex);
97
+ const [params, setSearchParams] = useSearchParamsEx1({
98
+ [indexField]: "number"
99
+ });
100
+ const [value, setValue] = React.useState(params[indexField] ?? defaultIndex);
90
101
 
91
102
  React.useEffect(() => {
92
103
  if (index == null) return;
@@ -101,6 +112,11 @@ export function TabBox(props: TabBoxProps) {
101
112
  <Tabs
102
113
  value={value}
103
114
  onChange={(event, newValue) => {
115
+ setSearchParams((prev) => {
116
+ if (newValue == defaultIndex) prev.delete(indexField);
117
+ else prev.set(indexField, newValue);
118
+ return prev;
119
+ });
104
120
  const { children } = tabs[newValue];
105
121
  if (isActionTab(children)) {
106
122
  children();
@@ -44,6 +44,11 @@ export interface CommonPageProps extends Omit<ContainerProps, "id"> {
44
44
  */
45
45
  fabPanel?: boolean;
46
46
 
47
+ /**
48
+ * Fab refresh button is supported or not
49
+ */
50
+ fabRefresh?: boolean;
51
+
47
52
  /**
48
53
  * Fab lays in the top
49
54
  */
@@ -117,6 +122,7 @@ export function CommonPage(props: CommonPageProps) {
117
122
  scrollContainer,
118
123
  supportBack = false,
119
124
  targetFields,
125
+ fabRefresh = onRefresh != null,
120
126
  sx = {},
121
127
  ...rest
122
128
  } = props;
@@ -208,7 +214,7 @@ export function CommonPage(props: CommonPageProps) {
208
214
  />
209
215
  )}
210
216
  {fabButtons}
211
- {onRefresh != null && (
217
+ {fabRefresh && (
212
218
  <Fab
213
219
  title={labels.refresh}
214
220
  size={fabSize}