@onehat/ui 0.2.66 → 0.2.67

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.2.66",
3
+ "version": "0.2.67",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -38,12 +38,11 @@ export default function Editor(props) {
38
38
 
39
39
  if (Repository.isRemotePhantomMode && selection.length === 1 && editorMode === EDITOR_MODE__VIEW) {
40
40
  return <Viewer
41
+ {...props}
41
42
  record={selection[0]}
42
- Repository={Repository}
43
43
  onEditMode={isViewOnly ? null : onEditMode}
44
44
  onClose={onClose}
45
- onDelete={onDelete}
46
- {...props}
45
+ // onDelete={onDelete}
47
46
  />;
48
47
  }
49
48
 
@@ -6,23 +6,55 @@ import {
6
6
  Row,
7
7
  Text,
8
8
  } from 'native-base';
9
+ import UiGlobals from '../../UiGlobals.js';
10
+ import getComponentFromType from '../../Functions/getComponentFromType.js';
9
11
  import Label from '../Form/Label.js';
10
12
  import Pencil from '../Icons/Pencil.js';
11
13
  import Footer from '../Layout/Footer.js';
12
14
  import _ from 'lodash';
13
15
 
14
- // This is a wrapper for the Viewer subcomponent passed to props,]
15
- // that adds
16
-
16
+ // This is a wrapper for the Viewer subcomponent passed to props,
17
+ // that adds buttons and a footer
17
18
 
18
19
  export default function Viewer(props) {
19
20
  const {
20
- Viewer, // Subcomponent
21
21
  additionalViewButtons = [],
22
+ ancillaryItems = [],
23
+ record,
22
24
  onEditMode,
23
25
  onClose,
24
26
  onDelete,
25
- } = props;
27
+ } = props,
28
+ styles = UiGlobals.styles,
29
+ buildAncillary = () => {
30
+ let components = [];
31
+ if (ancillaryItems.length) {
32
+ components = _.map(ancillaryItems, (item, ix) => {
33
+ let {
34
+ type,
35
+ title = null,
36
+ selectorId,
37
+ ...propsToPass
38
+ } = item;
39
+ const
40
+ Element = getComponentFromType(type),
41
+ element = <Element
42
+ selectorId={selectorId}
43
+ selectorSelected={selectorId ? record : selectorSelected}
44
+ flex={1}
45
+ {...propsToPass}
46
+ />;
47
+ if (title) {
48
+ title = <Text
49
+ fontSize={styles.VIEWER_ANCILLARY_FONTSIZE}
50
+ fontWeight="bold"
51
+ >{title}</Text>;
52
+ }
53
+ return <Column key={'ancillary-' + ix} px={2} pb={1}>{title}{element}</Column>;
54
+ });
55
+ }
56
+ return components;
57
+ };
26
58
 
27
59
  return <Column flex={1} w="100%">
28
60
  <ScrollView flex={1} w="100%">
@@ -41,7 +73,9 @@ export default function Viewer(props) {
41
73
  {additionalViewButtons}
42
74
  </Row>}
43
75
 
44
- <Viewer {...props} />
76
+ {props.children}
77
+
78
+ {buildAncillary()}
45
79
 
46
80
  </Column>
47
81
  </ScrollView>
@@ -22,6 +22,7 @@ import { useForm, Controller } from 'react-hook-form'; // https://react-hook-for
22
22
  import * as yup from 'yup'; // https://github.com/jquense/yup#string
23
23
  import { yupResolver } from '@hookform/resolvers/yup';
24
24
  import useForceUpdate from '../../Hooks/useForceUpdate.js';
25
+ import UiGlobals from '../../UiGlobals.js';
25
26
  import withAlert from '../Hoc/withAlert.js';
26
27
  import withEditor from '../Hoc/withEditor.js';
27
28
  import inArray from '../../Functions/inArray.js';
@@ -57,6 +58,7 @@ function Form(props) {
57
58
  editorType = EDITOR_TYPE__WINDOWED, // EDITOR_TYPE__INLINE | EDITOR_TYPE__WINDOWED | EDITOR_TYPE__SIDE | EDITOR_TYPE__SMART | EDITOR_TYPE__PLAIN
58
59
  startingValues = {},
59
60
  items = [], // Columns, FieldSets, Fields, etc to define the form
61
+ ancillaryItems = [], // additional items which are not controllable form elements, but should appear in the form
60
62
  columnDefaults = {}, // defaults for each Column defined in items (above)
61
63
  columnsConfig, // Which columns are shown in Grid, so the inline editor can match. Used only for EDITOR_TYPE__INLINE
62
64
  validator, // custom validator, mainly for EDITOR_TYPE__PLAIN
@@ -66,7 +68,6 @@ function Form(props) {
66
68
  onReset,
67
69
  onViewMode,
68
70
  additionalEditButtons = [],
69
- ancillaryComponents = [],
70
71
 
71
72
  // sizing of outer container
72
73
  h,
@@ -95,6 +96,7 @@ function Form(props) {
95
96
  alert,
96
97
  confirm,
97
98
  } = props,
99
+ styles = UiGlobals.styles,
98
100
  record = props.record?.length === 1 ? props.record[0] : props.record,
99
101
  isMultiple = _.isArray(record),
100
102
  isSingle = !isMultiple, // for convenience
@@ -239,9 +241,7 @@ function Form(props) {
239
241
  return <Row>{elements}</Row>;
240
242
  },
241
243
  buildFromItems = () => {
242
- const
243
- regularItems = _.map(items, (item, ix) => buildNextLayer(item, ix, columnDefaults));
244
- return [...regularItems, ...ancillaryComponents];
244
+ return _.map(items, (item, ix) => buildNextLayer(item, ix, columnDefaults));
245
245
  },
246
246
  buildNextLayer = (item, ix, defaults) => {
247
247
  let {
@@ -399,6 +399,35 @@ function Form(props) {
399
399
  }}
400
400
  />;
401
401
  },
402
+ buildAncillary = () => {
403
+ let components = [];
404
+ if (ancillaryItems.length) {
405
+ components = _.map(ancillaryItems, (item, ix) => {
406
+ let {
407
+ type,
408
+ title = null,
409
+ selectorId,
410
+ ...propsToPass
411
+ } = item;
412
+ const
413
+ Element = getComponentFromType(type),
414
+ element = <Element
415
+ selectorId={selectorId}
416
+ selectorSelected={selectorId ? record : selectorSelected}
417
+ flex={1}
418
+ {...propsToPass}
419
+ />;
420
+ if (title) {
421
+ title = <Text
422
+ fontSize={styles.FORM_ANCILLARY_TITLE_FONTSIZE}
423
+ fontWeight="bold"
424
+ >{title}</Text>;
425
+ }
426
+ return <Column key={'ancillary-' + ix} px={2} pb={1}>{title}{element}</Column>;
427
+ });
428
+ }
429
+ return components;
430
+ },
402
431
  onSubmitError = (errors, e) => {
403
432
  debugger;
404
433
  if (editorType === EDITOR_TYPE__INLINE) {
@@ -459,10 +488,12 @@ function Form(props) {
459
488
  borderBottomColor="primary.100"
460
489
  >{formComponents}</ScrollView>;
461
490
  } else {
462
- // for Windowed editor
491
+ // for all other editor types
463
492
  formComponents = buildFromItems();
493
+ const formAncillaryComponents = buildAncillary();
464
494
  editor = <ScrollView flex={1} width="100%" pb={1}>
465
- <Row flex={1}>{formComponents}</Row>
495
+ <Row>{formComponents}</Row>
496
+ <Column pt={4}>{formAncillaryComponents}</Column>
466
497
  </ScrollView>;
467
498
  }
468
499
 
@@ -85,6 +85,9 @@ export function Grid(props) {
85
85
  bottomToolbar = 'pagination',
86
86
  topToolbar = null,
87
87
  additionalToolbarButtons = [],
88
+ h,
89
+ flex,
90
+ bg,
88
91
 
89
92
  // withEditor
90
93
  onAdd,
@@ -784,10 +787,17 @@ export function Grid(props) {
784
787
  }
785
788
  }
786
789
 
790
+ const sizeProps = {};
791
+ if (!_.isNil(h)) {
792
+ sizeProps.h = h;
793
+ } else {
794
+ sizeProps.flex = flex ?? 1;
795
+ }
787
796
  return <Column
788
797
  {...testProps('Grid')}
789
- flex={1}
790
798
  w="100%"
799
+ bg={bg}
800
+ {...sizeProps}
791
801
  >
792
802
  {topToolbar}
793
803
 
@@ -7,6 +7,7 @@ const
7
7
 
8
8
  const defaults = {
9
9
  FILTER_LABEL_FONTSIZE: DEFAULT_FONTSIZE,
10
+ FORM_ANCILLARY_TITLE_FONTSIZE: 22,
10
11
  FORM_COLOR_READOUT_FONTSIZE: DEFAULT_FONTSIZE,
11
12
  FORM_COLOR_INPUT_BG: WHITE,
12
13
  FORM_COLOR_INPUT_FOCUS_BG: FOCUS,
@@ -99,6 +100,7 @@ const defaults = {
99
100
  TREE_TOOLBAR_ITEMS_COLOR: 'trueGray.800',
100
101
  TREE_TOOLBAR_ITEMS_DISABLED_COLOR: 'disabled',
101
102
  TREE_TOOLBAR_ITEMS_ICON_SIZE: 'sm',
103
+ VIEWER_ANCILLARY_FONTSIZE: 22,
102
104
  };
103
105
 
104
106
  export default defaults;