@tecsinapse/react-native-kit 1.17.6 → 1.17.9

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/CHANGELOG.md CHANGED
@@ -3,6 +3,39 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.17.9](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.17.8...@tecsinapse/react-native-kit@1.17.9) (2022-07-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * ternary verification in model text title ([813b68c](https://github.com/tecsinapse/design-system/commit/813b68c186b9b7e5c1793f90b171444f23007993))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.17.8](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.17.7...@tecsinapse/react-native-kit@1.17.8) (2022-07-06)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * ternary verification in model text title ([40c0126](https://github.com/tecsinapse/design-system/commit/40c01260684421cde54bffc70ca1663ac4856e65))
23
+
24
+
25
+
26
+
27
+
28
+ ## [1.17.7](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.17.6...@tecsinapse/react-native-kit@1.17.7) (2022-07-06)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * select modal text overflow and prettier files ([11dff1e](https://github.com/tecsinapse/design-system/commit/11dff1ecdc117f3e08191dd1c488f6e8ed7459c6))
34
+
35
+
36
+
37
+
38
+
6
39
  ## [1.17.6](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.17.5...@tecsinapse/react-native-kit@1.17.6) (2022-06-24)
7
40
 
8
41
  **Note:** Version bump only for package @tecsinapse/react-native-kit
@@ -54,10 +54,14 @@ const Input = _react.default.forwardRef(({
54
54
  handleBlur,
55
55
  handleFocus
56
56
  } = (0, _reactCore.useInputFocus)(onFocus, onBlur, !disabled);
57
+ const internalStyle = {
58
+ minHeight: (0, _reactCore.RFValue)(50),
59
+ ...{
60
+ inputContainerStyle
61
+ }
62
+ };
57
63
  const onlyLabel = label && !placeholder;
58
- return _react.default.createElement(_reactNative.View, {
59
- style: style
60
- }, _react.default.createElement(_styled.StyledInputContainer, {
64
+ return _react.default.createElement(_reactNative.View, null, _react.default.createElement(_reactCore.InputContainer, {
61
65
  label: value ? label : undefined,
62
66
  labelColor: labelColor,
63
67
  labelColorVariant: labelColorVariant,
@@ -70,7 +74,7 @@ const Input = _react.default.forwardRef(({
70
74
  rightComponent: rightComponent,
71
75
  borderColor: borderColor,
72
76
  borderColorGradation: borderColorGradation,
73
- inputContainerStyle: inputContainerStyle,
77
+ inputContainerStyle: internalStyle,
74
78
  focused: focused,
75
79
  disabled: disabled,
76
80
  variant: variant
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/atoms/Input/Input.tsx"],"names":["Input","React","forwardRef","label","labelColor","labelColorVariant","labelColorTone","labelTypography","labelStack","labelWeight","leftComponent","rightComponent","disabled","style","borderColor","borderColorGradation","inputFontStack","inputFontWeight","inputContainerStyle","variant","hintComponent","hint","onFocus","onBlur","value","placeholder","rest","ref","_hint","Text","focused","handleBlur","handleFocus","onlyLabel","undefined","displayName"],"mappings":";;;;;AAAA;;AAQA;;AACA;;AACA;;AACA;;;;;;AASA,MAAMA,KAA2B,GAAGC,eAAMC,UAAN,CAClC,CACE;AACEC,EAAAA,KADF;AAEEC,EAAAA,UAFF;AAGEC,EAAAA,iBAHF;AAIEC,EAAAA,cAJF;AAKEC,EAAAA,eALF;AAMEC,EAAAA,UANF;AAOEC,EAAAA,WAPF;AAQEC,EAAAA,aARF;AASEC,EAAAA,cATF;AAUEC,EAAAA,QAVF;AAWEC,EAAAA,KAXF;AAYEC,EAAAA,WAZF;AAaEC,EAAAA,oBAbF;AAcEC,EAAAA,cAAc,GAAG,SAdnB;AAeEC,EAAAA,eAAe,GAAG,MAfpB;AAgBEC,EAAAA,mBAhBF;AAiBEC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AA,WAAW,EAAEO,SAAS,GAAG9B,KAAH,GAAWsB,WAFnC;AAGE,IAAA,KAAK,EAAED,KAHT;AAIE,IAAA,GAAG,EAAEG,GAJP;AAKE,IAAA,SAAS,EAAEX,cALb;AAME,IAAA,UAAU,EAAEC,eANd;AAOE,IAAA,QAAQ,EAAEL,QAPZ;AAQE,IAAA,OAAO,EAAEoB,WARX;AASE,IAAA,MAAM,EAAED;AATV,KAlBF,CADF,EA+BGV,IAAI,IAAIO,KA/BX,CADF;AAmCD,CA5EiC,CAApC;;AA+EA5B,KAAK,CAACmC,WAAN,GAAoB,OAApB;eAEenC,K","sourcesContent":["import {\n FontStackType,\n FontWeightType,\n Hint,\n InputContainerProps,\n InputElementProps,\n useInputFocus,\n} from '@tecsinapse/react-core';\nimport React, { FC } from 'react';\nimport { View } from 'react-native';\nimport { Text } from '../Text';\nimport { StyledInputContainer, StyledNativeInput } from './styled';\n\nexport interface InputNativeProps\n extends Omit<InputElementProps, 'style'>,\n InputContainerProps {\n inputFontStack?: FontStackType;\n inputFontWeight?: FontWeightType;\n}\n\nconst Input: FC<InputNativeProps> = React.forwardRef(\n (\n {\n label,\n labelColor,\n labelColorVariant,\n labelColorTone,\n labelTypography,\n labelStack,\n labelWeight,\n leftComponent,\n rightComponent,\n disabled,\n style,\n borderColor,\n borderColorGradation,\n inputFontStack = 'default',\n inputFontWeight = 'bold',\n inputContainerStyle,\n variant = 'default',\n hintComponent,\n hint,\n onFocus,\n onBlur,\n value,\n placeholder,\n ...rest\n },\n ref\n ) => {\n const _hint = hintComponent || (\n <Hint TextComponent={Text} text={hint} variant={variant} />\n );\n const { focused, handleBlur, handleFocus } = useInputFocus(\n onFocus,\n onBlur,\n !disabled\n );\n\n const onlyLabel = label && !placeholder;\n\n return (\n <View style={style}>\n <StyledInputContainer\n label={value ? label : undefined}\n labelColor={labelColor}\n labelColorVariant={labelColorVariant}\n labelColorTone={labelColorTone}\n labelTypography={labelTypography}\n labelStack={labelStack}\n labelWeight={labelWeight}\n LabelComponent={Text}\n leftComponent={leftComponent}\n rightComponent={rightComponent}\n borderColor={borderColor}\n borderColorGradation={borderColorGradation}\n inputContainerStyle={inputContainerStyle}\n focused={focused}\n disabled={disabled}\n variant={variant}\n >\n <StyledNativeInput\n {...rest}\n placeholder={onlyLabel ? label : placeholder}\n value={value}\n ref={ref}\n fontStack={inputFontStack}\n fontWeight={inputFontWeight}\n disabled={disabled}\n onFocus={handleFocus}\n onBlur={handleBlur}\n />\n </StyledInputContainer>\n {hint && _hint}\n </View>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"Input.js"}
1
+ {"version":3,"sources":["../../../../src/components/atoms/Input/Input.tsx"],"names":["Input","React","forwardRef","label","labelColor","labelColorVariant","labelColorTone","labelTypography","labelStack","labelWeight","leftComponent","rightComponent","disabled","style","borderColor","borderColorGradation","inputFontStack","inputFontWeight","inputContainerStyle","variant","hintComponent","hint","onFocus","onBlur","value","placeholder","rest","ref","_hint","Text","focused","handleBlur","handleFocus","internalStyle","minHeight","onlyLabel","undefined","displayName"],"mappings":";;;;;AAAA;;AAUA;;AACA;;AACA;;AACA;;;;;;AASA,MAAMA,KAA2B,GAAGC,eAAMC,UAAN,CAClC,CACE;AACEC,EAAAA,KADF;AAEEC,EAAAA,UAFF;AAGEC,EAAAA,iBAHF;AAIEC,EAAAA,cAJF;AAKEC,EAAAA,eALF;AAMEC,EAAAA,UANF;AAOEC,EAAAA,WAPF;AAQEC,EAAAA,aARF;AASEC,EAAAA,cATF;AAUEC,EAAAA,QAVF;AAWEC,EAAAA,KAXF;AAYEC,EAAAA,WAZF;AAaEC,EAAAA,oBAbF;AAcEC,EAAAA,cAAc,GAAG,SAdnB;AAeEC,EAAAA,eAAe,GAAG,MAfpB;AAgBEC,EAAAA,mBAhBF;AAiBEC,EAAAA,OAAO,GAAG,SAjBZ;AAkBEC,EAAAA,aAlBF;AAmBEC,EAAAA,IAnBF;AAoBEC,EAAAA,OApBF;AAqBEC,EA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AS,GAAGhC,KAAH,GAAWsB,WAFnC;AAGE,IAAA,KAAK,EAAED,KAHT;AAIE,IAAA,GAAG,EAAEG,GAJP;AAKE,IAAA,SAAS,EAAEX,cALb;AAME,IAAA,UAAU,EAAEC,eANd;AAOE,IAAA,QAAQ,EAAEL,QAPZ;AAQE,IAAA,OAAO,EAAEoB,WARX;AASE,IAAA,MAAM,EAAED;AATV,KAlBF,CADF,EA+BGV,IAAI,IAAIO,KA/BX,CADF;AAmCD,CA7EiC,CAApC;;AAgFA5B,KAAK,CAACqC,WAAN,GAAoB,OAApB;eAEerC,K","sourcesContent":["import {\n FontStackType,\n FontWeightType,\n Hint,\n InputContainer,\n InputContainerProps,\n InputElementProps,\n RFValue,\n useInputFocus\n} from '@tecsinapse/react-core';\nimport React, { FC } from 'react';\nimport { StyleProp, View, ViewStyle } from 'react-native';\nimport { Text } from '../Text';\nimport { StyledNativeInput } from './styled';\n\nexport interface InputNativeProps\n extends Omit<InputElementProps, 'style'>,\n InputContainerProps {\n inputFontStack?: FontStackType;\n inputFontWeight?: FontWeightType;\n}\n\nconst Input: FC<InputNativeProps> = React.forwardRef(\n (\n {\n label,\n labelColor,\n labelColorVariant,\n labelColorTone,\n labelTypography,\n labelStack,\n labelWeight,\n leftComponent,\n rightComponent,\n disabled,\n style,\n borderColor,\n borderColorGradation,\n inputFontStack = 'default',\n inputFontWeight = 'bold',\n inputContainerStyle,\n variant = 'default',\n hintComponent,\n hint,\n onFocus,\n onBlur,\n value,\n placeholder,\n ...rest\n },\n ref\n ) => {\n const _hint = hintComponent || (\n <Hint TextComponent={Text} text={hint} variant={variant} />\n );\n const { focused, handleBlur, handleFocus } = useInputFocus(\n onFocus,\n onBlur,\n !disabled\n );\n\n const internalStyle: StyleProp<ViewStyle> = { minHeight: RFValue(50), ...{ inputContainerStyle }}\n const onlyLabel = label && !placeholder;\n\n return (\n <View>\n <InputContainer\n label={value ? label : undefined}\n labelColor={labelColor}\n labelColorVariant={labelColorVariant}\n labelColorTone={labelColorTone}\n labelTypography={labelTypography}\n labelStack={labelStack}\n labelWeight={labelWeight}\n LabelComponent={Text}\n leftComponent={leftComponent}\n rightComponent={rightComponent}\n borderColor={borderColor}\n borderColorGradation={borderColorGradation}\n inputContainerStyle={internalStyle}\n focused={focused}\n disabled={disabled}\n variant={variant}\n >\n <StyledNativeInput\n {...rest}\n placeholder={onlyLabel ? label : placeholder}\n value={value}\n ref={ref}\n fontStack={inputFontStack}\n fontWeight={inputFontWeight}\n disabled={disabled}\n onFocus={handleFocus}\n onBlur={handleBlur}\n />\n </InputContainer>\n {hint && _hint}\n </View>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"Input.js"}
@@ -1,5 +1 @@
1
- /// <reference types="react" />
2
- export declare const StyledInputContainer: import("@emotion/native").StyledComponent<any, {}, {
3
- ref?: import("react").Ref<any> | undefined;
4
- }>;
5
1
  export declare const StyledNativeInput: import("@emotion/native").StyledComponent<any, {}, {}>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.StyledNativeInput = exports.StyledInputContainer = void 0;
4
+ exports.StyledNativeInput = void 0;
5
5
 
6
6
  var _native = _interopRequireDefault(require("@emotion/native"));
7
7
 
@@ -11,10 +11,6 @@ var _styled = require("../Text/styled");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- const StyledInputContainer = (0, _native.default)(_reactCore.InputContainer)`
15
- min-height: ${(0, _reactCore.RFValueStr)('50px')};
16
- `;
17
- exports.StyledInputContainer = StyledInputContainer;
18
14
  const StyledNativeInputBase = (0, _native.default)(_reactCore.InputElement)`
19
15
  height: ${({
20
16
  theme
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/atoms/Input/styled.ts"],"names":["StyledInputContainer","InputContainer","StyledNativeInputBase","InputElement","theme","typography","h5","lineHeight","StyledNativeInput","fontStyles"],"mappings":";;;;;AAAA;;AACA;;AAMA;;;;AAGO,MAAMA,oBAAoB,GAAG,qBAAOC,yBAAP,CAA4C;AAChF,gBAAgB,2BAAW,MAAX,CAAmB;AACnC,CAFO;;AAIP,MAAMC,qBAAqB,GAAG,qBAAOC,uBAAP,CAE5B;AACF,YAAY,CAAC;AAAEC,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACC,UAAN,CAAiBC,EAAjB,CAAoBC,UAAW;AAC1D;AACA;AACA,CANA;AAQO,MAAMC,iBAAiB,GAAG,qBAAON,qBAAP,EAE/BO,kBAF+B,CAA1B","sourcesContent":["import styled from '@emotion/native';\nimport {\n InputContainer,\n InputElement,\n RFValueStr,\n StyleProps\n} from '@tecsinapse/react-core';\nimport { Font, fontStyles } from '../Text/styled';\nimport { InputNativeProps } from './Input';\n\nexport const StyledInputContainer = styled(InputContainer)<Partial<StyleProps>>`\n min-height: ${RFValueStr('50px')};\n`;\n\nconst StyledNativeInputBase = styled(InputElement)<\n Partial<InputNativeProps> & Partial<StyleProps>\n>`\n height: ${({ theme }) => theme.typography.h5.lineHeight};\n width: 100%;\n padding: 0;\n`;\n\nexport const StyledNativeInput = styled(StyledNativeInputBase)<\n Font & Partial<InputNativeProps> & Partial<StyleProps>\n>(fontStyles);\n"],"file":"styled.js"}
1
+ {"version":3,"sources":["../../../../src/components/atoms/Input/styled.ts"],"names":["StyledNativeInputBase","InputElement","theme","typography","h5","lineHeight","StyledNativeInput","fontStyles"],"mappings":";;;;;AAAA;;AACA;;AAGA;;;;AAGA,MAAMA,qBAAqB,GAAG,qBAAOC,uBAAP,CAE5B;AACF,YAAY,CAAC;AAAEC,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACC,UAAN,CAAiBC,EAAjB,CAAoBC,UAAW;AAC1D;AACA;AACA,CANA;AAQO,MAAMC,iBAAiB,GAAG,qBAAON,qBAAP,EAE/BO,kBAF+B,CAA1B","sourcesContent":["import styled from '@emotion/native';\nimport {\n InputElement, StyleProps\n} from '@tecsinapse/react-core';\nimport { Font, fontStyles } from '../Text/styled';\nimport { InputNativeProps } from './Input';\n\nconst StyledNativeInputBase = styled(InputElement)<\n Partial<InputNativeProps> & Partial<StyleProps>\n>`\n height: ${({ theme }) => theme.typography.h5.lineHeight};\n width: 100%;\n padding: 0;\n`;\n\nexport const StyledNativeInput = styled(StyledNativeInputBase)<\n Font & Partial<InputNativeProps> & Partial<StyleProps>\n>(fontStyles);\n"],"file":"styled.js"}
@@ -56,16 +56,13 @@ const Component = ({
56
56
  React.useEffect(() => {
57
57
  setSelectedValues(value ? type === 'multi' ? value : [value] : []);
58
58
  }, [value, focused, setSelectedValues]);
59
-
60
- const getData = options => {
59
+ const getData = React.useCallback(options => {
61
60
  return options == null ? void 0 : options.map((option, index) => ({ ...option,
62
61
  _checked: type === 'multi' ? !!selectedValues.find(value => keyExtractor(option, index) == keyExtractor(value, index)) : keyExtractor(selectedValues[0] || {}, index) == keyExtractor(option, index)
63
62
  }));
64
- };
65
-
66
- const data = typeof options !== 'function' ? getData(options) : [];
67
-
68
- const handlePressItem = option => () => {
63
+ }, [keyExtractor, selectedValues, type]);
64
+ const data = React.useMemo(() => typeof options !== 'function' ? getData(options) : [], [options, getData]);
65
+ const handlePressItem = React.useCallback(option => {
69
66
  setSelectedValues(selectedValues => {
70
67
  if (type === 'multi') {
71
68
  const newArr = [];
@@ -81,23 +78,41 @@ const Component = ({
81
78
 
82
79
  return keyExtractor(selectedValues[0] || {}) === keyExtractor(option) ? [] : [option];
83
80
  });
84
- };
85
-
81
+ }, [selectedValues, setSelectedValues, keyExtractor, type]);
86
82
  React.useEffect(() => {
87
83
  if (_closeOnPick && selectedValues[0] && selectedValues[0] !== value) {
88
84
  handleConfirm();
89
85
  }
90
86
  }, [selectedValues[0], value, closeOnPick]);
91
-
92
- const handleConfirm = () => {
87
+ const handleConfirm = React.useCallback(() => {
93
88
  onSelect(type === 'single' ? selectedValues[0] : selectedValues);
94
89
  close == null ? void 0 : close();
95
- };
96
-
97
- const headerContent = selectModalTitleComponent ? selectModalTitleComponent : selectModalTitle ? React.createElement(_Text.Text, {
90
+ }, [selectedValues]);
91
+ const optionBuilder = React.useCallback(({
92
+ item
93
+ }) => React.createElement(MemoizedOption, {
94
+ item: item,
95
+ type: type,
96
+ handlePressItem: handlePressItem,
97
+ labelExtractor: labelExtractor
98
+ }), []);
99
+ const anyChecked = data.filter(item => item._checked).length;
100
+ const dataLengthChanged = data.length;
101
+ const memoizedFlatlist = React.useMemo(() => React.createElement(_reactNative.FlatList, {
102
+ data: data,
103
+ keyExtractor: keyExtractor,
104
+ fadingEdgeLength: 200,
105
+ renderItem: optionBuilder
106
+ }), [selectedValues, anyChecked, dataLengthChanged]);
107
+ const titleTextModal = selectModalTitle ? React.createElement(_styled.TextTitleModal, {
98
108
  typography: "h4",
99
- fontWeight: "bold"
109
+ fontWeight: "bold",
110
+ numberOfLines: 3,
111
+ style: {
112
+ maxWidth: (0, _reactCore.RFValue)(250)
113
+ }
100
114
  }, selectModalTitle) : null;
115
+ const headerContent = selectModalTitleComponent ? selectModalTitleComponent : titleTextModal;
101
116
  return React.createElement(_Modal.ModalView, _extends({}, others, {
102
117
  BoxComponent: ModalComponent,
103
118
  showCloseBar: false
@@ -123,14 +138,27 @@ const Component = ({
123
138
  animating: true,
124
139
  color: 'grey',
125
140
  size: 'large'
126
- }), React.createElement(_reactNative.FlatList, {
127
- data: data,
128
- keyExtractor: keyExtractor,
129
- fadingEdgeLength: 200,
130
- renderItem: ({
131
- item
132
- }) => React.createElement(_styled.ListItem, {
133
- onPress: handlePressItem(item)
141
+ }), memoizedFlatlist, !_closeOnPick && React.createElement(_styled.ModalFooter, null, React.createElement(_Button.Button, {
142
+ variant: 'filled',
143
+ color: 'primary',
144
+ onPress: handleConfirm,
145
+ disabled: loading
146
+ }, React.createElement(_Text.Text, {
147
+ fontColor: 'light',
148
+ fontWeight: "bold"
149
+ }, confirmButtonText))));
150
+ };
151
+
152
+ const MemoizedOption = ({
153
+ handlePressItem,
154
+ labelExtractor,
155
+ item,
156
+ type
157
+ }) => {
158
+ return React.useMemo(() => {
159
+ const label = labelExtractor(item);
160
+ return React.createElement(_styled.ListItem, {
161
+ onPress: () => handlePressItem(item)
134
162
  }, React.createElement(_reactNative.View, {
135
163
  pointerEvents: 'none'
136
164
  }, type === 'multi' ? React.createElement(_reactCore.Checkbox, {
@@ -139,22 +167,14 @@ const Component = ({
139
167
  checked: item._checked
140
168
  }, React.createElement(_Text.Text, {
141
169
  fontWeight: item._checked ? 'bold' : 'regular'
142
- }, labelExtractor(item))) : React.createElement(_reactCore.RadioButton, {
170
+ }, label)) : React.createElement(_reactCore.RadioButton, {
143
171
  color: 'primary',
144
172
  labelPosition: 'right',
145
173
  checked: item._checked
146
174
  }, React.createElement(_Text.Text, {
147
175
  fontWeight: item._checked ? 'bold' : 'regular'
148
- }, labelExtractor(item)))))
149
- }), !_closeOnPick && React.createElement(_styled.ModalFooter, null, React.createElement(_Button.Button, {
150
- variant: 'filled',
151
- color: 'primary',
152
- onPress: handleConfirm,
153
- disabled: loading
154
- }, React.createElement(_Text.Text, {
155
- fontColor: 'light',
156
- fontWeight: "bold"
157
- }, confirmButtonText))));
176
+ }, label))));
177
+ }, [item._checked]);
158
178
  };
159
179
 
160
180
  const Modal = Component;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/molecules/Select/Modal.tsx"],"names":["Component","options","keyExtractor","labelExtractor","groupKeyExtractor","hideSearchBar","searchBarPlaceholder","focused","type","value","onSelect","onSearch","selectModalTitle","selectModalTitleComponent","confirmButtonText","loading","close","closeOnPick","others","selectedValues","setSelectedValues","React","useState","searchArg","setSearchArg","ModalComponent","useMemo","_closeOnPick","useEffect","getData","map","option","index","_checked","find","data","handlePressItem","newArr","found","push","handleConfirm","headerContent","onPress","icon","name","fontColor","text","item","Modal"],"mappings":";;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AASA,MAAMA,SAAS,GAAG,CAAwC;AACxDC,EAA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AAd","sourcesContent":["import { Checkbox, getStatusBarHeight, RadioButton, useDebouncedState } from '@tecsinapse/react-core';\nimport * as React from 'react';\nimport { FlatList, StatusBar, View } from 'react-native';\nimport { Button } from '../../atoms/Button';\nimport { Header } from '../../atoms/Header';\nimport { Input } from '../../atoms/Input';\nimport { IBaseModal, ModalView } from '../../atoms/Modal';\nimport { Text } from '../../atoms/Text';\nimport { SelectNativeProps } from './Select';\nimport {\n FetchIndicator, getStyledModal, ListItem, ModalFooter, SearchBarContainer,\n SelectIcon\n} from './styled';\n\ninterface LoadingProps {\n loading?: boolean;\n}\n\nconst Component = <Data, Type extends 'single' | 'multi'>({\n options,\n keyExtractor,\n labelExtractor,\n groupKeyExtractor,\n hideSearchBar,\n searchBarPlaceholder,\n focused,\n type,\n value,\n onSelect,\n onSearch,\n selectModalTitle,\n selectModalTitleComponent,\n confirmButtonText,\n loading,\n close,\n closeOnPick,\n ...others\n}: SelectNativeProps<Data, Type> & LoadingProps & IBaseModal): JSX.Element => {\n const [selectedValues, setSelectedValues] = React.useState<Data[]>([]);\n const [searchArg, setSearchArg] = useDebouncedState<string>('', onSearch);\n const ModalComponent = React.useMemo(() => getStyledModal(getStatusBarHeight(true)), [])\n const _closeOnPick = closeOnPick && type === 'single'\n\n // Resets the temporary state to the initial state whenever the\n // modal is reopened or the value changes\n React.useEffect(() => {\n setSelectedValues(\n (value ? (type === 'multi' ? value : [value]) : []) as Data[]\n );\n }, [value, focused, setSelectedValues]);\n\n const getData = (options: Data[]) => {\n return options?.map((option, index) => ({\n ...option,\n _checked:\n type === 'multi'\n ? !!selectedValues.find(\n value => keyExtractor(option, index) == keyExtractor(value, index)\n )\n : keyExtractor((selectedValues[0] || {}) as Data, index) ==\n keyExtractor(option, index),\n }));\n };\n\n const data = typeof options !== 'function' ? getData(options) : [];\n\n const handlePressItem = (option: Data) => () => {\n setSelectedValues(selectedValues => {\n if (type === 'multi') {\n const newArr: Data[] = [];\n let found = false;\n for (const value of selectedValues) {\n if (keyExtractor(value) != keyExtractor(option)) newArr.push(value);\n else found = true;\n }\n if (!found) newArr.push(option);\n return newArr;\n }\n return keyExtractor((selectedValues[0] || {}) as Data) ===\n keyExtractor(option)\n ? []\n : [option];\n });\n };\n\n React.useEffect(() => {\n if (_closeOnPick && selectedValues[0] && (selectedValues[0] !== value)) {\n handleConfirm()\n }\n }, [selectedValues[0], value, closeOnPick])\n\n const handleConfirm = () => {\n // TS Workaround since TS won't infer the ternary operator's result type correctly\n type OnSelectArg = Parameters<typeof onSelect>[0];\n onSelect(\n (type === 'single' ? selectedValues[0] : selectedValues) as OnSelectArg\n );\n close?.()\n };\n\n const headerContent = selectModalTitleComponent ? (\n selectModalTitleComponent\n ) : selectModalTitle ? (\n <Text typography=\"h4\" fontWeight=\"bold\">\n {selectModalTitle}\n </Text>\n ) : null;\n\n return (\n <ModalView {...others} BoxComponent={ModalComponent} showCloseBar={false}>\n <Header\n rightButton={{\n onPress: close,\n icon: {\n name: 'close',\n type: 'material-community',\n fontColor: 'light',\n },\n }}\n >\n {headerContent}\n </Header>\n\n {!hideSearchBar && (\n <SearchBarContainer>\n <Input\n placeholder={searchBarPlaceholder}\n value={searchArg}\n onChange={text => setSearchArg(text)}\n leftComponent={\n <SelectIcon name=\"search\" type=\"ionicon\" size=\"centi\" />\n }\n />\n </SearchBarContainer>\n )}\n\n {loading && (\n <FetchIndicator animating={true} color={'grey'} size={'large'} />\n )}\n\n <FlatList\n data={data}\n keyExtractor={keyExtractor}\n fadingEdgeLength={200}\n renderItem={({ item }) => (\n <ListItem onPress={handlePressItem(item)}>\n <View pointerEvents={'none'}>\n {type === 'multi' ? (\n <Checkbox\n color={'primary'}\n labelPosition={'right'}\n checked={item._checked}\n >\n <Text fontWeight={item._checked ? 'bold' : 'regular'}>\n {labelExtractor(item)}\n </Text>\n </Checkbox>\n ) : (\n <RadioButton\n color={'primary'}\n labelPosition={'right'}\n checked={item._checked}\n >\n <Text fontWeight={item._checked ? 'bold' : 'regular'}>\n {labelExtractor(item)}\n </Text>\n </RadioButton>\n )}\n </View>\n </ListItem>\n )}\n />\n \n { !_closeOnPick && <ModalFooter>\n <Button\n variant={'filled'}\n color={'primary'}\n onPress={handleConfirm}\n disabled={loading}\n >\n <Text fontColor={'light'} fontWeight=\"bold\">\n {confirmButtonText}\n </Text>\n </Button>\n </ModalFooter>}\n </ModalView>\n );\n};\n\nexport const Modal = Component;\n"],"file":"Modal.js"}
1
+ {"version":3,"sources":["../../../../src/components/molecules/Select/Modal.tsx"],"names":["Component","options","keyExtractor","labelExtractor","groupKeyExtractor","hideSearchBar","searchBarPlaceholder","focused","type","value","onSelect","onSearch","selectModalTitle","selectModalTitleComponent","confirmButtonText","loading","close","closeOnPick","others","selectedValues","setSelectedValues","React","useState","searchArg","setSearchArg","ModalComponent","useMemo","_closeOnPick","useEffect","getData","useCallback","map","option","index","_checked","find","data","handlePressItem","newArr","found","push","handleConfirm","optionBuilder","item","anyChecked","filter","length","dataLengthChanged","memoizedFlatlist","titleTextModal","maxWidth","headerContent","onPress","icon","name","fontColor","text","MemoizedOption","label","Modal"],"mappings":";;;;;AAAA;;AAOA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AAcA,MAAMA,SAAS,GAAG,CAAwC;AACxDC,EAAAA,OADwD;AAExDC,EAAAA,YAFwD;AAGxDC,EAAAA,cAHwD;AAIxDC,EAAAA,iBAJwD;AAKxDC,EAAAA,aALwD;AAMxDC,EAAAA,oBANwD;AAOxDC,EAAAA,OAPwD;AAQxDC,EAAAA,IARwD;AASxDC,EAAAA,KATwD;AAUxDC,EAAAA,QAVwD;AAWxDC,EAAAA,QAXwD;AAYxDC,EAAAA,gBAZwD;AAaxDC,EAAAA,yBAbwD;AAcxDC,EAAAA,iBAdwD;AAexDC,EAAAA,OAfwD;AAgBxDC,EAAAA,KAhBwD;AAiBxDC,EAAAA,WAjBwD;AAkBxD,KAAGC;AAlBqD,CAAxC,KAmB4D;AAC5E,QAAM,CAACC,cAAD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Oa,KAAK,CAACK,OAAN,CAAc,MAAM;AACzB,UAAMgC,KAAK,GAAGvD,cAAc,CAACwC,IAAD,CAA5B;AACA,WACE,oBAAC,gBAAD;AAAU,MAAA,OAAO,EAAE,MAAMN,eAAe,CAACM,IAAD;AAAxC,OACE,oBAAC,iBAAD;AAAM,MAAA,aAAa,EAAE;AAArB,OACGnC,IAAI,KAAK,OAAT,GACC,oBAAC,mBAAD;AACE,MAAA,KAAK,EAAE,SADT;AAEE,MAAA,aAAa,EAAE,OAFjB;AAGE,MAAA,OAAO,EAAEmC,IAAI,CAACT;AAHhB,OAKE,oBAAC,UAAD;AAAM,MAAA,UAAU,EAAES,IAAI,CAACT,QAAL,GAAgB,MAAhB,GAAyB;AAA3C,OACGwB,KADH,CALF,CADD,GAWC,oBAAC,sBAAD;AACE,MAAA,KAAK,EAAE,SADT;AAEE,MAAA,aAAa,EAAE,OAFjB;AAGE,MAAA,OAAO,EAAEf,IAAI,CAACT;AAHhB,OAKE,oBAAC,UAAD;AAAM,MAAA,UAAU,EAAES,IAAI,CAACT,QAAL,GAAgB,MAAhB,GAAyB;AAA3C,OACGwB,KADH,CALF,CAZJ,CADF,CADF;AA2BD,GA7BM,EA6BJ,CAACf,IAAI,CAACT,QAAN,CA7BI,CAAP;AA8BD,CA/BD;;AAiCO,MAAMyB,KAAK,GAAG3D,SAAd","sourcesContent":["import {\n Checkbox,\n getStatusBarHeight,\n RadioButton,\n RFValue,\n useDebouncedState,\n} from '@tecsinapse/react-core';\nimport * as React from 'react';\nimport { FlatList, ListRenderItemInfo, View } from 'react-native';\nimport { Button } from '../../atoms/Button';\nimport { Header } from '../../atoms/Header';\nimport { Input } from '../../atoms/Input';\nimport { IBaseModal, ModalView } from '../../atoms/Modal';\nimport { Text } from '../../atoms/Text';\nimport { SelectNativeProps } from './Select';\nimport {\n FetchIndicator,\n getStyledModal,\n ListItem,\n ModalFooter,\n SearchBarContainer,\n SelectIcon,\n TextTitleModal,\n} from './styled';\n\ninterface LoadingProps {\n loading?: boolean;\n}\n\nconst Component = <Data, Type extends 'single' | 'multi'>({\n options,\n keyExtractor,\n labelExtractor,\n groupKeyExtractor,\n hideSearchBar,\n searchBarPlaceholder,\n focused,\n type,\n value,\n onSelect,\n onSearch,\n selectModalTitle,\n selectModalTitleComponent,\n confirmButtonText,\n loading,\n close,\n closeOnPick,\n ...others\n}: SelectNativeProps<Data, Type> & LoadingProps & IBaseModal): JSX.Element => {\n const [selectedValues, setSelectedValues] = React.useState<Data[]>([]);\n const [searchArg, setSearchArg] = useDebouncedState<string>('', onSearch);\n const ModalComponent = React.useMemo(\n () => getStyledModal(getStatusBarHeight(true)),\n []\n );\n const _closeOnPick = closeOnPick && type === 'single';\n\n // Resets the temporary state to the initial state whenever the\n // modal is reopened or the value changes\n React.useEffect(() => {\n setSelectedValues(\n (value ? (type === 'multi' ? value : [value]) : []) as Data[]\n );\n }, [value, focused, setSelectedValues]);\n\n const getData = React.useCallback((options: Data[]) => {\n return options?.map((option, index) => ({\n ...option,\n _checked:\n type === 'multi'\n ? !!selectedValues.find(\n value => keyExtractor(option, index) == keyExtractor(value, index)\n )\n : keyExtractor((selectedValues[0] || {}) as Data, index) ==\n keyExtractor(option, index),\n }));\n }, [keyExtractor, selectedValues, type])\n\n const data = React.useMemo(() => typeof options !== 'function' ? getData(options) : [], [options, getData]);\n\n const handlePressItem = React.useCallback((option: Data) => {\n setSelectedValues(selectedValues => {\n if (type === 'multi') {\n const newArr: Data[] = [];\n let found = false;\n for (const value of selectedValues) {\n if (keyExtractor(value) != keyExtractor(option)) newArr.push(value);\n else found = true;\n }\n if (!found) newArr.push(option);\n return newArr;\n }\n return keyExtractor((selectedValues[0] || {}) as Data) ===\n keyExtractor(option)\n ? []\n : [option];\n });\n }, [selectedValues, setSelectedValues, keyExtractor, type])\n\n React.useEffect(() => {\n if (_closeOnPick && selectedValues[0] && selectedValues[0] !== value) {\n handleConfirm();\n }\n }, [selectedValues[0], value, closeOnPick]);\n\n const handleConfirm = React.useCallback(() => {\n // TS Workaround since TS won't infer the ternary operator's result type correctly\n type OnSelectArg = Parameters<typeof onSelect>[0];\n onSelect(\n (type === 'single' ? selectedValues[0] : selectedValues) as OnSelectArg\n );\n close?.()\n }, [selectedValues]);\n\n const optionBuilder = React.useCallback(({ item }: ListRenderItemInfo<Data & { _checked: boolean }>) => (\n <MemoizedOption\n item={item}\n type={type}\n handlePressItem={handlePressItem}\n labelExtractor={labelExtractor}\n />\n ), [])\n\n const anyChecked = data.filter(item => item._checked).length\n const dataLengthChanged = data.length\n\n const memoizedFlatlist = React.useMemo(() => (\n <FlatList\n data={data}\n keyExtractor={keyExtractor}\n fadingEdgeLength={200}\n renderItem={optionBuilder}\n />\n ), [selectedValues, anyChecked, dataLengthChanged])\n\n const titleTextModal = selectModalTitle ? (\n <TextTitleModal\n typography=\"h4\"\n fontWeight=\"bold\"\n numberOfLines={3}\n style={{ maxWidth: RFValue(250) }}\n >\n {selectModalTitle}\n </TextTitleModal>\n ) : null;\n\n const headerContent = selectModalTitleComponent\n ? selectModalTitleComponent\n : titleTextModal;\n\n return (\n <ModalView {...others} BoxComponent={ModalComponent} showCloseBar={false}>\n <Header\n rightButton={{\n onPress: close,\n icon: {\n name: 'close',\n type: 'material-community',\n fontColor: 'light',\n },\n }}\n >\n {headerContent}\n </Header>\n\n {!hideSearchBar && (\n <SearchBarContainer>\n <Input\n placeholder={searchBarPlaceholder}\n value={searchArg}\n onChange={text => setSearchArg(text)}\n leftComponent={\n <SelectIcon name=\"search\" type=\"ionicon\" size=\"centi\" />\n }\n />\n </SearchBarContainer>\n )}\n\n {loading && (\n <FetchIndicator animating={true} color={'grey'} size={'large'} />\n )}\n\n {memoizedFlatlist}\n\n { !_closeOnPick && <ModalFooter>\n <Button\n variant={'filled'}\n color={'primary'}\n onPress={handleConfirm}\n disabled={loading}\n >\n <Text fontColor={'light'} fontWeight=\"bold\">\n {confirmButtonText}\n </Text>\n </Button>\n </ModalFooter>}\n </ModalView>\n );\n};\n\ninterface IOption<T> {\n item: T & { _checked: boolean }\n type: 'single' | 'multi'\n labelExtractor: (option: T) => string\n handlePressItem: (option: T) => void\n}\n\nconst MemoizedOption: React.FC<IOption<any>> = ({ handlePressItem, labelExtractor, item, type }) => {\n return React.useMemo(() => {\n const label = labelExtractor(item)\n return (\n <ListItem onPress={() => handlePressItem(item)}>\n <View pointerEvents={'none'}>\n {type === 'multi' ? (\n <Checkbox\n color={'primary'}\n labelPosition={'right'}\n checked={item._checked}\n >\n <Text fontWeight={item._checked ? 'bold' : 'regular'}>\n {label}\n </Text>\n </Checkbox>\n ) : (\n <RadioButton\n color={'primary'}\n labelPosition={'right'}\n checked={item._checked}\n >\n <Text fontWeight={item._checked ? 'bold' : 'regular'}>\n {label}\n </Text>\n </RadioButton>\n )}\n </View>\n </ListItem>\n )\n }, [item._checked])\n}\n\nexport const Modal = Component;\n"],"file":"Modal.js"}
@@ -2,7 +2,7 @@ import { InputContainerProps } from '@tecsinapse/react-core';
2
2
  export interface SelectNativeProps<Data, Type extends 'single' | 'multi'> extends Omit<InputContainerProps, 'value' | 'onChange' | 'onChangeText'> {
3
3
  options: ((searchInput?: string) => Promise<Data[]>) | Data[];
4
4
  onSelect: (option: Type extends 'single' ? Data | undefined : Data[]) => never | void;
5
- value: Type extends 'single' ? Data | undefined : Data[];
5
+ value: Type extends 'single' ? Data | null | undefined : Data[];
6
6
  type: Type;
7
7
  keyExtractor: (t: Data, index?: number) => string;
8
8
  labelExtractor: (t: Data) => string;
@@ -61,15 +61,7 @@ function Select({
61
61
  setSelectOptions(options);
62
62
  }
63
63
  }, [options]);
64
- (0, React.useEffect)(() => {
65
- if (typeof options === 'function') {
66
- if (value) {
67
- if (type === 'single') setSelectOptions([value]);else setSelectOptions([...value]);
68
- } else setSelectOptions([]);
69
- }
70
- }, [value]);
71
-
72
- const handleLazyFocus = async () => {
64
+ const handleLazyFocus = React.useCallback(async () => {
73
65
  if (typeof options === 'function') {
74
66
  setLoading(true);
75
67
 
@@ -85,8 +77,7 @@ function Select({
85
77
  setLoading(false);
86
78
  }
87
79
  }
88
- };
89
-
80
+ }, [options, value, setSelectOptions]);
90
81
  const handleOnSearch = React.useCallback(async searchInput => {
91
82
  if (searchInput !== undefined && onSearch) {
92
83
  setLoading(true);
@@ -114,8 +105,7 @@ function Select({
114
105
  }
115
106
  }
116
107
  }, [options, value, keyExtractor]);
117
-
118
- const getDisplayValue = () => {
108
+ const getDisplayValue = React.useCallback(() => {
119
109
  if (Array.isArray(value)) {
120
110
  if (value.length === 0) return placeholder;else {
121
111
  return selectOptions == null ? void 0 : selectOptions.reduce((acc, option, index) => value.find(key => keyExtractor(option, index) == keyExtractor(key, index)) ? acc + labelExtractor(option) + ', ' : acc, '').slice(0, -2);
@@ -125,8 +115,7 @@ function Select({
125
115
  const selectedOption = selectOptions == null ? void 0 : selectOptions.find((option, index) => keyExtractor(option, index) == keyExtractor(value, index));
126
116
  return selectedOption ? labelExtractor(selectedOption) : placeholder;
127
117
  }
128
- };
129
-
118
+ }, [placeholder, value, selectOptions]);
130
119
  modal.sync(React.createElement(_Modal2.Modal, {
131
120
  options: selectOptions || [],
132
121
  focused: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/molecules/Select/Select.tsx"],"names":["Select","value","options","keyExtractor","groupKeyExtractor","onSelect","type","labelExtractor","placeholder","onFocus","onBlur","disabled","onSearch","selectModalTitle","selectModalTitleComponent","searchBarPlaceholder","hideSearchBar","confirmButtonText","rightComponent","variant","hintComponent","hint","style","controlComponent","closeOnPick","rest","focused","handleBlur","handleFocus","selectOptions","setSelectOptions","modal","loading","setLoading","handleLazyFocus","result","find","v","e","handleOnSearch","React","useCallback","searchInput","undefined","length","selectedValues","filter","current","requestUpdate","getDisplayValue","Array","isArray","reduce","acc","option","index","key","slice","selectedOption","sync","handlePressInput","show","Text"],"mappings":";;;;;AAAA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;;;;;;;AAkCA,SAASA,MAAT,CAAuD;AAErDC,EAAA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gBAAgB,CAACqC,gBAAD,EAAmBX,eAAe,MAAM,EAAxC,CADD,GAGf,oBAAC,6BAAD;AACE,IAAA,SAAS,EAAE3B,KADb;AAEE,IAAA,OAAO,EAAEsC,gBAFX;AAGE,IAAA,OAAO,EAAElC,OAHX;AAIE,IAAA,QAAQ,EAAEf,QAJZ;AAKE,IAAA,cAAc,EAAEmD,UALlB;AAME,IAAA,OAAO,EAAE3C,OANX;AAOE,IAAA,IAAI,EAAEE,IAPR;AAQE,IAAA,aAAa,EAAED,aARjB;AASE,IAAA,cAAc,EACZ,0CACE,oBAAC,kBAAD;AAAY,MAAA,IAAI,EAAC,cAAjB;AAAgC,MAAA,IAAI,EAAC,SAArC;AAA+C,MAAA,IAAI,EAAC;AAApD,MADF,EAEGF,cAFH;AAVJ,KAeMO,IAfN,GAiBE,oBAAC,2BAAD;AAAqB,IAAA,UAAU,EAAC,MAAhC;AAAuC,IAAA,QAAQ,EAAEd;AAAjD,KACGsC,eAAe,MAAM,GADxB,CAjBF,CAJJ,CADF;AA6BD;;eAEcjD,M","sourcesContent":["import {\n HintInputContainer,\n InputContainerProps,\n useInputFocus,\n} from '@tecsinapse/react-core';\nimport * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { useLazyModalManager } from '../../atoms/Modal';\nimport { Text } from '../../atoms/Text';\nimport { Modal } from './Modal';\nimport { SelectIcon, StyledSelectionText } from './styled';\n\nexport interface SelectNativeProps<Data, Type extends 'single' | 'multi'>\n extends Omit<InputContainerProps, 'value' | 'onChange' | 'onChangeText'> {\n options: ((searchInput?: string) => Promise<Data[]>) | Data[];\n onSelect: (\n option: Type extends 'single' ? Data | undefined : Data[]\n ) => never | void;\n value: Type extends 'single' ? Data | undefined : Data[];\n type: Type;\n\n keyExtractor: (t: Data, index?: number) => string;\n labelExtractor: (t: Data) => string;\n groupKeyExtractor?: (t: Data) => string;\n\n hideSearchBar?: boolean;\n placeholder?: string;\n onFocus?: () => void | never;\n onBlur?: () => void | never;\n onSearch?:\n | ((searchArg: string) => void)\n | ((searchInput?: string) => Promise<Data[]>)\n | never;\n searchBarPlaceholder?: string;\n confirmButtonText?: string;\n selectModalTitle?: string;\n selectModalTitleComponent?: JSX.Element;\n closeOnPick?: boolean;\n controlComponent?: (\n onPress: () => void,\n displayValue?: string\n ) => JSX.Element;\n}\n\nfunction Select<Data, Type extends 'single' | 'multi'>({\n /** Select props */\n value,\n options,\n keyExtractor,\n groupKeyExtractor,\n onSelect,\n type,\n labelExtractor,\n placeholder,\n onFocus,\n onBlur,\n disabled,\n onSearch,\n selectModalTitle,\n selectModalTitleComponent,\n searchBarPlaceholder,\n hideSearchBar,\n confirmButtonText,\n rightComponent,\n variant = 'default',\n hintComponent,\n hint,\n style,\n controlComponent,\n closeOnPick = type === 'single',\n ...rest\n}: SelectNativeProps<Data, Type>): JSX.Element {\n const { focused, handleBlur, handleFocus } = useInputFocus(\n onFocus,\n onBlur,\n !disabled\n );\n\n const [selectOptions, setSelectOptions] = useState<Data[]>([]);\n const modal = useLazyModalManager();\n\n // TODO: Add Skeleton to modal height when loading is true\n const [loading, setLoading] = useState<boolean>(false);\n\n useEffect(() => {\n if (typeof options !== 'function') {\n setSelectOptions(options);\n }\n }, [options]);\n\n useEffect(() => {\n if (typeof options === 'function') {\n if (value) {\n if (type === 'single') setSelectOptions([value as Data]);\n else setSelectOptions([...(value as Data[])]);\n } else setSelectOptions([]);\n }\n }, [value]);\n\n const handleLazyFocus = async () => {\n if (typeof options === 'function') {\n setLoading(true);\n try {\n const result = await options();\n if (result) {\n if (\n value &&\n !result.find(v => keyExtractor(value as Data) === keyExtractor(v))\n ) {\n setSelectOptions([value as Data, ...result]);\n } else setSelectOptions(result);\n }\n } catch (e) {\n // TODO: Catch error\n } finally {\n setLoading(false);\n }\n }\n };\n\n const handleOnSearch = React.useCallback(\n async (searchInput: string | undefined) => {\n if (searchInput !== undefined && onSearch) {\n setLoading(true);\n try {\n const result = await onSearch(searchInput);\n if (result) {\n if (type === 'single') {\n if (\n value &&\n !result.find(\n v => keyExtractor(value as Data) === keyExtractor(v)\n )\n ) {\n setSelectOptions([value as Data, ...result]);\n } else setSelectOptions(result);\n } else {\n if ((value as Data[]).length > 0) {\n const selectedValues =\n (value as Data[]).filter(\n v =>\n !result.find(\n current =>\n keyExtractor(v as Data) === keyExtractor(current)\n )\n ) || [];\n setSelectOptions([...selectedValues, ...result]);\n } else {\n setSelectOptions(result);\n }\n }\n }\n } catch (e) {\n // TODO: Catch error\n } finally {\n modal.requestUpdate();\n setLoading(false);\n }\n }\n },\n [options, value, keyExtractor]\n );\n\n const getDisplayValue = () => {\n if (Array.isArray(value)) {\n if (value.length === 0) return placeholder;\n else {\n return selectOptions\n ?.reduce(\n (acc, option, index) =>\n value.find(\n key => keyExtractor(option, index) == keyExtractor(key, index)\n )\n ? acc + labelExtractor(option) + ', '\n : acc,\n ''\n )\n .slice(0, -2);\n }\n } else {\n if (value === undefined) return placeholder;\n const selectedOption = selectOptions?.find(\n (option, index) =>\n keyExtractor(option, index) == keyExtractor(value as Data, index)\n );\n return selectedOption ? labelExtractor(selectedOption) : placeholder;\n }\n };\n\n modal.sync(\n <Modal\n options={selectOptions || []}\n focused={true}\n keyExtractor={keyExtractor}\n labelExtractor={labelExtractor}\n groupKeyExtractor={groupKeyExtractor}\n searchBarPlaceholder={searchBarPlaceholder}\n type={type}\n onSelect={onSelect}\n value={value}\n hideSearchBar={hideSearchBar}\n onSearch={handleOnSearch}\n selectModalTitle={selectModalTitle}\n selectModalTitleComponent={selectModalTitleComponent}\n confirmButtonText={confirmButtonText}\n loading={loading}\n onClose={handleBlur}\n closeOnPick={closeOnPick}\n />\n );\n\n const handlePressInput = async () => {\n modal.show();\n handleFocus();\n await handleLazyFocus();\n };\n\n return (\n <>\n {controlComponent ? (\n controlComponent(handlePressInput, getDisplayValue() || '')\n ) : (\n <HintInputContainer\n viewStyle={style}\n onPress={handlePressInput}\n focused={focused}\n disabled={disabled}\n LabelComponent={Text}\n variant={variant}\n hint={hint}\n hintComponent={hintComponent}\n rightComponent={\n <>\n <SelectIcon name=\"chevron-down\" type=\"ionicon\" size=\"centi\" />\n {rightComponent}\n </>\n }\n {...rest}\n >\n <StyledSelectionText fontWeight=\"bold\" disabled={disabled}>\n {getDisplayValue() || ' '}\n </StyledSelectionText>\n </HintInputContainer>\n )}\n </>\n );\n}\n\nexport default Select;\n"],"file":"Select.js"}
1
+ {"version":3,"sources":["../../../../src/components/molecules/Select/Select.tsx"],"names":["Select","value","options","keyExtractor","groupKeyExtractor","onSelect","type","labelExtractor","placeholder","onFocus","onBlur","disabled","onSearch","selectModalTitle","selectModalTitleComponent","searchBarPlaceholder","hideSearchBar","confirmButtonText","rightComponent","variant","hintComponent","hint","style","controlComponent","closeOnPick","rest","focused","handleBlur","handleFocus","selectOptions","setSelectOptions","modal","loading","setLoading","handleLazyFocus","React","useCallback","result","find","v","e","handleOnSearch","searchInput","undefined","length","selectedValues","filter","current","requestUpdate","getDisplayValue","Array","isArray","reduce","acc","option","index","key","slice","selectedOption","sync","handlePressInput","show","Text"],"mappings":";;;;;AAAA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;;;;;;;AAkCA,SAASA,MAAT,CAAuD;AAErDC,EAAAA,KAFqD;AAGrDC,EAAAA,OAHqD;AAIrDC,EAAAA,YAJqD;AAKrDC,EAAAA,iBALqD;AAMrDC,EAAAA,QANqD;AAOrDC,EAAAA,IAPqD;AAQrDC,EAAAA,cARqD;AASrDC,EAAAA,WATqD;AAUrDC,EAAAA,OAVqD;AAWrDC,EAAAA,MAXqD;AAYrDC,EAAAA,QAZqD;AAarDC,EAAAA,QAbqD;AAcrDC,EAAAA,gBAdqD;AAerDC,EAAAA,yBAfqD;AAgBrDC,EAAAA,oBAhBqD;AAiBrDC,EAAAA,aAjBqD;AAkBrDC,EAAAA,iBAlBqD;AAmBrDC,EAAAA,cAnBqD;AAoBrDC,EAAAA,OAAO,GAAG,SApB2C;AAqBrDC,EAAAA,aArBqD;AAsBrDC,EAAAA,IA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jBF,CAJJ,CADF;AA6BD;;eAEcjD,M","sourcesContent":["import {\n HintInputContainer,\n InputContainerProps,\n useInputFocus\n} from '@tecsinapse/react-core';\nimport * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { useLazyModalManager } from '../../atoms/Modal';\nimport { Text } from '../../atoms/Text';\nimport { Modal } from './Modal';\nimport { SelectIcon, StyledSelectionText } from './styled';\n\nexport interface SelectNativeProps<Data, Type extends 'single' | 'multi'>\n extends Omit<InputContainerProps, 'value' | 'onChange' | 'onChangeText'> {\n options: ((searchInput?: string) => Promise<Data[]>) | Data[];\n onSelect: (\n option: Type extends 'single' ? Data | undefined : Data[]\n ) => never | void;\n value: Type extends 'single' ? Data | null | undefined : Data[];\n type: Type;\n\n keyExtractor: (t: Data, index?: number) => string;\n labelExtractor: (t: Data) => string;\n groupKeyExtractor?: (t: Data) => string;\n\n hideSearchBar?: boolean;\n placeholder?: string;\n onFocus?: () => void | never;\n onBlur?: () => void | never;\n onSearch?:\n | ((searchArg: string) => void)\n | ((searchInput?: string) => Promise<Data[]>)\n | never;\n searchBarPlaceholder?: string;\n confirmButtonText?: string;\n selectModalTitle?: string;\n selectModalTitleComponent?: JSX.Element;\n closeOnPick?: boolean;\n controlComponent?: (\n onPress: () => void,\n displayValue?: string\n ) => JSX.Element;\n}\n\nfunction Select<Data, Type extends 'single' | 'multi'>({\n /** Select props */\n value,\n options,\n keyExtractor,\n groupKeyExtractor,\n onSelect,\n type,\n labelExtractor,\n placeholder,\n onFocus,\n onBlur,\n disabled,\n onSearch,\n selectModalTitle,\n selectModalTitleComponent,\n searchBarPlaceholder,\n hideSearchBar,\n confirmButtonText,\n rightComponent,\n variant = 'default',\n hintComponent,\n hint,\n style,\n controlComponent,\n closeOnPick = type === 'single',\n ...rest\n}: SelectNativeProps<Data, Type>): JSX.Element {\n const { focused, handleBlur, handleFocus } = useInputFocus(\n onFocus,\n onBlur,\n !disabled\n );\n\n const [selectOptions, setSelectOptions] = useState<Data[]>([]);\n const modal = useLazyModalManager();\n\n // TODO: Add Skeleton to modal height when loading is true\n const [loading, setLoading] = useState<boolean>(false);\n\n useEffect(() => {\n if (typeof options !== 'function') {\n setSelectOptions(options);\n }\n }, [options]);\n\n const handleLazyFocus = React.useCallback(async () => {\n if (typeof options === 'function') {\n setLoading(true);\n try {\n const result = await options();\n if (result) {\n if (\n value &&\n !result.find(v => keyExtractor(value as Data) === keyExtractor(v))\n ) {\n setSelectOptions([value as Data, ...result]);\n } else setSelectOptions(result);\n }\n } catch (e) {\n // TODO: Catch error\n } finally {\n setLoading(false);\n }\n }\n }, [options, value, setSelectOptions])\n\n const handleOnSearch = React.useCallback(\n async (searchInput: string | undefined) => {\n if (searchInput !== undefined && onSearch) {\n setLoading(true);\n try {\n const result = await onSearch(searchInput);\n if (result) {\n if (type === 'single') {\n if (\n value &&\n !result.find(\n v => keyExtractor(value as Data) === keyExtractor(v)\n )\n ) {\n setSelectOptions([value as Data, ...result]);\n } else setSelectOptions(result);\n } else {\n if ((value as Data[]).length > 0) {\n const selectedValues =\n (value as Data[]).filter(\n v =>\n !result.find(\n current =>\n keyExtractor(v as Data) === keyExtractor(current)\n )\n ) || [];\n setSelectOptions([...selectedValues, ...result]);\n } else {\n setSelectOptions(result);\n }\n }\n }\n } catch (e) {\n // TODO: Catch error\n } finally {\n modal.requestUpdate();\n setLoading(false);\n }\n }\n },\n [options, value, keyExtractor]\n );\n\n const getDisplayValue = React.useCallback(() => {\n if (Array.isArray(value)) {\n if (value.length === 0) return placeholder;\n else {\n return selectOptions\n ?.reduce(\n (acc, option, index) =>\n value.find(\n key => keyExtractor(option, index) == keyExtractor(key, index)\n )\n ? acc + labelExtractor(option) + ', '\n : acc,\n ''\n )\n .slice(0, -2);\n }\n } else {\n if (value === undefined) return placeholder;\n const selectedOption = selectOptions?.find(\n (option, index) =>\n keyExtractor(option, index) == keyExtractor(value as Data, index)\n );\n return selectedOption ? labelExtractor(selectedOption) : placeholder;\n }\n }, [placeholder, value, selectOptions]);\n\n modal.sync(\n <Modal\n options={selectOptions || []}\n focused={true}\n keyExtractor={keyExtractor}\n labelExtractor={labelExtractor}\n groupKeyExtractor={groupKeyExtractor}\n searchBarPlaceholder={searchBarPlaceholder}\n type={type}\n onSelect={onSelect}\n value={value}\n hideSearchBar={hideSearchBar}\n onSearch={handleOnSearch}\n selectModalTitle={selectModalTitle}\n selectModalTitleComponent={selectModalTitleComponent}\n confirmButtonText={confirmButtonText}\n loading={loading}\n onClose={handleBlur}\n closeOnPick={closeOnPick}\n />\n );\n\n const handlePressInput = async () => {\n modal.show();\n handleFocus();\n await handleLazyFocus();\n };\n\n return (\n <>\n {controlComponent ? (\n controlComponent(handlePressInput, getDisplayValue() || '')\n ) : (\n <HintInputContainer\n viewStyle={style}\n onPress={handlePressInput}\n focused={focused}\n disabled={disabled}\n LabelComponent={Text}\n variant={variant}\n hint={hint}\n hintComponent={hintComponent}\n rightComponent={\n <>\n <SelectIcon name=\"chevron-down\" type=\"ionicon\" size=\"centi\" />\n {rightComponent}\n </>\n }\n {...rest}\n >\n <StyledSelectionText fontWeight=\"bold\" disabled={disabled}>\n {getDisplayValue() || ' '}\n </StyledSelectionText>\n </HintInputContainer>\n )}\n </>\n );\n}\n\nexport default Select;\n"],"file":"Select.js"}
@@ -38,3 +38,4 @@ export declare const FetchIndicator: import("@emotion/native").StyledComponent<i
38
38
  }, {}, {
39
39
  ref?: import("react").Ref<ActivityIndicator> | undefined;
40
40
  }>;
41
+ export declare const TextTitleModal: import("@emotion/native").StyledComponent<any, {}, {}>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.FetchIndicator = exports.SelectIcon = exports.ModalFooter = exports.ListItem = exports.SearchBar = exports.SearchBarContainer = exports.CloseButton = exports.Header = exports.StyledPressableSurface = exports.Dummy = exports.StyledSelectionText = exports.getStyledModal = void 0;
4
+ exports.TextTitleModal = exports.FetchIndicator = exports.SelectIcon = exports.ModalFooter = exports.ListItem = exports.SearchBar = exports.SearchBarContainer = exports.CloseButton = exports.Header = exports.StyledPressableSurface = exports.Dummy = exports.StyledSelectionText = exports.getStyledModal = void 0;
5
5
 
6
6
  var _native = _interopRequireWildcard(require("@emotion/native"));
7
7
 
@@ -115,4 +115,8 @@ const FetchIndicator = (0, _native.default)(_reactNative.ActivityIndicator)`
115
115
  align-self: center;
116
116
  `;
117
117
  exports.FetchIndicator = FetchIndicator;
118
+ const TextTitleModal = (0, _native.default)(_Text.Text)`
119
+ text-align: center;
120
+ `;
121
+ exports.TextTitleModal = TextTitleModal;
118
122
  //# sourceMappingURL=styled.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/molecules/Select/styled.ts"],"names":["getStyledModal","safeTop","View","theme","miscellaneous","bodyColor","StyledSelectionText","Text","props","typography","h5","lineHeight","Dummy","StyledPressableSurface","PressableSurface","Header","spacing","deca","CloseButton","Button","SearchBarContainer","SearchBar","Input","ListItem","color","secondary","light","mili","ModalFooter","SelectIcon","Icon","centi","medium","FetchIndicator","ActivityIndicator"],"mappings":";;;;;AAAA;;AACA;;AAYA;;AACA;;AACA;;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,OAAe,GAAG,CAAnB,KAAyB;AACrD,SAAO,qBAAOC,iBAAP,CAA+C;AACxD,mBAAoB,GAAE,wBAAQD,OAAR,CAAiB,IAAI;AAC3C,wBAAwB,CAAC;AAAEE,IAAAA;AAAF,GAAD,KAAeA,KAAK,CAACC,aAAN,CAAoBC,SAAU;AACrE;AACA,GAJE;AAKD,CANM;;;AAQA,MAAMC,mBAAmB,GAAG,qBAAOC,UAAP,EAChCC,KAAD;AAAA;;AAAA,SAA+D,gBAAI;AACrE,mBADoE,gBACjDA,KAAK,CAACL,KAD2C,qBACjD,aAAaM,UAAb,CAAwBC,EAAxB,CAA2BC,UAAW;AACzD,MAAM,oCAAoBH,KAApB,CAA2B;AACjC,GAHE;AAAA,CADiC,CAA5B;;AAOA,MAAMI,KAAK,GAAG,qBAAOV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EF,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACa,OAAN,CAAcC,IAAK;AAC/C,CANO;;AAQA,MAAMY,UAAU,GAAG,qBAAOC,eAAP,CAAkC;AAC5D,aAAa,CAAC;AAAE3B,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACa,OAAN,CAAce,KAAM;AAChD,WAAW,CAAC;AAAE5B,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACqB,KAAN,CAAYC,SAAZ,CAAsBO,MAAO;AACvD,CAHO;;AAKA,MAAMC,cAAc,GAAG,qBAAOC,8BAAP,CAA0B;AACxD;AACA,CAFO","sourcesContent":["import styled, { css } from '@emotion/native';\nimport {\n Button,\n ButtonProps,\n disabledInputStyles,\n Icon,\n InputContainerProps,\n PressableSurface,\n PressableSurfaceProps,\n RFValue,\n RFValueStr,\n StyleProps\n} from '@tecsinapse/react-core';\nimport { ActivityIndicator, ModalProps, View, ViewProps } from 'react-native';\nimport { Input, InputNativeProps } from '../../atoms/Input';\nimport { Text } from '../../atoms/Text';\n\nexport const getStyledModal = (safeTop: number = 0) => {\n return styled(View)<ModalProps & Partial<StyleProps>>`\n padding-top: ${`${RFValue(safeTop)}px`};\n background-color: ${({ theme }) => theme.miscellaneous.bodyColor};\n height: 100%;\n `\n}\n\nexport const StyledSelectionText = styled(Text)(\n (props: Partial<InputContainerProps> & Partial<StyleProps>) => css`\n line-height: ${props.theme?.typography.h5.lineHeight};\n ${disabledInputStyles(props)};\n `\n);\n\nexport const Dummy = styled(View)`\n aspect-ratio: 1;\n height: 100%;\n`;\n\nexport const StyledPressableSurface = styled(\n PressableSurface\n)<PressableSurfaceProps>`\n width: 100%;\n`;\n\nexport const Header = styled(View)<ViewProps & Partial<StyleProps>>`\n position: relative;\n width: 100%;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n padding: ${({ theme }) => theme.spacing.deca};\n height: ${RFValueStr('75px')};\n`;\n\nexport const CloseButton = styled(Button)<ButtonProps & Partial<StyleProps>>`\n aspect-ratio: 1;\n height: 100%;\n`;\n\nexport const SearchBarContainer = styled(View)<ViewProps & Partial<StyleProps>>`\n padding: ${({ theme }) => theme.spacing.deca};\n position: relative;\n`;\n\nexport const SearchBar = styled(Input)<InputNativeProps & Partial<StyleProps>>`\n margin-bottom: ${({ theme }) => theme.spacing.deca};\n`;\n\nexport const ListItem = styled(PressableSurface)<\n PressableSurfaceProps & Partial<StyleProps>\n>`\n border-bottom-width: ${RFValueStr('1px')};\n border-color: ${({ theme }) => theme.color.secondary.light};\n padding-vertical: ${({ theme }) => theme.spacing.mili};\n padding-horizontal: ${({ theme }) => theme.spacing.deca};\n`;\n\nexport const ModalFooter = styled(View)<Partial<StyleProps>>`\n width: 100%;\n height: auto;\n bottom: 0;\n background-color: ${({ theme }) => theme.miscellaneous.bodyColor};\n padding: ${({ theme }) => theme.spacing.deca};\n`;\n\nexport const SelectIcon = styled(Icon)<Partial<StyleProps>>`\n padding: ${({ theme }) => theme.spacing.centi};\n color: ${({ theme }) => theme.color.secondary.medium};\n`;\n\nexport const FetchIndicator = styled(ActivityIndicator)`\n align-self: center;\n`;\n"],"file":"styled.js"}
1
+ {"version":3,"sources":["../../../../src/components/molecules/Select/styled.ts"],"names":["getStyledModal","safeTop","View","theme","miscellaneous","bodyColor","StyledSelectionText","Text","props","typography","h5","lineHeight","Dummy","StyledPressableSurface","PressableSurface","Header","spacing","deca","CloseButton","Button","SearchBarContainer","SearchBar","Input","ListItem","color","secondary","light","mili","ModalFooter","SelectIcon","Icon","centi","medium","FetchIndicator","ActivityIndicator","TextTitleModal"],"mappings":";;;;;AAAA;;AACA;;AAYA;;AACA;;AACA;;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,OAAO,GAAG,CAAX,KAAiB;AAC7C,SAAO,qBAAOC,iBAAP,CAA+C;AACxD,mBAAoB,GAAE,wBAAQD,OAAR,CAAiB,IAAI;AAC3C,wBAAwB,CAAC;AAAEE,IAAAA;AAAF,GAAD,KAAeA,KAAK,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,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACa,OAAN,CAAcW,IAAK;AACxD,wBAAwB,CAAC;AAAExB,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACa,OAAN,CAAcC,IAAK;AAC1D,CAPO;;AASA,MAAMW,WAAW,GAAG,qBAAO1B,iBAAP,CAAkC;AAC7D;AACA;AACA;AACA,sBAAsB,CAAC;AAAEC,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACC,aAAN,CAAoBC,SAAU;AACnE,aAAa,CAAC;AAAEF,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACa,OAAN,CAAcC,IAAK;AAC/C,CANO;;AAQA,MAAMY,UAAU,GAAG,qBAAOC,eAAP,CAAkC;AAC5D,aAAa,CAAC;AAAE3B,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACa,OAAN,CAAce,KAAM;AAChD,WAAW,CAAC;AAAE5B,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACqB,KAAN,CAAYC,SAAZ,CAAsBO,MAAO;AACvD,CAHO;;AAKA,MAAMC,cAAc,GAAG,qBAAOC,8BAAP,CAA0B;AACxD;AACA,CAFO;;AAIA,MAAMC,cAAc,GAAG,qBAAO5B,UAAP,CAAkC;AAChE;AACA,CAFO","sourcesContent":["import styled, { css } from '@emotion/native';\nimport {\n Button,\n ButtonProps,\n disabledInputStyles,\n Icon,\n InputContainerProps,\n PressableSurface,\n PressableSurfaceProps,\n RFValue,\n RFValueStr,\n StyleProps,\n} from '@tecsinapse/react-core';\nimport { ActivityIndicator, ModalProps, View, ViewProps } from 'react-native';\nimport { Input, InputNativeProps } from '../../atoms/Input';\nimport { Text } from '../../atoms/Text';\n\nexport const getStyledModal = (safeTop = 0) => {\n return styled(View)<ModalProps & Partial<StyleProps>>`\n padding-top: ${`${RFValue(safeTop)}px`};\n background-color: ${({ theme }) => theme.miscellaneous.bodyColor};\n height: 100%;\n `;\n};\n\nexport const StyledSelectionText = styled(Text)(\n (props: Partial<InputContainerProps> & Partial<StyleProps>) => css`\n line-height: ${props.theme?.typography.h5.lineHeight};\n ${disabledInputStyles(props)};\n `\n);\n\nexport const Dummy = styled(View)`\n aspect-ratio: 1;\n height: 100%;\n`;\n\nexport const StyledPressableSurface = styled(\n PressableSurface\n)<PressableSurfaceProps>`\n width: 100%;\n`;\n\nexport const Header = styled(View)<ViewProps & Partial<StyleProps>>`\n position: relative;\n width: 100%;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n padding: ${({ theme }) => theme.spacing.deca};\n height: ${RFValueStr('75px')};\n`;\n\nexport const CloseButton = styled(Button)<ButtonProps & Partial<StyleProps>>`\n aspect-ratio: 1;\n height: 100%;\n`;\n\nexport const SearchBarContainer = styled(View)<ViewProps & Partial<StyleProps>>`\n padding: ${({ theme }) => theme.spacing.deca};\n position: relative;\n`;\n\nexport const SearchBar = styled(Input)<InputNativeProps & Partial<StyleProps>>`\n margin-bottom: ${({ theme }) => theme.spacing.deca};\n`;\n\nexport const ListItem = styled(PressableSurface)<\n PressableSurfaceProps & Partial<StyleProps>\n>`\n border-bottom-width: ${RFValueStr('1px')};\n border-color: ${({ theme }) => theme.color.secondary.light};\n padding-vertical: ${({ theme }) => theme.spacing.mili};\n padding-horizontal: ${({ theme }) => theme.spacing.deca};\n`;\n\nexport const ModalFooter = styled(View)<Partial<StyleProps>>`\n width: 100%;\n height: auto;\n bottom: 0;\n background-color: ${({ theme }) => theme.miscellaneous.bodyColor};\n padding: ${({ theme }) => theme.spacing.deca};\n`;\n\nexport const SelectIcon = styled(Icon)<Partial<StyleProps>>`\n padding: ${({ theme }) => theme.spacing.centi};\n color: ${({ theme }) => theme.color.secondary.medium};\n`;\n\nexport const FetchIndicator = styled(ActivityIndicator)`\n align-self: center;\n`;\n\nexport const TextTitleModal = styled(Text)<Partial<StyleProps>>`\n text-align: center;\n`;\n"],"file":"styled.js"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tecsinapse/react-native-kit",
3
3
  "description": "TecSinapse React Native components",
4
- "version": "1.17.6",
4
+ "version": "1.17.9",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@emotion/native": "^11.0.0",
18
18
  "@emotion/react": "^11.4.1",
19
- "@tecsinapse/react-core": "^1.16.4",
19
+ "@tecsinapse/react-core": "^1.16.5",
20
20
  "react-native-linear-gradient": "^2.5.6"
21
21
  },
22
22
  "repository": {
@@ -39,5 +39,5 @@
39
39
  "devDependencies": {
40
40
  "@types/uuid": "^8.3.3"
41
41
  },
42
- "gitHead": "ab944cad9dc3a840ebf3ebc9ed525926ebe3a436"
42
+ "gitHead": "41a7cd4c1031d3561019af3afffdc549f185ac02"
43
43
  }
@@ -2,14 +2,16 @@ import {
2
2
  FontStackType,
3
3
  FontWeightType,
4
4
  Hint,
5
+ InputContainer,
5
6
  InputContainerProps,
6
7
  InputElementProps,
7
- useInputFocus,
8
+ RFValue,
9
+ useInputFocus
8
10
  } from '@tecsinapse/react-core';
9
11
  import React, { FC } from 'react';
10
- import { View } from 'react-native';
12
+ import { StyleProp, View, ViewStyle } from 'react-native';
11
13
  import { Text } from '../Text';
12
- import { StyledInputContainer, StyledNativeInput } from './styled';
14
+ import { StyledNativeInput } from './styled';
13
15
 
14
16
  export interface InputNativeProps
15
17
  extends Omit<InputElementProps, 'style'>,
@@ -57,11 +59,12 @@ const Input: FC<InputNativeProps> = React.forwardRef(
57
59
  !disabled
58
60
  );
59
61
 
62
+ const internalStyle: StyleProp<ViewStyle> = { minHeight: RFValue(50), ...{ inputContainerStyle }}
60
63
  const onlyLabel = label && !placeholder;
61
64
 
62
65
  return (
63
- <View style={style}>
64
- <StyledInputContainer
66
+ <View>
67
+ <InputContainer
65
68
  label={value ? label : undefined}
66
69
  labelColor={labelColor}
67
70
  labelColorVariant={labelColorVariant}
@@ -74,7 +77,7 @@ const Input: FC<InputNativeProps> = React.forwardRef(
74
77
  rightComponent={rightComponent}
75
78
  borderColor={borderColor}
76
79
  borderColorGradation={borderColorGradation}
77
- inputContainerStyle={inputContainerStyle}
80
+ inputContainerStyle={internalStyle}
78
81
  focused={focused}
79
82
  disabled={disabled}
80
83
  variant={variant}
@@ -90,7 +93,7 @@ const Input: FC<InputNativeProps> = React.forwardRef(
90
93
  onFocus={handleFocus}
91
94
  onBlur={handleBlur}
92
95
  />
93
- </StyledInputContainer>
96
+ </InputContainer>
94
97
  {hint && _hint}
95
98
  </View>
96
99
  );
@@ -1,17 +1,10 @@
1
1
  import styled from '@emotion/native';
2
2
  import {
3
- InputContainer,
4
- InputElement,
5
- RFValueStr,
6
- StyleProps
3
+ InputElement, StyleProps
7
4
  } from '@tecsinapse/react-core';
8
5
  import { Font, fontStyles } from '../Text/styled';
9
6
  import { InputNativeProps } from './Input';
10
7
 
11
- export const StyledInputContainer = styled(InputContainer)<Partial<StyleProps>>`
12
- min-height: ${RFValueStr('50px')};
13
- `;
14
-
15
8
  const StyledNativeInputBase = styled(InputElement)<
16
9
  Partial<InputNativeProps> & Partial<StyleProps>
17
10
  >`
@@ -1,6 +1,12 @@
1
- import { Checkbox, getStatusBarHeight, RadioButton, useDebouncedState } from '@tecsinapse/react-core';
1
+ import {
2
+ Checkbox,
3
+ getStatusBarHeight,
4
+ RadioButton,
5
+ RFValue,
6
+ useDebouncedState,
7
+ } from '@tecsinapse/react-core';
2
8
  import * as React from 'react';
3
- import { FlatList, StatusBar, View } from 'react-native';
9
+ import { FlatList, ListRenderItemInfo, View } from 'react-native';
4
10
  import { Button } from '../../atoms/Button';
5
11
  import { Header } from '../../atoms/Header';
6
12
  import { Input } from '../../atoms/Input';
@@ -8,8 +14,13 @@ import { IBaseModal, ModalView } from '../../atoms/Modal';
8
14
  import { Text } from '../../atoms/Text';
9
15
  import { SelectNativeProps } from './Select';
10
16
  import {
11
- FetchIndicator, getStyledModal, ListItem, ModalFooter, SearchBarContainer,
12
- SelectIcon
17
+ FetchIndicator,
18
+ getStyledModal,
19
+ ListItem,
20
+ ModalFooter,
21
+ SearchBarContainer,
22
+ SelectIcon,
23
+ TextTitleModal,
13
24
  } from './styled';
14
25
 
15
26
  interface LoadingProps {
@@ -38,8 +49,11 @@ const Component = <Data, Type extends 'single' | 'multi'>({
38
49
  }: SelectNativeProps<Data, Type> & LoadingProps & IBaseModal): JSX.Element => {
39
50
  const [selectedValues, setSelectedValues] = React.useState<Data[]>([]);
40
51
  const [searchArg, setSearchArg] = useDebouncedState<string>('', onSearch);
41
- const ModalComponent = React.useMemo(() => getStyledModal(getStatusBarHeight(true)), [])
42
- const _closeOnPick = closeOnPick && type === 'single'
52
+ const ModalComponent = React.useMemo(
53
+ () => getStyledModal(getStatusBarHeight(true)),
54
+ []
55
+ );
56
+ const _closeOnPick = closeOnPick && type === 'single';
43
57
 
44
58
  // Resets the temporary state to the initial state whenever the
45
59
  // modal is reopened or the value changes
@@ -49,7 +63,7 @@ const Component = <Data, Type extends 'single' | 'multi'>({
49
63
  );
50
64
  }, [value, focused, setSelectedValues]);
51
65
 
52
- const getData = (options: Data[]) => {
66
+ const getData = React.useCallback((options: Data[]) => {
53
67
  return options?.map((option, index) => ({
54
68
  ...option,
55
69
  _checked:
@@ -60,11 +74,11 @@ const Component = <Data, Type extends 'single' | 'multi'>({
60
74
  : keyExtractor((selectedValues[0] || {}) as Data, index) ==
61
75
  keyExtractor(option, index),
62
76
  }));
63
- };
77
+ }, [keyExtractor, selectedValues, type])
64
78
 
65
- const data = typeof options !== 'function' ? getData(options) : [];
79
+ const data = React.useMemo(() => typeof options !== 'function' ? getData(options) : [], [options, getData]);
66
80
 
67
- const handlePressItem = (option: Data) => () => {
81
+ const handlePressItem = React.useCallback((option: Data) => {
68
82
  setSelectedValues(selectedValues => {
69
83
  if (type === 'multi') {
70
84
  const newArr: Data[] = [];
@@ -81,96 +95,93 @@ const Component = <Data, Type extends 'single' | 'multi'>({
81
95
  ? []
82
96
  : [option];
83
97
  });
84
- };
98
+ }, [selectedValues, setSelectedValues, keyExtractor, type])
85
99
 
86
100
  React.useEffect(() => {
87
- if (_closeOnPick && selectedValues[0] && (selectedValues[0] !== value)) {
88
- handleConfirm()
101
+ if (_closeOnPick && selectedValues[0] && selectedValues[0] !== value) {
102
+ handleConfirm();
89
103
  }
90
- }, [selectedValues[0], value, closeOnPick])
104
+ }, [selectedValues[0], value, closeOnPick]);
91
105
 
92
- const handleConfirm = () => {
106
+ const handleConfirm = React.useCallback(() => {
93
107
  // TS Workaround since TS won't infer the ternary operator's result type correctly
94
108
  type OnSelectArg = Parameters<typeof onSelect>[0];
95
109
  onSelect(
96
110
  (type === 'single' ? selectedValues[0] : selectedValues) as OnSelectArg
97
111
  );
98
112
  close?.()
99
- };
113
+ }, [selectedValues]);
114
+
115
+ const optionBuilder = React.useCallback(({ item }: ListRenderItemInfo<Data & { _checked: boolean }>) => (
116
+ <MemoizedOption
117
+ item={item}
118
+ type={type}
119
+ handlePressItem={handlePressItem}
120
+ labelExtractor={labelExtractor}
121
+ />
122
+ ), [])
123
+
124
+ const anyChecked = data.filter(item => item._checked).length
125
+ const dataLengthChanged = data.length
100
126
 
101
- const headerContent = selectModalTitleComponent ? (
102
- selectModalTitleComponent
103
- ) : selectModalTitle ? (
104
- <Text typography="h4" fontWeight="bold">
127
+ const memoizedFlatlist = React.useMemo(() => (
128
+ <FlatList
129
+ data={data}
130
+ keyExtractor={keyExtractor}
131
+ fadingEdgeLength={200}
132
+ renderItem={optionBuilder}
133
+ />
134
+ ), [selectedValues, anyChecked, dataLengthChanged])
135
+
136
+ const titleTextModal = selectModalTitle ? (
137
+ <TextTitleModal
138
+ typography="h4"
139
+ fontWeight="bold"
140
+ numberOfLines={3}
141
+ style={{ maxWidth: RFValue(250) }}
142
+ >
105
143
  {selectModalTitle}
106
- </Text>
144
+ </TextTitleModal>
107
145
  ) : null;
108
146
 
147
+ const headerContent = selectModalTitleComponent
148
+ ? selectModalTitleComponent
149
+ : titleTextModal;
150
+
109
151
  return (
110
152
  <ModalView {...others} BoxComponent={ModalComponent} showCloseBar={false}>
111
- <Header
112
- rightButton={{
113
- onPress: close,
114
- icon: {
115
- name: 'close',
116
- type: 'material-community',
117
- fontColor: 'light',
118
- },
119
- }}
120
- >
121
- {headerContent}
122
- </Header>
123
-
124
- {!hideSearchBar && (
125
- <SearchBarContainer>
126
- <Input
127
- placeholder={searchBarPlaceholder}
128
- value={searchArg}
129
- onChange={text => setSearchArg(text)}
130
- leftComponent={
131
- <SelectIcon name="search" type="ionicon" size="centi" />
132
- }
133
- />
134
- </SearchBarContainer>
135
- )}
136
-
137
- {loading && (
138
- <FetchIndicator animating={true} color={'grey'} size={'large'} />
139
- )}
140
-
141
- <FlatList
142
- data={data}
143
- keyExtractor={keyExtractor}
144
- fadingEdgeLength={200}
145
- renderItem={({ item }) => (
146
- <ListItem onPress={handlePressItem(item)}>
147
- <View pointerEvents={'none'}>
148
- {type === 'multi' ? (
149
- <Checkbox
150
- color={'primary'}
151
- labelPosition={'right'}
152
- checked={item._checked}
153
- >
154
- <Text fontWeight={item._checked ? 'bold' : 'regular'}>
155
- {labelExtractor(item)}
156
- </Text>
157
- </Checkbox>
158
- ) : (
159
- <RadioButton
160
- color={'primary'}
161
- labelPosition={'right'}
162
- checked={item._checked}
163
- >
164
- <Text fontWeight={item._checked ? 'bold' : 'regular'}>
165
- {labelExtractor(item)}
166
- </Text>
167
- </RadioButton>
168
- )}
169
- </View>
170
- </ListItem>
171
- )}
172
- />
173
-
153
+ <Header
154
+ rightButton={{
155
+ onPress: close,
156
+ icon: {
157
+ name: 'close',
158
+ type: 'material-community',
159
+ fontColor: 'light',
160
+ },
161
+ }}
162
+ >
163
+ {headerContent}
164
+ </Header>
165
+
166
+ {!hideSearchBar && (
167
+ <SearchBarContainer>
168
+ <Input
169
+ placeholder={searchBarPlaceholder}
170
+ value={searchArg}
171
+ onChange={text => setSearchArg(text)}
172
+ leftComponent={
173
+ <SelectIcon name="search" type="ionicon" size="centi" />
174
+ }
175
+ />
176
+ </SearchBarContainer>
177
+ )}
178
+
179
+ {loading && (
180
+ <FetchIndicator animating={true} color={'grey'} size={'large'} />
181
+ )}
182
+
183
+ {memoizedFlatlist}
184
+
174
185
  { !_closeOnPick && <ModalFooter>
175
186
  <Button
176
187
  variant={'filled'}
@@ -187,4 +198,44 @@ const Component = <Data, Type extends 'single' | 'multi'>({
187
198
  );
188
199
  };
189
200
 
201
+ interface IOption<T> {
202
+ item: T & { _checked: boolean }
203
+ type: 'single' | 'multi'
204
+ labelExtractor: (option: T) => string
205
+ handlePressItem: (option: T) => void
206
+ }
207
+
208
+ const MemoizedOption: React.FC<IOption<any>> = ({ handlePressItem, labelExtractor, item, type }) => {
209
+ return React.useMemo(() => {
210
+ const label = labelExtractor(item)
211
+ return (
212
+ <ListItem onPress={() => handlePressItem(item)}>
213
+ <View pointerEvents={'none'}>
214
+ {type === 'multi' ? (
215
+ <Checkbox
216
+ color={'primary'}
217
+ labelPosition={'right'}
218
+ checked={item._checked}
219
+ >
220
+ <Text fontWeight={item._checked ? 'bold' : 'regular'}>
221
+ {label}
222
+ </Text>
223
+ </Checkbox>
224
+ ) : (
225
+ <RadioButton
226
+ color={'primary'}
227
+ labelPosition={'right'}
228
+ checked={item._checked}
229
+ >
230
+ <Text fontWeight={item._checked ? 'bold' : 'regular'}>
231
+ {label}
232
+ </Text>
233
+ </RadioButton>
234
+ )}
235
+ </View>
236
+ </ListItem>
237
+ )
238
+ }, [item._checked])
239
+ }
240
+
190
241
  export const Modal = Component;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  HintInputContainer,
3
3
  InputContainerProps,
4
- useInputFocus,
4
+ useInputFocus
5
5
  } from '@tecsinapse/react-core';
6
6
  import * as React from 'react';
7
7
  import { useEffect, useState } from 'react';
@@ -16,7 +16,7 @@ export interface SelectNativeProps<Data, Type extends 'single' | 'multi'>
16
16
  onSelect: (
17
17
  option: Type extends 'single' ? Data | undefined : Data[]
18
18
  ) => never | void;
19
- value: Type extends 'single' ? Data | undefined : Data[];
19
+ value: Type extends 'single' ? Data | null | undefined : Data[];
20
20
  type: Type;
21
21
 
22
22
  keyExtractor: (t: Data, index?: number) => string;
@@ -88,16 +88,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
88
88
  }
89
89
  }, [options]);
90
90
 
91
- useEffect(() => {
92
- if (typeof options === 'function') {
93
- if (value) {
94
- if (type === 'single') setSelectOptions([value as Data]);
95
- else setSelectOptions([...(value as Data[])]);
96
- } else setSelectOptions([]);
97
- }
98
- }, [value]);
99
-
100
- const handleLazyFocus = async () => {
91
+ const handleLazyFocus = React.useCallback(async () => {
101
92
  if (typeof options === 'function') {
102
93
  setLoading(true);
103
94
  try {
@@ -116,7 +107,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
116
107
  setLoading(false);
117
108
  }
118
109
  }
119
- };
110
+ }, [options, value, setSelectOptions])
120
111
 
121
112
  const handleOnSearch = React.useCallback(
122
113
  async (searchInput: string | undefined) => {
@@ -161,7 +152,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
161
152
  [options, value, keyExtractor]
162
153
  );
163
154
 
164
- const getDisplayValue = () => {
155
+ const getDisplayValue = React.useCallback(() => {
165
156
  if (Array.isArray(value)) {
166
157
  if (value.length === 0) return placeholder;
167
158
  else {
@@ -185,7 +176,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
185
176
  );
186
177
  return selectedOption ? labelExtractor(selectedOption) : placeholder;
187
178
  }
188
- };
179
+ }, [placeholder, value, selectOptions]);
189
180
 
190
181
  modal.sync(
191
182
  <Modal
@@ -9,19 +9,19 @@ import {
9
9
  PressableSurfaceProps,
10
10
  RFValue,
11
11
  RFValueStr,
12
- StyleProps
12
+ StyleProps,
13
13
  } from '@tecsinapse/react-core';
14
14
  import { ActivityIndicator, ModalProps, View, ViewProps } from 'react-native';
15
15
  import { Input, InputNativeProps } from '../../atoms/Input';
16
16
  import { Text } from '../../atoms/Text';
17
17
 
18
- export const getStyledModal = (safeTop: number = 0) => {
18
+ export const getStyledModal = (safeTop = 0) => {
19
19
  return styled(View)<ModalProps & Partial<StyleProps>>`
20
20
  padding-top: ${`${RFValue(safeTop)}px`};
21
21
  background-color: ${({ theme }) => theme.miscellaneous.bodyColor};
22
22
  height: 100%;
23
- `
24
- }
23
+ `;
24
+ };
25
25
 
26
26
  export const StyledSelectionText = styled(Text)(
27
27
  (props: Partial<InputContainerProps> & Partial<StyleProps>) => css`
@@ -91,3 +91,7 @@ export const SelectIcon = styled(Icon)<Partial<StyleProps>>`
91
91
  export const FetchIndicator = styled(ActivityIndicator)`
92
92
  align-self: center;
93
93
  `;
94
+
95
+ export const TextTitleModal = styled(Text)<Partial<StyleProps>>`
96
+ text-align: center;
97
+ `;