@tecsinapse/react-native-kit 1.12.8 → 1.12.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/components/atoms/Modal/ModalLifecycleHandler.js +24 -22
  3. package/dist/components/atoms/Modal/ModalLifecycleHandler.js.map +1 -1
  4. package/dist/components/atoms/Modal/index.d.ts +1 -0
  5. package/dist/components/atoms/Modal/index.js +13 -0
  6. package/dist/components/atoms/Modal/index.js.map +1 -1
  7. package/dist/components/atoms/Modal/ui/BaseModalView.js +20 -8
  8. package/dist/components/atoms/Modal/ui/BaseModalView.js.map +1 -1
  9. package/dist/components/atoms/Modal/ui/types.d.ts +1 -0
  10. package/dist/components/atoms/Modal/useLazyModalManager.d.ts +8 -0
  11. package/dist/components/atoms/Modal/useLazyModalManager.js +40 -0
  12. package/dist/components/atoms/Modal/useLazyModalManager.js.map +1 -0
  13. package/dist/components/molecules/Calendar/Calendar.js +2 -2
  14. package/dist/components/molecules/Calendar/Calendar.js.map +1 -1
  15. package/dist/components/molecules/DatePicker/DatePicker.d.ts +2 -4
  16. package/dist/components/molecules/DatePicker/DatePicker.js +29 -3
  17. package/dist/components/molecules/DatePicker/DatePicker.js.map +1 -1
  18. package/dist/components/molecules/DatePicker/styled.d.ts +4 -0
  19. package/dist/components/molecules/DatePicker/styled.js +20 -0
  20. package/dist/components/molecules/DatePicker/styled.js.map +1 -0
  21. package/dist/components/molecules/DateTimePicker/DateTimePicker.d.ts +1 -1
  22. package/dist/components/molecules/DateTimePicker/DateTimePicker.js +18 -4
  23. package/dist/components/molecules/DateTimePicker/DateTimePicker.js.map +1 -1
  24. package/dist/components/molecules/Select/Modal.d.ts +7 -0
  25. package/dist/components/{atoms → molecules}/Select/Modal.js +31 -18
  26. package/dist/components/molecules/Select/Modal.js.map +1 -0
  27. package/dist/components/{atoms → molecules}/Select/Select.d.ts +2 -1
  28. package/dist/components/{atoms → molecules}/Select/Select.js +35 -36
  29. package/dist/components/molecules/Select/Select.js.map +1 -0
  30. package/dist/components/{atoms → molecules}/Select/index.d.ts +0 -0
  31. package/dist/components/{atoms → molecules}/Select/index.js +0 -0
  32. package/dist/components/molecules/Select/index.js.map +1 -0
  33. package/dist/components/{atoms → molecules}/Select/styled.d.ts +1 -1
  34. package/dist/components/{atoms → molecules}/Select/styled.js +14 -12
  35. package/dist/components/molecules/Select/styled.js.map +1 -0
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.js +8 -1
  38. package/dist/index.js.map +1 -1
  39. package/package.json +3 -3
  40. package/src/components/atoms/Modal/ModalLifecycleHandler.ts +22 -20
  41. package/src/components/atoms/Modal/index.ts +2 -1
  42. package/src/components/atoms/Modal/ui/BaseModalView.tsx +29 -15
  43. package/src/components/atoms/Modal/ui/types.ts +1 -0
  44. package/src/components/atoms/Modal/useLazyModalManager.ts +43 -0
  45. package/src/components/molecules/Calendar/Calendar.tsx +2 -6
  46. package/src/components/molecules/DatePicker/DatePicker.tsx +31 -10
  47. package/src/components/molecules/DatePicker/styled.ts +6 -0
  48. package/src/components/molecules/DateTimePicker/DateTimePicker.tsx +22 -7
  49. package/src/components/{atoms → molecules}/Select/Modal.tsx +32 -33
  50. package/src/components/{atoms → molecules}/Select/Select.tsx +38 -39
  51. package/src/components/{atoms → molecules}/Select/index.ts +0 -0
  52. package/src/components/{atoms → molecules}/Select/styled.ts +9 -8
  53. package/src/index.ts +2 -2
  54. package/dist/components/atoms/Select/Modal.d.ts +0 -7
  55. package/dist/components/atoms/Select/Modal.js.map +0 -1
  56. package/dist/components/atoms/Select/Select.js.map +0 -1
  57. package/dist/components/atoms/Select/index.js.map +0 -1
  58. package/dist/components/atoms/Select/styled.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { ReactElement, useCallback, useEffect, useState } from "react"
2
+ import { v4 as uuidv4 } from 'uuid'
3
+ import { modalLifecycle } from "./ModalGroupManager"
4
+ import { IBaseModal } from "./ui/types"
5
+
6
+ /**
7
+ * Use this hook to tell the modal lifecycle handler that you want to add
8
+ * a new modal component.
9
+ *
10
+ * @param id
11
+ * @param modal
12
+ * @returns
13
+ */
14
+ export const useLazyModalManager = () => {
15
+
16
+ const [id] = useState(uuidv4())
17
+
18
+ const requestUpdate = useCallback(() => modalLifecycle.update(), [])
19
+
20
+ const sync = useCallback((modal: ReactElement<IBaseModal>) => {
21
+ modalLifecycle.sync(id, () => modal)
22
+ return null
23
+ }, [id])
24
+
25
+ const show = useCallback(() => {
26
+ modalLifecycle.show(id)
27
+ }, [id])
28
+
29
+ const close = useCallback(() => {
30
+ modalLifecycle.close(id)
31
+ }, [id])
32
+
33
+ useEffect(() => {
34
+ return () => modalLifecycle.destroy(id)
35
+ }, [])
36
+
37
+ return {
38
+ requestUpdate,
39
+ sync,
40
+ show,
41
+ close
42
+ }
43
+ }
@@ -1,11 +1,7 @@
1
- import {
2
- Calendar as CalendarCore,
3
- CalendarProps,
4
- SelectionType,
5
- } from '@tecsinapse/react-core';
1
+ import { Calendar as CalendarCore, SelectionType } from '@tecsinapse/react-core';
6
2
  import React from 'react';
7
- import { Text } from '../../atoms/Text';
8
3
  import { getLocale } from '../../../utils/date';
4
+ import { Text } from '../../atoms/Text';
9
5
 
10
6
  export const Calendar = <T extends SelectionType>({
11
7
  locale,
@@ -1,24 +1,45 @@
1
1
  import {
2
- DatePicker as DatePickerCore,
3
- DatePickerProps,
4
- SelectionType,
2
+ DatePicker as DatePickerCore, DatePickerProps, SelectionType, Value
5
3
  } from '@tecsinapse/react-core';
6
- import React from 'react';
4
+ import React, { FC } from 'react';
5
+ import { getLocale } from '../../../utils/date';
6
+ import { IBaseModal, ModalView, useLazyModalManager } from '../../atoms/Modal';
7
7
  import { Text } from '../../atoms/Text';
8
8
  import { Calendar } from '../Calendar';
9
- import { getLocale } from '../../../utils/date';
9
+ import { CalendarBoxContent } from './styled';
10
+
11
+ export const DatePicker = <T extends SelectionType>({ locale, onChange, ...rest }: Omit<DatePickerProps<T>, 'CalendarComponent' | 'renderCalendar' | 'requestCloseCalendar' | 'requestShowCalendar'>): JSX.Element => {
10
12
 
11
- export const DatePicker = <T extends SelectionType>({
12
- locale,
13
- ...rest
14
- }): JSX.Element => {
13
+ const modal = useLazyModalManager()
14
+
15
+ const handleChange = (value?: Value<T>) => {
16
+ onChange?.(value)
17
+ modal.requestUpdate()
18
+ }
19
+
15
20
  return (
16
21
  <DatePickerCore
17
22
  {...rest}
18
23
  TextComponent={Text}
19
24
  CalendarComponent={Calendar}
20
- animationType="slide"
21
25
  locale={locale ?? getLocale()}
26
+ onChange={handleChange}
27
+ requestShowCalendar={() => modal.show()}
28
+ requestCloseCalendar={() => modal.close()}
29
+ renderCalendar={(calendar, blur) => modal.sync(
30
+ <NativeModal onClose={blur}>
31
+ {calendar}
32
+ </NativeModal>
33
+ )}
22
34
  />
23
35
  );
36
+
24
37
  };
38
+
39
+ const NativeModal: FC<IBaseModal> = ({ children, ...others }) => {
40
+ return (
41
+ <ModalView BoxComponent={CalendarBoxContent} {...others}>
42
+ {children}
43
+ </ModalView>
44
+ )
45
+ }
@@ -0,0 +1,6 @@
1
+ import styled from "@emotion/native";
2
+ import { BoxContent, StyleProps } from "@tecsinapse/react-core";
3
+
4
+ export const CalendarBoxContent = styled(BoxContent)<Partial<StyleProps>>`
5
+ background-color: ${({ theme }) => theme.color.secondary.xlight};
6
+ `
@@ -1,23 +1,38 @@
1
1
  import {
2
2
  DateTimePicker as DateTimePickerCore,
3
- DateTimePickerProps,
3
+ DateTimePickerProps
4
4
  } from '@tecsinapse/react-core';
5
5
  import React, { FC } from 'react';
6
+ import { getLocale } from '../../../utils/date';
7
+ import { IBaseModal, ModalView, useLazyModalManager } from '../../atoms/Modal';
6
8
  import { Text } from '../../atoms/Text';
7
9
  import { DateTimeSelector } from '../DateTimeSelector';
8
- import { getLocale } from '../../../utils/date';
9
10
 
10
- export const DateTimePicker: FC<DateTimePickerProps> = ({
11
- locale,
12
- ...rest
13
- }) => {
11
+ export const DateTimePicker: FC<Omit<DateTimePickerProps, 'DateTimeSelectorComponent' | 'renderSelector' | 'requestCloseSelector' | 'requestShowSelector'>> = ({ locale, ...rest }) => {
12
+
13
+ const modal = useLazyModalManager()
14
+
14
15
  return (
15
16
  <DateTimePickerCore
16
17
  {...rest}
17
18
  TextComponent={Text}
18
19
  DateTimeSelectorComponent={DateTimeSelector}
19
- animationType="slide"
20
20
  locale={locale ?? getLocale()}
21
+ requestShowSelector={() => modal.show()}
22
+ requestCloseSelector={() => modal.close()}
23
+ renderSelector={(selector, blur) => modal.sync(
24
+ <NativeModal onClose={blur}>
25
+ {selector}
26
+ </NativeModal>
27
+ )}
21
28
  />
22
29
  );
23
30
  };
31
+
32
+ const NativeModal: FC<IBaseModal> = ({ children, ...others }) => {
33
+ return (
34
+ <ModalView {...others}>
35
+ {children}
36
+ </ModalView>
37
+ )
38
+ }
@@ -1,23 +1,16 @@
1
+ import { Checkbox, RadioButton, useDebouncedState } from '@tecsinapse/react-core';
1
2
  import * as React from 'react';
2
- import {
3
- FetchIndicator,
4
- ModalFooter,
5
- ListItem,
6
- SearchBarContainer,
7
- SelectIcon,
8
- StyledModal,
9
- } from './styled';
10
- import { FlatList, Modal as RNModal, ModalProps, View } from 'react-native';
3
+ import { FlatList, StatusBar, View } from 'react-native';
4
+ import { Button } from '../../atoms/Button';
5
+ import { Header } from '../../atoms/Header';
6
+ import { Input } from '../../atoms/Input';
7
+ import { IBaseModal, ModalView } from '../../atoms/Modal';
8
+ import { Text } from '../../atoms/Text';
11
9
  import { SelectNativeProps } from './Select';
12
- import { Text } from '../Text';
13
10
  import {
14
- Button,
15
- Checkbox,
16
- RadioButton,
17
- useDebouncedState,
18
- } from '@tecsinapse/react-core';
19
- import { Input } from '../Input';
20
- import { Header } from '../Header';
11
+ FetchIndicator, getStyledModal, ListItem, ModalFooter, SearchBarContainer,
12
+ SelectIcon
13
+ } from './styled';
21
14
 
22
15
  interface LoadingProps {
23
16
  loading?: boolean;
@@ -35,15 +28,18 @@ const Component = <Data, Type extends 'single' | 'multi'>({
35
28
  value,
36
29
  onSelect,
37
30
  onSearch,
38
- onRequestClose,
39
31
  selectModalTitle,
40
32
  selectModalTitleComponent,
41
33
  confirmButtonText,
42
34
  loading,
43
- ...modalProps
44
- }: SelectNativeProps<Data, Type> & ModalProps & LoadingProps): JSX.Element => {
35
+ close,
36
+ closeOnPick,
37
+ ...others
38
+ }: SelectNativeProps<Data, Type> & LoadingProps & IBaseModal): JSX.Element => {
45
39
  const [selectedValues, setSelectedValues] = React.useState<Data[]>([]);
46
40
  const [searchArg, setSearchArg] = useDebouncedState<string>('', onSearch);
41
+ const ModalComponent = React.useMemo(() => getStyledModal(StatusBar.currentHeight), [])
42
+ const _closeOnPick = closeOnPick && type === 'single'
47
43
 
48
44
  // Resets the temporary state to the initial state whenever the
49
45
  // modal is reopened or the value changes
@@ -87,13 +83,19 @@ const Component = <Data, Type extends 'single' | 'multi'>({
87
83
  });
88
84
  };
89
85
 
86
+ React.useEffect(() => {
87
+ if (_closeOnPick && selectedValues[0] && (selectedValues[0] !== value)) {
88
+ handleConfirm()
89
+ }
90
+ }, [selectedValues[0], value, closeOnPick])
91
+
90
92
  const handleConfirm = () => {
91
93
  // TS Workaround since TS won't infer the ternary operator's result type correctly
92
94
  type OnSelectArg = Parameters<typeof onSelect>[0];
93
95
  onSelect(
94
96
  (type === 'single' ? selectedValues[0] : selectedValues) as OnSelectArg
95
97
  );
96
- onRequestClose && onRequestClose();
98
+ close?.()
97
99
  };
98
100
 
99
101
  const headerContent = selectModalTitleComponent ? (
@@ -105,16 +107,10 @@ const Component = <Data, Type extends 'single' | 'multi'>({
105
107
  ) : null;
106
108
 
107
109
  return (
108
- <RNModal
109
- transparent
110
- hardwareAccelerated
111
- {...modalProps}
112
- onRequestClose={onRequestClose}
113
- >
114
- <StyledModal>
110
+ <ModalView {...others} BoxComponent={ModalComponent} showCloseBar={false}>
115
111
  <Header
116
112
  rightButton={{
117
- onPress: onRequestClose,
113
+ onPress: close,
118
114
  icon: {
119
115
  name: 'close',
120
116
  type: 'material-community',
@@ -124,6 +120,7 @@ const Component = <Data, Type extends 'single' | 'multi'>({
124
120
  >
125
121
  {headerContent}
126
122
  </Header>
123
+
127
124
  {!hideSearchBar && (
128
125
  <SearchBarContainer>
129
126
  <Input
@@ -136,9 +133,11 @@ const Component = <Data, Type extends 'single' | 'multi'>({
136
133
  />
137
134
  </SearchBarContainer>
138
135
  )}
136
+
139
137
  {loading && (
140
138
  <FetchIndicator animating={true} color={'grey'} size={'large'} />
141
139
  )}
140
+
142
141
  <FlatList
143
142
  data={data}
144
143
  keyExtractor={keyExtractor}
@@ -171,7 +170,8 @@ const Component = <Data, Type extends 'single' | 'multi'>({
171
170
  </ListItem>
172
171
  )}
173
172
  />
174
- <ModalFooter>
173
+
174
+ { !_closeOnPick && <ModalFooter>
175
175
  <Button
176
176
  variant={'filled'}
177
177
  color={'primary'}
@@ -182,9 +182,8 @@ const Component = <Data, Type extends 'single' | 'multi'>({
182
182
  {confirmButtonText}
183
183
  </Text>
184
184
  </Button>
185
- </ModalFooter>
186
- </StyledModal>
187
- </RNModal>
185
+ </ModalFooter>}
186
+ </ModalView>
188
187
  );
189
188
  };
190
189
 
@@ -1,13 +1,13 @@
1
- import * as React from 'react';
2
1
  import {
3
- InputContainerProps,
4
- useInputFocus,
5
- HintInputContainer,
2
+ HintInputContainer, InputContainerProps,
3
+ useInputFocus
6
4
  } from '@tecsinapse/react-core';
7
- import { Text } from '../Text';
5
+ import * as React from 'react';
6
+ import { useEffect, useState } from 'react';
7
+ import { useLazyModalManager } from '../../atoms/Modal';
8
+ import { Text } from '../../atoms/Text';
8
9
  import { Modal } from './Modal';
9
10
  import { SelectIcon, StyledSelectionText } from './styled';
10
- import { useEffect, useState } from 'react';
11
11
 
12
12
  export interface SelectNativeProps<Data, Type extends 'single' | 'multi'>
13
13
  extends Omit<InputContainerProps, 'value' | 'onChange' | 'onChangeText'> {
@@ -34,6 +34,7 @@ export interface SelectNativeProps<Data, Type extends 'single' | 'multi'>
34
34
  confirmButtonText?: string;
35
35
  selectModalTitle?: string;
36
36
  selectModalTitleComponent?: JSX.Element;
37
+ closeOnPick?: boolean;
37
38
  }
38
39
 
39
40
  function Select<Data, Type extends 'single' | 'multi'>({
@@ -60,6 +61,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
60
61
  hintComponent,
61
62
  hint,
62
63
  style,
64
+ closeOnPick = type === 'single',
63
65
  ...rest
64
66
  }: SelectNativeProps<Data, Type>): JSX.Element {
65
67
  const { focused, handleBlur, handleFocus } = useInputFocus(
@@ -68,8 +70,8 @@ function Select<Data, Type extends 'single' | 'multi'>({
68
70
  !disabled
69
71
  );
70
72
 
71
- const [modalVisible, setModalVisible] = React.useState(false);
72
73
  const [selectOptions, setSelectOptions] = useState<Data[]>([]);
74
+ const modal = useLazyModalManager()
73
75
 
74
76
  // TODO: Add Skeleton to modal height when loading is true
75
77
  const [loading, setLoading] = useState<boolean>(false);
@@ -145,6 +147,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
145
147
  } catch (e) {
146
148
  // TODO: Catch error
147
149
  } finally {
150
+ modal.requestUpdate()
148
151
  setLoading(false);
149
152
  }
150
153
  }
@@ -152,17 +155,6 @@ function Select<Data, Type extends 'single' | 'multi'>({
152
155
  [options, value, keyExtractor]
153
156
  );
154
157
 
155
- const handlePressInput = async () => {
156
- setModalVisible(true);
157
- handleFocus();
158
- await handleLazyFocus();
159
- };
160
-
161
- const handleCloseModal = () => {
162
- setModalVisible(false);
163
- handleBlur();
164
- };
165
-
166
158
  const getDisplayValue = () => {
167
159
  if (Array.isArray(value)) {
168
160
  if (value.length === 0) return placeholder;
@@ -189,6 +181,34 @@ function Select<Data, Type extends 'single' | 'multi'>({
189
181
  }
190
182
  };
191
183
 
184
+ modal.sync(
185
+ <Modal
186
+ options={selectOptions || []}
187
+ focused={true}
188
+ keyExtractor={keyExtractor}
189
+ labelExtractor={labelExtractor}
190
+ groupKeyExtractor={groupKeyExtractor}
191
+ searchBarPlaceholder={searchBarPlaceholder}
192
+ type={type}
193
+ onSelect={onSelect}
194
+ value={value}
195
+ hideSearchBar={hideSearchBar}
196
+ onSearch={handleOnSearch}
197
+ selectModalTitle={selectModalTitle}
198
+ selectModalTitleComponent={selectModalTitleComponent}
199
+ confirmButtonText={confirmButtonText}
200
+ loading={loading}
201
+ onClose={handleBlur}
202
+ closeOnPick={closeOnPick}
203
+ />
204
+ )
205
+
206
+ const handlePressInput = async () => {
207
+ modal.show()
208
+ handleFocus();
209
+ await handleLazyFocus();
210
+ };
211
+
192
212
  return (
193
213
  <>
194
214
  <HintInputContainer
@@ -212,27 +232,6 @@ function Select<Data, Type extends 'single' | 'multi'>({
212
232
  {getDisplayValue() || ' '}
213
233
  </StyledSelectionText>
214
234
  </HintInputContainer>
215
- <Modal
216
- visible={modalVisible}
217
- options={selectOptions || []}
218
- focused={modalVisible}
219
- keyExtractor={keyExtractor}
220
- labelExtractor={labelExtractor}
221
- groupKeyExtractor={groupKeyExtractor}
222
- searchBarPlaceholder={searchBarPlaceholder}
223
- type={type}
224
- onSelect={onSelect}
225
- value={value}
226
- hideSearchBar={hideSearchBar}
227
- onRequestClose={handleCloseModal}
228
- animated
229
- animationType={'slide'}
230
- onSearch={handleOnSearch}
231
- selectModalTitle={selectModalTitle}
232
- selectModalTitleComponent={selectModalTitleComponent}
233
- confirmButtonText={confirmButtonText}
234
- loading={loading}
235
- />
236
235
  </>
237
236
  );
238
237
  }
@@ -11,15 +11,16 @@ import {
11
11
  StyleProps
12
12
  } from '@tecsinapse/react-core';
13
13
  import { ActivityIndicator, ModalProps, View, ViewProps } from 'react-native';
14
- import { Input, InputNativeProps } from '../Input';
15
- import { Text } from '../Text';
14
+ import { Input, InputNativeProps } from '../../atoms/Input';
15
+ import { Text } from '../../atoms/Text';
16
16
 
17
- export const StyledModal = styled(View)<ModalProps & Partial<StyleProps>>`
18
- position: relative;
19
- background-color: ${({ theme }) => theme.miscellaneous.bodyColor};
20
- height: 100%;
21
- width: 100%;
22
- `;
17
+ export const getStyledModal = (safeTop: number = 0) => {
18
+ return styled(View)<ModalProps & Partial<StyleProps>>`
19
+ padding-top: ${`${safeTop}px`};
20
+ background-color: ${({ theme }) => theme.miscellaneous.bodyColor};
21
+ height: 100%;
22
+ `
23
+ }
23
24
 
24
25
  export const StyledSelectionText = styled(Text)(
25
26
  (props: Partial<InputContainerProps> & Partial<StyleProps>) => css`
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from '@tecsinapse/react-core';
2
2
  export { Header, HeaderProps } from './components/atoms/Header';
3
- export { Select, SelectNativeProps } from './components/atoms/Select';
3
+ export { Select, SelectNativeProps } from './components/molecules/Select';
4
4
  export { Input, InputNativeProps } from './components/atoms/Input';
5
5
  export { TextArea, TextAreaProps } from './components/atoms/TextArea';
6
6
  export { Text, TextNativeProps } from './components/atoms/Text';
@@ -26,4 +26,4 @@ export { DateTimePicker } from './components/molecules/DateTimePicker';
26
26
  export { Avatar } from './components/atoms/Avatar';
27
27
  export { Calendar } from './components/molecules/Calendar';
28
28
  export { DateTimeSelector } from './components/molecules/DateTimeSelector';
29
- export { ModalGroupManager, ModalView, ModalLifecycleHandler, useModalManager, IBaseModal } from './components/atoms/Modal';
29
+ export { ModalGroupManager, ModalView, ModalLifecycleHandler, useLazyModalManager, useModalManager, IBaseModal } from './components/atoms/Modal';
@@ -1,7 +0,0 @@
1
- import { ModalProps } from 'react-native';
2
- import { SelectNativeProps } from './Select';
3
- interface LoadingProps {
4
- loading?: boolean;
5
- }
6
- export declare const Modal: <Data, Type extends "single" | "multi">({ options, keyExtractor, labelExtractor, groupKeyExtractor, hideSearchBar, searchBarPlaceholder, focused, type, value, onSelect, onSearch, onRequestClose, selectModalTitle, selectModalTitleComponent, confirmButtonText, loading, ...modalProps }: SelectNativeProps<Data, Type> & import("react-native").ModalBaseProps & import("react-native").ModalPropsIOS & import("react-native").ModalPropsAndroid & import("react-native").ViewProps & LoadingProps) => JSX.Element;
7
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/components/atoms/Select/Modal.tsx"],"names":["Component","options","keyExtractor","labelExtractor","groupKeyExtractor","hideSearchBar","searchBarPlaceholder","focused","type","value","onSelect","onSearch","onRequestClose","selectModalTitle","selectModalTitleComponent","confirmButtonText","loading","modalProps","selectedValues","setSelectedValues","React","useState","searchArg","setSearchArg","useEffect","getData","map","option","index","_checked","find","data","handlePressItem","newArr","found","push","handleConfirm","headerContent","onPress","icon","name","fontColor","text","item","Modal"],"mappings":";;;;;;;AAAA;;AACA;;AAQA;;AAEA;;AACA;;AAMA;;AACA;;;;;;;;AAMA,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,cAZwD;AAaxDC,EAAAA,gBAbwD;AAcxDC,EAAAA,yBAdwD;AAexDC,EAAAA,iBAfwD;AAgBxDC,EAAAA,OAhBwD;AAiBxD,KAAGC;AAjBqD,CAAxC,KAkB4D;AAC5E,QAAM,CAACC,cAAD,EAAiBC,iBAAjB,IAAsCC,KAAK,CAACC,QAAN,CAAuB,EAAvB,CAA5C;AACA,QAAM,CAACC,SAAD,EAAYC,YAAZ,IAA4B,kCAA0B,EAA1B,EAA8BZ,QAA9B,CAAlC;AAIAS,EAAAA,KAAK,CAACI,SAAN,CAAgB,MAAM;AACpBL,IAAAA,iBAAiB,CACdV,KAAK,GAAID,IAAI,KAAK,OAAT,GAAmBC,KAAnB,GAA2B,CAACA,KAAD,CAA/B,GAA0C,EADjC,CAAjB;AAGD,GAJD,EAIG,CAACA,KAAD,EAAQF,O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,KAAK,GAAG5C,SAAd","sourcesContent":["import * as React from 'react';\nimport {\n FetchIndicator,\n ModalFooter,\n ListItem,\n SearchBarContainer,\n SelectIcon,\n StyledModal,\n} from './styled';\nimport { FlatList, Modal as RNModal, ModalProps, View } from 'react-native';\nimport { SelectNativeProps } from './Select';\nimport { Text } from '../Text';\nimport {\n Button,\n Checkbox,\n RadioButton,\n useDebouncedState,\n} from '@tecsinapse/react-core';\nimport { Input } from '../Input';\nimport { Header } from '../Header';\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 onRequestClose,\n selectModalTitle,\n selectModalTitleComponent,\n confirmButtonText,\n loading,\n ...modalProps\n}: SelectNativeProps<Data, Type> & ModalProps & LoadingProps): JSX.Element => {\n const [selectedValues, setSelectedValues] = React.useState<Data[]>([]);\n const [searchArg, setSearchArg] = useDebouncedState<string>('', onSearch);\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 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 onRequestClose && onRequestClose();\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 <RNModal\n transparent\n hardwareAccelerated\n {...modalProps}\n onRequestClose={onRequestClose}\n >\n <StyledModal>\n <Header\n rightButton={{\n onPress: onRequestClose,\n icon: {\n name: 'close',\n type: 'material-community',\n fontColor: 'light',\n },\n }}\n >\n {headerContent}\n </Header>\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 {loading && (\n <FetchIndicator animating={true} color={'grey'} size={'large'} />\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 <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 </StyledModal>\n </RNModal>\n );\n};\n\nexport const Modal = Component;\n"],"file":"Modal.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/components/atoms/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","rest","focused","handleBlur","handleFocus","modalVisible","setModalVisible","React","useState","selectOptions","setSelectOptions","loading","setLoading","handleLazyFocus","result","find","v","e","handleOnSearch","useCallback","searchInput","undefined","length","selectedValues","filter","current","handlePressInput","handleCloseModal","getDisplayValue","Array","isArray","reduce","acc","option","index","key","slice","selectedOption","Text"],"mappings":";;;;;;;AAAA;;AACA;;AAKA;;AACA;;AACA;;;;;;;;AA8BA,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;AAwBrD,KAAGC;AAxBkD,CAAvD,EAyB+C;AAC7C,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA,UAAX;AAAuBC,IAAAA;AAAvB,M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AAEgB;AAnBX,IAtBF,CADF;AA8CD;;eAEcjC,M","sourcesContent":["import * as React from 'react';\nimport {\n InputContainerProps,\n useInputFocus,\n HintInputContainer,\n} from '@tecsinapse/react-core';\nimport { Text } from '../Text';\nimport { Modal } from './Modal';\nimport { SelectIcon, StyledSelectionText } from './styled';\nimport { useEffect, useState } from 'react';\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}\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 ...rest\n}: SelectNativeProps<Data, Type>): JSX.Element {\n const { focused, handleBlur, handleFocus } = useInputFocus(\n onFocus,\n onBlur,\n !disabled\n );\n\n const [modalVisible, setModalVisible] = React.useState(false);\n const [selectOptions, setSelectOptions] = useState<Data[]>([]);\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 setLoading(false);\n }\n }\n },\n [options, value, keyExtractor]\n );\n\n const handlePressInput = async () => {\n setModalVisible(true);\n handleFocus();\n await handleLazyFocus();\n };\n\n const handleCloseModal = () => {\n setModalVisible(false);\n handleBlur();\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 return (\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 <Modal\n visible={modalVisible}\n options={selectOptions || []}\n focused={modalVisible}\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 onRequestClose={handleCloseModal}\n animated\n animationType={'slide'}\n onSearch={handleOnSearch}\n selectModalTitle={selectModalTitle}\n selectModalTitleComponent={selectModalTitleComponent}\n confirmButtonText={confirmButtonText}\n loading={loading}\n />\n </>\n );\n}\n\nexport default Select;\n"],"file":"Select.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/components/atoms/Select/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA","sourcesContent":["export { default as Select, SelectNativeProps } from './Select';\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/components/atoms/Select/styled.ts"],"names":["StyledModal","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;;AAWA;;AACA;;AACA;;;;;;AAEO,MAAMA,WAAW,GAAG,qBAAOC,i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CAACqB,KAAN,CAAYC,SAAZ,CAAsBC,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","sourcesContent":["import styled, { css } from '@emotion/native';\nimport {\n Button,\n ButtonProps,\n disabledInputStyles,\n Icon,\n InputContainerProps,\n PressableSurface,\n PressableSurfaceProps,\n RFValueStr,\n StyleProps\n} from '@tecsinapse/react-core';\nimport { ActivityIndicator, ModalProps, View, ViewProps } from 'react-native';\nimport { Input, InputNativeProps } from '../Input';\nimport { Text } from '../Text';\n\nexport const StyledModal = styled(View)<ModalProps & Partial<StyleProps>>`\n position: relative;\n background-color: ${({ theme }) => theme.miscellaneous.bodyColor};\n height: 100%;\n width: 100%;\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"}