@tecsinapse/react-native-kit 3.4.2 → 3.5.0
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/LICENSE.md +1 -1
- package/README.md +9 -7
- package/dist/cjs/components/atoms/Modal/ui/BaseModalView.js +3 -6
- package/dist/cjs/components/molecules/Select/Select.js +42 -157
- package/dist/cjs/components/molecules/Select/components/Flat.js +24 -0
- package/dist/cjs/components/molecules/Select/components/Modal.js +96 -0
- package/dist/cjs/components/molecules/Select/components/Option.js +50 -0
- package/dist/cjs/components/molecules/Select/components/Section.js +29 -0
- package/dist/cjs/components/molecules/Select/functions.js +43 -0
- package/dist/cjs/components/molecules/Select/hooks/useModal.js +109 -0
- package/dist/cjs/components/molecules/Select/hooks/useSelect.js +147 -0
- package/dist/cjs/components/molecules/Select/styled.js +12 -2
- package/dist/esm/components/atoms/Modal/ui/BaseModalView.js +3 -6
- package/dist/esm/components/molecules/Select/Select.js +44 -141
- package/dist/esm/components/molecules/Select/components/Flat.js +22 -0
- package/dist/esm/components/molecules/Select/components/Modal.js +94 -0
- package/dist/esm/components/molecules/Select/components/Option.js +48 -0
- package/dist/esm/components/molecules/Select/components/Section.js +27 -0
- package/dist/esm/components/molecules/Select/functions.js +35 -0
- package/dist/esm/components/molecules/Select/hooks/useModal.js +107 -0
- package/dist/esm/components/molecules/Select/hooks/useSelect.js +145 -0
- package/dist/esm/components/molecules/Select/styled.js +11 -3
- package/dist/types/components/molecules/Select/Select.d.ts +2 -23
- package/dist/types/components/molecules/Select/components/Flat.d.ts +8 -0
- package/dist/types/components/molecules/Select/components/Modal.d.ts +4 -0
- package/dist/types/components/molecules/Select/components/Option.d.ts +10 -0
- package/dist/types/components/molecules/Select/components/Section.d.ts +8 -0
- package/dist/types/components/molecules/Select/functions.d.ts +9 -0
- package/dist/types/components/molecules/Select/hooks/useModal.d.ts +66 -0
- package/dist/types/components/molecules/Select/hooks/useSelect.d.ts +58 -0
- package/dist/types/components/molecules/Select/index.d.ts +1 -1
- package/dist/types/components/molecules/Select/styled.d.ts +12 -0
- package/dist/types/components/molecules/Select/types.d.ts +33 -0
- package/package.json +9 -6
- package/dist/cjs/components/molecules/Select/Modal.js +0 -224
- package/dist/esm/components/molecules/Select/Modal.js +0 -203
- package/dist/types/components/molecules/Select/Modal.d.ts +0 -8
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
require('react-native');
|
|
5
|
+
var reactCore = require('@tecsinapse/react-core');
|
|
6
|
+
require('react-native-safe-area-context');
|
|
7
|
+
require('../../../atoms/Modal/ui/styled.js');
|
|
8
|
+
var useLazyModalManager = require('../../../atoms/Modal/useLazyModalManager.js');
|
|
9
|
+
var functions = require('../functions.js');
|
|
10
|
+
|
|
11
|
+
const useSelect = ({
|
|
12
|
+
value,
|
|
13
|
+
options,
|
|
14
|
+
keyExtractor,
|
|
15
|
+
type,
|
|
16
|
+
labelExtractor,
|
|
17
|
+
placeholder,
|
|
18
|
+
onFocus,
|
|
19
|
+
onBlur,
|
|
20
|
+
disabled,
|
|
21
|
+
onSearch,
|
|
22
|
+
label,
|
|
23
|
+
...rest
|
|
24
|
+
}) => {
|
|
25
|
+
const { focused, handleBlur, handleFocus } = reactCore.useInputFocus(
|
|
26
|
+
onFocus,
|
|
27
|
+
onBlur,
|
|
28
|
+
!disabled
|
|
29
|
+
);
|
|
30
|
+
const [selectOptions, setSelectOptions] = React.useState([]);
|
|
31
|
+
const modal = useLazyModalManager.useLazyModalManager();
|
|
32
|
+
const [loading, setLoading] = React.useState(false);
|
|
33
|
+
const onlyLabel = label && !placeholder;
|
|
34
|
+
const hasValue = type === "single" ? !!value : (value || []).length > 0;
|
|
35
|
+
const _placeholder = onlyLabel ? label : placeholder;
|
|
36
|
+
const _label = hasValue ? label : void 0;
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (typeof options !== "function") {
|
|
39
|
+
setSelectOptions(options);
|
|
40
|
+
}
|
|
41
|
+
}, [options]);
|
|
42
|
+
const handleLazyFocus = React.useCallback(async () => {
|
|
43
|
+
if (typeof options === "function" && !onSearch) {
|
|
44
|
+
setLoading(true);
|
|
45
|
+
try {
|
|
46
|
+
const result = await options();
|
|
47
|
+
if (result) {
|
|
48
|
+
const _value = value;
|
|
49
|
+
if (_value && !(result instanceof Map) && !functions.findValue(result, _value, keyExtractor)) {
|
|
50
|
+
setSelectOptions([_value, ...result]);
|
|
51
|
+
} else setSelectOptions(result);
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
} finally {
|
|
55
|
+
setLoading(false);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, [options, value, setSelectOptions]);
|
|
59
|
+
const handleOnSearch = React.useCallback(
|
|
60
|
+
async (searchInput) => {
|
|
61
|
+
if (searchInput !== void 0 && onSearch) {
|
|
62
|
+
setLoading(true);
|
|
63
|
+
modal.requestUpdate();
|
|
64
|
+
try {
|
|
65
|
+
const result = await onSearch(searchInput);
|
|
66
|
+
if (result) {
|
|
67
|
+
if (type === "single") {
|
|
68
|
+
const _value = value;
|
|
69
|
+
if (_value && !(result instanceof Map) && !functions.findValue(result, _value, keyExtractor)) {
|
|
70
|
+
setSelectOptions([_value, ...result]);
|
|
71
|
+
} else setSelectOptions(result);
|
|
72
|
+
} else {
|
|
73
|
+
const _value = value;
|
|
74
|
+
if (_value?.length && !(result instanceof Map)) {
|
|
75
|
+
const selected = _value.filter((it) => !functions.findValue(result, it, keyExtractor)) ?? [];
|
|
76
|
+
setSelectOptions([...selected, ...result]);
|
|
77
|
+
} else {
|
|
78
|
+
setSelectOptions(result);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (e) {
|
|
83
|
+
} finally {
|
|
84
|
+
modal.requestUpdate();
|
|
85
|
+
setLoading(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
[options, value, keyExtractor]
|
|
90
|
+
);
|
|
91
|
+
const getDisplayValue = React.useCallback(() => {
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
return functions.getMultiLabel(
|
|
94
|
+
value,
|
|
95
|
+
String(_placeholder),
|
|
96
|
+
selectOptions,
|
|
97
|
+
keyExtractor,
|
|
98
|
+
labelExtractor
|
|
99
|
+
);
|
|
100
|
+
} else {
|
|
101
|
+
return functions.getSingleLabel(
|
|
102
|
+
value,
|
|
103
|
+
String(_placeholder),
|
|
104
|
+
selectOptions,
|
|
105
|
+
keyExtractor,
|
|
106
|
+
labelExtractor
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}, [_placeholder, value, selectOptions]);
|
|
110
|
+
const handlePressInput = async () => {
|
|
111
|
+
modal.show();
|
|
112
|
+
handleFocus();
|
|
113
|
+
await handleLazyFocus();
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
/**
|
|
117
|
+
* Hook props
|
|
118
|
+
*/
|
|
119
|
+
focused,
|
|
120
|
+
handleBlur,
|
|
121
|
+
handlePressInput,
|
|
122
|
+
getDisplayValue,
|
|
123
|
+
handleOnSearch,
|
|
124
|
+
_label,
|
|
125
|
+
loading,
|
|
126
|
+
modal,
|
|
127
|
+
selectOptions,
|
|
128
|
+
setSelectOptions,
|
|
129
|
+
/**
|
|
130
|
+
* Component props
|
|
131
|
+
*/
|
|
132
|
+
value,
|
|
133
|
+
options,
|
|
134
|
+
keyExtractor,
|
|
135
|
+
type,
|
|
136
|
+
labelExtractor,
|
|
137
|
+
placeholder,
|
|
138
|
+
onFocus,
|
|
139
|
+
onBlur,
|
|
140
|
+
disabled,
|
|
141
|
+
onSearch,
|
|
142
|
+
label,
|
|
143
|
+
...rest
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
module.exports = useSelect;
|
|
@@ -33,8 +33,6 @@ const SearchBarContainer = styled(reactNative.View)`
|
|
|
33
33
|
position: relative;
|
|
34
34
|
`;
|
|
35
35
|
const ListItem = styled(reactCore.PressableSurface)`
|
|
36
|
-
border-bottom-width: ${reactCore.RFValueStr("1px")};
|
|
37
|
-
border-color: ${({ theme }) => theme.color.secondary.light};
|
|
38
36
|
padding-top: ${({ theme }) => theme.spacing.mili};
|
|
39
37
|
padding-bottom: ${({ theme }) => theme.spacing.mili};
|
|
40
38
|
padding-left: ${({ theme }) => theme.spacing.deca};
|
|
@@ -60,11 +58,23 @@ const TextTitleModal = styled(Text)`
|
|
|
60
58
|
const StyledTextItemSelect = styled(Text)`
|
|
61
59
|
width: 90%;
|
|
62
60
|
`;
|
|
61
|
+
const Divider = styled(reactNative.View)`
|
|
62
|
+
height: ${reactCore.RFValueStr("1px")};
|
|
63
|
+
display: flex;
|
|
64
|
+
flex: 1 1 auto;
|
|
65
|
+
background-color: ${({ theme }) => theme.color.secondary.light};
|
|
66
|
+
`;
|
|
67
|
+
const SectionHeader = styled(reactNative.View)`
|
|
68
|
+
background-color: #fff;
|
|
69
|
+
padding: ${({ theme }) => theme.spacing.deca};
|
|
70
|
+
`;
|
|
63
71
|
|
|
72
|
+
exports.Divider = Divider;
|
|
64
73
|
exports.FetchIndicator = FetchIndicator;
|
|
65
74
|
exports.ListItem = ListItem;
|
|
66
75
|
exports.ModalFooter = ModalFooter;
|
|
67
76
|
exports.SearchBarContainer = SearchBarContainer;
|
|
77
|
+
exports.SectionHeader = SectionHeader;
|
|
68
78
|
exports.SelectIcon = SelectIcon;
|
|
69
79
|
exports.StyledSelectionText = StyledSelectionText;
|
|
70
80
|
exports.StyledTextItemSelect = StyledTextItemSelect;
|
|
@@ -27,8 +27,7 @@ const ModalView = ({
|
|
|
27
27
|
const opacityCarrier = useRef(new Animated.Value(0)).current;
|
|
28
28
|
const offset = isLastShown && keyboardOpened > 0 ? 0 : bottom;
|
|
29
29
|
const getKeyboardHeight = (keyboard) => {
|
|
30
|
-
if (keyboard === 0)
|
|
31
|
-
return 0;
|
|
30
|
+
if (keyboard === 0) return 0;
|
|
32
31
|
const wHeight = Math.ceil(Dimensions.get("window").height);
|
|
33
32
|
const sHeight = Math.ceil(Dimensions.get("screen").height);
|
|
34
33
|
if (wHeight !== sHeight) {
|
|
@@ -99,14 +98,12 @@ const ModalView = ({
|
|
|
99
98
|
[show, ready, visible, setReady]
|
|
100
99
|
);
|
|
101
100
|
useEffect(() => {
|
|
102
|
-
if (visible && ready)
|
|
103
|
-
requestAnimationFrame(() => show());
|
|
101
|
+
if (visible && ready) requestAnimationFrame(() => show());
|
|
104
102
|
if (!visible && !ready) {
|
|
105
103
|
Keyboard.dismiss();
|
|
106
104
|
requestAnimationFrame(() => hide(boxHeight));
|
|
107
105
|
}
|
|
108
|
-
if (!visible && ready)
|
|
109
|
-
setReady(false);
|
|
106
|
+
if (!visible && ready) setReady(false);
|
|
110
107
|
}, [ready, visible]);
|
|
111
108
|
useEffect(() => {
|
|
112
109
|
const showEvent = Keyboard.addListener(
|
|
@@ -1,139 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { useState, useEffect } from 'react';
|
|
4
|
-
import 'react-native';
|
|
5
|
-
import 'react-native-safe-area-context';
|
|
6
|
-
import '../../atoms/Modal/ui/styled.js';
|
|
7
|
-
import { useLazyModalManager } from '../../atoms/Modal/useLazyModalManager.js';
|
|
1
|
+
import { HintInputContainer } from '@tecsinapse/react-core';
|
|
2
|
+
import React__default from 'react';
|
|
8
3
|
import Text from '../../atoms/Text/Text.js';
|
|
9
|
-
import { Modal } from './Modal.js';
|
|
4
|
+
import { Modal } from './components/Modal.js';
|
|
10
5
|
import { SelectIcon, StyledSelectionText } from './styled.js';
|
|
6
|
+
import useSelect from './hooks/useSelect.js';
|
|
11
7
|
|
|
12
|
-
function Select({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
const [selectOptions, setSelectOptions] = useState([]);
|
|
48
|
-
const modal = useLazyModalManager();
|
|
49
|
-
const [loading, setLoading] = useState(false);
|
|
50
|
-
const onlyLabel = label && !placeholder;
|
|
51
|
-
const hasValue = type === "single" ? !!value : (value || []).length > 0;
|
|
52
|
-
const _placeholder = onlyLabel ? label : placeholder;
|
|
53
|
-
const _label = hasValue ? label : void 0;
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (typeof options !== "function") {
|
|
56
|
-
setSelectOptions(options);
|
|
57
|
-
}
|
|
58
|
-
}, [options]);
|
|
59
|
-
const handleLazyFocus = React.useCallback(async () => {
|
|
60
|
-
if (typeof options === "function" && !onSearch) {
|
|
61
|
-
setLoading(true);
|
|
62
|
-
try {
|
|
63
|
-
const result = await options();
|
|
64
|
-
if (result) {
|
|
65
|
-
if (value && !result.find((v) => keyExtractor(value) === keyExtractor(v))) {
|
|
66
|
-
setSelectOptions([value, ...result]);
|
|
67
|
-
} else
|
|
68
|
-
setSelectOptions(result);
|
|
69
|
-
}
|
|
70
|
-
} catch (e) {
|
|
71
|
-
} finally {
|
|
72
|
-
setLoading(false);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}, [options, value, setSelectOptions]);
|
|
76
|
-
const handleOnSearch = React.useCallback(
|
|
77
|
-
async (searchInput) => {
|
|
78
|
-
if (searchInput !== void 0 && onSearch) {
|
|
79
|
-
setLoading(true);
|
|
80
|
-
modal.requestUpdate();
|
|
81
|
-
try {
|
|
82
|
-
const result = await onSearch(searchInput);
|
|
83
|
-
if (result) {
|
|
84
|
-
if (type === "single") {
|
|
85
|
-
if (value && !result.find(
|
|
86
|
-
(v) => keyExtractor(value) === keyExtractor(v)
|
|
87
|
-
)) {
|
|
88
|
-
setSelectOptions([value, ...result]);
|
|
89
|
-
} else
|
|
90
|
-
setSelectOptions(result);
|
|
91
|
-
} else {
|
|
92
|
-
if (value?.length) {
|
|
93
|
-
const selectedValues = value.filter(
|
|
94
|
-
(v) => !result.find(
|
|
95
|
-
(current) => keyExtractor(v) === keyExtractor(current)
|
|
96
|
-
)
|
|
97
|
-
) || [];
|
|
98
|
-
setSelectOptions([...selectedValues, ...result]);
|
|
99
|
-
} else {
|
|
100
|
-
setSelectOptions(result);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
} catch (e) {
|
|
105
|
-
} finally {
|
|
106
|
-
modal.requestUpdate();
|
|
107
|
-
setLoading(false);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
[options, value, keyExtractor]
|
|
112
|
-
);
|
|
113
|
-
const getDisplayValue = React.useCallback(() => {
|
|
114
|
-
if (Array.isArray(value)) {
|
|
115
|
-
if (value.length === 0)
|
|
116
|
-
return _placeholder;
|
|
117
|
-
else {
|
|
118
|
-
const options2 = selectOptions.length > 0 ? selectOptions : value;
|
|
119
|
-
return options2?.reduce(
|
|
120
|
-
(acc, option, index) => value.find(
|
|
121
|
-
(key) => keyExtractor(option, index) == keyExtractor(key, index)
|
|
122
|
-
) ? acc + labelExtractor(option) + ", " : acc,
|
|
123
|
-
""
|
|
124
|
-
).slice(0, -2);
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
if (!value)
|
|
128
|
-
return _placeholder;
|
|
129
|
-
const selectedOption = selectOptions?.find(
|
|
130
|
-
(option, index) => keyExtractor(option, index) == keyExtractor(value, index)
|
|
131
|
-
);
|
|
132
|
-
return labelExtractor(selectedOption ?? value);
|
|
133
|
-
}
|
|
134
|
-
}, [_placeholder, value, selectOptions]);
|
|
8
|
+
function Select(props) {
|
|
9
|
+
const {
|
|
10
|
+
groupKeyExtractor,
|
|
11
|
+
onSelect,
|
|
12
|
+
selectModalTitle,
|
|
13
|
+
selectModalTitleComponent,
|
|
14
|
+
searchBarPlaceholder,
|
|
15
|
+
hideSearchBar,
|
|
16
|
+
confirmButtonText,
|
|
17
|
+
rightComponent,
|
|
18
|
+
variant = "default",
|
|
19
|
+
hintComponent,
|
|
20
|
+
hint,
|
|
21
|
+
style,
|
|
22
|
+
controlComponent,
|
|
23
|
+
type,
|
|
24
|
+
numberOfLines,
|
|
25
|
+
closeOnPick = type === "single",
|
|
26
|
+
modal,
|
|
27
|
+
selectOptions,
|
|
28
|
+
keyExtractor,
|
|
29
|
+
labelExtractor,
|
|
30
|
+
value,
|
|
31
|
+
handleOnSearch,
|
|
32
|
+
loading,
|
|
33
|
+
options,
|
|
34
|
+
setSelectOptions,
|
|
35
|
+
handleBlur,
|
|
36
|
+
handlePressInput,
|
|
37
|
+
getDisplayValue,
|
|
38
|
+
focused,
|
|
39
|
+
disabled,
|
|
40
|
+
_label,
|
|
41
|
+
...rest
|
|
42
|
+
} = useSelect(props);
|
|
135
43
|
modal.sync(
|
|
136
|
-
/* @__PURE__ */
|
|
44
|
+
/* @__PURE__ */ React__default.createElement(
|
|
137
45
|
Modal,
|
|
138
46
|
{
|
|
139
47
|
options: selectOptions || [],
|
|
@@ -161,14 +69,10 @@ function Select({
|
|
|
161
69
|
}
|
|
162
70
|
)
|
|
163
71
|
);
|
|
164
|
-
|
|
165
|
-
modal.show();
|
|
166
|
-
handleFocus();
|
|
167
|
-
await handleLazyFocus();
|
|
168
|
-
};
|
|
169
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, controlComponent ? controlComponent(handlePressInput, getDisplayValue() || "") : /* @__PURE__ */ React.createElement(
|
|
72
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, controlComponent ? controlComponent(handlePressInput, getDisplayValue() || "") : /* @__PURE__ */ React__default.createElement(
|
|
170
73
|
HintInputContainer,
|
|
171
74
|
{
|
|
75
|
+
...rest,
|
|
172
76
|
viewStyle: style,
|
|
173
77
|
onPress: handlePressInput,
|
|
174
78
|
focused,
|
|
@@ -178,10 +82,9 @@ function Select({
|
|
|
178
82
|
hint,
|
|
179
83
|
hintComponent,
|
|
180
84
|
label: _label,
|
|
181
|
-
rightComponent: /* @__PURE__ */
|
|
182
|
-
...rest
|
|
85
|
+
rightComponent: /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(SelectIcon, { name: "chevron-down", type: "ionicon", size: "centi" }), rightComponent)
|
|
183
86
|
},
|
|
184
|
-
/* @__PURE__ */
|
|
87
|
+
/* @__PURE__ */ React__default.createElement(
|
|
185
88
|
StyledSelectionText,
|
|
186
89
|
{
|
|
187
90
|
numberOfLines,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { Divider } from '../styled.js';
|
|
3
|
+
import { FlatList } from 'react-native';
|
|
4
|
+
|
|
5
|
+
const Flat = ({ options, keyExtractor, renderItem, getData }) => {
|
|
6
|
+
const data = React__default.useMemo(
|
|
7
|
+
() => typeof options !== "function" ? getData(options) : [],
|
|
8
|
+
[options, getData]
|
|
9
|
+
);
|
|
10
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
11
|
+
FlatList,
|
|
12
|
+
{
|
|
13
|
+
data,
|
|
14
|
+
keyExtractor,
|
|
15
|
+
fadingEdgeLength: 200,
|
|
16
|
+
ItemSeparatorComponent: Divider,
|
|
17
|
+
renderItem
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { Flat as default };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { Button } from '../../../atoms/Button/Button.js';
|
|
3
|
+
import { RFValue } from '@tecsinapse/react-core';
|
|
4
|
+
import Text from '../../../atoms/Text/Text.js';
|
|
5
|
+
import Header from '../../../atoms/Header/Header.js';
|
|
6
|
+
import Input from '../../../atoms/Input/Input.js';
|
|
7
|
+
import 'react-native';
|
|
8
|
+
import { ModalView } from '../../../atoms/Modal/ui/BaseModalView.js';
|
|
9
|
+
import { SearchBarContainer, SelectIcon, FetchIndicator, ModalFooter, TextTitleModal } from '../styled.js';
|
|
10
|
+
import Section from './Section.js';
|
|
11
|
+
import Flat from './Flat.js';
|
|
12
|
+
import useModal from '../hooks/useModal.js';
|
|
13
|
+
|
|
14
|
+
const ModalTitle = ({ title }) => title ? /* @__PURE__ */ React__default.createElement(
|
|
15
|
+
TextTitleModal,
|
|
16
|
+
{
|
|
17
|
+
typography: "h4",
|
|
18
|
+
fontWeight: "bold",
|
|
19
|
+
numberOfLines: 3,
|
|
20
|
+
style: { maxWidth: RFValue(250) }
|
|
21
|
+
},
|
|
22
|
+
title
|
|
23
|
+
) : null;
|
|
24
|
+
const Component = (props) => {
|
|
25
|
+
const {
|
|
26
|
+
ModalComponent,
|
|
27
|
+
selectModalTitleComponent,
|
|
28
|
+
selectModalTitle,
|
|
29
|
+
hideSearchBar,
|
|
30
|
+
searchBarPlaceholder,
|
|
31
|
+
searchArg,
|
|
32
|
+
setSearchArg,
|
|
33
|
+
loading,
|
|
34
|
+
options,
|
|
35
|
+
getData,
|
|
36
|
+
renderItem,
|
|
37
|
+
keyExtractor,
|
|
38
|
+
closeOnPick,
|
|
39
|
+
confirmButtonText,
|
|
40
|
+
handleConfirm,
|
|
41
|
+
close,
|
|
42
|
+
...others
|
|
43
|
+
} = useModal(props);
|
|
44
|
+
return /* @__PURE__ */ React__default.createElement(ModalView, { ...others, BoxComponent: ModalComponent, showCloseBar: false }, /* @__PURE__ */ React__default.createElement(
|
|
45
|
+
Header,
|
|
46
|
+
{
|
|
47
|
+
rightButton: {
|
|
48
|
+
onPress: close,
|
|
49
|
+
icon: {
|
|
50
|
+
name: "close",
|
|
51
|
+
type: "material-community",
|
|
52
|
+
fontColor: "light"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
selectModalTitleComponent ? selectModalTitleComponent : /* @__PURE__ */ React__default.createElement(ModalTitle, { title: selectModalTitle })
|
|
57
|
+
), !hideSearchBar ? /* @__PURE__ */ React__default.createElement(SearchBarContainer, null, /* @__PURE__ */ React__default.createElement(
|
|
58
|
+
Input,
|
|
59
|
+
{
|
|
60
|
+
placeholder: searchBarPlaceholder,
|
|
61
|
+
value: searchArg,
|
|
62
|
+
onChange: setSearchArg,
|
|
63
|
+
leftComponent: /* @__PURE__ */ React__default.createElement(SelectIcon, { name: "search", type: "ionicon", size: "centi" })
|
|
64
|
+
}
|
|
65
|
+
)) : null, loading ? /* @__PURE__ */ React__default.createElement(FetchIndicator, { animating: true, color: "grey", size: "large" }) : null, options instanceof Map ? /* @__PURE__ */ React__default.createElement(
|
|
66
|
+
Section,
|
|
67
|
+
{
|
|
68
|
+
options,
|
|
69
|
+
getData,
|
|
70
|
+
renderItem,
|
|
71
|
+
keyExtractor
|
|
72
|
+
}
|
|
73
|
+
) : /* @__PURE__ */ React__default.createElement(
|
|
74
|
+
Flat,
|
|
75
|
+
{
|
|
76
|
+
renderItem,
|
|
77
|
+
getData,
|
|
78
|
+
options,
|
|
79
|
+
keyExtractor
|
|
80
|
+
}
|
|
81
|
+
), !closeOnPick ? /* @__PURE__ */ React__default.createElement(ModalFooter, null, /* @__PURE__ */ React__default.createElement(
|
|
82
|
+
Button,
|
|
83
|
+
{
|
|
84
|
+
variant: "filled",
|
|
85
|
+
color: "primary",
|
|
86
|
+
onPress: handleConfirm,
|
|
87
|
+
disabled: loading
|
|
88
|
+
},
|
|
89
|
+
/* @__PURE__ */ React__default.createElement(Text, { fontColor: "light", fontWeight: "bold" }, confirmButtonText)
|
|
90
|
+
)) : null);
|
|
91
|
+
};
|
|
92
|
+
const Modal = Component;
|
|
93
|
+
|
|
94
|
+
export { Modal };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { ListItem, StyledTextItemSelect } from '../styled.js';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import { Checkbox, RadioButton } from '@tecsinapse/react-core';
|
|
5
|
+
|
|
6
|
+
const Component = ({
|
|
7
|
+
handlePressItem,
|
|
8
|
+
labelExtractor,
|
|
9
|
+
item,
|
|
10
|
+
type
|
|
11
|
+
}) => {
|
|
12
|
+
const label = labelExtractor(item);
|
|
13
|
+
return /* @__PURE__ */ React__default.createElement(ListItem, { onPress: () => handlePressItem(item) }, /* @__PURE__ */ React__default.createElement(View, { pointerEvents: "none" }, type === "multi" ? /* @__PURE__ */ React__default.createElement(
|
|
14
|
+
Checkbox,
|
|
15
|
+
{
|
|
16
|
+
color: "primary",
|
|
17
|
+
labelPosition: "right",
|
|
18
|
+
checked: item._checked
|
|
19
|
+
},
|
|
20
|
+
/* @__PURE__ */ React__default.createElement(
|
|
21
|
+
StyledTextItemSelect,
|
|
22
|
+
{
|
|
23
|
+
fontWeight: item._checked ? "bold" : "regular",
|
|
24
|
+
ellipsizeMode: "tail",
|
|
25
|
+
numberOfLines: 1
|
|
26
|
+
},
|
|
27
|
+
label
|
|
28
|
+
)
|
|
29
|
+
) : /* @__PURE__ */ React__default.createElement(
|
|
30
|
+
RadioButton,
|
|
31
|
+
{
|
|
32
|
+
color: "primary",
|
|
33
|
+
labelPosition: "right",
|
|
34
|
+
checked: item._checked
|
|
35
|
+
},
|
|
36
|
+
/* @__PURE__ */ React__default.createElement(
|
|
37
|
+
StyledTextItemSelect,
|
|
38
|
+
{
|
|
39
|
+
fontWeight: item._checked ? "bold" : "regular",
|
|
40
|
+
ellipsizeMode: "tail",
|
|
41
|
+
numberOfLines: 1
|
|
42
|
+
},
|
|
43
|
+
label
|
|
44
|
+
)
|
|
45
|
+
)));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { Component as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React__default, { useMemo } from 'react';
|
|
2
|
+
import { Divider, SectionHeader } from '../styled.js';
|
|
3
|
+
import { SectionList } from 'react-native';
|
|
4
|
+
import Text from '../../../atoms/Text/Text.js';
|
|
5
|
+
|
|
6
|
+
const SectionHead = ({ section: { title } }) => /* @__PURE__ */ React__default.createElement(SectionHeader, null, /* @__PURE__ */ React__default.createElement(Text, { fontWeight: "bold" }, title));
|
|
7
|
+
const Section = ({ options, renderItem, getData, keyExtractor }) => {
|
|
8
|
+
const sectionList = useMemo(
|
|
9
|
+
() => options instanceof Map ? [...options].map(([key, value]) => ({
|
|
10
|
+
title: key,
|
|
11
|
+
data: getData(value)
|
|
12
|
+
})) : [],
|
|
13
|
+
[options, getData]
|
|
14
|
+
);
|
|
15
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
16
|
+
SectionList,
|
|
17
|
+
{
|
|
18
|
+
sections: sectionList,
|
|
19
|
+
renderItem,
|
|
20
|
+
ItemSeparatorComponent: Divider,
|
|
21
|
+
renderSectionHeader: SectionHead,
|
|
22
|
+
keyExtractor
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { Section as default };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const findValue = (array, value, keyExtractor, idx) => array.find((it) => keyExtractor(value, idx) === keyExtractor(it, idx));
|
|
2
|
+
const isOptionChecked = (type, option, src, keyExtractor, idx) => type === "multi" ? !!findValue(src, option, keyExtractor, idx) : keyExtractor(src[0] ?? {}, idx) == keyExtractor(option, idx);
|
|
3
|
+
const multiBuilder = (option, src, keyExtractor) => {
|
|
4
|
+
const array = [];
|
|
5
|
+
let found = false;
|
|
6
|
+
for (const value of src) {
|
|
7
|
+
if (keyExtractor(value) != keyExtractor(option)) array.push(value);
|
|
8
|
+
else found = true;
|
|
9
|
+
}
|
|
10
|
+
if (!found) array.push(option);
|
|
11
|
+
return array;
|
|
12
|
+
};
|
|
13
|
+
const singleBuilder = (option, src, keyExtractor) => keyExtractor(src[0] ?? {}) === keyExtractor(option) ? [] : [option];
|
|
14
|
+
const mapToArray = (map) => [...map.values()].flatMap((v) => v);
|
|
15
|
+
const getMultiLabel = (value, placeholder, options, keyExtractor, labelExtractor) => {
|
|
16
|
+
if (value.length === 0) return placeholder;
|
|
17
|
+
else {
|
|
18
|
+
const optionsArray = options instanceof Map ? mapToArray(options) : options;
|
|
19
|
+
const available = optionsArray.length > 0 ? optionsArray : value;
|
|
20
|
+
return available?.reduce(
|
|
21
|
+
(acc, option, index) => findValue(value, option, keyExtractor, index) ? acc + labelExtractor(option) + ", " : acc,
|
|
22
|
+
""
|
|
23
|
+
).slice(0, -2);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const getSingleLabel = (value, placeholder, options, keyExtractor, labelExtractor) => {
|
|
27
|
+
if (!value) return placeholder;
|
|
28
|
+
const optionsArray = options instanceof Map ? mapToArray(options) : options;
|
|
29
|
+
const selectedOption = optionsArray?.find(
|
|
30
|
+
(option, index) => keyExtractor(option, index) == keyExtractor(value, index)
|
|
31
|
+
);
|
|
32
|
+
return labelExtractor(selectedOption ?? value);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { findValue, getMultiLabel, getSingleLabel, isOptionChecked, mapToArray, multiBuilder, singleBuilder };
|