@onehat/ui 0.3.130 → 0.3.133

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.3.130",
3
+ "version": "0.3.133",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -51,6 +51,7 @@ export function ComboComponent(props) {
51
51
  onRowPress,
52
52
  icon,
53
53
  Editor, // only used for the eyeButton
54
+ onSave, // to hook into when menu saves (ComboEditor only)
54
55
 
55
56
  // withComponent
56
57
  self,
@@ -81,6 +82,7 @@ export function ComboComponent(props) {
81
82
  [isRendered, setIsRendered] = useState(false),
82
83
  [isReady, setIsReady] = useState(false),
83
84
  [isSearchMode, setIsSearchMode] = useState(false),
85
+ [containerWidth, setContainerWidth] = useState(),
84
86
  [gridSelection, setGridSelection] = useState(null),
85
87
  [textInputValue, setTextInputValue] = useState(''),
86
88
  [newEntityDisplayValue, setNewEntityDisplayValue] = useState(null),
@@ -88,6 +90,10 @@ export function ComboComponent(props) {
88
90
  [width, setWidth] = useState(0),
89
91
  [top, setTop] = useState(0),
90
92
  [left, setLeft] = useState(0),
93
+ onLayout = (e) => {
94
+ setIsRendered(true);
95
+ setContainerWidth(e.nativeEvent.layout.width);
96
+ },
91
97
  showMenu = async () => {
92
98
  if (isMenuShown) {
93
99
  return;
@@ -738,6 +744,9 @@ export function ComboComponent(props) {
738
744
  const id = entity.id;
739
745
  setValue(id);
740
746
  }
747
+ if (onSave) {
748
+ onSave(selection);
749
+ }
741
750
  }}
742
751
  onRowPress={(item, e) => {
743
752
  if (onRowPress) {
@@ -896,13 +905,31 @@ export function ComboComponent(props) {
896
905
  if (tooltipRef) {
897
906
  refProps.ref = tooltipRef;
898
907
  }
899
- assembledComponents = <Row {...refProps} justifyContent="center" alignItems="center" h={styles.FORM_COMBO_HEIGHT} flex={1} onLayout={() => setIsRendered(true)}>
900
- {xButton}
901
- {eyeButton}
902
- {inputAndTrigger}
903
- {additionalButtons}
904
- {dropdownMenu}
905
- </Row>;
908
+
909
+ if (isRendered && additionalButtons?.length && containerWidth < 500) {
910
+ // be responsive for small screen sizes and bump additionalButtons to the next line
911
+ assembledComponents =
912
+ <Column>
913
+ <Row {...refProps} justifyContent="center" alignItems="center" h={styles.FORM_COMBO_HEIGHT} flex={1}>
914
+ {xButton}
915
+ {eyeButton}
916
+ {inputAndTrigger}
917
+ {dropdownMenu}
918
+ </Row>
919
+ <Row mt={2}>
920
+ {additionalButtons}
921
+ </Row>
922
+ </Column>;
923
+ } else {
924
+ assembledComponents =
925
+ <Row {...refProps} justifyContent="center" alignItems="center" h={styles.FORM_COMBO_HEIGHT} flex={1} onLayout={onLayout}>
926
+ {xButton}
927
+ {eyeButton}
928
+ {inputAndTrigger}
929
+ {additionalButtons}
930
+ {dropdownMenu}
931
+ </Row>;
932
+ }
906
933
 
907
934
  if (isViewerShown && Editor) {
908
935
  const propsForViewer = _.pick(props, [
@@ -521,10 +521,20 @@ function Form(props) {
521
521
  }
522
522
 
523
523
  if (item.additionalEditButtons) {
524
- element = <Row flex={1} flexWrap="wrap">
524
+ const buttons = buildAdditionalButtons(item.additionalEditButtons, self, { fieldState, formSetValue, formGetValues, formState });
525
+ if (containerWidth > 400) {
526
+ element = <Row flex={1} flexWrap="wrap">
527
+ {element}
528
+ {buttons}
529
+ </Row>;
530
+ } else {
531
+ element = <Column flex={1} w="100%">
525
532
  {element}
526
- {buildAdditionalButtons(item.additionalEditButtons, self, { fieldState, formSetValue, formGetValues, formState })}
527
- </Row>;
533
+ <Row flex={1} w="100%" mt={2} flexWrap="wrap">
534
+ {buttons}
535
+ </Row>
536
+ </Column>;
537
+ }
528
538
  }
529
539
 
530
540
  let isRequired = false,
@@ -10,8 +10,14 @@ import {
10
10
  Spacer,
11
11
  Text,
12
12
  } from 'native-base';
13
+ import {
14
+ UI_MODE_WEB,
15
+ CURRENT_MODE,
16
+ } from '../../Constants/UiModes.js';
13
17
  import _ from 'lodash';
14
18
 
19
+ const CONTEXT_MENU_WIDTH = 180;
20
+
15
21
  export default function withContextMenu(WrappedComponent) {
16
22
  return (props) => {
17
23
  const {
@@ -42,6 +48,29 @@ export default function withContextMenu(WrappedComponent) {
42
48
  setIsContextMenuShown(true);
43
49
  setContextMenuX(e.nativeEvent.pageX);
44
50
  setContextMenuY(e.nativeEvent.pageY);
51
+ },
52
+ onLayout = (e) => {
53
+ if (CURRENT_MODE !== UI_MODE_WEB) {
54
+ return;
55
+ }
56
+
57
+ const
58
+ {
59
+ top,
60
+ left,
61
+ // width,
62
+ height,
63
+ } = e.nativeEvent.layout,
64
+ screenWidth = window.innerWidth,
65
+ screenHeight = window.innerHeight,
66
+ width = CONTEXT_MENU_WIDTH;
67
+
68
+ if (screenWidth - width < left) {
69
+ setContextMenuX(screenWidth - width);
70
+ }
71
+ if (screenHeight - height < top) {
72
+ setContextMenuY(screenHeight - height);
73
+ }
45
74
  };
46
75
 
47
76
  useEffect(() => {
@@ -133,7 +162,7 @@ export default function withContextMenu(WrappedComponent) {
133
162
  isOpen={isContextMenuShown && !disableContextMenu}
134
163
  onClose={() => setIsContextMenuShown(false)}
135
164
  >
136
- <Column bg="#fff" w={180} position="absolute" top={contextMenuY} left={contextMenuX}>
165
+ <Column bg="#fff" w={CONTEXT_MENU_WIDTH} position="absolute" top={contextMenuY} left={contextMenuX} onLayout={onLayout}>
137
166
  {contextMenuItemComponents}
138
167
  </Column>
139
168
  </Modal>
@@ -25,9 +25,13 @@ function ManagerScreen(props) {
25
25
  } = props,
26
26
  styles = UiGlobals.styles,
27
27
  id = props.id || props.self?.path,
28
- [isReady, setIsReady] = useState(false),
28
+ [isRendered, setIsRendered] = useState(false),
29
+ [allowSideBySide, setAllowSideBySide] = useState(false),
29
30
  [mode, setModeRaw] = useState(MODE_FULL),
30
31
  setMode = (newMode) => {
32
+ if (!allowSideBySide && newMode === MODE_SIDE) {
33
+ return;
34
+ }
31
35
  if (newMode === mode) {
32
36
  return; // no change
33
37
  }
@@ -35,12 +39,22 @@ function ManagerScreen(props) {
35
39
  if (id) {
36
40
  setSaved(id + '-mode', newMode);
37
41
  }
42
+ },
43
+ onLayout = (e) => {
44
+ const
45
+ containerWidth = e.nativeEvent.layout.width,
46
+ allowSideBySide = containerWidth > 600;
47
+ setAllowSideBySide(allowSideBySide);
48
+ setIsRendered(true);
38
49
  };
39
50
 
40
51
  useEffect(() => {
52
+ if (!isRendered) {
53
+ return;
54
+ }
55
+
41
56
  // Restore saved settings
42
57
  (async () => {
43
-
44
58
  if (id) {
45
59
  const
46
60
  key = id + '-mode',
@@ -49,19 +63,11 @@ function ManagerScreen(props) {
49
63
  setMode(val);
50
64
  }
51
65
  }
52
-
53
- if (!isReady) {
54
- setIsReady(true);
55
- }
56
66
  })();
57
- }, []);
58
-
59
- if (!isReady) {
60
- return null;
61
- }
67
+ }, [isRendered]);
62
68
 
63
69
  let whichComponent;
64
- if (mode === MODE_FULL) {
70
+ if (!allowSideBySide || mode === MODE_FULL) {
65
71
  whichComponent = fullModeComponent;
66
72
  } else if (mode === MODE_SIDE) {
67
73
  whichComponent = sideModeComponent;
@@ -74,38 +80,42 @@ function ManagerScreen(props) {
74
80
  };
75
81
  }
76
82
 
77
- return <Column maxHeight="100vh" overflow="hidden" flex={1} w="100%">
78
- <Row
79
- h="80px"
80
- py={2}
81
- borderBottomWidth={2}
82
- borderBottomColor="#ccc"
83
- >
84
- <Text p={4} fontSize="26" fontWeight={700} {...textProps}>{title}</Text>
85
- <IconButton
86
- icon={FullWidth}
87
- _icon={{
88
- size: '25px',
89
- color: mode === MODE_FULL ? 'primary.100' : '#000',
90
- }}
91
- disabled={mode === MODE_FULL}
92
- onPress={() => setMode(MODE_FULL)}
93
- tooltip="Full Width"
94
- />
95
- <IconButton
96
- icon={SideBySide}
97
- _icon={{
98
- size: '25px',
99
- color: mode === MODE_SIDE ? 'primary.100' : '#000',
100
- }}
101
- disabled={mode === MODE_SIDE}
102
- onPress={() => setMode(MODE_SIDE)}
103
- tooltip="Side Editor"
104
- />
105
- </Row>
106
-
107
- {whichComponent}
108
-
83
+ return <Column maxHeight="100vh" overflow="hidden" flex={1} w="100%" onLayout={onLayout}>
84
+ {isRendered &&
85
+ <>
86
+ <Row
87
+ h="80px"
88
+ py={2}
89
+ borderBottomWidth={2}
90
+ borderBottomColor="#ccc"
91
+ >
92
+ <Text p={4} fontSize="26" fontWeight={700} {...textProps}>{title}</Text>
93
+ {allowSideBySide &&
94
+ <>
95
+ <IconButton
96
+ icon={FullWidth}
97
+ _icon={{
98
+ size: '25px',
99
+ color: mode === MODE_FULL ? 'primary.100' : '#000',
100
+ }}
101
+ disabled={mode === MODE_FULL}
102
+ onPress={() => setMode(MODE_FULL)}
103
+ tooltip="Full Width"
104
+ />
105
+ <IconButton
106
+ icon={SideBySide}
107
+ _icon={{
108
+ size: '25px',
109
+ color: mode === MODE_SIDE ? 'primary.100' : '#000',
110
+ }}
111
+ disabled={mode === MODE_SIDE}
112
+ onPress={() => setMode(MODE_SIDE)}
113
+ tooltip="Side Editor"
114
+ />
115
+ </>}
116
+ </Row>
117
+ {whichComponent}
118
+ </>}
109
119
  </Column>;
110
120
  }
111
121