@onehat/ui 0.2.30 → 0.2.34

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.30",
3
+ "version": "0.2.34",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "license": "UNLICENSED",
21
21
  "dependencies": {
22
- "@onehat/data": "^1.13.6",
22
+ "@onehat/data": "^1.15.5",
23
23
  "@hookform/resolvers": "^2.9.11",
24
24
  "ckeditor5-custom-build": "file:ckeditor5",
25
25
  "js-cookie": "^3.0.1",
@@ -30,7 +30,8 @@ function NumberElement(props) {
30
30
  debouncedSetValueRef = useRef(),
31
31
  [localValue, setLocalValue] = useState(value),
32
32
  onInputKeyPress = (e) => {
33
- switch(e.key) {
33
+ const key = e.nativeEvent.key; // e.key works on web, but not mobile; so use e.nativeEvent.key which works on both
34
+ switch(key) {
34
35
  case 'ArrowDown':
35
36
  case 'ArrowLeft':
36
37
  onDecrement();
@@ -48,7 +49,7 @@ function NumberElement(props) {
48
49
  break;
49
50
  default:
50
51
  }
51
- if (!e.key.match(/^[\-\d\.]*$/)) {
52
+ if (!key.match(/^[\-\d\.]*$/)) {
52
53
  e.preventDefault(); // kill anything that's not a number
53
54
  }
54
55
  },
@@ -56,6 +57,7 @@ function NumberElement(props) {
56
57
  if (value === '') {
57
58
  value = null; // empty string makes value null
58
59
  }
60
+ value = parseFloat(value, 10);
59
61
  setLocalValue(value);
60
62
  debouncedSetValueRef.current(value);
61
63
  },
@@ -91,7 +93,9 @@ function NumberElement(props) {
91
93
  useEffect(() => {
92
94
 
93
95
  // Make local value conform to externally changed value
94
- setLocalValue(value);
96
+ if (value !== localValue) {
97
+ setLocalValue(value);
98
+ }
95
99
 
96
100
  }, [value]);
97
101
 
@@ -99,6 +103,12 @@ function NumberElement(props) {
99
103
  localValue = ''; // If the value is null or undefined, don't let this be an uncontrolled input
100
104
  }
101
105
 
106
+ // convert localValue to string if necessary, because numbers work on web but not mobile; while strings work in both places
107
+ let inputValue = localValue;
108
+ if (_.isNumber(inputValue)) {
109
+ inputValue = '' + inputValue;
110
+ }
111
+
102
112
  const
103
113
  isIncrementDisabled = typeof maxValue !== 'undefined' && value === maxValue,
104
114
  isDecrementDisabled = typeof minValue !== 'undefined' && (value === minValue || (!value && minValue === 0));
@@ -118,7 +128,7 @@ function NumberElement(props) {
118
128
  zIndex={10}
119
129
  />
120
130
  <InputWithTooltip
121
- value={localValue}
131
+ value={inputValue}
122
132
  onChangeText={onChangeText}
123
133
  onKeyPress={onInputKeyPress}
124
134
  flex={5}
@@ -11,11 +11,14 @@ const
11
11
  const {
12
12
  value,
13
13
  setValue,
14
+ flex, // flex doesn't work right on mobile
15
+ ...propsToPass
14
16
  } = props,
15
17
  styles = UiGlobals.styles,
16
18
  onToggle = () => {
17
19
  setValue(!value);
18
20
  };
21
+
19
22
  return <Switch
20
23
  ref={props.outerRef}
21
24
  onToggle={onToggle}
@@ -29,7 +32,7 @@ const
29
32
  onTrackColor: styles.FORM_TOGGLE_ON_HOVER_COLOR,
30
33
  offTrackColor: styles.FORM_TOGGLE_OFF_HOVER_COLOR,
31
34
  }}
32
- {...props}
35
+ {...propsToPass}
33
36
  />;
34
37
  },
35
38
  ToggleField = withValue(ToggleElement);
@@ -361,10 +361,22 @@ export function Grid(props) {
361
361
  bg = styles.GRID_ROW_BG;
362
362
  }
363
363
  }
364
- let WhichGridRow = GridRow;
364
+ let WhichGridRow = GridRow,
365
+ rowReorderProps = {};
365
366
  if (canRowsReorder && isReorderMode) {
366
367
  WhichGridRow = ReorderableGridRow;
368
+ rowReorderProps = {
369
+ mode: VERTICAL,
370
+ onDragStart: onRowReorderDragStart,
371
+ onDrag: onRowReorderDrag,
372
+ onDragStop: onRowReorderDragStop,
373
+ proxyParent: gridRef.current?.getScrollableNode().children[0],
374
+ proxyPositionRelativeToParent: true,
375
+ getParentNode: (node) => node.parentElement.parentElement.parentElement,
376
+ getProxy: getReorderProxy,
377
+ };
367
378
  }
379
+
368
380
  return <WhichGridRow
369
381
  columnsConfig={localColumnsConfig}
370
382
  columnProps={columnProps}
@@ -373,15 +385,7 @@ export function Grid(props) {
373
385
  hideNavColumn={hideNavColumn}
374
386
  bg={bg}
375
387
  item={item}
376
-
377
- mode={VERTICAL}
378
- onDragStart={onRowReorderDragStart}
379
- onDrag={onRowReorderDrag}
380
- onDragStop={onRowReorderDragStop}
381
- proxyParent={gridRef.current?.getScrollableNode().children[0]}
382
- proxyPositionRelativeToParent={true}
383
- getParentNode={(node) => node.parentElement.parentElement.parentElement}
384
- getProxy={getReorderProxy}
388
+ {...rowReorderProps}
385
389
  />;
386
390
  }}
387
391
  </Pressable>;