@tecsinapse/react-native-kit 1.10.2 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/components/atoms/Button/Button.d.ts +6 -0
  3. package/dist/components/atoms/Button/Button.js +35 -0
  4. package/dist/components/atoms/Button/Button.js.map +1 -0
  5. package/dist/components/atoms/Button/index.d.ts +1 -0
  6. package/dist/components/atoms/Button/index.js +14 -0
  7. package/dist/components/atoms/Button/index.js.map +1 -1
  8. package/dist/components/atoms/Select/Modal.d.ts +5 -1
  9. package/dist/components/atoms/Select/Modal.js +19 -8
  10. package/dist/components/atoms/Select/Modal.js.map +1 -1
  11. package/dist/components/atoms/Select/Select.d.ts +2 -2
  12. package/dist/components/atoms/Select/Select.js +66 -5
  13. package/dist/components/atoms/Select/Select.js.map +1 -1
  14. package/dist/components/atoms/Select/styled.d.ts +8 -5
  15. package/dist/components/atoms/Select/styled.js +13 -17
  16. package/dist/components/atoms/Select/styled.js.map +1 -1
  17. package/dist/components/molecules/Calendar/Calendar.d.ts +4 -1
  18. package/dist/components/molecules/Calendar/Calendar.js +9 -3
  19. package/dist/components/molecules/Calendar/Calendar.js.map +1 -1
  20. package/dist/components/molecules/DatePicker/DatePicker.d.ts +4 -1
  21. package/dist/components/molecules/DatePicker/DatePicker.js +9 -3
  22. package/dist/components/molecules/DatePicker/DatePicker.js.map +1 -1
  23. package/dist/components/molecules/DateTimePicker/DateTimePicker.js +9 -3
  24. package/dist/components/molecules/DateTimePicker/DateTimePicker.js.map +1 -1
  25. package/dist/components/molecules/DateTimeSelector/DateTimeSelector.js +9 -3
  26. package/dist/components/molecules/DateTimeSelector/DateTimeSelector.js.map +1 -1
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +14 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/utils/date.d.ts +1 -0
  31. package/dist/utils/date.js +30 -0
  32. package/dist/utils/date.js.map +1 -0
  33. package/package.json +3 -3
  34. package/src/components/atoms/Button/Button.tsx +17 -0
  35. package/src/components/atoms/Button/index.ts +2 -1
  36. package/src/components/atoms/Select/Modal.tsx +39 -23
  37. package/src/components/atoms/Select/Select.tsx +95 -7
  38. package/src/components/atoms/Select/styled.ts +11 -11
  39. package/src/components/molecules/Calendar/Calendar.tsx +12 -4
  40. package/src/components/molecules/DatePicker/DatePicker.tsx +7 -4
  41. package/src/components/molecules/DateTimePicker/DateTimePicker.tsx +7 -2
  42. package/src/components/molecules/DateTimeSelector/DateTimeSelector.tsx +9 -2
  43. package/src/index.ts +1 -1
  44. package/src/utils/date.ts +17 -0
@@ -13,15 +13,21 @@ var _Text = require("../../atoms/Text");
13
13
 
14
14
  var _DateTimeSelector = require("../DateTimeSelector");
15
15
 
16
+ var _date = require("../../../utils/date");
17
+
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
18
20
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
19
21
 
20
- const DateTimePicker = props => {
21
- return _react.default.createElement(_reactCore.DateTimePicker, _extends({}, props, {
22
+ const DateTimePicker = ({
23
+ locale,
24
+ ...rest
25
+ }) => {
26
+ return _react.default.createElement(_reactCore.DateTimePicker, _extends({}, rest, {
22
27
  TextComponent: _Text.Text,
23
28
  DateTimeSelectorComponent: _DateTimeSelector.DateTimeSelector,
24
- animationType: "slide"
29
+ animationType: "slide",
30
+ locale: locale ?? (0, _date.getLocale)()
25
31
  }));
26
32
  };
27
33
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/molecules/DateTimePicker/DateTimePicker.tsx"],"names":["DateTimePicker","props","Text","DateTimeSelector"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AACA;;;;;;AAEO,MAAMA,cAAuC,GAAGC,KAAK,IAAI;AAC9D,SACE,6BAAC,yBAAD,eACMA,KADN;AAEE,IAAA,aAAa,EAAEC,UAFjB;AAGE,IAAA,yBAAyB,EAAEC,kCAH7B;AAIE,IAAA,aAAa,EAAC;AAJhB,KADF;AAQD,CATM","sourcesContent":["import {\n DateTimePicker as DateTimePickerCore,\n DateTimePickerProps,\n} from '@tecsinapse/react-core';\nimport React, { FC } from 'react';\nimport { Text } from '../../atoms/Text';\nimport { DateTimeSelector } from '../DateTimeSelector';\n\nexport const DateTimePicker: FC<DateTimePickerProps> = props => {\n return (\n <DateTimePickerCore\n {...props}\n TextComponent={Text}\n DateTimeSelectorComponent={DateTimeSelector}\n animationType=\"slide\"\n />\n );\n};\n"],"file":"DateTimePicker.js"}
1
+ {"version":3,"sources":["../../../../src/components/molecules/DateTimePicker/DateTimePicker.tsx"],"names":["DateTimePicker","locale","rest","Text","DateTimeSelector"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AACA;;AACA;;;;;;AAEO,MAAMA,cAAuC,GAAG,CAAC;AACtDC,EAAAA,MADsD;AAEtD,KAAGC;AAFmD,CAAD,KAGjD;AACJ,SACE,6BAAC,yBAAD,eACMA,IADN;AAEE,IAAA,aAAa,EAAEC,UAFjB;AAGE,IAAA,yBAAyB,EAAEC,kCAH7B;AAIE,IAAA,aAAa,EAAC,OAJhB;AAKE,IAAA,MAAM,EAAEH,MAAM,IAAI;AALpB,KADF;AASD,CAbM","sourcesContent":["import {\n DateTimePicker as DateTimePickerCore,\n DateTimePickerProps,\n} from '@tecsinapse/react-core';\nimport React, { FC } from 'react';\nimport { Text } from '../../atoms/Text';\nimport { DateTimeSelector } from '../DateTimeSelector';\nimport { getLocale } from '../../../utils/date';\n\nexport const DateTimePicker: FC<DateTimePickerProps> = ({\n locale,\n ...rest\n}) => {\n return (\n <DateTimePickerCore\n {...rest}\n TextComponent={Text}\n DateTimeSelectorComponent={DateTimeSelector}\n animationType=\"slide\"\n locale={locale ?? getLocale()}\n />\n );\n};\n"],"file":"DateTimePicker.js"}
@@ -11,13 +11,19 @@ var _react = _interopRequireDefault(require("react"));
11
11
 
12
12
  var _Text = require("../../atoms/Text");
13
13
 
14
+ var _date = require("../../../utils/date");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
18
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
17
19
 
18
- const DateTimeSelector = props => {
19
- return _react.default.createElement(_reactCore.DateTimeSelector, _extends({}, props, {
20
- TextComponent: _Text.Text
20
+ const DateTimeSelector = ({
21
+ locale,
22
+ ...rest
23
+ }) => {
24
+ return _react.default.createElement(_reactCore.DateTimeSelector, _extends({}, rest, {
25
+ TextComponent: _Text.Text,
26
+ locale: locale ?? (0, _date.getLocale)()
21
27
  }));
22
28
  };
23
29
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/molecules/DateTimeSelector/DateTimeSelector.tsx"],"names":["DateTimeSelector","props","Text"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;;;;;AAEO,MAAMA,gBAA2C,GAAGC,KAAK,IAAI;AAClE,SAAO,6BAAC,2BAAD,eAA0BA,KAA1B;AAAiC,IAAA,aAAa,EAAEC;AAAhD,KAAP;AACD,CAFM","sourcesContent":["import {\n DateTimeSelector as DateTimeSelectorCore,\n DateTimeSelectorProps,\n} from '@tecsinapse/react-core';\nimport React, { FC } from 'react';\nimport { Text } from '../../atoms/Text';\n\nexport const DateTimeSelector: FC<DateTimeSelectorProps> = props => {\n return <DateTimeSelectorCore {...props} TextComponent={Text} />;\n};\n"],"file":"DateTimeSelector.js"}
1
+ {"version":3,"sources":["../../../../src/components/molecules/DateTimeSelector/DateTimeSelector.tsx"],"names":["DateTimeSelector","locale","rest","Text"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AACA;;;;;;AAEO,MAAMA,gBAA2C,GAAG,CAAC;AAACC,EAAAA,MAAD;AAAS,KAAGC;AAAZ,CAAD,KAAuB;AAChF,SACE,6BAAC,2BAAD,eACMA,IADN;AAEE,IAAA,aAAa,EAAEC,UAFjB;AAGE,IAAA,MAAM,EAAEF,MAAM,IAAI;AAHpB,KADF;AAOD,CARM","sourcesContent":["import {\n DateTimeSelector as DateTimeSelectorCore,\n DateTimeSelectorProps,\n} from '@tecsinapse/react-core';\nimport React, { FC } from 'react';\nimport { Text } from '../../atoms/Text';\nimport { getLocale } from '../../../utils/date';\n\nexport const DateTimeSelector: FC<DateTimeSelectorProps> = ({locale, ...rest}) => {\n return (\n <DateTimeSelectorCore\n {...rest}\n TextComponent={Text}\n locale={locale ?? getLocale()}\n />\n );\n};\n"],"file":"DateTimeSelector.js"}
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { Select, SelectNativeProps } from './components/atoms/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';
7
- export { Error, Loading, Success } from './components/atoms/Button';
7
+ export { Error, Loading, Success, Button, ButtonNativeProps } from './components/atoms/Button';
8
8
  export { GroupButtonOption } from './components/atoms/GroupButton';
9
9
  export { InputPassword, InputPasswordNativeProps, } from './components/molecules/InputPassword';
10
10
  export { BottomNavigator, BottomNavigatorProps, } from './components/atoms/BottomNavigator';
package/dist/index.js CHANGED
@@ -17,6 +17,8 @@ var _exportNames = {
17
17
  Error: true,
18
18
  Loading: true,
19
19
  Success: true,
20
+ Button: true,
21
+ ButtonNativeProps: true,
20
22
  GroupButtonOption: true,
21
23
  InputPassword: true,
22
24
  InputPasswordNativeProps: true,
@@ -114,6 +116,18 @@ Object.defineProperty(exports, "Success", {
114
116
  return _Button.Success;
115
117
  }
116
118
  });
119
+ Object.defineProperty(exports, "Button", {
120
+ enumerable: true,
121
+ get: function () {
122
+ return _Button.Button;
123
+ }
124
+ });
125
+ Object.defineProperty(exports, "ButtonNativeProps", {
126
+ enumerable: true,
127
+ get: function () {
128
+ return _Button.ButtonNativeProps;
129
+ }
130
+ });
117
131
  Object.defineProperty(exports, "GroupButtonOption", {
118
132
  enumerable: true,
119
133
  get: function () {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAIA;;AAIA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["export * from '@tecsinapse/react-core';\nexport { Header, HeaderProps } from './components/atoms/Header';\nexport { Select, SelectNativeProps } from './components/atoms/Select';\nexport { Input, InputNativeProps } from './components/atoms/Input';\nexport { TextArea, TextAreaProps } from './components/atoms/TextArea';\nexport { Text, TextNativeProps } from './components/atoms/Text';\nexport { Error, Loading, Success } from './components/atoms/Button';\nexport { GroupButtonOption } from './components/atoms/GroupButton';\nexport {\n InputPassword,\n InputPasswordNativeProps,\n} from './components/molecules/InputPassword';\nexport {\n BottomNavigator,\n BottomNavigatorProps,\n} from './components/atoms/BottomNavigator';\nexport { Tag, TagProps } from './components/atoms/Tag';\nexport {\n SnappingSlider,\n SnappingSliderProps,\n} from './components/atoms/SnappingSlider';\nexport { Badge, BadgeNativeProps } from './components/atoms/Badge';\nexport { Snackbar, SnackbarNativeProps } from './components/molecules/Snackbar';\nexport { DatePicker } from './components/molecules/DatePicker';\nexport { DateTimePicker } from './components/molecules/DateTimePicker';\nexport { Avatar } from './components/atoms/Avatar';\nexport { Calendar } from './components/molecules/Calendar';\nexport { DateTimeSelector } from './components/molecules/DateTimeSelector';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAIA;;AAIA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["export * from '@tecsinapse/react-core';\nexport { Header, HeaderProps } from './components/atoms/Header';\nexport { Select, SelectNativeProps } from './components/atoms/Select';\nexport { Input, InputNativeProps } from './components/atoms/Input';\nexport { TextArea, TextAreaProps } from './components/atoms/TextArea';\nexport { Text, TextNativeProps } from './components/atoms/Text';\nexport { Error, Loading, Success, Button, ButtonNativeProps } from './components/atoms/Button';\nexport { GroupButtonOption } from './components/atoms/GroupButton';\nexport {\n InputPassword,\n InputPasswordNativeProps,\n} from './components/molecules/InputPassword';\nexport {\n BottomNavigator,\n BottomNavigatorProps,\n} from './components/atoms/BottomNavigator';\nexport { Tag, TagProps } from './components/atoms/Tag';\nexport {\n SnappingSlider,\n SnappingSliderProps,\n} from './components/atoms/SnappingSlider';\nexport { Badge, BadgeNativeProps } from './components/atoms/Badge';\nexport { Snackbar, SnackbarNativeProps } from './components/molecules/Snackbar';\nexport { DatePicker } from './components/molecules/DatePicker';\nexport { DateTimePicker } from './components/molecules/DateTimePicker';\nexport { Avatar } from './components/atoms/Avatar';\nexport { Calendar } from './components/molecules/Calendar';\nexport { DateTimeSelector } from './components/molecules/DateTimeSelector';\n"],"file":"index.js"}
@@ -0,0 +1 @@
1
+ export declare const getLocale: () => Locale;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getLocale = void 0;
7
+
8
+ var _reactNative = require("react-native");
9
+
10
+ var dateFnsLocales = _interopRequireWildcard(require("date-fns/locale"));
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+
16
+ const getLocale = () => {
17
+ let locale;
18
+
19
+ if (_reactNative.Platform.OS === 'ios') {
20
+ locale = _reactNative.NativeModules.SettingsManager.settings.AppleLocale || _reactNative.NativeModules.SettingsManager.settings.AppleLanguages[0];
21
+ } else {
22
+ locale = _reactNative.NativeModules.I18nManager.localeIdentifier;
23
+ }
24
+
25
+ const code = locale.replace('_', '');
26
+ return dateFnsLocales[code];
27
+ };
28
+
29
+ exports.getLocale = getLocale;
30
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/date.ts"],"names":["getLocale","locale","Platform","OS","NativeModules","SettingsManager","settings","AppleLocale","AppleLanguages","I18nManager","localeIdentifier","code","replace","dateFnsLocales"],"mappings":";;;;;;;AAAA;;AACA;;;;;;AAEO,MAAMA,SAAS,GAAG,MAAc;AACrC,MAAIC,MAAJ;;AACA,MAAIC,sBAASC,EAAT,KAAgB,KAApB,EAA2B;AACzBF,IAAAA,MAAM,GACJG,2BAAcC,eAAd,CAA8BC,QAA9B,CAAuCC,WAAvC,IACAH,2BAAcC,eAAd,CAA8BC,QAA9B,CAAuCE,cAAvC,CAAsD,CAAtD,CAFF;AAGD,GAJD,MAIO;AACLP,IAAAA,MAAM,GAAGG,2BAAcK,WAAd,CAA0BC,gBAAnC;AACD;;AAED,QAAMC,IAAI,GAAGV,MAAM,CAACW,OAAP,CAAe,GAAf,EAAoB,EAApB,CAAb;AAEA,SAAOC,cAAc,CAACF,IAAD,CAArB;AACD,CAbM","sourcesContent":["import { NativeModules, Platform } from 'react-native';\nimport * as dateFnsLocales from 'date-fns/locale';\n\nexport const getLocale = (): Locale => {\n let locale: string;\n if (Platform.OS === 'ios') {\n locale =\n NativeModules.SettingsManager.settings.AppleLocale ||\n NativeModules.SettingsManager.settings.AppleLanguages[0];\n } else {\n locale = NativeModules.I18nManager.localeIdentifier;\n }\n\n const code = locale.replace('_', '');\n\n return dateFnsLocales[code];\n};\n"],"file":"date.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.10.2",
4
+ "version": "1.11.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "@emotion/native": "^11.0.0",
15
15
  "@emotion/react": "^11.4.1",
16
- "@tecsinapse/react-core": "^1.10.2"
16
+ "@tecsinapse/react-core": "^1.11.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
@@ -29,5 +29,5 @@
29
29
  "react-native": ">=0.64.0",
30
30
  "react-native-vector-icons": ">=8.1.0"
31
31
  },
32
- "gitHead": "fb3e15d84dc2e9d529dc3a00343751302c325c39"
32
+ "gitHead": "27a01035cee1b709734bd4b6b6f518c4320814f6"
33
33
  }
@@ -0,0 +1,17 @@
1
+ import { Button as ButtonCore, ButtonProps } from "@tecsinapse/react-core";
2
+ import React, { FC, useCallback } from "react";
3
+ import { Keyboard } from "react-native";
4
+
5
+ export type ButtonNativeProps = ButtonProps & {
6
+ autoDismissKeyboard?: boolean
7
+ }
8
+
9
+ export const Button: FC<ButtonNativeProps> = ({ autoDismissKeyboard = true, onPress, ...others }) => {
10
+
11
+ const handleOnPress = useCallback((event) => {
12
+ autoDismissKeyboard && Keyboard.dismiss()
13
+ onPress?.(event)
14
+ }, [onPress])
15
+
16
+ return <ButtonCore {...others} onPress={handleOnPress}/>
17
+ }
@@ -1 +1,2 @@
1
- export { Error, Loading, Success } from './States';
1
+ export { Button, ButtonNativeProps } from './Button';
2
+ export { Error, Loading, Success } from './States';
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import {
3
- FloatingButton,
4
- ListFooter,
3
+ FetchIndicator,
4
+ ModalFooter,
5
5
  ListItem,
6
6
  SearchBarContainer,
7
7
  SelectIcon,
@@ -11,6 +11,7 @@ import { FlatList, Modal as RNModal, ModalProps, View } from 'react-native';
11
11
  import { SelectNativeProps } from './Select';
12
12
  import { Text } from '../Text';
13
13
  import {
14
+ Button,
14
15
  Checkbox,
15
16
  RadioButton,
16
17
  useDebouncedState,
@@ -18,6 +19,10 @@ import {
18
19
  import { Input } from '../Input';
19
20
  import { Header } from '../Header';
20
21
 
22
+ interface LoadingProps {
23
+ loading?: boolean;
24
+ }
25
+
21
26
  const Component = <Data, Type extends 'single' | 'multi'>({
22
27
  options,
23
28
  keyExtractor,
@@ -34,8 +39,9 @@ const Component = <Data, Type extends 'single' | 'multi'>({
34
39
  selectModalTitle,
35
40
  selectModalTitleComponent,
36
41
  confirmButtonText,
42
+ loading,
37
43
  ...modalProps
38
- }: SelectNativeProps<Data, Type> & ModalProps): JSX.Element => {
44
+ }: SelectNativeProps<Data, Type> & ModalProps & LoadingProps): JSX.Element => {
39
45
  const [selectedValues, setSelectedValues] = React.useState<Data[]>([]);
40
46
  const [searchArg, setSearchArg] = useDebouncedState<string>('', onSearch);
41
47
 
@@ -47,16 +53,20 @@ const Component = <Data, Type extends 'single' | 'multi'>({
47
53
  );
48
54
  }, [value, focused, setSelectedValues]);
49
55
 
50
- const data = options.map((option, index) => ({
51
- ...option,
52
- _checked:
53
- type === 'multi'
54
- ? !!selectedValues.find(
55
- value => keyExtractor(option, index) == keyExtractor(value, index)
56
- )
57
- : keyExtractor((selectedValues[0] || {}) as Data, index) ==
58
- keyExtractor(option, index),
59
- }));
56
+ const getData = (options: Data[]) => {
57
+ return options?.map((option, index) => ({
58
+ ...option,
59
+ _checked:
60
+ type === 'multi'
61
+ ? !!selectedValues.find(
62
+ value => keyExtractor(option, index) == keyExtractor(value, index)
63
+ )
64
+ : keyExtractor((selectedValues[0] || {}) as Data, index) ==
65
+ keyExtractor(option, index),
66
+ }));
67
+ };
68
+
69
+ const data = typeof options !== 'function' ? getData(options) : [];
60
70
 
61
71
  const handlePressItem = (option: Data) => () => {
62
72
  setSelectedValues(selectedValues => {
@@ -126,10 +136,13 @@ const Component = <Data, Type extends 'single' | 'multi'>({
126
136
  />
127
137
  </SearchBarContainer>
128
138
  )}
139
+ {loading && (
140
+ <FetchIndicator animating={true} color={'grey'} size={'large'} />
141
+ )}
129
142
  <FlatList
130
143
  data={data}
131
144
  keyExtractor={keyExtractor}
132
- ListFooterComponent={<ListFooter />}
145
+ fadingEdgeLength={200}
133
146
  renderItem={({ item }) => (
134
147
  <ListItem onPress={handlePressItem(item)}>
135
148
  <View pointerEvents={'none'}>
@@ -158,15 +171,18 @@ const Component = <Data, Type extends 'single' | 'multi'>({
158
171
  </ListItem>
159
172
  )}
160
173
  />
161
- <FloatingButton
162
- variant={'filled'}
163
- color={'primary'}
164
- onPress={handleConfirm}
165
- >
166
- <Text fontColor={'light'} fontWeight="bold">
167
- {confirmButtonText}
168
- </Text>
169
- </FloatingButton>
174
+ <ModalFooter>
175
+ <Button
176
+ variant={'filled'}
177
+ color={'primary'}
178
+ onPress={handleConfirm}
179
+ disabled={loading}
180
+ >
181
+ <Text fontColor={'light'} fontWeight="bold">
182
+ {confirmButtonText}
183
+ </Text>
184
+ </Button>
185
+ </ModalFooter>
170
186
  </StyledModal>
171
187
  </RNModal>
172
188
  );
@@ -7,10 +7,11 @@ import {
7
7
  import { Text } from '../Text';
8
8
  import { Modal } from './Modal';
9
9
  import { SelectIcon, StyledSelectionText } from './styled';
10
+ import { useEffect, useState } from 'react';
10
11
 
11
12
  export interface SelectNativeProps<Data, Type extends 'single' | 'multi'>
12
13
  extends Omit<InputContainerProps, 'value' | 'onChange' | 'onChangeText'> {
13
- options: Data[];
14
+ options: ((searchInput?: string) => Promise<Data[]>) | Data[];
14
15
  onSelect: (
15
16
  option: Type extends 'single' ? Data | undefined : Data[]
16
17
  ) => never | void;
@@ -25,7 +26,10 @@ export interface SelectNativeProps<Data, Type extends 'single' | 'multi'>
25
26
  placeholder?: string;
26
27
  onFocus?: () => void | never;
27
28
  onBlur?: () => void | never;
28
- onSearch?: (searchArg: string) => void | never;
29
+ onSearch?:
30
+ | ((searchArg: string) => void)
31
+ | ((searchInput?: string) => Promise<Data[]>)
32
+ | never;
29
33
  searchBarPlaceholder?: string;
30
34
  confirmButtonText?: string;
31
35
  selectModalTitle?: string;
@@ -65,6 +69,88 @@ function Select<Data, Type extends 'single' | 'multi'>({
65
69
  );
66
70
 
67
71
  const [modalVisible, setModalVisible] = React.useState(false);
72
+ const [selectOptions, setSelectOptions] = useState<Data[]>([]);
73
+
74
+ // TODO: Add Skeleton to modal height when loading is true
75
+ const [loading, setLoading] = useState<boolean>(false);
76
+
77
+ useEffect(() => {
78
+ if (typeof options !== 'function') {
79
+ setSelectOptions(options);
80
+ }
81
+ }, [options]);
82
+
83
+ useEffect(() => {
84
+ if (typeof options === 'function') {
85
+ if (value) {
86
+ if (type === 'single') setSelectOptions([value as Data]);
87
+ else setSelectOptions([...(value as Data[])]);
88
+ } else setSelectOptions([]);
89
+ }
90
+ }, [value]);
91
+
92
+ const handleOnFocus = async () => {
93
+ if (typeof options === 'function') {
94
+ setLoading(true);
95
+ try {
96
+ const result = await options();
97
+ if (result) {
98
+ if (
99
+ value &&
100
+ !result.find(v => keyExtractor(value as Data) === keyExtractor(v))
101
+ ) {
102
+ setSelectOptions([value as Data, ...result]);
103
+ } else setSelectOptions(result);
104
+ }
105
+ } catch (e) {
106
+ // TODO: Catch error
107
+ } finally {
108
+ setLoading(false);
109
+ }
110
+ }
111
+ };
112
+
113
+ const handleOnSearch = React.useCallback(
114
+ async (searchInput: string | undefined) => {
115
+ if (searchInput !== undefined && onSearch) {
116
+ setLoading(true);
117
+ try {
118
+ const result = await onSearch(searchInput);
119
+ if (result) {
120
+ if (type === 'single') {
121
+ if (
122
+ value &&
123
+ !result.find(
124
+ v => keyExtractor(value as Data) === keyExtractor(v)
125
+ )
126
+ ) {
127
+ setSelectOptions([value as Data, ...result]);
128
+ } else setSelectOptions(result);
129
+ } else {
130
+ if ((value as Data[]).length > 0) {
131
+ const selectedValues =
132
+ (value as Data[]).filter(
133
+ v =>
134
+ !result.find(
135
+ current =>
136
+ keyExtractor(v as Data) === keyExtractor(current)
137
+ )
138
+ ) || [];
139
+ setSelectOptions([...selectedValues, ...result]);
140
+ } else {
141
+ setSelectOptions(result);
142
+ }
143
+ }
144
+ }
145
+ } catch (e) {
146
+ // TODO: Catch error
147
+ } finally {
148
+ setLoading(false);
149
+ }
150
+ }
151
+ },
152
+ [options, value, keyExtractor]
153
+ );
68
154
 
69
155
  const handlePressInput = () => {
70
156
  setModalVisible(true);
@@ -80,8 +166,8 @@ function Select<Data, Type extends 'single' | 'multi'>({
80
166
  if (Array.isArray(value)) {
81
167
  if (value.length === 0) return placeholder;
82
168
  else {
83
- return options
84
- .reduce(
169
+ return selectOptions
170
+ ?.reduce(
85
171
  (acc, option, index) =>
86
172
  value.find(
87
173
  key => keyExtractor(option, index) == keyExtractor(key, index)
@@ -94,7 +180,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
94
180
  }
95
181
  } else {
96
182
  if (value === undefined) return placeholder;
97
- const selectedOption = options.find(
183
+ const selectedOption = selectOptions?.find(
98
184
  (option, index) =>
99
185
  keyExtractor(option, index) == keyExtractor(value as Data, index)
100
186
  );
@@ -127,7 +213,7 @@ function Select<Data, Type extends 'single' | 'multi'>({
127
213
  </HintInputContainer>
128
214
  <Modal
129
215
  visible={modalVisible}
130
- options={options}
216
+ options={selectOptions || []}
131
217
  focused={modalVisible}
132
218
  keyExtractor={keyExtractor}
133
219
  labelExtractor={labelExtractor}
@@ -140,10 +226,12 @@ function Select<Data, Type extends 'single' | 'multi'>({
140
226
  onRequestClose={handleCloseModal}
141
227
  animated
142
228
  animationType={'slide'}
143
- onSearch={onSearch}
229
+ onSearch={handleOnSearch}
144
230
  selectModalTitle={selectModalTitle}
145
231
  selectModalTitleComponent={selectModalTitleComponent}
146
232
  confirmButtonText={confirmButtonText}
233
+ onFocus={typeof options === 'function' ? handleOnFocus : undefined}
234
+ loading={loading}
147
235
  />
148
236
  </>
149
237
  );
@@ -9,7 +9,7 @@ import {
9
9
  PressableSurfaceProps,
10
10
  StyleProps,
11
11
  } from '@tecsinapse/react-core';
12
- import { ModalProps, View, ViewProps } from 'react-native';
12
+ import { ActivityIndicator, ModalProps, View, ViewProps } from 'react-native';
13
13
  import { Input, InputNativeProps } from '../Input';
14
14
  import { Text } from '../Text';
15
15
 
@@ -56,6 +56,7 @@ export const CloseButton = styled(Button)<ButtonProps & Partial<StyleProps>>`
56
56
 
57
57
  export const SearchBarContainer = styled(View)<ViewProps & Partial<StyleProps>>`
58
58
  padding: ${({ theme }) => theme.spacing.deca};
59
+ position: relative;
59
60
  `;
60
61
 
61
62
  export const SearchBar = styled(Input)<InputNativeProps & Partial<StyleProps>>`
@@ -71,20 +72,19 @@ export const ListItem = styled(PressableSurface)<
71
72
  padding-horizontal: ${({ theme }) => theme.spacing.deca};
72
73
  `;
73
74
 
74
- export const ListFooter = styled.View<Partial<StyleProps>>`
75
+ export const ModalFooter = styled(View)<Partial<StyleProps>>`
75
76
  width: 100%;
76
- min-height: 44px;
77
- margin-vertical: ${({ theme }) => theme.spacing.deca};
78
- `;
79
-
80
- export const FloatingButton = styled(Button)<ButtonProps & Partial<StyleProps>>`
81
- position: absolute;
82
- bottom: ${({ theme }) => theme.spacing.deca};
83
- left: ${({ theme }) => theme.spacing.deca};
84
- right: ${({ theme }) => theme.spacing.deca};
77
+ height: auto;
78
+ bottom: 0;
79
+ background-color: ${({ theme }) => theme.miscellaneous.bodyColor};
80
+ padding: ${({ theme }) => theme.spacing.deca};
85
81
  `;
86
82
 
87
83
  export const SelectIcon = styled(Icon)<Partial<StyleProps>>`
88
84
  padding: ${({ theme }) => theme.spacing.centi};
89
85
  color: ${({ theme }) => theme.color.secondary.medium};
90
86
  `;
87
+
88
+ export const FetchIndicator = styled(ActivityIndicator)`
89
+ align-self: center;
90
+ `;
@@ -5,9 +5,17 @@ import {
5
5
  } from '@tecsinapse/react-core';
6
6
  import React from 'react';
7
7
  import { Text } from '../../atoms/Text';
8
+ import { getLocale } from '../../../utils/date';
8
9
 
9
- export const Calendar = <T extends SelectionType>(
10
- props: CalendarProps<T>
11
- ): JSX.Element => {
12
- return <CalendarCore {...props} TextComponent={Text} />;
10
+ export const Calendar = <T extends SelectionType>({
11
+ locale,
12
+ ...rest
13
+ }): JSX.Element => {
14
+ return (
15
+ <CalendarCore
16
+ {...rest}
17
+ TextComponent={Text}
18
+ locale={locale ?? getLocale()}
19
+ />
20
+ );
13
21
  };
@@ -6,16 +6,19 @@ import {
6
6
  import React from 'react';
7
7
  import { Text } from '../../atoms/Text';
8
8
  import { Calendar } from '../Calendar';
9
+ import { getLocale } from '../../../utils/date';
9
10
 
10
- export const DatePicker = <T extends SelectionType>(
11
- props: DatePickerProps<T>
12
- ): JSX.Element => {
11
+ export const DatePicker = <T extends SelectionType>({
12
+ locale,
13
+ ...rest
14
+ }): JSX.Element => {
13
15
  return (
14
16
  <DatePickerCore
15
- {...props}
17
+ {...rest}
16
18
  TextComponent={Text}
17
19
  CalendarComponent={Calendar}
18
20
  animationType="slide"
21
+ locale={locale ?? getLocale()}
19
22
  />
20
23
  );
21
24
  };
@@ -5,14 +5,19 @@ import {
5
5
  import React, { FC } from 'react';
6
6
  import { Text } from '../../atoms/Text';
7
7
  import { DateTimeSelector } from '../DateTimeSelector';
8
+ import { getLocale } from '../../../utils/date';
8
9
 
9
- export const DateTimePicker: FC<DateTimePickerProps> = props => {
10
+ export const DateTimePicker: FC<DateTimePickerProps> = ({
11
+ locale,
12
+ ...rest
13
+ }) => {
10
14
  return (
11
15
  <DateTimePickerCore
12
- {...props}
16
+ {...rest}
13
17
  TextComponent={Text}
14
18
  DateTimeSelectorComponent={DateTimeSelector}
15
19
  animationType="slide"
20
+ locale={locale ?? getLocale()}
16
21
  />
17
22
  );
18
23
  };
@@ -4,7 +4,14 @@ import {
4
4
  } from '@tecsinapse/react-core';
5
5
  import React, { FC } from 'react';
6
6
  import { Text } from '../../atoms/Text';
7
+ import { getLocale } from '../../../utils/date';
7
8
 
8
- export const DateTimeSelector: FC<DateTimeSelectorProps> = props => {
9
- return <DateTimeSelectorCore {...props} TextComponent={Text} />;
9
+ export const DateTimeSelector: FC<DateTimeSelectorProps> = ({locale, ...rest}) => {
10
+ return (
11
+ <DateTimeSelectorCore
12
+ {...rest}
13
+ TextComponent={Text}
14
+ locale={locale ?? getLocale()}
15
+ />
16
+ );
10
17
  };
package/src/index.ts CHANGED
@@ -4,7 +4,7 @@ export { Select, SelectNativeProps } from './components/atoms/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';
7
- export { Error, Loading, Success } from './components/atoms/Button';
7
+ export { Error, Loading, Success, Button, ButtonNativeProps } from './components/atoms/Button';
8
8
  export { GroupButtonOption } from './components/atoms/GroupButton';
9
9
  export {
10
10
  InputPassword,
@@ -0,0 +1,17 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import * as dateFnsLocales from 'date-fns/locale';
3
+
4
+ export const getLocale = (): Locale => {
5
+ let locale: string;
6
+ if (Platform.OS === 'ios') {
7
+ locale =
8
+ NativeModules.SettingsManager.settings.AppleLocale ||
9
+ NativeModules.SettingsManager.settings.AppleLanguages[0];
10
+ } else {
11
+ locale = NativeModules.I18nManager.localeIdentifier;
12
+ }
13
+
14
+ const code = locale.replace('_', '');
15
+
16
+ return dateFnsLocales[code];
17
+ };