@tecsinapse/react-native-kit 3.4.1 → 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.
Files changed (42) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +9 -7
  3. package/dist/cjs/components/atoms/Modal/ModalGroupManager.js +1 -0
  4. package/dist/cjs/components/atoms/Modal/ModalLifecycleHandler.js +5 -0
  5. package/dist/cjs/components/atoms/Modal/ui/BaseModalView.js +3 -6
  6. package/dist/cjs/components/molecules/Select/Select.js +42 -157
  7. package/dist/cjs/components/molecules/Select/components/Flat.js +24 -0
  8. package/dist/cjs/components/molecules/Select/components/Modal.js +96 -0
  9. package/dist/cjs/components/molecules/Select/components/Option.js +50 -0
  10. package/dist/cjs/components/molecules/Select/components/Section.js +29 -0
  11. package/dist/cjs/components/molecules/Select/functions.js +43 -0
  12. package/dist/cjs/components/molecules/Select/hooks/useModal.js +109 -0
  13. package/dist/cjs/components/molecules/Select/hooks/useSelect.js +147 -0
  14. package/dist/cjs/components/molecules/Select/styled.js +12 -2
  15. package/dist/esm/components/atoms/Modal/ModalGroupManager.js +1 -0
  16. package/dist/esm/components/atoms/Modal/ModalLifecycleHandler.js +5 -0
  17. package/dist/esm/components/atoms/Modal/ui/BaseModalView.js +3 -6
  18. package/dist/esm/components/molecules/Select/Select.js +44 -141
  19. package/dist/esm/components/molecules/Select/components/Flat.js +22 -0
  20. package/dist/esm/components/molecules/Select/components/Modal.js +94 -0
  21. package/dist/esm/components/molecules/Select/components/Option.js +48 -0
  22. package/dist/esm/components/molecules/Select/components/Section.js +27 -0
  23. package/dist/esm/components/molecules/Select/functions.js +35 -0
  24. package/dist/esm/components/molecules/Select/hooks/useModal.js +107 -0
  25. package/dist/esm/components/molecules/Select/hooks/useSelect.js +145 -0
  26. package/dist/esm/components/molecules/Select/styled.js +11 -3
  27. package/dist/types/components/atoms/Modal/ModalLifecycleHandler.d.ts +1 -0
  28. package/dist/types/components/molecules/Select/Select.d.ts +2 -23
  29. package/dist/types/components/molecules/Select/components/Flat.d.ts +8 -0
  30. package/dist/types/components/molecules/Select/components/Modal.d.ts +4 -0
  31. package/dist/types/components/molecules/Select/components/Option.d.ts +10 -0
  32. package/dist/types/components/molecules/Select/components/Section.d.ts +8 -0
  33. package/dist/types/components/molecules/Select/functions.d.ts +9 -0
  34. package/dist/types/components/molecules/Select/hooks/useModal.d.ts +66 -0
  35. package/dist/types/components/molecules/Select/hooks/useSelect.d.ts +58 -0
  36. package/dist/types/components/molecules/Select/index.d.ts +1 -1
  37. package/dist/types/components/molecules/Select/styled.d.ts +12 -0
  38. package/dist/types/components/molecules/Select/types.d.ts +33 -0
  39. package/package.json +9 -6
  40. package/dist/cjs/components/molecules/Select/Modal.js +0 -224
  41. package/dist/esm/components/molecules/Select/Modal.js +0 -203
  42. package/dist/types/components/molecules/Select/Modal.d.ts +0 -8
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tecsinapse/react-native-kit",
3
- "description": "TecSinapse React Native components",
4
- "version": "3.4.1",
3
+ "description": "React Native components library",
4
+ "version": "3.5.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/esm/index.js",
7
7
  "module": "dist/esm/index.js",
@@ -20,9 +20,12 @@
20
20
  "dependencies": {
21
21
  "@emotion/native": "~11.11.0",
22
22
  "@emotion/react": "~11.11.0",
23
- "@tecsinapse/react-core": "3.4.0",
23
+ "@tecsinapse/react-core": "3.4.1",
24
24
  "react-native-linear-gradient": "~2.8.3"
25
25
  },
26
+ "devDependencies": {
27
+ "react-native-safe-area-context": "^4"
28
+ },
26
29
  "repository": {
27
30
  "type": "git",
28
31
  "directory": "packages/react-native-kit",
@@ -33,11 +36,11 @@
33
36
  },
34
37
  "homepage": "https://tecsinapse.github.io/design-system/",
35
38
  "peerDependencies": {
36
- "react": "^18.0.0",
37
- "react-native": "^0.71.0",
39
+ "react": ">=18.0.0",
40
+ "react-native": ">=0.71.0",
38
41
  "react-native-linear-gradient": "^2.5.6",
39
42
  "react-native-safe-area-context": "^4.0.0",
40
43
  "react-native-vector-icons": "^9.2.0"
41
44
  },
42
- "gitHead": "c34d507099dda166804b5a2562337583dc58caaa"
45
+ "gitHead": "555f96fdf1bfb87f0b339668a1ccfa6e4dc6611e"
43
46
  }
@@ -1,224 +0,0 @@
1
- 'use strict';
2
-
3
- var reactCore = require('@tecsinapse/react-core');
4
- var React = require('react');
5
- var reactNative = require('react-native');
6
- var Button = require('../../atoms/Button/Button.js');
7
- var Text = require('../../atoms/Text/Text.js');
8
- var Header = require('../../atoms/Header/Header.js');
9
- var Input = require('../../atoms/Input/Input.js');
10
- var BaseModalView = require('../../atoms/Modal/ui/BaseModalView.js');
11
- var styled = require('./styled.js');
12
-
13
- function _interopNamespaceDefault(e) {
14
- var n = Object.create(null);
15
- if (e) {
16
- Object.keys(e).forEach(function (k) {
17
- if (k !== 'default') {
18
- var d = Object.getOwnPropertyDescriptor(e, k);
19
- Object.defineProperty(n, k, d.get ? d : {
20
- enumerable: true,
21
- get: function () { return e[k]; }
22
- });
23
- }
24
- });
25
- }
26
- n.default = e;
27
- return Object.freeze(n);
28
- }
29
-
30
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
31
-
32
- const Component = ({
33
- options,
34
- keyExtractor,
35
- labelExtractor,
36
- hideSearchBar,
37
- searchBarPlaceholder,
38
- focused,
39
- type,
40
- value,
41
- onSelect,
42
- onSearch,
43
- selectModalTitle,
44
- selectModalTitleComponent,
45
- confirmButtonText,
46
- loading,
47
- close,
48
- closeOnPick,
49
- ...others
50
- }) => {
51
- const [selectedValues, setSelectedValues] = React__namespace.useState([]);
52
- const [searchArg, setSearchArg] = reactCore.useDebouncedState("", onSearch);
53
- const ModalComponent = React__namespace.useMemo(
54
- () => styled.getStyledModal(reactCore.getStatusBarHeight(true)),
55
- []
56
- );
57
- const _closeOnPick = closeOnPick && type === "single";
58
- React__namespace.useEffect(() => {
59
- setSelectedValues(
60
- value ? type === "multi" ? value : [value] : []
61
- );
62
- }, [value, focused, setSelectedValues]);
63
- const getData = React__namespace.useCallback(
64
- (options2) => {
65
- return options2?.map((option, index) => ({
66
- ...option,
67
- _checked: type === "multi" ? !!selectedValues.find(
68
- (value2) => keyExtractor(option, index) == keyExtractor(value2, index)
69
- ) : keyExtractor(selectedValues[0] || {}, index) == keyExtractor(option, index)
70
- }));
71
- },
72
- [keyExtractor, selectedValues, type]
73
- );
74
- const data = React__namespace.useMemo(
75
- () => typeof options !== "function" ? getData(options) : [],
76
- [options, getData]
77
- );
78
- const handlePressItem = React__namespace.useCallback(
79
- (option) => {
80
- setSelectedValues((selectedValues2) => {
81
- if (type === "multi") {
82
- const newArr = [];
83
- let found = false;
84
- for (const value2 of selectedValues2) {
85
- if (keyExtractor(value2) != keyExtractor(option))
86
- newArr.push(value2);
87
- else
88
- found = true;
89
- }
90
- if (!found)
91
- newArr.push(option);
92
- return newArr;
93
- }
94
- return keyExtractor(selectedValues2[0] || {}) === keyExtractor(option) ? [] : [option];
95
- });
96
- },
97
- [selectedValues, setSelectedValues, keyExtractor, type]
98
- );
99
- React__namespace.useEffect(() => {
100
- if (_closeOnPick && selectedValues[0] && selectedValues[0] !== value) {
101
- handleConfirm();
102
- }
103
- }, [selectedValues[0], value, closeOnPick]);
104
- const handleConfirm = React__namespace.useCallback(() => {
105
- onSelect(
106
- type === "single" ? selectedValues[0] : selectedValues
107
- );
108
- close?.();
109
- }, [selectedValues]);
110
- const optionBuilder = React__namespace.useCallback(
111
- ({ item }) => /* @__PURE__ */ React__namespace.createElement(
112
- MemoizedOption,
113
- {
114
- item,
115
- type,
116
- handlePressItem,
117
- labelExtractor
118
- }
119
- ),
120
- []
121
- );
122
- const anyChecked = data.filter((item) => item._checked).length;
123
- const dataLengthChanged = data.length;
124
- const memoizedFlatlist = React__namespace.useMemo(
125
- () => /* @__PURE__ */ React__namespace.createElement(
126
- reactNative.FlatList,
127
- {
128
- data,
129
- keyExtractor,
130
- fadingEdgeLength: 200,
131
- renderItem: optionBuilder
132
- }
133
- ),
134
- [selectedValues, anyChecked, dataLengthChanged]
135
- );
136
- const titleTextModal = selectModalTitle ? /* @__PURE__ */ React__namespace.createElement(
137
- styled.TextTitleModal,
138
- {
139
- typography: "h4",
140
- fontWeight: "bold",
141
- numberOfLines: 3,
142
- style: { maxWidth: reactCore.RFValue(250) }
143
- },
144
- selectModalTitle
145
- ) : null;
146
- const headerContent = selectModalTitleComponent ? selectModalTitleComponent : titleTextModal;
147
- return /* @__PURE__ */ React__namespace.createElement(BaseModalView.ModalView, { ...others, BoxComponent: ModalComponent, showCloseBar: false }, /* @__PURE__ */ React__namespace.createElement(
148
- Header,
149
- {
150
- rightButton: {
151
- onPress: close,
152
- icon: {
153
- name: "close",
154
- type: "material-community",
155
- fontColor: "light"
156
- }
157
- }
158
- },
159
- headerContent
160
- ), !hideSearchBar && /* @__PURE__ */ React__namespace.createElement(styled.SearchBarContainer, null, /* @__PURE__ */ React__namespace.createElement(
161
- Input,
162
- {
163
- placeholder: searchBarPlaceholder,
164
- value: searchArg,
165
- onChange: setSearchArg,
166
- leftComponent: /* @__PURE__ */ React__namespace.createElement(styled.SelectIcon, { name: "search", type: "ionicon", size: "centi" })
167
- }
168
- )), loading && /* @__PURE__ */ React__namespace.createElement(styled.FetchIndicator, { animating: true, color: "grey", size: "large" }), memoizedFlatlist, !_closeOnPick && /* @__PURE__ */ React__namespace.createElement(styled.ModalFooter, null, /* @__PURE__ */ React__namespace.createElement(
169
- Button.Button,
170
- {
171
- variant: "filled",
172
- color: "primary",
173
- onPress: handleConfirm,
174
- disabled: loading
175
- },
176
- /* @__PURE__ */ React__namespace.createElement(Text, { fontColor: "light", fontWeight: "bold" }, confirmButtonText)
177
- )));
178
- };
179
- const MemoizedOption = ({
180
- handlePressItem,
181
- labelExtractor,
182
- item,
183
- type
184
- }) => {
185
- return React__namespace.useMemo(() => {
186
- const label = labelExtractor(item);
187
- return /* @__PURE__ */ React__namespace.createElement(styled.ListItem, { onPress: () => handlePressItem(item) }, /* @__PURE__ */ React__namespace.createElement(reactNative.View, { pointerEvents: "none" }, type === "multi" ? /* @__PURE__ */ React__namespace.createElement(
188
- reactCore.Checkbox,
189
- {
190
- color: "primary",
191
- labelPosition: "right",
192
- checked: item._checked
193
- },
194
- /* @__PURE__ */ React__namespace.createElement(
195
- styled.StyledTextItemSelect,
196
- {
197
- fontWeight: item._checked ? "bold" : "regular",
198
- ellipsizeMode: "tail",
199
- numberOfLines: 1
200
- },
201
- label
202
- )
203
- ) : /* @__PURE__ */ React__namespace.createElement(
204
- reactCore.RadioButton,
205
- {
206
- color: "primary",
207
- labelPosition: "right",
208
- checked: item._checked
209
- },
210
- /* @__PURE__ */ React__namespace.createElement(
211
- styled.StyledTextItemSelect,
212
- {
213
- fontWeight: item._checked ? "bold" : "regular",
214
- ellipsizeMode: "tail",
215
- numberOfLines: 1
216
- },
217
- label
218
- )
219
- )));
220
- }, [item._checked]);
221
- };
222
- const Modal = Component;
223
-
224
- exports.Modal = Modal;
@@ -1,203 +0,0 @@
1
- import { useDebouncedState, getStatusBarHeight, RFValue, Checkbox, RadioButton } from '@tecsinapse/react-core';
2
- import * as React from 'react';
3
- import { FlatList, View } from 'react-native';
4
- import { Button } from '../../atoms/Button/Button.js';
5
- import Text from '../../atoms/Text/Text.js';
6
- import Header from '../../atoms/Header/Header.js';
7
- import Input from '../../atoms/Input/Input.js';
8
- import { ModalView } from '../../atoms/Modal/ui/BaseModalView.js';
9
- import { getStyledModal, TextTitleModal, SearchBarContainer, SelectIcon, FetchIndicator, ModalFooter, ListItem, StyledTextItemSelect } from './styled.js';
10
-
11
- const Component = ({
12
- options,
13
- keyExtractor,
14
- labelExtractor,
15
- hideSearchBar,
16
- searchBarPlaceholder,
17
- focused,
18
- type,
19
- value,
20
- onSelect,
21
- onSearch,
22
- selectModalTitle,
23
- selectModalTitleComponent,
24
- confirmButtonText,
25
- loading,
26
- close,
27
- closeOnPick,
28
- ...others
29
- }) => {
30
- const [selectedValues, setSelectedValues] = React.useState([]);
31
- const [searchArg, setSearchArg] = useDebouncedState("", onSearch);
32
- const ModalComponent = React.useMemo(
33
- () => getStyledModal(getStatusBarHeight(true)),
34
- []
35
- );
36
- const _closeOnPick = closeOnPick && type === "single";
37
- React.useEffect(() => {
38
- setSelectedValues(
39
- value ? type === "multi" ? value : [value] : []
40
- );
41
- }, [value, focused, setSelectedValues]);
42
- const getData = React.useCallback(
43
- (options2) => {
44
- return options2?.map((option, index) => ({
45
- ...option,
46
- _checked: type === "multi" ? !!selectedValues.find(
47
- (value2) => keyExtractor(option, index) == keyExtractor(value2, index)
48
- ) : keyExtractor(selectedValues[0] || {}, index) == keyExtractor(option, index)
49
- }));
50
- },
51
- [keyExtractor, selectedValues, type]
52
- );
53
- const data = React.useMemo(
54
- () => typeof options !== "function" ? getData(options) : [],
55
- [options, getData]
56
- );
57
- const handlePressItem = React.useCallback(
58
- (option) => {
59
- setSelectedValues((selectedValues2) => {
60
- if (type === "multi") {
61
- const newArr = [];
62
- let found = false;
63
- for (const value2 of selectedValues2) {
64
- if (keyExtractor(value2) != keyExtractor(option))
65
- newArr.push(value2);
66
- else
67
- found = true;
68
- }
69
- if (!found)
70
- newArr.push(option);
71
- return newArr;
72
- }
73
- return keyExtractor(selectedValues2[0] || {}) === keyExtractor(option) ? [] : [option];
74
- });
75
- },
76
- [selectedValues, setSelectedValues, keyExtractor, type]
77
- );
78
- React.useEffect(() => {
79
- if (_closeOnPick && selectedValues[0] && selectedValues[0] !== value) {
80
- handleConfirm();
81
- }
82
- }, [selectedValues[0], value, closeOnPick]);
83
- const handleConfirm = React.useCallback(() => {
84
- onSelect(
85
- type === "single" ? selectedValues[0] : selectedValues
86
- );
87
- close?.();
88
- }, [selectedValues]);
89
- const optionBuilder = React.useCallback(
90
- ({ item }) => /* @__PURE__ */ React.createElement(
91
- MemoizedOption,
92
- {
93
- item,
94
- type,
95
- handlePressItem,
96
- labelExtractor
97
- }
98
- ),
99
- []
100
- );
101
- const anyChecked = data.filter((item) => item._checked).length;
102
- const dataLengthChanged = data.length;
103
- const memoizedFlatlist = React.useMemo(
104
- () => /* @__PURE__ */ React.createElement(
105
- FlatList,
106
- {
107
- data,
108
- keyExtractor,
109
- fadingEdgeLength: 200,
110
- renderItem: optionBuilder
111
- }
112
- ),
113
- [selectedValues, anyChecked, dataLengthChanged]
114
- );
115
- const titleTextModal = selectModalTitle ? /* @__PURE__ */ React.createElement(
116
- TextTitleModal,
117
- {
118
- typography: "h4",
119
- fontWeight: "bold",
120
- numberOfLines: 3,
121
- style: { maxWidth: RFValue(250) }
122
- },
123
- selectModalTitle
124
- ) : null;
125
- const headerContent = selectModalTitleComponent ? selectModalTitleComponent : titleTextModal;
126
- return /* @__PURE__ */ React.createElement(ModalView, { ...others, BoxComponent: ModalComponent, showCloseBar: false }, /* @__PURE__ */ React.createElement(
127
- Header,
128
- {
129
- rightButton: {
130
- onPress: close,
131
- icon: {
132
- name: "close",
133
- type: "material-community",
134
- fontColor: "light"
135
- }
136
- }
137
- },
138
- headerContent
139
- ), !hideSearchBar && /* @__PURE__ */ React.createElement(SearchBarContainer, null, /* @__PURE__ */ React.createElement(
140
- Input,
141
- {
142
- placeholder: searchBarPlaceholder,
143
- value: searchArg,
144
- onChange: setSearchArg,
145
- leftComponent: /* @__PURE__ */ React.createElement(SelectIcon, { name: "search", type: "ionicon", size: "centi" })
146
- }
147
- )), loading && /* @__PURE__ */ React.createElement(FetchIndicator, { animating: true, color: "grey", size: "large" }), memoizedFlatlist, !_closeOnPick && /* @__PURE__ */ React.createElement(ModalFooter, null, /* @__PURE__ */ React.createElement(
148
- Button,
149
- {
150
- variant: "filled",
151
- color: "primary",
152
- onPress: handleConfirm,
153
- disabled: loading
154
- },
155
- /* @__PURE__ */ React.createElement(Text, { fontColor: "light", fontWeight: "bold" }, confirmButtonText)
156
- )));
157
- };
158
- const MemoizedOption = ({
159
- handlePressItem,
160
- labelExtractor,
161
- item,
162
- type
163
- }) => {
164
- return React.useMemo(() => {
165
- const label = labelExtractor(item);
166
- return /* @__PURE__ */ React.createElement(ListItem, { onPress: () => handlePressItem(item) }, /* @__PURE__ */ React.createElement(View, { pointerEvents: "none" }, type === "multi" ? /* @__PURE__ */ React.createElement(
167
- Checkbox,
168
- {
169
- color: "primary",
170
- labelPosition: "right",
171
- checked: item._checked
172
- },
173
- /* @__PURE__ */ React.createElement(
174
- StyledTextItemSelect,
175
- {
176
- fontWeight: item._checked ? "bold" : "regular",
177
- ellipsizeMode: "tail",
178
- numberOfLines: 1
179
- },
180
- label
181
- )
182
- ) : /* @__PURE__ */ React.createElement(
183
- RadioButton,
184
- {
185
- color: "primary",
186
- labelPosition: "right",
187
- checked: item._checked
188
- },
189
- /* @__PURE__ */ React.createElement(
190
- StyledTextItemSelect,
191
- {
192
- fontWeight: item._checked ? "bold" : "regular",
193
- ellipsizeMode: "tail",
194
- numberOfLines: 1
195
- },
196
- label
197
- )
198
- )));
199
- }, [item._checked]);
200
- };
201
- const Modal = Component;
202
-
203
- export { Modal };
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- import { IBaseModal } from '../../atoms/Modal';
3
- import { SelectNativeProps } from './Select';
4
- interface LoadingProps {
5
- loading?: boolean;
6
- }
7
- export declare const Modal: <Data, Type extends "single" | "multi">({ options, keyExtractor, labelExtractor, hideSearchBar, searchBarPlaceholder, focused, type, value, onSelect, onSearch, selectModalTitle, selectModalTitleComponent, confirmButtonText, loading, close, closeOnPick, ...others }: SelectNativeProps<Data, Type> & LoadingProps & IBaseModal) => JSX.Element;
8
- export {};