@onehat/ui 0.3.294 → 0.3.296
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
|
@@ -88,6 +88,7 @@ function Form(props) {
|
|
|
88
88
|
additionalEditButtons,
|
|
89
89
|
useAdditionalEditButtons = true,
|
|
90
90
|
additionalFooterButtons,
|
|
91
|
+
disableFooter = false,
|
|
91
92
|
|
|
92
93
|
// sizing of outer container
|
|
93
94
|
h,
|
|
@@ -949,18 +950,6 @@ function Form(props) {
|
|
|
949
950
|
const formIsDirty = formState.isDirty;
|
|
950
951
|
// console.log('formIsDirty', formIsDirty);
|
|
951
952
|
// console.log('isPhantom', isPhantom);
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
// LEFT OFF HERE
|
|
957
|
-
// The code I wrote below was supposed to be for the Tree search but messed up the standard
|
|
958
|
-
// windowed editors. Need to figure out how to make it work for both.
|
|
959
|
-
// Also, when crudding two records on the same tree in succession, the second record throws an error.
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
953
|
if (editorType === EDITOR_TYPE__WINDOWED && onCancel) {
|
|
965
954
|
showCancelBtn = true;
|
|
966
955
|
}
|
|
@@ -1003,79 +992,80 @@ function Form(props) {
|
|
|
1003
992
|
{editor}
|
|
1004
993
|
</ScrollView>}
|
|
1005
994
|
|
|
1006
|
-
|
|
1007
|
-
|
|
995
|
+
{!disableFooter &&
|
|
996
|
+
<Footer justifyContent="flex-end" {...footerProps} {...savingProps}>
|
|
997
|
+
{onDelete && editorMode === EDITOR_MODE__EDIT && isSingle &&
|
|
1008
998
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
999
|
+
<Row flex={1} justifyContent="flex-start">
|
|
1000
|
+
<Button
|
|
1001
|
+
{...testProps('deleteBtn')}
|
|
1002
|
+
key="deleteBtn"
|
|
1003
|
+
onPress={onDelete}
|
|
1004
|
+
bg="warning"
|
|
1005
|
+
_hover={{
|
|
1006
|
+
bg: 'warningHover',
|
|
1007
|
+
}}
|
|
1008
|
+
color="#fff"
|
|
1009
|
+
>Delete</Button>
|
|
1010
|
+
</Row>}
|
|
1011
|
+
|
|
1012
|
+
{showResetBtn &&
|
|
1013
|
+
<IconButton
|
|
1014
|
+
{...testProps('resetBtn')}
|
|
1015
|
+
key="resetBtn"
|
|
1016
|
+
onPress={() => doReset()}
|
|
1017
|
+
icon={Rotate}
|
|
1018
|
+
_icon={{
|
|
1019
|
+
color: !formState.isDirty ? 'trueGray.400' : '#000',
|
|
1017
1020
|
}}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
+
isDisabled={!formState.isDirty}
|
|
1022
|
+
mr={2}
|
|
1023
|
+
/>}
|
|
1021
1024
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1025
|
+
{showCancelBtn &&
|
|
1026
|
+
<Button
|
|
1027
|
+
{...testProps('cancelBtn')}
|
|
1028
|
+
key="cancelBtn"
|
|
1029
|
+
variant="ghost"
|
|
1030
|
+
onPress={onCancel}
|
|
1031
|
+
color="#fff"
|
|
1032
|
+
>Cancel</Button>}
|
|
1033
|
+
|
|
1034
|
+
{showCloseBtn &&
|
|
1035
|
+
<Button
|
|
1036
|
+
{...testProps('closeBtn')}
|
|
1037
|
+
key="closeBtn"
|
|
1038
|
+
variant="ghost"
|
|
1039
|
+
onPress={onClose}
|
|
1040
|
+
color="#fff"
|
|
1041
|
+
>Close</Button>}
|
|
1034
1042
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
+
{showSaveBtn &&
|
|
1044
|
+
<Button
|
|
1045
|
+
{...testProps('saveBtn')}
|
|
1046
|
+
key="saveBtn"
|
|
1047
|
+
onPress={(e) => handleSubmit(onSaveDecorated, onSubmitError)(e)}
|
|
1048
|
+
isDisabled={isSaveDisabled}
|
|
1049
|
+
color="#fff"
|
|
1050
|
+
>{editorMode === EDITOR_MODE__ADD ? 'Add' : 'Save'}</Button>}
|
|
1043
1051
|
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
{showSaveBtn &&
|
|
1054
|
-
<Button
|
|
1055
|
-
{...testProps('saveBtn')}
|
|
1056
|
-
key="saveBtn"
|
|
1057
|
-
onPress={(e) => handleSubmit(onSaveDecorated, onSubmitError)(e)}
|
|
1058
|
-
isDisabled={isSaveDisabled}
|
|
1059
|
-
color="#fff"
|
|
1060
|
-
>{editorMode === EDITOR_MODE__ADD ? 'Add' : 'Save'}</Button>}
|
|
1052
|
+
{showSubmitBtn &&
|
|
1053
|
+
<Button
|
|
1054
|
+
{...testProps('submitBtn')}
|
|
1055
|
+
key="submitBtn"
|
|
1056
|
+
onPress={(e) => handleSubmit(onSubmitDecorated, onSubmitError)(e)}
|
|
1057
|
+
isDisabled={isSubmitDisabled}
|
|
1058
|
+
color="#fff"
|
|
1059
|
+
>{submitBtnLabel || 'Submit'}</Button>}
|
|
1061
1060
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
{additionalFooterButtons && _.map(additionalFooterButtons, (props) => {
|
|
1072
|
-
return <Button
|
|
1073
|
-
{...testProps('additionalFooterBtn-' + props.key)}
|
|
1074
|
-
{...props}
|
|
1075
|
-
onPress={(e) => handleSubmit(props.onPress, onSubmitError)(e)}
|
|
1076
|
-
>{props.text}</Button>;
|
|
1077
|
-
})}
|
|
1078
|
-
</Footer>
|
|
1061
|
+
{additionalFooterButtons && _.map(additionalFooterButtons, (props) => {
|
|
1062
|
+
return <Button
|
|
1063
|
+
{...testProps('additionalFooterBtn-' + props.key)}
|
|
1064
|
+
{...props}
|
|
1065
|
+
onPress={(e) => handleSubmit(props.onPress, onSubmitError)(e)}
|
|
1066
|
+
>{props.text}</Button>;
|
|
1067
|
+
})}
|
|
1068
|
+
</Footer>}
|
|
1079
1069
|
</>}
|
|
1080
1070
|
</Column>;
|
|
1081
1071
|
}
|
|
@@ -20,6 +20,9 @@ import TriangleExclamation from '../Icons/TriangleExclamation.js';
|
|
|
20
20
|
import CircleInfo from '../Icons/CircleInfo.js';
|
|
21
21
|
import _ from 'lodash';
|
|
22
22
|
|
|
23
|
+
// This HOC enables easy usage of alert dialogs in the wrapped component.
|
|
24
|
+
// It can be used for simple alerts, confirmations, and custom dialogs.
|
|
25
|
+
|
|
23
26
|
export default function withAlert(WrappedComponent) {
|
|
24
27
|
return (props) => {
|
|
25
28
|
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect, } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Box,
|
|
4
|
+
Button,
|
|
5
|
+
Column,
|
|
6
|
+
Icon,
|
|
7
|
+
Modal,
|
|
8
|
+
Row,
|
|
9
|
+
Text,
|
|
10
|
+
} from 'native-base';
|
|
11
|
+
import Panel from '../Panel/Panel.js';
|
|
12
|
+
import TriangleExclamation from '../Icons/TriangleExclamation.js';
|
|
13
|
+
import useAdjustedWindowSize from '../../Hooks/useAdjustedWindowSize.js';
|
|
14
|
+
import testProps from '../../Functions/testProps.js';
|
|
15
|
+
import _ from 'lodash';
|
|
16
|
+
|
|
17
|
+
// This HOC enables easy usage of more complex dialogs in the wrapped component.
|
|
18
|
+
// Add en embedded Form,
|
|
19
|
+
|
|
20
|
+
// Use withAlert for simple alerts, confirmations, and custom dialogs.
|
|
21
|
+
|
|
22
|
+
export default function withModal(WrappedComponent) {
|
|
23
|
+
return (props) => {
|
|
24
|
+
|
|
25
|
+
if (props.disableWithModal || props.showModal) {
|
|
26
|
+
return <WrappedComponent {...props} />;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const
|
|
30
|
+
[title, setTitle] = useState(''),
|
|
31
|
+
[message, setMessage] = useState(''),
|
|
32
|
+
[canClose, setCanClose] = useState(true),
|
|
33
|
+
[includeCancel, setIncludeCancel] = useState(false),
|
|
34
|
+
[isModalShown, setIsModalShown] = useState(false),
|
|
35
|
+
[h, setHeight] = useState(250),
|
|
36
|
+
[w, setWidth] = useState(400),
|
|
37
|
+
[onOk, setOnOk] = useState(),
|
|
38
|
+
[onYes, setOnYes] = useState(),
|
|
39
|
+
[onNo, setOnNo] = useState(),
|
|
40
|
+
[customButtons, setCustomButtons] = useState(),
|
|
41
|
+
[color, setColor] = useState('#000'),
|
|
42
|
+
[body, setBody] = useState(),
|
|
43
|
+
autoFocusRef = useRef(null),
|
|
44
|
+
cancelRef = useRef(null),
|
|
45
|
+
[width, height] = useAdjustedWindowSize(w, h),
|
|
46
|
+
onCancel = () => {
|
|
47
|
+
setIsModalShown(false);
|
|
48
|
+
},
|
|
49
|
+
showModal = (args) => {
|
|
50
|
+
const {
|
|
51
|
+
title = '',
|
|
52
|
+
message = '',
|
|
53
|
+
canClose = true,
|
|
54
|
+
includeCancel = false,
|
|
55
|
+
onOk,
|
|
56
|
+
onYes,
|
|
57
|
+
onNo,
|
|
58
|
+
customButtons,
|
|
59
|
+
color,
|
|
60
|
+
// formItems = {},
|
|
61
|
+
body,
|
|
62
|
+
h,
|
|
63
|
+
w,
|
|
64
|
+
} = args;
|
|
65
|
+
|
|
66
|
+
if (title) {
|
|
67
|
+
setTitle(title);
|
|
68
|
+
}
|
|
69
|
+
if (!message) {
|
|
70
|
+
throw new Error('Message is required for showModal');
|
|
71
|
+
}
|
|
72
|
+
setMessage(message);
|
|
73
|
+
setCanClose(canClose);
|
|
74
|
+
setIncludeCancel(includeCancel);
|
|
75
|
+
if (onNo) {
|
|
76
|
+
setOnNo(() => onNo);
|
|
77
|
+
}
|
|
78
|
+
if (onOk) {
|
|
79
|
+
setOnOk(() => onOk);
|
|
80
|
+
}
|
|
81
|
+
if (onYes) {
|
|
82
|
+
setOnYes(() => onYes);
|
|
83
|
+
}
|
|
84
|
+
if (customButtons) {
|
|
85
|
+
setCustomButtons(customButtons);
|
|
86
|
+
}
|
|
87
|
+
if (color) {
|
|
88
|
+
setColor(color);
|
|
89
|
+
}
|
|
90
|
+
if (body) {
|
|
91
|
+
setBody(body);
|
|
92
|
+
}
|
|
93
|
+
if (h) {
|
|
94
|
+
setHeight(h);
|
|
95
|
+
}
|
|
96
|
+
if (w) {
|
|
97
|
+
setWidth(w);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
setIsModalShown(true);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
let buttons = [];
|
|
104
|
+
if (isModalShown) {
|
|
105
|
+
// assemble buttons
|
|
106
|
+
if (includeCancel) {
|
|
107
|
+
buttons.push(<Button
|
|
108
|
+
{...testProps('cancelBtn')}
|
|
109
|
+
key="cancelBtn"
|
|
110
|
+
onPress={onCancel}
|
|
111
|
+
colorScheme="coolGray"
|
|
112
|
+
variant="ghost" // or unstyled
|
|
113
|
+
ref={cancelRef}
|
|
114
|
+
>Cancel</Button>);
|
|
115
|
+
}
|
|
116
|
+
if (onNo) {
|
|
117
|
+
buttons.push(<Button
|
|
118
|
+
{...testProps('noBtn')}
|
|
119
|
+
key="noBtn"
|
|
120
|
+
onPress={onNo}
|
|
121
|
+
color="trueGray.800"
|
|
122
|
+
variant="ghost"
|
|
123
|
+
mr={2}
|
|
124
|
+
>No</Button>);
|
|
125
|
+
}
|
|
126
|
+
if (onOk) {
|
|
127
|
+
buttons.push(<Button
|
|
128
|
+
{...testProps('okBtn')}
|
|
129
|
+
key="okBtn"
|
|
130
|
+
ref={autoFocusRef}
|
|
131
|
+
onPress={onOk}
|
|
132
|
+
>OK</Button>);
|
|
133
|
+
}
|
|
134
|
+
if (onYes) {
|
|
135
|
+
buttons.push(<Button
|
|
136
|
+
{...testProps('yesBtn')}
|
|
137
|
+
key="yesBtn"
|
|
138
|
+
ref={autoFocusRef}
|
|
139
|
+
onPress={onYes}
|
|
140
|
+
>Yes</Button>);
|
|
141
|
+
}
|
|
142
|
+
if (customButtons) {
|
|
143
|
+
_.each(customButtons, (button) => {
|
|
144
|
+
buttons.push(button);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return <>
|
|
150
|
+
<WrappedComponent
|
|
151
|
+
{...props}
|
|
152
|
+
disableWithModal={false}
|
|
153
|
+
showModal={showModal}
|
|
154
|
+
hideModal={onCancel}
|
|
155
|
+
/>
|
|
156
|
+
{isModalShown &&
|
|
157
|
+
<Modal
|
|
158
|
+
isOpen={true}
|
|
159
|
+
onClose={onCancel}
|
|
160
|
+
>
|
|
161
|
+
<Panel
|
|
162
|
+
{...props}
|
|
163
|
+
reference="modal"
|
|
164
|
+
isCollapsible={false}
|
|
165
|
+
bg="#fff"
|
|
166
|
+
w={width}
|
|
167
|
+
h={height}
|
|
168
|
+
flex={null}
|
|
169
|
+
>
|
|
170
|
+
{title && <Modal.Header>{title}</Modal.Header>}
|
|
171
|
+
<Modal.Body
|
|
172
|
+
borderTopWidth={0}
|
|
173
|
+
bg="#fff"
|
|
174
|
+
p={3}
|
|
175
|
+
justifyContent=" center"
|
|
176
|
+
alignItems="center"
|
|
177
|
+
borderRadius={5}
|
|
178
|
+
flexDirection="row"
|
|
179
|
+
>
|
|
180
|
+
{body ||
|
|
181
|
+
<>
|
|
182
|
+
<Box w="50px" mx={2}>
|
|
183
|
+
<Icon as={TriangleExclamation} color={color} size="10" />
|
|
184
|
+
</Box>
|
|
185
|
+
<Text flex={1} color={color} fontSize="18px">{message}</Text>
|
|
186
|
+
</>}
|
|
187
|
+
</Modal.Body>
|
|
188
|
+
<Modal.Footer py={2} pr={4} justifyContent="flex-end">
|
|
189
|
+
{buttons}
|
|
190
|
+
</Modal.Footer>
|
|
191
|
+
</Panel>
|
|
192
|
+
</Modal>}
|
|
193
|
+
|
|
194
|
+
</>;
|
|
195
|
+
};
|
|
196
|
+
}
|