@onehat/ui 0.2.37 → 0.2.39

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.37",
3
+ "version": "0.2.39",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -119,7 +119,7 @@ export default function Container(props) {
119
119
  }
120
120
  if (east) {
121
121
  componentProps.collapseDirection = HORIZONTAL;
122
- if (!east.props.h && !east.props.flex) {
122
+ if (!east.props.w && !east.props.flex) {
123
123
  componentProps.flex = 50;
124
124
  }
125
125
  if (canResize && east.props.isResizable) {
@@ -143,7 +143,7 @@ export default function Container(props) {
143
143
  }
144
144
  if (west) {
145
145
  componentProps.collapseDirection = HORIZONTAL;
146
- if (!west.props.h && !west.props.flex) {
146
+ if (!west.props.w && !west.props.flex) {
147
147
  componentProps.flex = 50;
148
148
  }
149
149
  if (canResize && west.props.isResizable) {
@@ -1,10 +1,17 @@
1
- import React from 'react';
1
+ import React, { useRef, } from 'react';
2
2
  import {
3
+ Icon,
4
+ Pressable,
5
+ Row,
3
6
  Switch,
7
+ Text,
4
8
  } from 'native-base';
5
9
  import UiGlobals from '../../../UiGlobals.js';
10
+ import IconButton from '../../Buttons/IconButton.js';
11
+ import Na from '../../Icons/Na.js';
6
12
  import withTooltip from '../../Hoc/withTooltip.js';
7
13
  import withValue from '../../Hoc/withValue.js';
14
+ import _ from 'lodash';
8
15
 
9
16
  const
10
17
  ToggleElement = (props) => {
@@ -14,26 +21,53 @@ const
14
21
  flex, // flex doesn't work right on mobile
15
22
  ...propsToPass
16
23
  } = props,
24
+ isBlocked = useRef(false),
17
25
  styles = UiGlobals.styles,
18
- onToggle = () => {
19
- setValue(!value);
26
+ onToggle = (val, e) => {
27
+ if (!isBlocked.current) {
28
+ setValue(!value);
29
+ }
30
+ },
31
+ onNullify = (e) => {
32
+ if (e.shiftKey) {
33
+ // If user presses shift key while pressing...
34
+ // Set value to null, and tempoarily disable the onToggle method
35
+ setValue(null);
36
+ isBlocked.current = true;
37
+ setTimeout(() => {
38
+ isBlocked.current = false;
39
+ }, 200);
40
+ }
20
41
  };
21
42
 
22
- return <Switch
23
- ref={props.outerRef}
24
- onToggle={onToggle}
25
- isChecked={!!value}
26
- // flex={1}
27
- bg={styles.FORM_TOGGLE_BG}
28
- size={styles.FORM_TOGGLE_SIZE}
29
- onTrackColor={styles.FORM_TOGGLE_ON_COLOR}
30
- offTrackColor={styles.FORM_TOGGLE_OFF_COLOR}
31
- _hover={{
32
- onTrackColor: styles.FORM_TOGGLE_ON_HOVER_COLOR,
33
- offTrackColor: styles.FORM_TOGGLE_OFF_HOVER_COLOR,
34
- }}
35
- {...propsToPass}
36
- />;
43
+ if (_.isNil(value)) {
44
+ return <IconButton
45
+ icon={<Icon as={Na} color="trueGray.400" />}
46
+ onPress={onToggle}
47
+ borderWidth={1}
48
+ borderColor="trueGray.700"
49
+ />;
50
+ }
51
+
52
+ return <Row alignItems="center">
53
+ <Pressable onPress={onNullify}>
54
+ <Switch
55
+ ref={props.outerRef}
56
+ onToggle={onToggle}
57
+ isChecked={!!value}
58
+ bg={styles.FORM_TOGGLE_BG}
59
+ size={styles.FORM_TOGGLE_SIZE}
60
+ onTrackColor={styles.FORM_TOGGLE_ON_COLOR}
61
+ offTrackColor={styles.FORM_TOGGLE_OFF_COLOR}
62
+ _hover={{
63
+ onTrackColor: styles.FORM_TOGGLE_ON_HOVER_COLOR,
64
+ offTrackColor: styles.FORM_TOGGLE_OFF_HOVER_COLOR,
65
+ }}
66
+ {...propsToPass}
67
+ />
68
+ </Pressable>
69
+ <Text ml={2} fontSize={styles.FORM_TOGGLE_FONTSIZE}>{_.isNil(value) ? 'N/A' : (!!value ? 'Yes' : 'No')}</Text>
70
+ </Row>;
37
71
  },
38
72
  ToggleField = withValue(ToggleElement);
39
73
 
@@ -24,6 +24,7 @@ import withEditor from '../Hoc/withEditor.js';
24
24
  import inArray from '../../Functions/inArray.js';
25
25
  import getComponentFromType from '../../Functions/getComponentFromType.js';
26
26
  import IconButton from '../Buttons/IconButton.js';
27
+ import AngleLeft from '../Icons/AngleLeft.js';
27
28
  import Rotate from '../Icons/Rotate.js';
28
29
  import Pencil from '../Icons/Pencil.js';
29
30
  import Footer from '../Panel/Footer.js';
@@ -37,7 +38,8 @@ import _ from 'lodash';
37
38
  // Form is a single scrollable row, based on columnsConfig and Repository
38
39
  //
39
40
  // EDITOR_TYPE__WINDOWED
40
- // Form is a popup window, used for editing items in a grid. Integrated with Repository
41
+ // EDITOR_TYPE__SIDE
42
+ // Form is a popup or side window, used for editing items in a grid. Integrated with Repository
41
43
  //
42
44
  // EDITOR_TYPE__SMART
43
45
  // Form is a standalone editor
@@ -56,6 +58,8 @@ function Form(props) {
56
58
  validator, // custom validator, mainly for EDITOR_TYPE__PLAIN
57
59
  footerProps = {},
58
60
  buttonGroupProps = {}, // buttons in footer
61
+ onBack,
62
+ ancillaryComponents = [],
59
63
 
60
64
  // sizing of outer container
61
65
  h,
@@ -227,7 +231,9 @@ function Form(props) {
227
231
  return <Row>{elements}</Row>;
228
232
  },
229
233
  buildFromItems = () => {
230
- return _.map(items, (item, ix) => buildNextLayer(item, ix, columnDefaults));
234
+ const
235
+ regularItems = _.map(items, (item, ix) => buildNextLayer(item, ix, columnDefaults));
236
+ return [...regularItems, ...ancillaryComponents];
231
237
  },
232
238
  buildNextLayer = (item, ix, defaults) => {
233
239
  let {
@@ -452,6 +458,16 @@ function Form(props) {
452
458
  }
453
459
 
454
460
  return <Column {...sizeProps} onLayout={onLayout}>
461
+
462
+ {onBack && <Row p={2} alignItems="center">
463
+ <Button
464
+ key="backBtn"
465
+ onPress={onBack}
466
+ leftIcon={<Icon as={AngleLeft} color="#fff" size="sm" />}
467
+ color="#fff"
468
+ >Back</Button>
469
+ <Text ml={2} fontSize={18}>Edit Mode</Text>
470
+ </Row>}
455
471
 
456
472
  {editor}
457
473
 
@@ -2,6 +2,7 @@ import { useState, useEffect, } from 'react';
2
2
  import {
3
3
  Column,
4
4
  Modal,
5
+ Row,
5
6
  Text,
6
7
  } from 'native-base';
7
8
  import inArray from '../../Functions/inArray.js';
@@ -11,6 +12,7 @@ import FormPanel from '../Panel/FormPanel.js';
11
12
  import Ban from '../Icons/Ban.js';
12
13
  import Gear from '../Icons/Gear.js';
13
14
  import Toolbar from '../Toolbar/Toolbar.js';
15
+ import UiGlobals from '../../UiGlobals.js';
14
16
  import _ from 'lodash';
15
17
 
16
18
  // Filters only work with Repository; not data array
@@ -20,6 +22,7 @@ export default function withFilters(WrappedComponent) {
20
22
  const {
21
23
  useFilters = false,
22
24
  searchAllText = true,
25
+ showLabels = true,
23
26
  filter1StartingField = '',
24
27
  filter2StartingField = '',
25
28
  filter3StartingField = '',
@@ -33,7 +36,8 @@ export default function withFilters(WrappedComponent) {
33
36
 
34
37
  // withData
35
38
  Repository,
36
- } = props;
39
+ } = props,
40
+ styles = UiGlobals.styles;
37
41
 
38
42
  let modal,
39
43
  topToolbar = null;
@@ -195,15 +199,22 @@ export default function withFilters(WrappedComponent) {
195
199
  if (!Element) {
196
200
  debugger;
197
201
  }
198
- filterElements.push(<Element
199
- key={ix}
202
+ let filterElement = <Element
203
+ key={'element-' + ix}
200
204
  tooltip={titles[fieldName]}
201
205
  placeholder={titles[fieldName]}
202
206
  value={getFilterValue(ix)}
203
207
  onChangeValue={(value) => onFilterChange(ix, value)}
204
208
  {...filterProps}
205
209
  {...modelProps}
206
- />);
210
+ />;
211
+ if (showLabels) {
212
+ filterElement = <Row key={'label-' + ix} alignItems="center">
213
+ <Text ml={2} mr={1} fontSize={styles.FILTER_LABEL_FONTSIZE}>{titles[fieldName]}</Text>
214
+ {filterElement}
215
+ </Row>;
216
+ }
217
+ filterElements.push(filterElement);
207
218
  };
208
219
  if (searchAllText) {
209
220
  addFilter(null, 'q');
@@ -11,12 +11,14 @@ export default function withSideEditor(WrappedComponent) {
11
11
  const {
12
12
  Editor,
13
13
  editorProps = {},
14
+ sideFlex = 100,
14
15
  } = props;
15
16
 
16
17
  return <Container
17
18
  center={<WrappedComponent {...props} />}
18
19
  east={<Editor
19
20
  editorType={EDITOR_TYPE__SIDE}
21
+ flex={sideFlex}
20
22
  {...props}
21
23
  {...editorProps}
22
24
  />}
@@ -0,0 +1,17 @@
1
+ import * as React from "react"
2
+ import Svg, { Path } from "react-native-svg"
3
+ import { Icon } from 'native-base';
4
+
5
+ function SvgComponent(props) {
6
+ return (
7
+ <Icon
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ viewBox="0 0 512.24 402.86"
10
+ {...props}
11
+ >
12
+ <Path d="M0 54.41h36.81L76.09 171.3c11.39 33.02 21.44 68.25 30.17 105.7-3.16-22.64-5.5-43.14-7.02-61.48-1.52-18.34-2.28-35.61-2.28-51.8V54.41h39.66V347.4h-37L55.41 215.52c-4.05-12.27-7.88-24.86-11.48-37.76s-6.93-26.44-9.96-40.61c-.26-1.77-.66-3.92-1.23-6.45-.57-2.53-1.23-5.44-1.99-8.73.38 3.29.69 6.1.95 8.44.25 2.34.44 4.33.57 5.98l2.09 29.79 2.09 36.24c.12 2.03.22 4.49.28 7.4.06 2.91.09 6.2.09 9.87l2.09 127.71H0V54.41zM335.39 0h30.55L191.36 402.86h-30.93L335.39 0zM418.69 54.41h30.74l62.81 292.99h-39.09l-11.01-57.12h-58.07l-11.2 57.12h-37.95l63.76-292.99zm37.76 205.32l-8.73-46.68c-5.82-31.75-10.56-65.66-14.23-101.71-1.77 17.59-4.05 35.39-6.83 53.42-2.79 18.03-6.07 37.16-9.87 57.4l-7.21 37.57h46.87z" />
13
+ </Icon>
14
+ )
15
+ }
16
+
17
+ export default SvgComponent
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState, } from 'react';
2
2
  import Panel from './Panel.js';
3
- import Grid, { InlineGridEditor, } from '../Grid/Grid.js';
3
+ import Grid, { InlineGridEditor, SideGridEditor, } from '../Grid/Grid.js';
4
4
  import {
5
5
  EDITOR_TYPE__INLINE,
6
6
  EDITOR_TYPE__WINDOWED,
@@ -10,15 +10,27 @@ import _ from 'lodash';
10
10
 
11
11
  export function GridPanel(props) {
12
12
  const {
13
- editorType,
13
+ editorType = EDITOR_TYPE__WINDOWED,
14
14
  disableTitleChange = false,
15
15
  selectorSelected,
16
16
  } = props,
17
17
  originalTitle = props.title,
18
- WhichGrid = (editorType === EDITOR_TYPE__INLINE) ? InlineGridEditor : Grid,
19
18
  [isReady, setIsReady] = useState(disableTitleChange),
20
19
  [title, setTitle] = useState(originalTitle);
21
20
 
21
+ let WhichGrid;
22
+ switch(editorType) {
23
+ case EDITOR_TYPE__INLINE:
24
+ WhichGrid = InlineGridEditor;
25
+ break;
26
+ case EDITOR_TYPE__WINDOWED:
27
+ WhichGrid = Grid;
28
+ break;
29
+ case EDITOR_TYPE__SIDE:
30
+ WhichGrid = SideGridEditor;
31
+ break;
32
+ }
33
+
22
34
  useEffect(() => {
23
35
  if (!disableTitleChange && originalTitle) {
24
36
  let newTitle = originalTitle;
@@ -6,6 +6,7 @@ const
6
6
  FOCUS = '#ffd';
7
7
 
8
8
  const defaults = {
9
+ FILTER_LABEL_FONTSIZE: DEFAULT_FONTSIZE,
9
10
  FORM_COLOR_READOUT_FONTSIZE: DEFAULT_FONTSIZE,
10
11
  FORM_COLOR_INPUT_BG: WHITE,
11
12
  FORM_COLOR_INPUT_FOCUS_BG: FOCUS,
@@ -41,6 +42,7 @@ const defaults = {
41
42
  FORM_TEXTAREA_FONTSIZE: DEFAULT_FONTSIZE,
42
43
  FORM_TEXTAREA_HEIGHT: 130,
43
44
  FORM_TOGGLE_BG: null,
45
+ FORM_TOGGLE_FONTSIZE: DEFAULT_FONTSIZE,
44
46
  FORM_TOGGLE_SIZE: 'md',
45
47
  FORM_TOGGLE_ON_COLOR: '#0b0',
46
48
  FORM_TOGGLE_ON_HOVER_COLOR: '#090',