@onehat/ui 0.2.38 → 0.2.40

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.38",
3
+ "version": "0.2.40",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,12 +1,17 @@
1
- import React from 'react';
1
+ import React, { useRef, } from 'react';
2
2
  import {
3
+ Icon,
4
+ Pressable,
3
5
  Row,
4
6
  Switch,
5
7
  Text,
6
8
  } from 'native-base';
7
9
  import UiGlobals from '../../../UiGlobals.js';
10
+ import IconButton from '../../Buttons/IconButton.js';
11
+ import Na from '../../Icons/Na.js';
8
12
  import withTooltip from '../../Hoc/withTooltip.js';
9
13
  import withValue from '../../Hoc/withValue.js';
14
+ import _ from 'lodash';
10
15
 
11
16
  const
12
17
  ToggleElement = (props) => {
@@ -16,28 +21,53 @@ const
16
21
  flex, // flex doesn't work right on mobile
17
22
  ...propsToPass
18
23
  } = props,
24
+ isBlocked = useRef(false),
19
25
  styles = UiGlobals.styles,
20
- onToggle = () => {
21
- 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
+ }
22
41
  };
23
42
 
24
- return <Row alignItems="center">
25
- <Switch
43
+ if (_.isNil(value)) {
44
+ return <IconButton
26
45
  ref={props.outerRef}
27
- onToggle={onToggle}
28
- isChecked={!!value}
29
- // flex={1}
30
- bg={styles.FORM_TOGGLE_BG}
31
- size={styles.FORM_TOGGLE_SIZE}
32
- onTrackColor={styles.FORM_TOGGLE_ON_COLOR}
33
- offTrackColor={styles.FORM_TOGGLE_OFF_COLOR}
34
- _hover={{
35
- onTrackColor: styles.FORM_TOGGLE_ON_HOVER_COLOR,
36
- offTrackColor: styles.FORM_TOGGLE_OFF_HOVER_COLOR,
37
- }}
38
- {...propsToPass}
39
- />
40
- <Text fontSize={styles.FORM_TOGGLE_FONTSIZE}>{!!value ? 'Yes' : 'No'}</Text>
46
+ icon={<Icon as={Na} color="trueGray.400" />}
47
+ onPress={onToggle}
48
+ borderWidth={1}
49
+ borderColor="trueGray.700"
50
+ />;
51
+ }
52
+
53
+ return <Row alignItems="center">
54
+ <Pressable onPress={onNullify}>
55
+ <Switch
56
+ ref={props.outerRef}
57
+ onToggle={onToggle}
58
+ isChecked={!!value}
59
+ bg={styles.FORM_TOGGLE_BG}
60
+ size={styles.FORM_TOGGLE_SIZE}
61
+ onTrackColor={styles.FORM_TOGGLE_ON_COLOR}
62
+ offTrackColor={styles.FORM_TOGGLE_OFF_COLOR}
63
+ _hover={{
64
+ onTrackColor: styles.FORM_TOGGLE_ON_HOVER_COLOR,
65
+ offTrackColor: styles.FORM_TOGGLE_OFF_HOVER_COLOR,
66
+ }}
67
+ {...propsToPass}
68
+ />
69
+ </Pressable>
70
+ <Text ml={2} fontSize={styles.FORM_TOGGLE_FONTSIZE}>{_.isNil(value) ? 'N/A' : (!!value ? 'Yes' : 'No')}</Text>
41
71
  </Row>;
42
72
  },
43
73
  ToggleField = withValue(ToggleElement);
@@ -1,8 +1,8 @@
1
1
  import { useState, } from 'react';
2
2
  import {
3
- EDITOR_VIEW_MODE__VIEW,
4
- EDITOR_VIEW_MODE__ADD,
5
- EDITOR_VIEW_MODE__EDIT,
3
+ EDITOR_MODE__VIEW,
4
+ EDITOR_MODE__ADD,
5
+ EDITOR_MODE__EDIT,
6
6
  } from '../../Constants/Editor.js';
7
7
  import _ from 'lodash';
8
8
 
@@ -38,7 +38,7 @@ export default function withEditor(WrappedComponent) {
38
38
  [currentRecord, setCurrentRecord] = useState(null),
39
39
  [isEditorShown, setIsEditorShown] = useState(false),
40
40
  [isEditorViewOnly, setIsEditorViewOnly] = useState(false),
41
- [editorViewMode, setEditorViewMode] = useState(EDITOR_VIEW_MODE__VIEW),
41
+ [editorMode, setEditorMode] = useState(EDITOR_MODE__VIEW),
42
42
  addRecord = async () => {
43
43
  if (!userCanEdit) {
44
44
  return;
@@ -48,7 +48,7 @@ export default function withEditor(WrappedComponent) {
48
48
  entity = await Repository.add(defaultValues, false, true, true);
49
49
  setSelection([entity]);
50
50
  setIsEditorViewOnly(false);
51
- setEditorViewMode(EDITOR_VIEW_MODE__ADD);
51
+ setEditorMode(EDITOR_MODE__ADD);
52
52
  setIsEditorShown(true);
53
53
  },
54
54
  editRecord = () => {
@@ -56,7 +56,7 @@ export default function withEditor(WrappedComponent) {
56
56
  return;
57
57
  }
58
58
  setIsEditorViewOnly(false);
59
- setEditorViewMode(EDITOR_VIEW_MODE__EDIT);
59
+ setEditorMode(EDITOR_MODE__EDIT);
60
60
  setIsEditorShown(true);
61
61
  },
62
62
  deleteRecord = (e) => {
@@ -88,7 +88,7 @@ export default function withEditor(WrappedComponent) {
88
88
  return;
89
89
  }
90
90
  setIsEditorViewOnly(true);
91
- setEditorViewMode(EDITOR_VIEW_MODE__VIEW);
91
+ setEditorMode(EDITOR_MODE__VIEW);
92
92
  setIsEditorShown(true);
93
93
  },
94
94
  duplicateRecord = async () => {
@@ -147,7 +147,8 @@ export default function withEditor(WrappedComponent) {
147
147
  setCurrentRecord={setCurrentRecord}
148
148
  isEditorShown={isEditorShown}
149
149
  isEditorViewOnly={isEditorViewOnly}
150
- editorViewMode={editorViewMode}
150
+ editorMode={editorMode}
151
+ setEditorMode={setEditorMode}
151
152
  setIsEditorShown={setIsEditorShown}
152
153
  onAdd={addRecord}
153
154
  onEdit={editRecord}
@@ -209,8 +209,8 @@ export default function withFilters(WrappedComponent) {
209
209
  {...modelProps}
210
210
  />;
211
211
  if (showLabels) {
212
- filterElement = <Row key={'label-' + ix}>
213
- <Text fontSize={styles.FILTER_LABEL_FONTSIZE}>{titles[fieldName]}:</Text>
212
+ filterElement = <Row key={'label-' + ix} alignItems="center">
213
+ <Text ml={2} mr={1} fontSize={styles.FILTER_LABEL_FONTSIZE}>{titles[fieldName]}</Text>
214
214
  {filterElement}
215
215
  </Row>;
216
216
  }
@@ -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
@@ -3,6 +3,6 @@ export const EDITOR_TYPE__WINDOWED = 'EDITOR_TYPE__WINDOWED';
3
3
  export const EDITOR_TYPE__SIDE = 'EDITOR_TYPE__SIDE';
4
4
  export const EDITOR_TYPE__SMART = 'EDITOR_TYPE__SMART';
5
5
  export const EDITOR_TYPE__PLAIN = 'EDITOR_TYPE__PLAIN';
6
- export const EDITOR_VIEW_MODE__VIEW = 'EDITOR_VIEW_MODE__VIEW';
7
- export const EDITOR_VIEW_MODE__ADD = 'EDITOR_VIEW_MODE__ADD';
8
- export const EDITOR_VIEW_MODE__EDIT = 'EDITOR_VIEW_MODE__EDIT';
6
+ export const EDITOR_MODE__VIEW = 'EDITOR_MODE__VIEW';
7
+ export const EDITOR_MODE__ADD = 'EDITOR_MODE__ADD';
8
+ export const EDITOR_MODE__EDIT = 'EDITOR_MODE__EDIT';