@tecsinapse/react-native-kit 1.17.8 → 1.17.11

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,33 @@
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.11](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.17.10...@tecsinapse/react-native-kit@1.17.11) (2022-07-14)
7
+
8
+ **Note:** Version bump only for package @tecsinapse/react-native-kit
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.17.10](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.17.9...@tecsinapse/react-native-kit@1.17.10) (2022-07-14)
15
+
16
+ **Note:** Version bump only for package @tecsinapse/react-native-kit
17
+
18
+
19
+
20
+
21
+
22
+ ## [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)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * ternary verification in model text title ([813b68c](https://github.com/tecsinapse/design-system/commit/813b68c186b9b7e5c1793f90b171444f23007993))
28
+
29
+
30
+
31
+
32
+
6
33
  ## [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)
7
34
 
8
35
 
@@ -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,EAAAA,OAAO,GAAG,SAjBZ;AAkBEC,EAAAA,aAlBF;AAmBEC,EAAAA,IAnBF;AAoBEC,EAAAA,OApBF;AAqBEC,EAAAA,MArBF;AAsBEC,EAAAA,KAtBF;AAuBEC,EAAAA,WAvBF;AAwBE,KAAGC;AA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AAA,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,EAAAA,MArBF;AAsBEC,EAAAA,KAtBF;AAuBEC,EAAAA,WAvBF;AAwBE,KAAGC;AAxBL,CADF,EA2BEC,GA3BF,KA4BK;AACH,QAAMC,KAAK,GAAGR,aAAa,IACzB,6BAAC,eAAD;AAAM,IAAA,aAAa,EAAES,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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,22 +78,39 @@ 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
-
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]);
97
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;
101
115
  const headerContent = selectModalTitleComponent ? selectModalTitleComponent : titleTextModal;
102
116
  return React.createElement(_Modal.ModalView, _extends({}, others, {
@@ -124,14 +138,27 @@ const Component = ({
124
138
  animating: true,
125
139
  color: 'grey',
126
140
  size: 'large'
127
- }), React.createElement(_reactNative.FlatList, {
128
- data: data,
129
- keyExtractor: keyExtractor,
130
- fadingEdgeLength: 200,
131
- renderItem: ({
132
- item
133
- }) => React.createElement(_styled.ListItem, {
134
- 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)
135
162
  }, React.createElement(_reactNative.View, {
136
163
  pointerEvents: 'none'
137
164
  }, type === 'multi' ? React.createElement(_reactCore.Checkbox, {
@@ -140,22 +167,14 @@ const Component = ({
140
167
  checked: item._checked
141
168
  }, React.createElement(_Text.Text, {
142
169
  fontWeight: item._checked ? 'bold' : 'regular'
143
- }, labelExtractor(item))) : React.createElement(_reactCore.RadioButton, {
170
+ }, label)) : React.createElement(_reactCore.RadioButton, {
144
171
  color: 'primary',
145
172
  labelPosition: 'right',
146
173
  checked: item._checked
147
174
  }, React.createElement(_Text.Text, {
148
175
  fontWeight: item._checked ? 'bold' : 'regular'
149
- }, labelExtractor(item)))))
150
- }), !_closeOnPick && React.createElement(_styled.ModalFooter, null, React.createElement(_Button.Button, {
151
- variant: 'filled',
152
- color: 'primary',
153
- onPress: handleConfirm,
154
- disabled: loading
155
- }, React.createElement(_Text.Text, {
156
- fontColor: 'light',
157
- fontWeight: "bold"
158
- }, confirmButtonText))));
176
+ }, label))));
177
+ }, [item._checked]);
159
178
  };
160
179
 
161
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","titleTextModal","headerContent","onPress","icon","name","fontColor","text","item","Modal"],"mappings":";;;;;AAAA;;AAMA;;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,yB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O,EAAEZ,eAAe,CAACY,IAAD;AAAlC,OACE,oBAAC,iBAAD;AAAM,MAAA,aAAa,EAAE;AAArB,OACGxC,IAAI,KAAK,OAAT,GACC,oBAAC,mBAAD;AACE,MAAA,KAAK,EAAE,SADT;AAEE,MAAA,aAAa,EAAE,OAFjB;AAGE,MAAA,OAAO,EAAEwC,IAAI,CAACf;AAHhB,OAKE,oBAAC,UAAD;AAAM,MAAA,UAAU,EAAEe,IAAI,CAACf,QAAL,GAAgB,MAAhB,GAAyB;AAA3C,OACG9B,cAAc,CAAC6C,IAAD,CADjB,CALF,CADD,GAWC,oBAAC,sBAAD;AACE,MAAA,KAAK,EAAE,SADT;AAEE,MAAA,aAAa,EAAE,OAFjB;AAGE,MAAA,OAAO,EAAEA,IAAI,CAACf;AAHhB,OAKE,oBAAC,UAAD;AAAM,MAAA,UAAU,EAAEe,IAAI,CAACf,QAAL,GAAgB,MAAhB,GAAyB;AAA3C,OACG9B,cAAc,CAAC6C,IAAD,CADjB,CALF,CAZJ,CADF;AALJ,IA/BF,EAgEG,CAACrB,YAAD,IACC,oBAAC,mBAAD,QACE,oBAAC,cAAD;AACE,IAAA,OAAO,EAAE,QADX;AAEE,IAAA,KAAK,EAAE,SAFT;AAGE,IAAA,OAAO,EAAEa,aAHX;AAIE,IAAA,QAAQ,EAAEzB;AAJZ,KAME,oBAAC,UAAD;AAAM,IAAA,SAAS,EAAE,OAAjB;AAA0B,IAAA,UAAU,EAAC;AAArC,KACGD,iBADH,CANF,CADF,CAjEJ,CADF;AAiFD,CAhLD;;AAkLO,MAAMmC,KAAK,GAAGjD,SAAd","sourcesContent":["import {\n Checkbox,\n getStatusBarHeight,\n RadioButton,\n useDebouncedState,\n} from '@tecsinapse/react-core';\nimport * as React from 'react';\nimport { FlatList, 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 = (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 titleTextModal = selectModalTitle ? (\n <TextTitleModal typography=\"h4\" fontWeight=\"bold\">\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 <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 && (\n <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 )}\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,EAAiBC,iBAAjB,IAAsCC,KAAK,CAACC,QAAN,CAAuB,EAAvB,CAA5C;AACA,QAAM,CAACC,SAAD,EAAYC,YAAZ,IAA4B,kCAA0B,EAA1B,EAA8Bb,QAA9B,CAAlC;AACA,QAAMc,cAA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xC,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;
@@ -19,5 +19,5 @@ export interface SelectNativeProps<Data, Type extends 'single' | 'multi'> extend
19
19
  closeOnPick?: boolean;
20
20
  controlComponent?: (onPress: () => void, displayValue?: string) => JSX.Element;
21
21
  }
22
- declare function Select<Data, Type extends 'single' | 'multi'>({ 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 }: SelectNativeProps<Data, Type>): JSX.Element;
22
+ declare function Select<Data, Type extends 'single' | 'multi'>({ value, options, keyExtractor, groupKeyExtractor, onSelect, type, labelExtractor, placeholder, onFocus, onBlur, disabled, onSearch, selectModalTitle, selectModalTitleComponent, searchBarPlaceholder, hideSearchBar, confirmButtonText, rightComponent, variant, hintComponent, hint, style, controlComponent, closeOnPick, label, ...rest }: SelectNativeProps<Data, Type>): JSX.Element;
23
23
  export default Select;
@@ -46,6 +46,7 @@ function Select({
46
46
  style,
47
47
  controlComponent,
48
48
  closeOnPick = type === 'single',
49
+ label,
49
50
  ...rest
50
51
  }) {
51
52
  const {
@@ -56,20 +57,19 @@ function Select({
56
57
  const [selectOptions, setSelectOptions] = (0, React.useState)([]);
57
58
  const modal = (0, _Modal.useLazyModalManager)();
58
59
  const [loading, setLoading] = (0, React.useState)(false);
60
+ const onlyLabel = label && !placeholder;
61
+ const hasValue = type === 'single' ? !!value : (value || []).length > 0;
62
+
63
+ const _placeholder = onlyLabel ? label : placeholder;
64
+
65
+ const _label = hasValue ? label : undefined;
66
+
59
67
  (0, React.useEffect)(() => {
60
68
  if (typeof options !== 'function') {
61
69
  setSelectOptions(options);
62
70
  }
63
71
  }, [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 () => {
72
+ const handleLazyFocus = React.useCallback(async () => {
73
73
  if (typeof options === 'function') {
74
74
  setLoading(true);
75
75
 
@@ -85,8 +85,7 @@ function Select({
85
85
  setLoading(false);
86
86
  }
87
87
  }
88
- };
89
-
88
+ }, [options, value, setSelectOptions]);
90
89
  const handleOnSearch = React.useCallback(async searchInput => {
91
90
  if (searchInput !== undefined && onSearch) {
92
91
  setLoading(true);
@@ -114,19 +113,17 @@ function Select({
114
113
  }
115
114
  }
116
115
  }, [options, value, keyExtractor]);
117
-
118
- const getDisplayValue = () => {
116
+ const getDisplayValue = React.useCallback(() => {
119
117
  if (Array.isArray(value)) {
120
- if (value.length === 0) return placeholder;else {
118
+ if (value.length === 0) return _placeholder;else {
121
119
  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);
122
120
  }
123
121
  } else {
124
- if (value === undefined) return placeholder;
122
+ if (value === undefined) return _placeholder;
125
123
  const selectedOption = selectOptions == null ? void 0 : selectOptions.find((option, index) => keyExtractor(option, index) == keyExtractor(value, index));
126
- return selectedOption ? labelExtractor(selectedOption) : placeholder;
124
+ return selectedOption ? labelExtractor(selectedOption) : _placeholder;
127
125
  }
128
- };
129
-
126
+ }, [_placeholder, value, selectOptions]);
130
127
  modal.sync(React.createElement(_Modal2.Modal, {
131
128
  options: selectOptions || [],
132
129
  focused: true,
@@ -162,6 +159,7 @@ function Select({
162
159
  variant: variant,
163
160
  hint: hint,
164
161
  hintComponent: hintComponent,
162
+ label: _label,
165
163
  rightComponent: React.createElement(React.Fragment, null, React.createElement(_styled.SelectIcon, {
166
164
  name: "chevron-down",
167
165
  type: "ionicon",
@@ -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,EAAAA,KAFqD;AAGrDC,EAAAA,OAHqD;AAIrDC,EAAAA,YAJqD;AAKrDC,EAAAA,iBALqD;AAMrDC,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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","label","rest","focused","handleBlur","handleFocus","selectOptions","setSelectOptions","modal","loading","setLoading","onlyLabel","hasValue","length","_placeholder","_label","undefined","handleLazyFocus","React","useCallback","result","find","v","e","handleOnSearch","searchInput","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,IAtBqD;AAuBrDC,EAAAA,KAvBqD;AAwBrDC,EAAAA,gBAxBqD;A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,IAAA,KAAK,EAAEmB,MATT;AAUE,IAAA,cAAc,EACZ,0CACE,oBAAC,kBAAD;AAAY,MAAA,IAAI,EAAC,cAAjB;AAAgC,MAAA,IAAI,EAAC,SAArC;AAA+C,MAAA,IAAI,EAAC;AAApD,MADF,EAEGrB,cAFH;AAXJ,KAgBMQ,IAhBN,GAkBE,oBAAC,2BAAD;AAAqB,IAAA,UAAU,EAAC,MAAhC;AAAuC,IAAA,QAAQ,EAAEf;AAAjD,KACG2C,eAAe,MAAM,GADxB,CAlBF,CAJJ,CADF;AA8BD;;eAEctD,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 label,\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 const onlyLabel = label && !placeholder;\n const hasValue = type === 'single' ? !!value : ((value || []) as []).length > 0\n const _placeholder = onlyLabel ? label : placeholder\n const _label = hasValue ? label : undefined\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 label={_label}\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"}
@@ -116,7 +116,6 @@ const FetchIndicator = (0, _native.default)(_reactNative.ActivityIndicator)`
116
116
  `;
117
117
  exports.FetchIndicator = FetchIndicator;
118
118
  const TextTitleModal = (0, _native.default)(_Text.Text)`
119
- max-width: ${(0, _reactCore.RFValue)(250)};
120
119
  text-align: center;
121
120
  `;
122
121
  exports.TextTitleModal = TextTitleModal;
@@ -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","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,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,iBAAP,CAAa;AAClC;AACA;AACA,CAHO;;AAKA,MAAMW,sBAAsB,GAAG,qBACpCC,2BADoC,CAEb;AACzB;AACA,CAJO;;AAMA,MAAMC,MAAM,GAAG,qBAAOb,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C;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,eAAe,wBAAQ,GAAR,CAAa;AAC5B;AACA,CAHO","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 max-width: ${RFValue(250)};\n text-align: 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;AAA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,KAAM;AAC7D,sBAAsB,CAAC;AAAEvB,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.8",
4
+ "version": "1.17.11",
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.6",
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": "213c34dd451202b14e9343f7e3f30d6e8f77f5f9"
42
+ "gitHead": "5b6adbc48490edb759d8f7d1a8519d5c7043360a"
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
  >`
@@ -2,10 +2,11 @@ import {
2
2
  Checkbox,
3
3
  getStatusBarHeight,
4
4
  RadioButton,
5
+ RFValue,
5
6
  useDebouncedState,
6
7
  } from '@tecsinapse/react-core';
7
8
  import * as React from 'react';
8
- import { FlatList, View } from 'react-native';
9
+ import { FlatList, ListRenderItemInfo, View } from 'react-native';
9
10
  import { Button } from '../../atoms/Button';
10
11
  import { Header } from '../../atoms/Header';
11
12
  import { Input } from '../../atoms/Input';
@@ -62,7 +63,7 @@ const Component = <Data, Type extends 'single' | 'multi'>({
62
63
  );
63
64
  }, [value, focused, setSelectedValues]);
64
65
 
65
- const getData = (options: Data[]) => {
66
+ const getData = React.useCallback((options: Data[]) => {
66
67
  return options?.map((option, index) => ({
67
68
  ...option,
68
69
  _checked:
@@ -73,11 +74,11 @@ const Component = <Data, Type extends 'single' | 'multi'>({
73
74
  : keyExtractor((selectedValues[0] || {}) as Data, index) ==
74
75
  keyExtractor(option, index),
75
76
  }));
76
- };
77
+ }, [keyExtractor, selectedValues, type])
77
78
 
78
- const data = typeof options !== 'function' ? getData(options) : [];
79
+ const data = React.useMemo(() => typeof options !== 'function' ? getData(options) : [], [options, getData]);
79
80
 
80
- const handlePressItem = (option: Data) => () => {
81
+ const handlePressItem = React.useCallback((option: Data) => {
81
82
  setSelectedValues(selectedValues => {
82
83
  if (type === 'multi') {
83
84
  const newArr: Data[] = [];
@@ -94,7 +95,7 @@ const Component = <Data, Type extends 'single' | 'multi'>({
94
95
  ? []
95
96
  : [option];
96
97
  });
97
- };
98
+ }, [selectedValues, setSelectedValues, keyExtractor, type])
98
99
 
99
100
  React.useEffect(() => {
100
101
  if (_closeOnPick && selectedValues[0] && selectedValues[0] !== value) {
@@ -102,17 +103,43 @@ const Component = <Data, Type extends 'single' | 'multi'>({
102
103
  }
103
104
  }, [selectedValues[0], value, closeOnPick]);
104
105
 
105
- const handleConfirm = () => {
106
+ const handleConfirm = React.useCallback(() => {
106
107
  // TS Workaround since TS won't infer the ternary operator's result type correctly
107
108
  type OnSelectArg = Parameters<typeof onSelect>[0];
108
109
  onSelect(
109
110
  (type === 'single' ? selectedValues[0] : selectedValues) as OnSelectArg
110
111
  );
111
- close?.();
112
- };
112
+ close?.()
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
126
+
127
+ const memoizedFlatlist = React.useMemo(() => (
128
+ <FlatList
129
+ data={data}
130
+ keyExtractor={keyExtractor}
131
+ fadingEdgeLength={200}
132
+ renderItem={optionBuilder}
133
+ />
134
+ ), [selectedValues, anyChecked, dataLengthChanged])
113
135
 
114
136
  const titleTextModal = selectModalTitle ? (
115
- <TextTitleModal typography="h4" fontWeight="bold">
137
+ <TextTitleModal
138
+ typography="h4"
139
+ fontWeight="bold"
140
+ numberOfLines={3}
141
+ style={{ maxWidth: RFValue(250) }}
142
+ >
116
143
  {selectModalTitle}
117
144
  </TextTitleModal>
118
145
  ) : null;
@@ -153,41 +180,9 @@ const Component = <Data, Type extends 'single' | 'multi'>({
153
180
  <FetchIndicator animating={true} color={'grey'} size={'large'} />
154
181
  )}
155
182
 
156
- <FlatList
157
- data={data}
158
- keyExtractor={keyExtractor}
159
- fadingEdgeLength={200}
160
- renderItem={({ item }) => (
161
- <ListItem onPress={handlePressItem(item)}>
162
- <View pointerEvents={'none'}>
163
- {type === 'multi' ? (
164
- <Checkbox
165
- color={'primary'}
166
- labelPosition={'right'}
167
- checked={item._checked}
168
- >
169
- <Text fontWeight={item._checked ? 'bold' : 'regular'}>
170
- {labelExtractor(item)}
171
- </Text>
172
- </Checkbox>
173
- ) : (
174
- <RadioButton
175
- color={'primary'}
176
- labelPosition={'right'}
177
- checked={item._checked}
178
- >
179
- <Text fontWeight={item._checked ? 'bold' : 'regular'}>
180
- {labelExtractor(item)}
181
- </Text>
182
- </RadioButton>
183
- )}
184
- </View>
185
- </ListItem>
186
- )}
187
- />
188
-
189
- {!_closeOnPick && (
190
- <ModalFooter>
183
+ {memoizedFlatlist}
184
+
185
+ { !_closeOnPick && <ModalFooter>
191
186
  <Button
192
187
  variant={'filled'}
193
188
  color={'primary'}
@@ -198,10 +193,49 @@ const Component = <Data, Type extends 'single' | 'multi'>({
198
193
  {confirmButtonText}
199
194
  </Text>
200
195
  </Button>
201
- </ModalFooter>
202
- )}
196
+ </ModalFooter>}
203
197
  </ModalView>
204
198
  );
205
199
  };
206
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
+
207
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;
@@ -68,6 +68,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
68
68
  style,
69
69
  controlComponent,
70
70
  closeOnPick = type === 'single',
71
+ label,
71
72
  ...rest
72
73
  }: SelectNativeProps<Data, Type>): JSX.Element {
73
74
  const { focused, handleBlur, handleFocus } = useInputFocus(
@@ -81,6 +82,11 @@ function Select<Data, Type extends 'single' | 'multi'>({
81
82
 
82
83
  // TODO: Add Skeleton to modal height when loading is true
83
84
  const [loading, setLoading] = useState<boolean>(false);
85
+
86
+ const onlyLabel = label && !placeholder;
87
+ const hasValue = type === 'single' ? !!value : ((value || []) as []).length > 0
88
+ const _placeholder = onlyLabel ? label : placeholder
89
+ const _label = hasValue ? label : undefined
84
90
 
85
91
  useEffect(() => {
86
92
  if (typeof options !== 'function') {
@@ -88,16 +94,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
88
94
  }
89
95
  }, [options]);
90
96
 
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 () => {
97
+ const handleLazyFocus = React.useCallback(async () => {
101
98
  if (typeof options === 'function') {
102
99
  setLoading(true);
103
100
  try {
@@ -116,7 +113,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
116
113
  setLoading(false);
117
114
  }
118
115
  }
119
- };
116
+ }, [options, value, setSelectOptions])
120
117
 
121
118
  const handleOnSearch = React.useCallback(
122
119
  async (searchInput: string | undefined) => {
@@ -161,9 +158,9 @@ function Select<Data, Type extends 'single' | 'multi'>({
161
158
  [options, value, keyExtractor]
162
159
  );
163
160
 
164
- const getDisplayValue = () => {
161
+ const getDisplayValue = React.useCallback(() => {
165
162
  if (Array.isArray(value)) {
166
- if (value.length === 0) return placeholder;
163
+ if (value.length === 0) return _placeholder;
167
164
  else {
168
165
  return selectOptions
169
166
  ?.reduce(
@@ -178,14 +175,14 @@ function Select<Data, Type extends 'single' | 'multi'>({
178
175
  .slice(0, -2);
179
176
  }
180
177
  } else {
181
- if (value === undefined) return placeholder;
178
+ if (value === undefined) return _placeholder;
182
179
  const selectedOption = selectOptions?.find(
183
180
  (option, index) =>
184
181
  keyExtractor(option, index) == keyExtractor(value as Data, index)
185
182
  );
186
- return selectedOption ? labelExtractor(selectedOption) : placeholder;
183
+ return selectedOption ? labelExtractor(selectedOption) : _placeholder;
187
184
  }
188
- };
185
+ }, [_placeholder, value, selectOptions]);
189
186
 
190
187
  modal.sync(
191
188
  <Modal
@@ -229,6 +226,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
229
226
  variant={variant}
230
227
  hint={hint}
231
228
  hintComponent={hintComponent}
229
+ label={_label}
232
230
  rightComponent={
233
231
  <>
234
232
  <SelectIcon name="chevron-down" type="ionicon" size="centi" />
@@ -93,6 +93,5 @@ export const FetchIndicator = styled(ActivityIndicator)`
93
93
  `;
94
94
 
95
95
  export const TextTitleModal = styled(Text)<Partial<StyleProps>>`
96
- max-width: ${RFValue(250)};
97
96
  text-align: center;
98
97
  `;