@etsoo/react 1.4.61 → 1.4.62

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.
@@ -13,6 +13,10 @@ export interface ViewPageField<T extends {}> extends GridProps {
13
13
  * Label field
14
14
  */
15
15
  label: string | (() => React.ReactNode);
16
+ /**
17
+ * Display as single row
18
+ */
19
+ singleRow?: boolean;
16
20
  }
17
21
  declare type ViewPageFieldType<T> = (string & keyof T) | ViewPageField<T>;
18
22
  /**
@@ -4,18 +4,25 @@ import { globalApp } from '../../app/ReactApp';
4
4
  import { MUGlobal } from '../MUGlobal';
5
5
  import { CommonPage } from './CommonPage';
6
6
  function formatItemData(fieldData) {
7
+ if (fieldData == null)
8
+ return undefined;
9
+ if (typeof fieldData === 'string')
10
+ return fieldData;
7
11
  if (fieldData instanceof Date)
8
12
  return globalApp.formatDate(fieldData, 'd');
9
- return new String(fieldData);
13
+ return `${fieldData}`;
10
14
  }
11
15
  function getItemField(field, data) {
12
16
  var _a, _b;
13
17
  // Item data and label
14
- let itemData, itemLabel, gridProps;
18
+ let itemData, itemLabel, gridProps = {};
15
19
  if (typeof field === 'object') {
16
20
  // Destruct
17
- const { data: fieldData, label: fieldLabel, ...rest } = field;
18
- gridProps = rest;
21
+ const { data: fieldData, label: fieldLabel, singleRow = false, ...rest } = field;
22
+ gridProps = {
23
+ ...rest,
24
+ ...(singleRow && { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 })
25
+ };
19
26
  // Field data
20
27
  if (typeof fieldData === 'function')
21
28
  itemData = fieldData(data);
@@ -30,9 +37,12 @@ function getItemField(field, data) {
30
37
  else {
31
38
  itemData = formatItemData(data[field]);
32
39
  itemLabel = (_b = globalApp.get(field)) !== null && _b !== void 0 ? _b : field;
33
- gridProps = { xs: 12, sm: 6, md: 4, lg: 3 };
34
40
  }
35
- return [itemData, itemLabel, gridProps];
41
+ return [
42
+ itemData,
43
+ itemLabel,
44
+ { xs: 12, sm: 6, md: 6, lg: 4, xl: 3, ...gridProps }
45
+ ];
36
46
  }
37
47
  /**
38
48
  * View page
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.61",
3
+ "version": "1.4.62",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,6 +18,11 @@ export interface ViewPageField<T extends {}> extends GridProps {
18
18
  * Label field
19
19
  */
20
20
  label: string | (() => React.ReactNode);
21
+
22
+ /**
23
+ * Display as single row
24
+ */
25
+ singleRow?: boolean;
21
26
  }
22
27
 
23
28
  type ViewPageFieldType<T> = (string & keyof T) | ViewPageField<T>;
@@ -42,9 +47,11 @@ export interface ViewPageProps<T extends {}> extends CommonPageProps {
42
47
  supportRefresh?: boolean;
43
48
  }
44
49
 
45
- function formatItemData(fieldData: unknown) {
50
+ function formatItemData(fieldData: unknown): string | undefined {
51
+ if (fieldData == null) return undefined;
52
+ if (typeof fieldData === 'string') return fieldData;
46
53
  if (fieldData instanceof Date) return globalApp.formatDate(fieldData, 'd');
47
- return new String(fieldData);
54
+ return `${fieldData}`;
48
55
  }
49
56
 
50
57
  function getItemField<T>(
@@ -54,12 +61,21 @@ function getItemField<T>(
54
61
  // Item data and label
55
62
  let itemData: React.ReactNode,
56
63
  itemLabel: React.ReactNode,
57
- gridProps: GridProps;
64
+ gridProps: GridProps = {};
58
65
 
59
66
  if (typeof field === 'object') {
60
67
  // Destruct
61
- const { data: fieldData, label: fieldLabel, ...rest } = field;
62
- gridProps = rest;
68
+ const {
69
+ data: fieldData,
70
+ label: fieldLabel,
71
+ singleRow = false,
72
+ ...rest
73
+ } = field;
74
+
75
+ gridProps = {
76
+ ...rest,
77
+ ...(singleRow && { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 })
78
+ };
63
79
 
64
80
  // Field data
65
81
  if (typeof fieldData === 'function') itemData = fieldData(data);
@@ -73,10 +89,13 @@ function getItemField<T>(
73
89
  } else {
74
90
  itemData = formatItemData(data[field]);
75
91
  itemLabel = globalApp.get<string>(field) ?? field;
76
- gridProps = { xs: 12, sm: 6, md: 4, lg: 3 };
77
92
  }
78
93
 
79
- return [itemData, itemLabel, gridProps];
94
+ return [
95
+ itemData,
96
+ itemLabel,
97
+ { xs: 12, sm: 6, md: 6, lg: 4, xl: 3, ...gridProps }
98
+ ];
80
99
  }
81
100
 
82
101
  /**