@onehat/ui 0.4.55 → 0.4.57

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.4.55",
3
+ "version": "0.4.57",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -64,6 +64,7 @@ export const ComboComponent = forwardRef((props, ref) => {
64
64
  viewerProps = {}, // popup for eyeButton
65
65
  _input = {},
66
66
  _editor = {},
67
+ _grid = {},
67
68
  isEditor = false,
68
69
  isDisabled = false,
69
70
  isInTag = false,
@@ -732,6 +733,9 @@ export const ComboComponent = forwardRef((props, ref) => {
732
733
  'selectorSelectedField',
733
734
  'usePermissions',
734
735
  ]);
736
+ if (!_.isEmpty(_grid)){
737
+ _.assign(gridProps, _grid);
738
+ }
735
739
  if (!isInTag) {
736
740
  gridProps.value = props.value;
737
741
  }
@@ -75,11 +75,11 @@ export default function withComponent(WrappedComponent) {
75
75
  });
76
76
 
77
77
  useEffect(() => {
78
- if (parent && !parent?.hasChild(selfRef.current)) {
78
+ if (parent?.hasChild && !parent.hasChild(selfRef.current)) {
79
79
  parent.registerChild(selfRef.current);
80
80
  }
81
81
  return () => {
82
- if (parent) {
82
+ if (parent?.unregisterChild) {
83
83
  parent.unregisterChild(selfRef.current);
84
84
  }
85
85
  childrenRef.current = {};
@@ -0,0 +1,11 @@
1
+ import { createIcon } from "../Gluestack/icon";
2
+ // Font Awesome Pro 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc.
3
+ import Svg, { Path } from 'react-native-svg';
4
+
5
+ const SvgComponent = createIcon({
6
+ Root: Svg,
7
+ viewBox: '0 0 384 512',
8
+ path: <Path d="M0 128c0-35.3 28.7-64 64-64h256c35.3 0 64 28.7 64 64v256c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128z" />,
9
+ });
10
+
11
+ export default SvgComponent
@@ -0,0 +1,146 @@
1
+ import { useState, } from 'react';
2
+ import {
3
+ Text,
4
+ VStack,
5
+ } from '@project-components/Gluestack';
6
+ import Form from '../Form/Form.js';
7
+ import Button from '../Buttons/Button.js';
8
+ import CenterBox from '../Layout/CenterBox.js';
9
+ import withComponent from '../Hoc/withComponent.js';
10
+ import withAlert from '../Hoc/withAlert.js';
11
+ import ChevronLeft from '../Icons/ChevronLeft.js';
12
+ import ChevronRight from '../Icons/ChevronRight.js';
13
+ import Play from '../Icons/Play.js';
14
+ import Stop from '../Icons/Stop.js';
15
+ import TabBar from '../Tab/TabBar.js';
16
+ import Panel from '../Panel/Panel.js';
17
+ import Toolbar from '../Toolbar/Toolbar.js';
18
+ import _ from 'lodash';
19
+
20
+
21
+ function AsyncOperation(props) {
22
+ const {
23
+ action,
24
+ Repository,
25
+ formItems = [],
26
+
27
+ // withComponent
28
+ self,
29
+
30
+ // withAlert
31
+ alert,
32
+ } = props,
33
+ initiate = async () => {
34
+
35
+ if (!Repository || !action) {
36
+ alert('AsyncOperation: Repository and action are required!');
37
+ return;
38
+ }
39
+
40
+ setFooter(getFooter('processing'));
41
+
42
+ const
43
+ method = Repository.methods.post,
44
+ uri = Repository.getModel() + '/' + action,
45
+ formValues = self.children.form.formGetValues(),
46
+ result = await Repository._send(method, uri, formValues);
47
+
48
+ const response = Repository._processServerResponse(result);
49
+ if (!response.success) {
50
+ alert(result.message);
51
+ reset();
52
+ return;
53
+ }
54
+
55
+ let results = <CenterBox><Text>Success</Text></CenterBox>;
56
+ if (response.message) {
57
+ const decodedMessage = JSON.parse(response.message);
58
+ results = _.isArray(decodedMessage) ?
59
+ <VStack>
60
+ {decodedMessage?.map((line, ix)=> {
61
+ return <Text key={ix}>{line}</Text>;
62
+ })}
63
+ </VStack> :
64
+ <Text>{decodedMessage}</Text>;
65
+ }
66
+ showResults(results);
67
+ },
68
+ getFooter = (which = 'initiate') => {
69
+ switch(which) {
70
+ case 'initiate':
71
+ return <Toolbar>
72
+ <Button
73
+ text="Initiate"
74
+ rightIcon={ChevronRight}
75
+ onPress={() => initiate()}
76
+ />
77
+ </Toolbar>;
78
+ case 'processing':
79
+ return <Toolbar>
80
+ <Button
81
+ text="Please wait"
82
+ isLoading={true}
83
+ variant="link"
84
+ />
85
+ </Toolbar>;
86
+ case 'results':
87
+ return <Toolbar>
88
+ <Button
89
+ text="Reset"
90
+ icon={ChevronLeft}
91
+ onPress={() => reset()}
92
+ />
93
+ </Toolbar>;
94
+ }
95
+ },
96
+ [footer, setFooter] = useState(getFooter()),
97
+ [results, setResults] = useState(''),
98
+ [currentTabIx, setCurrentTab] = useState(0),
99
+ showResults = (results) => {
100
+ setCurrentTab(1);
101
+ setFooter(getFooter('results'));
102
+ setResults(results);
103
+ },
104
+ reset = () => {
105
+ setCurrentTab(0);
106
+ setFooter(getFooter());
107
+ };
108
+
109
+ return <Panel {...props} footer={footer}>
110
+ <TabBar
111
+ tabs={[
112
+ {
113
+ title: 'Initiate',
114
+ icon: Play,
115
+ isDisabled: currentTabIx !== 0,
116
+ content: <Form
117
+ reference="form"
118
+ parent={self}
119
+ className="w-full h-full flex-1"
120
+ disableFooter={true}
121
+ items={formItems}
122
+ />,
123
+ },
124
+ {
125
+ title: 'Results',
126
+ icon: Stop,
127
+ isDisabled: currentTabIx !== 1,
128
+ content: results,
129
+ },
130
+ ]}
131
+ currentTabIx={currentTabIx}
132
+ canToggleCollapse={false}
133
+ />
134
+ </Panel>;
135
+ }
136
+
137
+ function withAdditionalProps(WrappedComponent) {
138
+ return (props) => {
139
+ return <WrappedComponent
140
+ reference={props.reference || 'AsyncOperation'}
141
+ {...props}
142
+ />;
143
+ };
144
+ }
145
+
146
+ export default withAdditionalProps(withComponent(withAlert(AsyncOperation)));
@@ -30,12 +30,13 @@ function TabBar(props) {
30
30
  content, // e.g. Expo Router slot
31
31
  direction = HORIZONTAL,
32
32
  tabWidth = 150, // used on VERTICAL mode only
33
- tabHeight = '47px', // used on HORIZONTAL mode only
33
+ tabHeight = 47, // used on HORIZONTAL mode only
34
34
  additionalButtons,
35
35
  initialTabIx = 0,
36
36
  currentTabIx,
37
37
  disableCollapse = false,
38
38
  startsCollapsed = true,
39
+ canToggleCollapse = true,
39
40
  onChangeCurrentTab,
40
41
  onChangeIsCollapsed,
41
42
  onPressTab,
@@ -126,7 +127,7 @@ function TabBar(props) {
126
127
  />;
127
128
  } else {
128
129
  buttonClassName += `
129
- w-[200px]
130
+ ${direction === VERTICAL ? 'w-[200px]' : ''}
130
131
  pr-0
131
132
  mr-0
132
133
  `;
@@ -294,6 +295,7 @@ function TabBar(props) {
294
295
  _icon={_icon}
295
296
  className={buttonClassName}
296
297
  tooltip={tab.title}
298
+ isDisabled={tab.isDisabled}
297
299
  />;
298
300
  } else {
299
301
  if (direction === VERTICAL) {
@@ -329,6 +331,7 @@ function TabBar(props) {
329
331
  className: textClassName,
330
332
  ...textPropsToPass,
331
333
  }}
334
+ isDisabled={tab.isDisabled}
332
335
  action="none"
333
336
  variant="none"
334
337
  />;
@@ -503,9 +506,10 @@ function TabBar(props) {
503
506
  `}
504
507
  >
505
508
  {renderedTabs}
506
- <VStack className="flex-1 w-full justify-end">
507
- {renderedToggleButton}
508
- </VStack>
509
+ {canToggleCollapse ?
510
+ <VStack className="flex-1 w-full justify-end">
511
+ {renderedToggleButton}
512
+ </VStack> : null}
509
513
  </VStackNative>;
510
514
  if (renderedCurrentTabContent) {
511
515
  tabBar = <HStackNative {...propsToPass} className="flex-1 w-full">
@@ -520,7 +524,7 @@ function TabBar(props) {
520
524
  tabBar = <HStackNative
521
525
  {...testProps('TabBar')}
522
526
  className={`
523
- ${isCollapsed ? 'h-[38px]' : 'h-[' + tabHeight + 'px]'}
527
+ ${'h-[' + tabHeight + 'px]'}
524
528
  items-center
525
529
  justify-start
526
530
  p-1
@@ -530,15 +534,16 @@ function TabBar(props) {
530
534
  >
531
535
  <ScrollView
532
536
  horizontal={true}
533
- className={` ${isCollapsed ? "h-[30px]" : 'h-[' + tabHeight + 'px]'} `}
537
+ className={'h-[' + tabHeight + 'px]'}
534
538
  >
535
539
  {renderedTabs}
536
540
  </ScrollView>
537
- <HStack className="flex-1 h-full justify-end">
538
- <HStack className="h-full">
539
- {renderedToggleButton}
540
- </HStack>
541
- </HStack>
541
+ {canToggleCollapse ?
542
+ <HStack className="flex-1 h-full justify-end">
543
+ <HStack className="h-full">
544
+ {renderedToggleButton}
545
+ </HStack>
546
+ </HStack> : null}
542
547
  </HStackNative>;
543
548
  if (renderedCurrentTabContent) {
544
549
  tabBar = <VStackNative {...propsToPass} className="flex-1 w-full">
@@ -165,6 +165,7 @@ import SquareCheck from './Icons/SquareCheck.js';
165
165
  import SquareCheckRegular from './Icons/SquareCheckRegular.js';
166
166
  import SquareMinus from './Icons/SquareMinus.js';
167
167
  import SquareRegular from './Icons/SquareRegular.js';
168
+ import Stop from './Icons/Stop.js';
168
169
  import Store from './Icons/Store.js';
169
170
  import Table from './Icons/Table.js';
170
171
  import ThumbsDown from './Icons/ThumbsDown.js';
@@ -408,6 +409,7 @@ const components = {
408
409
  SquareCheckRegular,
409
410
  SquareMinus,
410
411
  SquareRegular,
412
+ Stop,
411
413
  Store,
412
414
  Table,
413
415
  ThumbsDown,