@onehat/ui 0.3.295 → 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
|
|
|
@@ -14,6 +14,11 @@ import useAdjustedWindowSize from '../../Hooks/useAdjustedWindowSize.js';
|
|
|
14
14
|
import testProps from '../../Functions/testProps.js';
|
|
15
15
|
import _ from 'lodash';
|
|
16
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
|
+
|
|
17
22
|
export default function withModal(WrappedComponent) {
|
|
18
23
|
return (props) => {
|
|
19
24
|
|
|
@@ -27,14 +32,17 @@ export default function withModal(WrappedComponent) {
|
|
|
27
32
|
[canClose, setCanClose] = useState(true),
|
|
28
33
|
[includeCancel, setIncludeCancel] = useState(false),
|
|
29
34
|
[isModalShown, setIsModalShown] = useState(false),
|
|
35
|
+
[h, setHeight] = useState(250),
|
|
36
|
+
[w, setWidth] = useState(400),
|
|
30
37
|
[onOk, setOnOk] = useState(),
|
|
31
38
|
[onYes, setOnYes] = useState(),
|
|
32
39
|
[onNo, setOnNo] = useState(),
|
|
33
40
|
[customButtons, setCustomButtons] = useState(),
|
|
34
41
|
[color, setColor] = useState('#000'),
|
|
42
|
+
[body, setBody] = useState(),
|
|
35
43
|
autoFocusRef = useRef(null),
|
|
36
44
|
cancelRef = useRef(null),
|
|
37
|
-
[width, height] = useAdjustedWindowSize(
|
|
45
|
+
[width, height] = useAdjustedWindowSize(w, h),
|
|
38
46
|
onCancel = () => {
|
|
39
47
|
setIsModalShown(false);
|
|
40
48
|
},
|
|
@@ -49,6 +57,10 @@ export default function withModal(WrappedComponent) {
|
|
|
49
57
|
onNo,
|
|
50
58
|
customButtons,
|
|
51
59
|
color,
|
|
60
|
+
// formItems = {},
|
|
61
|
+
body,
|
|
62
|
+
h,
|
|
63
|
+
w,
|
|
52
64
|
} = args;
|
|
53
65
|
|
|
54
66
|
if (title) {
|
|
@@ -60,47 +72,47 @@ export default function withModal(WrappedComponent) {
|
|
|
60
72
|
setMessage(message);
|
|
61
73
|
setCanClose(canClose);
|
|
62
74
|
setIncludeCancel(includeCancel);
|
|
75
|
+
if (onNo) {
|
|
76
|
+
setOnNo(() => onNo);
|
|
77
|
+
}
|
|
63
78
|
if (onOk) {
|
|
64
79
|
setOnOk(() => onOk);
|
|
65
80
|
}
|
|
66
81
|
if (onYes) {
|
|
67
82
|
setOnYes(() => onYes);
|
|
68
83
|
}
|
|
69
|
-
if (onNo) {
|
|
70
|
-
setOnNo(() => onNo);
|
|
71
|
-
}
|
|
72
84
|
if (customButtons) {
|
|
73
85
|
setCustomButtons(customButtons);
|
|
74
86
|
}
|
|
75
87
|
if (color) {
|
|
76
88
|
setColor(color);
|
|
77
89
|
}
|
|
90
|
+
if (body) {
|
|
91
|
+
setBody(body);
|
|
92
|
+
}
|
|
93
|
+
if (h) {
|
|
94
|
+
setHeight(h);
|
|
95
|
+
}
|
|
96
|
+
if (w) {
|
|
97
|
+
setWidth(w);
|
|
98
|
+
}
|
|
78
99
|
|
|
79
100
|
setIsModalShown(true);
|
|
80
101
|
};
|
|
81
102
|
|
|
82
103
|
let buttons = [];
|
|
83
104
|
if (isModalShown) {
|
|
105
|
+
// assemble buttons
|
|
84
106
|
if (includeCancel) {
|
|
85
107
|
buttons.push(<Button
|
|
86
108
|
{...testProps('cancelBtn')}
|
|
87
109
|
key="cancelBtn"
|
|
88
110
|
onPress={onCancel}
|
|
89
|
-
color="#fff"
|
|
90
111
|
colorScheme="coolGray"
|
|
91
112
|
variant="ghost" // or unstyled
|
|
92
113
|
ref={cancelRef}
|
|
93
114
|
>Cancel</Button>);
|
|
94
115
|
}
|
|
95
|
-
if (onOk) {
|
|
96
|
-
buttons.push(<Button
|
|
97
|
-
{...testProps('okBtn')}
|
|
98
|
-
key="okBtn"
|
|
99
|
-
ref={autoFocusRef}
|
|
100
|
-
onPress={onOk}
|
|
101
|
-
color="#fff"
|
|
102
|
-
>OK</Button>);
|
|
103
|
-
}
|
|
104
116
|
if (onNo) {
|
|
105
117
|
buttons.push(<Button
|
|
106
118
|
{...testProps('noBtn')}
|
|
@@ -108,18 +120,23 @@ export default function withModal(WrappedComponent) {
|
|
|
108
120
|
onPress={onNo}
|
|
109
121
|
color="trueGray.800"
|
|
110
122
|
variant="ghost"
|
|
111
|
-
// colorScheme="neutral"
|
|
112
123
|
mr={2}
|
|
113
124
|
>No</Button>);
|
|
114
125
|
}
|
|
126
|
+
if (onOk) {
|
|
127
|
+
buttons.push(<Button
|
|
128
|
+
{...testProps('okBtn')}
|
|
129
|
+
key="okBtn"
|
|
130
|
+
ref={autoFocusRef}
|
|
131
|
+
onPress={onOk}
|
|
132
|
+
>OK</Button>);
|
|
133
|
+
}
|
|
115
134
|
if (onYes) {
|
|
116
135
|
buttons.push(<Button
|
|
117
136
|
{...testProps('yesBtn')}
|
|
118
137
|
key="yesBtn"
|
|
119
138
|
ref={autoFocusRef}
|
|
120
139
|
onPress={onYes}
|
|
121
|
-
color="#fff"
|
|
122
|
-
// colorScheme="danger"
|
|
123
140
|
>Yes</Button>);
|
|
124
141
|
}
|
|
125
142
|
if (customButtons) {
|
|
@@ -150,21 +167,23 @@ export default function withModal(WrappedComponent) {
|
|
|
150
167
|
h={height}
|
|
151
168
|
flex={null}
|
|
152
169
|
>
|
|
153
|
-
|
|
154
170
|
{title && <Modal.Header>{title}</Modal.Header>}
|
|
155
171
|
<Modal.Body
|
|
156
172
|
borderTopWidth={0}
|
|
157
173
|
bg="#fff"
|
|
158
174
|
p={3}
|
|
159
|
-
justifyContent="center"
|
|
175
|
+
justifyContent=" center"
|
|
160
176
|
alignItems="center"
|
|
161
177
|
borderRadius={5}
|
|
162
178
|
flexDirection="row"
|
|
163
179
|
>
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
+
</>}
|
|
168
187
|
</Modal.Body>
|
|
169
188
|
<Modal.Footer py={2} pr={4} justifyContent="flex-end">
|
|
170
189
|
{buttons}
|