@etsoo/react 1.4.32 → 1.4.36

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.
@@ -67,7 +67,7 @@ export var DataGridRenderers;
67
67
  if (value)
68
68
  return React.createElement(CheckIcon, { fontSize: "small" });
69
69
  else
70
- return React.createElement(ClearIcon, { fontSize: "small" });
70
+ return React.createElement(ClearIcon, { fontSize: "small", color: "error" });
71
71
  }
72
72
  // To string
73
73
  return new String(value);
@@ -40,14 +40,20 @@ export declare class MUGlobal {
40
40
  * @returns Updated object
41
41
  */
42
42
  static half(input: {}): {};
43
+ /**
44
+ * Reverse object number properties, like 5 to -5
45
+ * @param input Input object
46
+ * @returns Updated object
47
+ */
48
+ static reverse(input: {}): {};
43
49
  /**
44
50
  * Update object number properties with adjustment
45
51
  * @param input Input object
46
- * @param adjust Adjust value
52
+ * @param adjust Adjust value or new size object
47
53
  * @param field Specific field
48
54
  * @returns Updated object
49
55
  */
50
- static increase(input: {}, adjust: number, field?: string): {};
56
+ static increase(input: {}, adjust: number | {}, field?: string): {};
51
57
  /**
52
58
  * Adjust size with theme update
53
59
  * @param size Base size
@@ -14,10 +14,24 @@ export class MUGlobal {
14
14
  });
15
15
  return newObj;
16
16
  }
17
+ /**
18
+ * Reverse object number properties, like 5 to -5
19
+ * @param input Input object
20
+ * @returns Updated object
21
+ */
22
+ static reverse(input) {
23
+ const newObj = { ...input };
24
+ Object.entries(newObj).forEach(([key, value]) => {
25
+ if (typeof value === 'number') {
26
+ Reflect.set(newObj, key, -value);
27
+ }
28
+ });
29
+ return newObj;
30
+ }
17
31
  /**
18
32
  * Update object number properties with adjustment
19
33
  * @param input Input object
20
- * @param adjust Adjust value
34
+ * @param adjust Adjust value or new size object
21
35
  * @param field Specific field
22
36
  * @returns Updated object
23
37
  */
@@ -25,8 +39,14 @@ export class MUGlobal {
25
39
  const newObj = { ...input };
26
40
  Object.entries(newObj).forEach(([key, value]) => {
27
41
  if (typeof value === 'number') {
28
- if (field == null || field === key)
29
- Reflect.set(newObj, key, value + adjust);
42
+ if (field == null || field === key) {
43
+ const adjustValue = typeof adjust === 'number'
44
+ ? adjust
45
+ : Reflect.get(adjust, key);
46
+ if (adjustValue == null || typeof adjustValue !== 'number')
47
+ return;
48
+ Reflect.set(newObj, key, value + adjustValue);
49
+ }
30
50
  }
31
51
  });
32
52
  return newObj;
@@ -1,3 +1,4 @@
1
+ import { SxProps, Theme } from '@mui/material';
1
2
  import React from 'react';
2
3
  import { ListItemReact } from '../components/ListItemReact';
3
4
  import { ScrollerListExInnerItemRendererProps } from './ScrollerListEx';
@@ -8,7 +9,7 @@ import { ScrollerListExInnerItemRendererProps } from './ScrollerListEx';
8
9
  * @param renderer Renderer for card content
9
10
  * @returns Component
10
11
  */
11
- export declare function MobileListItemRenderer<T>({ data, itemHeight }: ScrollerListExInnerItemRendererProps<T>, margin: {}, renderer: (data: T) => [
12
+ export declare function MobileListItemRenderer<T>({ data, itemHeight }: ScrollerListExInnerItemRendererProps<T>, margin: {} | [{}, boolean] | (() => SxProps<Theme>), renderer: (data: T) => [
12
13
  string,
13
14
  string | undefined,
14
15
  React.ReactNode | (ListItemReact | boolean)[],
@@ -26,13 +26,45 @@ export function MobileListItemRenderer({ data, itemHeight }, margin, renderer) {
26
26
  // Elements
27
27
  const [title, subheader, actions, children] = renderer(data);
28
28
  // Half
29
- const halfMargin = MUGlobal.half(margin);
30
- return (React.createElement(Card, { sx: {
31
- height: (theme) => MUGlobal.adjustWithTheme(itemHeight, margin, theme.spacing),
29
+ //const halfMargin = MUGlobal.half(margin);
30
+ //const nMargin = MUGlobal.reverse(margin);
31
+ const calculateMargin = () => {
32
+ if (typeof margin === 'function')
33
+ return margin();
34
+ if (Array.isArray(margin)) {
35
+ const marginValue = margin[0];
36
+ const isNarrow = margin[1];
37
+ const nMargin = MUGlobal.reverse(marginValue);
38
+ const half = MUGlobal.half(marginValue);
39
+ if (isNarrow) {
40
+ const nHalf = MUGlobal.reverse(half);
41
+ return {
42
+ marginLeft: nHalf,
43
+ marginRight: nHalf,
44
+ marginTop: half,
45
+ marginBottom: half
46
+ };
47
+ }
48
+ else {
49
+ return {
50
+ marginLeft: nMargin,
51
+ marginRight: nMargin,
52
+ marginTop: half,
53
+ marginBottom: half
54
+ };
55
+ }
56
+ }
57
+ const half = MUGlobal.half(margin);
58
+ return {
32
59
  marginLeft: margin,
33
60
  marginRight: margin,
34
- marginTop: halfMargin,
35
- marginBottom: halfMargin
61
+ marginTop: half,
62
+ marginBottom: half
63
+ };
64
+ };
65
+ return (React.createElement(Card, { sx: {
66
+ height: (theme) => MUGlobal.adjustWithTheme(itemHeight, margin, theme.spacing),
67
+ ...calculateMargin()
36
68
  } },
37
69
  React.createElement(CardHeader, { sx: { paddingBottom: 0.5 }, action: Array.isArray(actions) ? (React.createElement(MoreFab, { iconButton: true, size: "small", anchorOrigin: {
38
70
  vertical: 'bottom',
@@ -23,7 +23,7 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
23
23
  /**
24
24
  * Container box SX (dataGrid determines the case)
25
25
  */
26
- containerBoxSx?: (dataGrid?: boolean) => SxProps<Theme>;
26
+ containerBoxSx?: (paddings: {}, dataGrid?: boolean) => SxProps<Theme>;
27
27
  /**
28
28
  * Min width to show Datagrid
29
29
  */
@@ -9,13 +9,12 @@ import { MUGlobal } from './MUGlobal';
9
9
  import { PullToRefreshUI } from './PullToRefreshUI';
10
10
  import { ScrollerListEx } from './ScrollerListEx';
11
11
  import { SearchBar } from './SearchBar';
12
- function getDefaultSearchBoxSx(paddings) {
12
+ function defaultContainerBoxSx(paddings, _dataGrid) {
13
13
  const half = MUGlobal.half(paddings);
14
14
  return {
15
- paddingLeft: (theme) => theme.spacing(1),
16
- paddingRight: (theme) => theme.spacing(1),
17
- paddingTop: half,
18
- marginBottom: half
15
+ '& .SearchBox': {
16
+ marginBottom: half
17
+ }
19
18
  };
20
19
  }
21
20
  /**
@@ -25,7 +24,7 @@ function getDefaultSearchBoxSx(paddings) {
25
24
  */
26
25
  export function ResponsibleContainer(props) {
27
26
  // Destruct
28
- const { adjustHeight, columns, containerBoxSx, dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total), elementReady, fields, fieldTemplate, height, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, sizeReadyMiliseconds = 0, ...rest } = props;
27
+ const { adjustHeight, columns, containerBoxSx = defaultContainerBoxSx, dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total), elementReady, fields, fieldTemplate, height, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, sizeReadyMiliseconds = 0, ...rest } = props;
29
28
  // Labels
30
29
  const labels = Labels.CommonPage;
31
30
  // Refs
@@ -146,7 +145,7 @@ export function ResponsibleContainer(props) {
146
145
  // Layout
147
146
  return (React.createElement(Box, { sx: containerBoxSx == null
148
147
  ? undefined
149
- : containerBoxSx(showDataGrid) },
148
+ : containerBoxSx(paddings, showDataGrid) },
150
149
  React.createElement(Stack, null,
151
150
  React.createElement(Box, { ref: dimensions[0][0], className: "SearchBox" }, searchBar),
152
151
  list),
@@ -21,6 +21,14 @@ export interface TabBoxPros extends BoxProps {
21
21
  * Container props
22
22
  */
23
23
  container?: Omit<TabsProps, 'value'>;
24
+ /**
25
+ * Default selected index
26
+ */
27
+ defaultIndex?: number;
28
+ /**
29
+ * Current index
30
+ */
31
+ index?: number;
24
32
  /**
25
33
  * Add a hidden input and its name
26
34
  */
package/lib/mu/TabBox.js CHANGED
@@ -8,10 +8,15 @@ import React from 'react';
8
8
  */
9
9
  export function TabBox(props) {
10
10
  // Destruct
11
- const { inputName, root, container = {}, tabs } = props;
11
+ const { index, inputName, root, container = {}, defaultIndex = 0, tabs } = props;
12
12
  const { onChange, ...rest } = container;
13
13
  // State
14
- const [value, setValue] = React.useState(0);
14
+ const [value, setValue] = React.useState(defaultIndex);
15
+ React.useEffect(() => {
16
+ if (index == null)
17
+ return;
18
+ setValue(index);
19
+ }, [index]);
15
20
  // Layout
16
21
  return (React.createElement(React.Fragment, null,
17
22
  inputName && (React.createElement("input", { type: "hidden", name: inputName, value: value })),
@@ -13,13 +13,14 @@ export function ResponsivePage(props) {
13
13
  const { pageProps = {}, ...rest } = props;
14
14
  (_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
15
15
  const { paddings, fabColumnDirection, ...pageRest } = pageProps;
16
- const half = MUGlobal.half(paddings);
17
16
  // State
18
17
  const [scrollContainer, setScrollContainer] = React.useState();
19
18
  const [direction, setDirection] = React.useState(fabColumnDirection);
20
19
  // Layout
21
20
  return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer: scrollContainer, fabColumnDirection: direction },
22
- React.createElement(ResponsibleContainer, { paddings: paddings, containerBoxSx: (dataGrid) => {
21
+ React.createElement(ResponsibleContainer, { paddings: paddings, containerBoxSx: (paddings, _dataGrid) => {
22
+ // Half
23
+ const half = MUGlobal.half(paddings);
23
24
  // .SearchBox keep the same to avoid flick when switching between DataGrid and List
24
25
  return {
25
26
  '& .SearchBox': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.32",
3
+ "version": "1.4.36",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -103,7 +103,7 @@ export namespace DataGridRenderers {
103
103
  }
104
104
 
105
105
  if (value) return <CheckIcon fontSize="small" />;
106
- else return <ClearIcon fontSize="small" />;
106
+ else return <ClearIcon fontSize="small" color="error" />;
107
107
  }
108
108
 
109
109
  // To string
@@ -56,19 +56,42 @@ export class MUGlobal {
56
56
  return newObj;
57
57
  }
58
58
 
59
+ /**
60
+ * Reverse object number properties, like 5 to -5
61
+ * @param input Input object
62
+ * @returns Updated object
63
+ */
64
+ static reverse(input: {}) {
65
+ const newObj = { ...input };
66
+ Object.entries(newObj).forEach(([key, value]) => {
67
+ if (typeof value === 'number') {
68
+ Reflect.set(newObj, key, -value);
69
+ }
70
+ });
71
+ return newObj;
72
+ }
73
+
59
74
  /**
60
75
  * Update object number properties with adjustment
61
76
  * @param input Input object
62
- * @param adjust Adjust value
77
+ * @param adjust Adjust value or new size object
63
78
  * @param field Specific field
64
79
  * @returns Updated object
65
80
  */
66
- static increase(input: {}, adjust: number, field?: string) {
81
+ static increase(input: {}, adjust: number | {}, field?: string) {
67
82
  const newObj = { ...input };
68
83
  Object.entries(newObj).forEach(([key, value]) => {
69
84
  if (typeof value === 'number') {
70
- if (field == null || field === key)
71
- Reflect.set(newObj, key, value + adjust);
85
+ if (field == null || field === key) {
86
+ const adjustValue =
87
+ typeof adjust === 'number'
88
+ ? adjust
89
+ : Reflect.get(adjust, key);
90
+ if (adjustValue == null || typeof adjustValue !== 'number')
91
+ return;
92
+
93
+ Reflect.set(newObj, key, value + adjustValue);
94
+ }
72
95
  }
73
96
  });
74
97
  return newObj;
@@ -1,4 +1,11 @@
1
- import { Card, CardContent, CardHeader, LinearProgress } from '@mui/material';
1
+ import {
2
+ Card,
3
+ CardContent,
4
+ CardHeader,
5
+ LinearProgress,
6
+ SxProps,
7
+ Theme
8
+ } from '@mui/material';
2
9
  import React from 'react';
3
10
  import { ListItemReact } from '../components/ListItemReact';
4
11
  import { MoreFab } from './MoreFab';
@@ -24,7 +31,7 @@ function getActions(input: (ListItemReact | boolean)[]): ListItemReact[] {
24
31
  */
25
32
  export function MobileListItemRenderer<T>(
26
33
  { data, itemHeight }: ScrollerListExInnerItemRendererProps<T>,
27
- margin: {},
34
+ margin: {} | [{}, boolean] | (() => SxProps<Theme>),
28
35
  renderer: (
29
36
  data: T
30
37
  ) => [
@@ -41,17 +48,48 @@ export function MobileListItemRenderer<T>(
41
48
  const [title, subheader, actions, children] = renderer(data);
42
49
 
43
50
  // Half
44
- const halfMargin = MUGlobal.half(margin);
51
+ //const halfMargin = MUGlobal.half(margin);
52
+ //const nMargin = MUGlobal.reverse(margin);
53
+ const calculateMargin = () => {
54
+ if (typeof margin === 'function') return margin();
55
+ if (Array.isArray(margin)) {
56
+ const marginValue = margin[0];
57
+ const isNarrow = margin[1];
58
+ const nMargin = MUGlobal.reverse(marginValue);
59
+ const half = MUGlobal.half(marginValue);
60
+ if (isNarrow) {
61
+ const nHalf = MUGlobal.reverse(half);
62
+ return {
63
+ marginLeft: nHalf,
64
+ marginRight: nHalf,
65
+ marginTop: half,
66
+ marginBottom: half
67
+ };
68
+ } else {
69
+ return {
70
+ marginLeft: nMargin,
71
+ marginRight: nMargin,
72
+ marginTop: half,
73
+ marginBottom: half
74
+ };
75
+ }
76
+ }
77
+
78
+ const half = MUGlobal.half(margin);
79
+ return {
80
+ marginLeft: margin,
81
+ marginRight: margin,
82
+ marginTop: half,
83
+ marginBottom: half
84
+ };
85
+ };
45
86
 
46
87
  return (
47
88
  <Card
48
89
  sx={{
49
90
  height: (theme) =>
50
91
  MUGlobal.adjustWithTheme(itemHeight, margin, theme.spacing),
51
- marginLeft: margin,
52
- marginRight: margin,
53
- marginTop: halfMargin,
54
- marginBottom: halfMargin
92
+ ...calculateMargin()
55
93
  }}
56
94
  >
57
95
  <CardHeader
@@ -54,7 +54,7 @@ export interface ResponsibleContainerProps<
54
54
  /**
55
55
  * Container box SX (dataGrid determines the case)
56
56
  */
57
- containerBoxSx?: (dataGrid?: boolean) => SxProps<Theme>;
57
+ containerBoxSx?: (paddings: {}, dataGrid?: boolean) => SxProps<Theme>;
58
58
 
59
59
  /**
60
60
  * Min width to show Datagrid
@@ -132,13 +132,15 @@ interface LocalRefs {
132
132
  mounted?: boolean;
133
133
  }
134
134
 
135
- function getDefaultSearchBoxSx(paddings: {}): SxProps<Theme> {
135
+ function defaultContainerBoxSx(
136
+ paddings: {},
137
+ _dataGrid?: boolean
138
+ ): SxProps<Theme> {
136
139
  const half = MUGlobal.half(paddings);
137
140
  return {
138
- paddingLeft: (theme) => theme.spacing(1),
139
- paddingRight: (theme) => theme.spacing(1),
140
- paddingTop: half,
141
- marginBottom: half
141
+ '& .SearchBox': {
142
+ marginBottom: half
143
+ }
142
144
  };
143
145
  }
144
146
 
@@ -155,7 +157,7 @@ export function ResponsibleContainer<
155
157
  const {
156
158
  adjustHeight,
157
159
  columns,
158
- containerBoxSx,
160
+ containerBoxSx = defaultContainerBoxSx,
159
161
  dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total),
160
162
  elementReady,
161
163
  fields,
@@ -342,7 +344,7 @@ export function ResponsibleContainer<
342
344
  sx={
343
345
  containerBoxSx == null
344
346
  ? undefined
345
- : containerBoxSx(showDataGrid)
347
+ : containerBoxSx(paddings, showDataGrid)
346
348
  }
347
349
  >
348
350
  <Stack>
package/src/mu/TabBox.tsx CHANGED
@@ -26,6 +26,16 @@ export interface TabBoxPros extends BoxProps {
26
26
  */
27
27
  container?: Omit<TabsProps, 'value'>;
28
28
 
29
+ /**
30
+ * Default selected index
31
+ */
32
+ defaultIndex?: number;
33
+
34
+ /**
35
+ * Current index
36
+ */
37
+ index?: number;
38
+
29
39
  /**
30
40
  * Add a hidden input and its name
31
41
  */
@@ -49,11 +59,23 @@ export interface TabBoxPros extends BoxProps {
49
59
  */
50
60
  export function TabBox(props: TabBoxPros) {
51
61
  // Destruct
52
- const { inputName, root, container = {}, tabs } = props;
62
+ const {
63
+ index,
64
+ inputName,
65
+ root,
66
+ container = {},
67
+ defaultIndex = 0,
68
+ tabs
69
+ } = props;
53
70
  const { onChange, ...rest } = container;
54
71
 
55
72
  // State
56
- const [value, setValue] = React.useState(0);
73
+ const [value, setValue] = React.useState(defaultIndex);
74
+
75
+ React.useEffect(() => {
76
+ if (index == null) return;
77
+ setValue(index);
78
+ }, [index]);
57
79
 
58
80
  // Layout
59
81
  return (
@@ -20,8 +20,6 @@ export function ResponsivePage<
20
20
  pageProps.paddings ??= MUGlobal.pagePaddings;
21
21
  const { paddings, fabColumnDirection, ...pageRest } = pageProps;
22
22
 
23
- const half = MUGlobal.half(paddings);
24
-
25
23
  // State
26
24
  const [scrollContainer, setScrollContainer] = React.useState<HTMLElement>();
27
25
  const [direction, setDirection] = React.useState(fabColumnDirection);
@@ -36,7 +34,10 @@ export function ResponsivePage<
36
34
  >
37
35
  <ResponsibleContainer<T, F>
38
36
  paddings={paddings}
39
- containerBoxSx={(dataGrid) => {
37
+ containerBoxSx={(paddings, _dataGrid) => {
38
+ // Half
39
+ const half = MUGlobal.half(paddings);
40
+
40
41
  // .SearchBox keep the same to avoid flick when switching between DataGrid and List
41
42
  return {
42
43
  '& .SearchBox': {