@etsoo/react 1.4.33 → 1.4.37

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.
@@ -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)[],
@@ -25,14 +25,42 @@ export function MobileListItemRenderer({ data, itemHeight }, margin, renderer) {
25
25
  return React.createElement(LinearProgress, null);
26
26
  // Elements
27
27
  const [title, subheader, actions, children] = renderer(data);
28
- // Half
29
- const halfMargin = MUGlobal.half(margin);
30
- return (React.createElement(Card, { sx: {
31
- height: (theme) => MUGlobal.adjustWithTheme(itemHeight, margin, theme.spacing),
28
+ // Calculate margin
29
+ const calculateMargin = () => {
30
+ if (typeof margin === 'function')
31
+ return margin();
32
+ if (Array.isArray(margin)) {
33
+ const marginValue = margin[0];
34
+ const isNarrow = margin[1];
35
+ const half = MUGlobal.half(marginValue);
36
+ if (isNarrow) {
37
+ return {
38
+ marginLeft: 0,
39
+ marginRight: 0,
40
+ marginTop: half,
41
+ marginBottom: half
42
+ };
43
+ }
44
+ else {
45
+ return {
46
+ marginLeft: half,
47
+ marginRight: half,
48
+ marginTop: half,
49
+ marginBottom: half
50
+ };
51
+ }
52
+ }
53
+ const half = MUGlobal.half(margin);
54
+ return {
32
55
  marginLeft: margin,
33
56
  marginRight: margin,
34
- marginTop: halfMargin,
35
- marginBottom: halfMargin
57
+ marginTop: half,
58
+ marginBottom: half
59
+ };
60
+ };
61
+ return (React.createElement(Card, { sx: {
62
+ height: (theme) => MUGlobal.adjustWithTheme(itemHeight, margin, theme.spacing),
63
+ ...calculateMargin()
36
64
  } },
37
65
  React.createElement(CardHeader, { sx: { paddingBottom: 0.5 }, action: Array.isArray(actions) ? (React.createElement(MoreFab, { iconButton: true, size: "small", anchorOrigin: {
38
66
  vertical: 'bottom',
@@ -66,5 +94,10 @@ export function MobileListItemRenderer({ data, itemHeight }, margin, renderer) {
66
94
  }
67
95
  }
68
96
  } })) : (actions), title: title, titleTypographyProps: { variant: 'body2' }, subheader: subheader, subheaderTypographyProps: { variant: 'caption' } }),
69
- React.createElement(CardContent, { sx: { paddingTop: 0 } }, children)));
97
+ React.createElement(CardContent, { sx: {
98
+ paddingTop: 0,
99
+ '&:last-child': {
100
+ paddingBottom: 0 // default 24px
101
+ }
102
+ } }, children)));
70
103
  }
@@ -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.33",
3
+ "version": "1.4.37",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -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
  ) => [
@@ -40,18 +47,45 @@ export function MobileListItemRenderer<T>(
40
47
  // Elements
41
48
  const [title, subheader, actions, children] = renderer(data);
42
49
 
43
- // Half
44
- const halfMargin = MUGlobal.half(margin);
50
+ // Calculate margin
51
+ const calculateMargin = () => {
52
+ if (typeof margin === 'function') return margin();
53
+ if (Array.isArray(margin)) {
54
+ const marginValue = margin[0];
55
+ const isNarrow = margin[1];
56
+ const half = MUGlobal.half(marginValue);
57
+ if (isNarrow) {
58
+ return {
59
+ marginLeft: 0,
60
+ marginRight: 0,
61
+ marginTop: half,
62
+ marginBottom: half
63
+ };
64
+ } else {
65
+ return {
66
+ marginLeft: half,
67
+ marginRight: half,
68
+ marginTop: half,
69
+ marginBottom: half
70
+ };
71
+ }
72
+ }
73
+
74
+ const half = MUGlobal.half(margin);
75
+ return {
76
+ marginLeft: margin,
77
+ marginRight: margin,
78
+ marginTop: half,
79
+ marginBottom: half
80
+ };
81
+ };
45
82
 
46
83
  return (
47
84
  <Card
48
85
  sx={{
49
86
  height: (theme) =>
50
87
  MUGlobal.adjustWithTheme(itemHeight, margin, theme.spacing),
51
- marginLeft: margin,
52
- marginRight: margin,
53
- marginTop: halfMargin,
54
- marginBottom: halfMargin
88
+ ...calculateMargin()
55
89
  }}
56
90
  >
57
91
  <CardHeader
@@ -107,7 +141,16 @@ export function MobileListItemRenderer<T>(
107
141
  subheader={subheader}
108
142
  subheaderTypographyProps={{ variant: 'caption' }}
109
143
  />
110
- <CardContent sx={{ paddingTop: 0 }}>{children}</CardContent>
144
+ <CardContent
145
+ sx={{
146
+ paddingTop: 0,
147
+ '&:last-child': {
148
+ paddingBottom: 0 // default 24px
149
+ }
150
+ }}
151
+ >
152
+ {children}
153
+ </CardContent>
111
154
  </Card>
112
155
  );
113
156
  }
@@ -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': {