@ornikar/kitt-universal 16.3.1 → 16.4.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.
- package/dist/definitions/GoogleMapsApiKeyProvider/GoogleMapsApiKeyProvider.d.ts +8 -0
- package/dist/definitions/GoogleMapsApiKeyProvider/GoogleMapsApiKeyProvider.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsApiKeyProvider/hooks/useGoogleMapApiKey.d.ts +2 -0
- package/dist/definitions/GoogleMapsApiKeyProvider/hooks/useGoogleMapApiKey.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/GoogleMapsAutocompleteProvider.d.ts +17 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/GoogleMapsAutocompleteProvider.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/hooks/useGoogleMapsApi.d.ts +20 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/hooks/useGoogleMapsApi.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/hooks/useGoogleMapsApi.web.d.ts +3 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/hooks/useGoogleMapsApi.web.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/hooks/useGoogleMapsAutocomplete.d.ts +3 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/hooks/useGoogleMapsAutocomplete.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/reducer/googleMapsAutocompleteReducer.d.ts +40 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/reducer/googleMapsAutocompleteReducer.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/types.d.ts +5 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/types.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/utils/formatAddressFromGoogle.d.ts +20 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/utils/formatAddressFromGoogle.d.ts.map +1 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/utils/makeMapsApiUrl.d.ts +2 -0
- package/dist/definitions/GoogleMapsAutocompleteProvider/utils/makeMapsApiUrl.d.ts.map +1 -0
- package/dist/definitions/forms/Autocomplete/Autocomplete.d.ts +40 -0
- package/dist/definitions/forms/Autocomplete/Autocomplete.d.ts.map +1 -0
- package/dist/definitions/forms/Autocomplete/AutocompleteItem.d.ts +13 -0
- package/dist/definitions/forms/Autocomplete/AutocompleteItem.d.ts.map +1 -0
- package/dist/definitions/forms/Autocomplete/AutocompleteItemsListContainer.d.ts +10 -0
- package/dist/definitions/forms/Autocomplete/AutocompleteItemsListContainer.d.ts.map +1 -0
- package/dist/definitions/forms/Autocomplete/AutocompleteOption.d.ts +8 -0
- package/dist/definitions/forms/Autocomplete/AutocompleteOption.d.ts.map +1 -0
- package/dist/definitions/forms/InputAddress/InputAddress.d.ts +15 -0
- package/dist/definitions/forms/InputAddress/InputAddress.d.ts.map +1 -0
- package/dist/definitions/forms/InputAddress/InputAddressOption.d.ts +7 -0
- package/dist/definitions/forms/InputAddress/InputAddressOption.d.ts.map +1 -0
- package/dist/definitions/forms/InputAddress/utils/defaultItemToString.d.ts +3 -0
- package/dist/definitions/forms/InputAddress/utils/defaultItemToString.d.ts.map +1 -0
- package/dist/definitions/forms/InputAddress/utils/formatInitialValueToAutocompletePrediction.d.ts +4 -0
- package/dist/definitions/forms/InputAddress/utils/formatInitialValueToAutocompletePrediction.d.ts.map +1 -0
- package/dist/definitions/index.d.ts +10 -0
- package/dist/definitions/index.d.ts.map +1 -1
- package/dist/definitions/native-base/KittNativeBaseProvider.d.ts +46 -13
- package/dist/definitions/native-base/KittNativeBaseProvider.d.ts.map +1 -1
- package/dist/definitions/story-components/StorySection.d.ts +3 -3
- package/dist/definitions/story-components/StorySection.d.ts.map +1 -1
- package/dist/definitions/themes/default.d.ts +1 -0
- package/dist/definitions/themes/default.d.ts.map +1 -1
- package/dist/definitions/themes/late-ocean/autocomplete.d.ts +37 -0
- package/dist/definitions/themes/late-ocean/autocomplete.d.ts.map +1 -0
- package/dist/definitions/themes/late-ocean/forms.d.ts +1 -0
- package/dist/definitions/themes/late-ocean/forms.d.ts.map +1 -1
- package/dist/index-browser-all.es.android.js +1073 -185
- package/dist/index-browser-all.es.android.js.map +1 -1
- package/dist/index-browser-all.es.ios.js +1073 -185
- package/dist/index-browser-all.es.ios.js.map +1 -1
- package/dist/index-browser-all.es.js +1073 -185
- package/dist/index-browser-all.es.js.map +1 -1
- package/dist/index-browser-all.es.web.js +1040 -190
- package/dist/index-browser-all.es.web.js.map +1 -1
- package/dist/index-node-14.17.cjs.js +931 -142
- package/dist/index-node-14.17.cjs.js.map +1 -1
- package/dist/index-node-14.17.cjs.web.js +892 -111
- package/dist/index-node-14.17.cjs.web.js.map +1 -1
- package/dist/linaria-themes-browser-all.es.android.js +37 -0
- package/dist/linaria-themes-browser-all.es.android.js.map +1 -1
- package/dist/linaria-themes-browser-all.es.ios.js +37 -0
- package/dist/linaria-themes-browser-all.es.ios.js.map +1 -1
- package/dist/linaria-themes-browser-all.es.js +37 -0
- package/dist/linaria-themes-browser-all.es.js.map +1 -1
- package/dist/linaria-themes-browser-all.es.web.js +37 -0
- package/dist/linaria-themes-browser-all.es.web.js.map +1 -1
- package/dist/linaria-themes-node-14.17.cjs.js +37 -0
- package/dist/linaria-themes-node-14.17.cjs.js.map +1 -1
- package/dist/linaria-themes-node-14.17.cjs.web.js +37 -0
- package/dist/linaria-themes-node-14.17.cjs.web.js.map +1 -1
- package/dist/tsbuildinfo +1 -1
- package/package.json +6 -3
|
@@ -12,8 +12,10 @@ const bottomSheet$1 = require('@gorhom/bottom-sheet');
|
|
|
12
12
|
const reactNativeSafeAreaContext = require('react-native-safe-area-context');
|
|
13
13
|
const twemojiParser = require('twemoji-parser');
|
|
14
14
|
const WebBrowser = require('expo-web-browser');
|
|
15
|
+
const Downshift = require('downshift');
|
|
15
16
|
const DateTimePicker = require('@react-native-community/datetimepicker');
|
|
16
17
|
const reactIntl = require('react-intl');
|
|
18
|
+
const useDebounce = require('use-debounce');
|
|
17
19
|
const libphonenumberJs = require('libphonenumber-js');
|
|
18
20
|
const Svg = require('react-native-svg');
|
|
19
21
|
const picker$1 = require('@react-native-picker/picker');
|
|
@@ -38,6 +40,7 @@ function _interopNamespace(e) {
|
|
|
38
40
|
const React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
39
41
|
const Animated__default = /*#__PURE__*/_interopDefaultLegacy(Animated);
|
|
40
42
|
const WebBrowser__namespace = /*#__PURE__*/_interopNamespace(WebBrowser);
|
|
43
|
+
const Downshift__default = /*#__PURE__*/_interopDefaultLegacy(Downshift);
|
|
41
44
|
const DateTimePicker__default = /*#__PURE__*/_interopDefaultLegacy(DateTimePicker);
|
|
42
45
|
const Svg__default = /*#__PURE__*/_interopDefaultLegacy(Svg);
|
|
43
46
|
|
|
@@ -759,6 +762,42 @@ const feedbackMessage = {
|
|
|
759
762
|
}
|
|
760
763
|
};
|
|
761
764
|
|
|
765
|
+
const autocomplete = {
|
|
766
|
+
option: {
|
|
767
|
+
verticalPadding: 2,
|
|
768
|
+
minHeight: 40,
|
|
769
|
+
default: {
|
|
770
|
+
backgroundColor: colors.white
|
|
771
|
+
},
|
|
772
|
+
hovered: {
|
|
773
|
+
backgroundColor: lateOceanColorPalette.black50
|
|
774
|
+
},
|
|
775
|
+
focused: {
|
|
776
|
+
backgroundColor: lateOceanColorPalette.black50
|
|
777
|
+
},
|
|
778
|
+
selected: {
|
|
779
|
+
backgroundColor: lateOceanColorPalette.black50
|
|
780
|
+
},
|
|
781
|
+
highlighted: {
|
|
782
|
+
backgroundColor: lateOceanColorPalette.black50
|
|
783
|
+
},
|
|
784
|
+
pressed: {
|
|
785
|
+
backgroundColor: lateOceanColorPalette.black100
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
optionsContainer: {
|
|
789
|
+
borderRadius: 10,
|
|
790
|
+
backgroundColor: colors.white,
|
|
791
|
+
shadow: {
|
|
792
|
+
color: colors.black,
|
|
793
|
+
offsetX: 0,
|
|
794
|
+
offsetY: 10,
|
|
795
|
+
opacity: 0.15,
|
|
796
|
+
radius: 20
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
762
801
|
const checkbox = {
|
|
763
802
|
borderWidth: 2,
|
|
764
803
|
borderRadius: 5,
|
|
@@ -1058,6 +1097,7 @@ const timePicker = {
|
|
|
1058
1097
|
};
|
|
1059
1098
|
|
|
1060
1099
|
const forms = {
|
|
1100
|
+
autocomplete,
|
|
1061
1101
|
datePicker,
|
|
1062
1102
|
input,
|
|
1063
1103
|
radio,
|
|
@@ -3152,7 +3192,7 @@ CardModal.Header = CardModalHeader;
|
|
|
3152
3192
|
CardModal.Footer = CardModalFooter;
|
|
3153
3193
|
CardModal.ModalBehaviour = CardModalBehaviour;
|
|
3154
3194
|
|
|
3155
|
-
function getBackgroundColor$
|
|
3195
|
+
function getBackgroundColor$4({
|
|
3156
3196
|
isDisabled,
|
|
3157
3197
|
isSelected,
|
|
3158
3198
|
isHovered,
|
|
@@ -3186,7 +3226,7 @@ function AnimatedChoiceItemView({
|
|
|
3186
3226
|
const style = sx({
|
|
3187
3227
|
position: 'relative',
|
|
3188
3228
|
borderRadius: getBorderRadius(variant),
|
|
3189
|
-
backgroundColor: getBackgroundColor$
|
|
3229
|
+
backgroundColor: getBackgroundColor$4({
|
|
3190
3230
|
isDisabled,
|
|
3191
3231
|
isSelected,
|
|
3192
3232
|
isHovered,
|
|
@@ -3909,6 +3949,411 @@ function ExternalLink({
|
|
|
3909
3949
|
});
|
|
3910
3950
|
}
|
|
3911
3951
|
|
|
3952
|
+
function getIconColor(state, disabled) {
|
|
3953
|
+
if (disabled) return 'black-light';
|
|
3954
|
+
switch (state) {
|
|
3955
|
+
case 'invalid':
|
|
3956
|
+
return 'danger';
|
|
3957
|
+
case 'valid':
|
|
3958
|
+
return 'success';
|
|
3959
|
+
default:
|
|
3960
|
+
return undefined;
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
function InputIcon({
|
|
3964
|
+
icon,
|
|
3965
|
+
state,
|
|
3966
|
+
disabled
|
|
3967
|
+
}) {
|
|
3968
|
+
const theme = useTheme();
|
|
3969
|
+
const color = getIconColor(state, disabled);
|
|
3970
|
+
return /*#__PURE__*/jsxRuntime.jsx(TypographyIcon, {
|
|
3971
|
+
color: color,
|
|
3972
|
+
icon: icon,
|
|
3973
|
+
size: theme.kitt.forms.input.icon.size
|
|
3974
|
+
});
|
|
3975
|
+
}
|
|
3976
|
+
|
|
3977
|
+
function InputPressable({
|
|
3978
|
+
...props
|
|
3979
|
+
}) {
|
|
3980
|
+
return /*#__PURE__*/jsxRuntime.jsx(reactNative.Pressable, {
|
|
3981
|
+
...props
|
|
3982
|
+
});
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3985
|
+
function InputTextContainer({
|
|
3986
|
+
children
|
|
3987
|
+
}) {
|
|
3988
|
+
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
3989
|
+
position: "relative",
|
|
3990
|
+
children: children
|
|
3991
|
+
});
|
|
3992
|
+
}
|
|
3993
|
+
|
|
3994
|
+
const InputText = /*#__PURE__*/React.forwardRef(({
|
|
3995
|
+
id,
|
|
3996
|
+
right,
|
|
3997
|
+
state: formState,
|
|
3998
|
+
variant = 'outline',
|
|
3999
|
+
internalForceState,
|
|
4000
|
+
disabled = false,
|
|
4001
|
+
autoCorrect = true,
|
|
4002
|
+
textContentType = 'none',
|
|
4003
|
+
autoComplete = 'off',
|
|
4004
|
+
keyboardType = 'default',
|
|
4005
|
+
multiline,
|
|
4006
|
+
onSubmitEditing,
|
|
4007
|
+
...props
|
|
4008
|
+
}, ref) => {
|
|
4009
|
+
const theme = useTheme();
|
|
4010
|
+
const fontSizeForNativeBase = createNativeBaseFontSize({
|
|
4011
|
+
base: 'body'
|
|
4012
|
+
});
|
|
4013
|
+
const shouldHandleSingleLineOnIOS = reactNative.Platform.OS === 'ios' && !multiline;
|
|
4014
|
+
return /*#__PURE__*/jsxRuntime.jsxs(InputTextContainer, {
|
|
4015
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(nativeBase.Input, {
|
|
4016
|
+
ref: ref,
|
|
4017
|
+
multiline: multiline,
|
|
4018
|
+
nativeID: id,
|
|
4019
|
+
isDisabled: internalForceState ? internalForceState === 'disabled' : disabled,
|
|
4020
|
+
isHovered: internalForceState ? internalForceState === 'hover' : undefined,
|
|
4021
|
+
isFocused: internalForceState ? internalForceState === 'focus' : undefined,
|
|
4022
|
+
keyboardType: keyboardType,
|
|
4023
|
+
autoComplete: autoComplete,
|
|
4024
|
+
autoCorrect: autoCorrect,
|
|
4025
|
+
textContentType: textContentType,
|
|
4026
|
+
fontSize: fontSizeForNativeBase,
|
|
4027
|
+
lineHeight:
|
|
4028
|
+
// On basic text input, we set the line-height to zero for iOS to fix vertical text alignment
|
|
4029
|
+
// This is a iOS only fix since having 0 as a line-height value breaks text inputs on Android
|
|
4030
|
+
shouldHandleSingleLineOnIOS ? 0 : fontSizeForNativeBase,
|
|
4031
|
+
fontWeight: "bodies.regular",
|
|
4032
|
+
fontFamily: "bodies.regular",
|
|
4033
|
+
py: !multiline && reactNative.Platform.OS !== 'web' ? 0 : undefined,
|
|
4034
|
+
variant: variant,
|
|
4035
|
+
...props,
|
|
4036
|
+
onSubmitEditing: multiline ? () => null : onSubmitEditing
|
|
4037
|
+
}), right ? /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4038
|
+
position: "absolute",
|
|
4039
|
+
right: 0,
|
|
4040
|
+
top: 0,
|
|
4041
|
+
bottom: 0,
|
|
4042
|
+
justifyContent: "center",
|
|
4043
|
+
padding: theme.kitt.forms.input.rightContainer.padding,
|
|
4044
|
+
children: right
|
|
4045
|
+
}) : null]
|
|
4046
|
+
});
|
|
4047
|
+
});
|
|
4048
|
+
|
|
4049
|
+
function getBackgroundColor$3({
|
|
4050
|
+
isSelected,
|
|
4051
|
+
isHighlighted,
|
|
4052
|
+
isPressed,
|
|
4053
|
+
isHovered,
|
|
4054
|
+
isFocused
|
|
4055
|
+
}) {
|
|
4056
|
+
const baseKey = 'kitt.forms.autocomplete.option';
|
|
4057
|
+
if (isHighlighted) {
|
|
4058
|
+
return `${baseKey}.highlighted.backgroundColor`;
|
|
4059
|
+
}
|
|
4060
|
+
if (isPressed) {
|
|
4061
|
+
return `${baseKey}.pressed.backgroundColor`;
|
|
4062
|
+
}
|
|
4063
|
+
if (isHovered) {
|
|
4064
|
+
return `${baseKey}.hovered.backgroundColor`;
|
|
4065
|
+
}
|
|
4066
|
+
if (isFocused) {
|
|
4067
|
+
return `${baseKey}.focused.backgroundColor`;
|
|
4068
|
+
}
|
|
4069
|
+
if (isSelected) {
|
|
4070
|
+
return `${baseKey}.selected.backgroundColor`;
|
|
4071
|
+
}
|
|
4072
|
+
return `${baseKey}.default.backgroundColor`;
|
|
4073
|
+
}
|
|
4074
|
+
function AutocompleteItem({
|
|
4075
|
+
children,
|
|
4076
|
+
isSelected,
|
|
4077
|
+
isHighlighted,
|
|
4078
|
+
isHovered,
|
|
4079
|
+
isFocused,
|
|
4080
|
+
isPressed
|
|
4081
|
+
}) {
|
|
4082
|
+
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4083
|
+
justifyContent: "center",
|
|
4084
|
+
width: "100%",
|
|
4085
|
+
minHeight: "kitt.forms.autocomplete.option.minHeight",
|
|
4086
|
+
borderRadius: "kitt.1",
|
|
4087
|
+
padding: "kitt.1",
|
|
4088
|
+
backgroundColor: getBackgroundColor$3({
|
|
4089
|
+
isSelected,
|
|
4090
|
+
isHighlighted,
|
|
4091
|
+
isPressed,
|
|
4092
|
+
isHovered,
|
|
4093
|
+
isFocused
|
|
4094
|
+
}),
|
|
4095
|
+
children: children
|
|
4096
|
+
});
|
|
4097
|
+
}
|
|
4098
|
+
|
|
4099
|
+
function AutocompleteItemsListContainer({
|
|
4100
|
+
testID,
|
|
4101
|
+
children,
|
|
4102
|
+
zIndex = 1000
|
|
4103
|
+
}) {
|
|
4104
|
+
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4105
|
+
testID: testID,
|
|
4106
|
+
zIndex: zIndex,
|
|
4107
|
+
top: "kitt.2",
|
|
4108
|
+
left: 0,
|
|
4109
|
+
position: "absolute",
|
|
4110
|
+
flexGrow: 1,
|
|
4111
|
+
width: "100%",
|
|
4112
|
+
paddingY: "kitt.2",
|
|
4113
|
+
borderRadius: "kitt.forms.autocomplete.optionsContainer.borderRadius",
|
|
4114
|
+
backgroundColor: "kitt.forms.autocomplete.optionsContainer.backgroundColor",
|
|
4115
|
+
shadow: "kitt.forms.autocomplete.optionsContainer.shadow",
|
|
4116
|
+
_android: {
|
|
4117
|
+
style: {
|
|
4118
|
+
elevation: 2
|
|
4119
|
+
}
|
|
4120
|
+
},
|
|
4121
|
+
children: children
|
|
4122
|
+
});
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
function AutocompleteOption({
|
|
4126
|
+
children,
|
|
4127
|
+
...props
|
|
4128
|
+
}) {
|
|
4129
|
+
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4130
|
+
paddingX: {
|
|
4131
|
+
base: 'kitt.2',
|
|
4132
|
+
small: 'kitt.4'
|
|
4133
|
+
},
|
|
4134
|
+
paddingY: "kitt.forms.autocomplete.option.verticalPadding",
|
|
4135
|
+
...props,
|
|
4136
|
+
children: children
|
|
4137
|
+
});
|
|
4138
|
+
}
|
|
4139
|
+
|
|
4140
|
+
function patchNativeEvent(event) {
|
|
4141
|
+
return event || {
|
|
4142
|
+
preventDownshiftDefault: false,
|
|
4143
|
+
preventDefault: () => {}
|
|
4144
|
+
};
|
|
4145
|
+
}
|
|
4146
|
+
function isReactElement(element) {
|
|
4147
|
+
return typeof element === 'object' && element !== null && 'type' in element && 'props' in element;
|
|
4148
|
+
}
|
|
4149
|
+
function Autocomplete({
|
|
4150
|
+
children,
|
|
4151
|
+
name,
|
|
4152
|
+
disabled,
|
|
4153
|
+
placeholder,
|
|
4154
|
+
isInitialOpen,
|
|
4155
|
+
initialValue,
|
|
4156
|
+
containerProps,
|
|
4157
|
+
filterItemBasedOnCurrentInputValue,
|
|
4158
|
+
checkSelectedItem,
|
|
4159
|
+
itemToString,
|
|
4160
|
+
right,
|
|
4161
|
+
onChange,
|
|
4162
|
+
onFocus,
|
|
4163
|
+
onBlur,
|
|
4164
|
+
onInputChange,
|
|
4165
|
+
onSelectItem,
|
|
4166
|
+
/**
|
|
4167
|
+
* @description web only callback
|
|
4168
|
+
*/
|
|
4169
|
+
onOuterPress,
|
|
4170
|
+
errorElement,
|
|
4171
|
+
emptyResultsElement,
|
|
4172
|
+
inputTestID = 'kitt.Autocomplete.inputText',
|
|
4173
|
+
listContainerTestID = 'kitt.Autocomplete.listContainer',
|
|
4174
|
+
zIndex = 1000,
|
|
4175
|
+
...props
|
|
4176
|
+
}) {
|
|
4177
|
+
const childrenArray = React.Children.toArray(children);
|
|
4178
|
+
const items = childrenArray.filter(isReactElement).map(child => ({
|
|
4179
|
+
child,
|
|
4180
|
+
item: child.props.item
|
|
4181
|
+
}));
|
|
4182
|
+
return /*#__PURE__*/jsxRuntime.jsx(Downshift__default, {
|
|
4183
|
+
defaultIsOpen: isInitialOpen,
|
|
4184
|
+
initialSelectedItem: initialValue,
|
|
4185
|
+
initialInputValue: initialValue ? itemToString(initialValue) : undefined,
|
|
4186
|
+
itemToString: item => {
|
|
4187
|
+
// Prevents returning null values
|
|
4188
|
+
if (!itemToString) return '';
|
|
4189
|
+
return itemToString(item || undefined);
|
|
4190
|
+
},
|
|
4191
|
+
stateReducer: (state, changes) => {
|
|
4192
|
+
switch (changes.type) {
|
|
4193
|
+
case Downshift__default.stateChangeTypes.changeInput:
|
|
4194
|
+
return {
|
|
4195
|
+
...changes,
|
|
4196
|
+
selectedItem: null
|
|
4197
|
+
};
|
|
4198
|
+
default:
|
|
4199
|
+
return changes;
|
|
4200
|
+
}
|
|
4201
|
+
},
|
|
4202
|
+
onChange: (selectedItem, stateAndHelpers) => {
|
|
4203
|
+
if (onChange) {
|
|
4204
|
+
onChange(selectedItem, stateAndHelpers);
|
|
4205
|
+
}
|
|
4206
|
+
},
|
|
4207
|
+
onSelect: onSelectItem,
|
|
4208
|
+
onOuterClick: onOuterPress,
|
|
4209
|
+
onInputValueChange: onInputChange,
|
|
4210
|
+
children: ({
|
|
4211
|
+
getRootProps,
|
|
4212
|
+
getInputProps,
|
|
4213
|
+
getMenuProps,
|
|
4214
|
+
getItemProps,
|
|
4215
|
+
getToggleButtonProps,
|
|
4216
|
+
isOpen,
|
|
4217
|
+
inputValue,
|
|
4218
|
+
highlightedIndex,
|
|
4219
|
+
selectedItem,
|
|
4220
|
+
openMenu
|
|
4221
|
+
}) => {
|
|
4222
|
+
const shouldSuppressRefError = reactNative.Platform.OS !== 'web';
|
|
4223
|
+
const rootProps = getRootProps(undefined, {
|
|
4224
|
+
suppressRefError: shouldSuppressRefError
|
|
4225
|
+
});
|
|
4226
|
+
const menuProps = getMenuProps(undefined, {
|
|
4227
|
+
suppressRefError: shouldSuppressRefError
|
|
4228
|
+
});
|
|
4229
|
+
const {
|
|
4230
|
+
onClick: onClickToggle,
|
|
4231
|
+
onPress: onPressToggle,
|
|
4232
|
+
...toggleProps
|
|
4233
|
+
} = getToggleButtonProps({
|
|
4234
|
+
disabled
|
|
4235
|
+
});
|
|
4236
|
+
const {
|
|
4237
|
+
onKeyDown,
|
|
4238
|
+
onFocus: onSearchInputFocus,
|
|
4239
|
+
onBlur: onSearchInputBlur,
|
|
4240
|
+
onChange: onSearchInputChange,
|
|
4241
|
+
...inputProps
|
|
4242
|
+
} = getInputProps({
|
|
4243
|
+
placeholder,
|
|
4244
|
+
disabled
|
|
4245
|
+
});
|
|
4246
|
+
const hasCurrentSearch = inputValue && inputValue.length > 0;
|
|
4247
|
+
const currentItems = hasCurrentSearch && filterItemBasedOnCurrentInputValue ? items.filter(({
|
|
4248
|
+
item
|
|
4249
|
+
}) => {
|
|
4250
|
+
if (!filterItemBasedOnCurrentInputValue) return true;
|
|
4251
|
+
return filterItemBasedOnCurrentInputValue(item, inputValue || '');
|
|
4252
|
+
}) : items;
|
|
4253
|
+
|
|
4254
|
+
// We need to check if the menu is open and if there is at least one item or an error element to prevent displaying an empty container
|
|
4255
|
+
const isCurrentlyOpen = isOpen ? currentItems.length > 0 || !!errorElement || !!emptyResultsElement : false;
|
|
4256
|
+
const canDisplayCollapseButton = currentItems.length > 0 || !!errorElement || !!emptyResultsElement;
|
|
4257
|
+
return /*#__PURE__*/jsxRuntime.jsxs(View, {
|
|
4258
|
+
...rootProps,
|
|
4259
|
+
...containerProps,
|
|
4260
|
+
zIndex: zIndex,
|
|
4261
|
+
position: "relative",
|
|
4262
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(InputText, {
|
|
4263
|
+
...inputProps,
|
|
4264
|
+
...props,
|
|
4265
|
+
name: name,
|
|
4266
|
+
testID: inputTestID,
|
|
4267
|
+
right: right || (canDisplayCollapseButton ? /*#__PURE__*/jsxRuntime.jsx(InputPressable, {
|
|
4268
|
+
...toggleProps,
|
|
4269
|
+
testID: "kitt.Autocomplete.listToggle",
|
|
4270
|
+
hitSlop: 40,
|
|
4271
|
+
onPress: e => {
|
|
4272
|
+
if (reactNative.Platform.OS === 'web') {
|
|
4273
|
+
onClickToggle(e);
|
|
4274
|
+
return;
|
|
4275
|
+
}
|
|
4276
|
+
onPressToggle(patchNativeEvent(e));
|
|
4277
|
+
},
|
|
4278
|
+
children: /*#__PURE__*/jsxRuntime.jsx(InputIcon, {
|
|
4279
|
+
icon: isCurrentlyOpen ? /*#__PURE__*/jsxRuntime.jsx(kittIcons.ArrowUpIcon, {}) : /*#__PURE__*/jsxRuntime.jsx(kittIcons.ArrowDownIcon, {})
|
|
4280
|
+
})
|
|
4281
|
+
}) : null),
|
|
4282
|
+
onFocus: e => {
|
|
4283
|
+
openMenu();
|
|
4284
|
+
/** @ts-expect-error onFocus wants web events */
|
|
4285
|
+
if (reactNative.Platform.OS !== 'android' && onSearchInputFocus) onSearchInputFocus(e);
|
|
4286
|
+
if (onFocus) onFocus(e);
|
|
4287
|
+
},
|
|
4288
|
+
onBlur: e => {
|
|
4289
|
+
/** @ts-expect-error onBlur wants web events */
|
|
4290
|
+
if (reactNative.Platform.OS !== 'android' && onSearchInputBlur) onSearchInputBlur(e);
|
|
4291
|
+
if (onBlur) onBlur(e);
|
|
4292
|
+
}
|
|
4293
|
+
/** @ts-expect-error onSearchInputChange wants web events */,
|
|
4294
|
+
onChange: onSearchInputChange
|
|
4295
|
+
/** @ts-expect-error onKeyDown wants web events */,
|
|
4296
|
+
onKeyPress: onKeyDown
|
|
4297
|
+
}), /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4298
|
+
...menuProps,
|
|
4299
|
+
position: "relative",
|
|
4300
|
+
children: isCurrentlyOpen ? /*#__PURE__*/jsxRuntime.jsxs(AutocompleteItemsListContainer, {
|
|
4301
|
+
testID: listContainerTestID,
|
|
4302
|
+
children: [currentItems.map(({
|
|
4303
|
+
child,
|
|
4304
|
+
item
|
|
4305
|
+
}, index) => {
|
|
4306
|
+
const {
|
|
4307
|
+
onClick,
|
|
4308
|
+
onPress,
|
|
4309
|
+
role,
|
|
4310
|
+
'aria-selected': ariaSelected,
|
|
4311
|
+
...itemProps
|
|
4312
|
+
} = getItemProps({
|
|
4313
|
+
item,
|
|
4314
|
+
index
|
|
4315
|
+
});
|
|
4316
|
+
return /*#__PURE__*/jsxRuntime.jsx(Pressable, {
|
|
4317
|
+
...itemProps,
|
|
4318
|
+
accessibilityRole: reactNative.Platform.OS === 'android' ? undefined : role,
|
|
4319
|
+
accessibilityState: {
|
|
4320
|
+
selected: ariaSelected
|
|
4321
|
+
},
|
|
4322
|
+
disabled: disabled,
|
|
4323
|
+
onPress: e => {
|
|
4324
|
+
if (reactNative.Platform.OS === 'web') {
|
|
4325
|
+
if (onClick) onClick(e);
|
|
4326
|
+
return;
|
|
4327
|
+
}
|
|
4328
|
+
if (onPress) onPress(patchNativeEvent(e));
|
|
4329
|
+
},
|
|
4330
|
+
children: ({
|
|
4331
|
+
isHovered,
|
|
4332
|
+
isFocused,
|
|
4333
|
+
isPressed
|
|
4334
|
+
}) => /*#__PURE__*/jsxRuntime.jsx(AutocompleteItem, {
|
|
4335
|
+
item: item,
|
|
4336
|
+
isHighlighted: highlightedIndex === index,
|
|
4337
|
+
isHovered: isHovered,
|
|
4338
|
+
isFocused: isFocused,
|
|
4339
|
+
isPressed: isPressed,
|
|
4340
|
+
isSelected: checkSelectedItem(selectedItem || undefined, item),
|
|
4341
|
+
children: child
|
|
4342
|
+
})
|
|
4343
|
+
}, itemProps.id);
|
|
4344
|
+
}), errorElement, emptyResultsElement]
|
|
4345
|
+
}) : null
|
|
4346
|
+
})]
|
|
4347
|
+
});
|
|
4348
|
+
}
|
|
4349
|
+
});
|
|
4350
|
+
}
|
|
4351
|
+
Autocomplete.Option = AutocompleteOption;
|
|
4352
|
+
/**
|
|
4353
|
+
* @description: This is exported for testing purposes only
|
|
4354
|
+
*/
|
|
4355
|
+
Autocomplete.UnsafeInternalItem = AutocompleteItem;
|
|
4356
|
+
|
|
3912
4357
|
function getBackgroundColor$2({
|
|
3913
4358
|
isDisabled,
|
|
3914
4359
|
isPressed,
|
|
@@ -4188,102 +4633,38 @@ function onDatePartChange({
|
|
|
4188
4633
|
if (minDate) {
|
|
4189
4634
|
minDate.setMinutes(0);
|
|
4190
4635
|
minDate.setHours(0);
|
|
4191
|
-
minDate.setSeconds(0);
|
|
4192
|
-
minDate.setMilliseconds(0);
|
|
4193
|
-
const isMinDateAfterNextValue = minDate.getTime() > nextValue.getTime();
|
|
4194
|
-
if (isMinDateAfterNextValue) {
|
|
4195
|
-
if (onFocus) onFocus();
|
|
4196
|
-
onChange(undefined);
|
|
4197
|
-
if (onBlur) onBlur();
|
|
4198
|
-
return;
|
|
4199
|
-
}
|
|
4200
|
-
}
|
|
4201
|
-
if (maxDate) {
|
|
4202
|
-
maxDate.setMinutes(0);
|
|
4203
|
-
maxDate.setHours(0);
|
|
4204
|
-
maxDate.setSeconds(0);
|
|
4205
|
-
maxDate.setMilliseconds(0);
|
|
4206
|
-
const isMaxDateBeforeNextValue = nextValue.getTime() > maxDate.getTime();
|
|
4207
|
-
if (isMaxDateBeforeNextValue) {
|
|
4208
|
-
if (onFocus) onFocus();
|
|
4209
|
-
onChange(undefined);
|
|
4210
|
-
if (onBlur) onBlur();
|
|
4211
|
-
return;
|
|
4212
|
-
}
|
|
4213
|
-
}
|
|
4214
|
-
if (onFocus) onFocus();
|
|
4215
|
-
onChange(nextValue);
|
|
4216
|
-
if (onBlur) onBlur();
|
|
4217
|
-
}
|
|
4218
|
-
|
|
4219
|
-
function stringToNumber(text) {
|
|
4220
|
-
if (text.length === 0) return undefined;
|
|
4221
|
-
return parseInt(text, 10);
|
|
4222
|
-
}
|
|
4223
|
-
|
|
4224
|
-
function InputTextContainer({
|
|
4225
|
-
children
|
|
4226
|
-
}) {
|
|
4227
|
-
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4228
|
-
position: "relative",
|
|
4229
|
-
children: children
|
|
4230
|
-
});
|
|
4231
|
-
}
|
|
4232
|
-
|
|
4233
|
-
const InputText = /*#__PURE__*/React.forwardRef(({
|
|
4234
|
-
id,
|
|
4235
|
-
right,
|
|
4236
|
-
state: formState,
|
|
4237
|
-
variant = 'outline',
|
|
4238
|
-
internalForceState,
|
|
4239
|
-
disabled = false,
|
|
4240
|
-
autoCorrect = true,
|
|
4241
|
-
textContentType = 'none',
|
|
4242
|
-
autoComplete = 'off',
|
|
4243
|
-
keyboardType = 'default',
|
|
4244
|
-
multiline,
|
|
4245
|
-
onSubmitEditing,
|
|
4246
|
-
...props
|
|
4247
|
-
}, ref) => {
|
|
4248
|
-
const theme = useTheme();
|
|
4249
|
-
const fontSizeForNativeBase = createNativeBaseFontSize({
|
|
4250
|
-
base: 'body'
|
|
4251
|
-
});
|
|
4252
|
-
const shouldHandleSingleLineOnIOS = reactNative.Platform.OS === 'ios' && !multiline;
|
|
4253
|
-
return /*#__PURE__*/jsxRuntime.jsxs(InputTextContainer, {
|
|
4254
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(nativeBase.Input, {
|
|
4255
|
-
ref: ref,
|
|
4256
|
-
multiline: multiline,
|
|
4257
|
-
nativeID: id,
|
|
4258
|
-
isDisabled: internalForceState ? internalForceState === 'disabled' : disabled,
|
|
4259
|
-
isHovered: internalForceState ? internalForceState === 'hover' : undefined,
|
|
4260
|
-
isFocused: internalForceState ? internalForceState === 'focus' : undefined,
|
|
4261
|
-
keyboardType: keyboardType,
|
|
4262
|
-
autoComplete: autoComplete,
|
|
4263
|
-
autoCorrect: autoCorrect,
|
|
4264
|
-
textContentType: textContentType,
|
|
4265
|
-
fontSize: fontSizeForNativeBase,
|
|
4266
|
-
lineHeight:
|
|
4267
|
-
// On basic text input, we set the line-height to zero for iOS to fix vertical text alignment
|
|
4268
|
-
// This is a iOS only fix since having 0 as a line-height value breaks text inputs on Android
|
|
4269
|
-
shouldHandleSingleLineOnIOS ? 0 : fontSizeForNativeBase,
|
|
4270
|
-
fontWeight: "bodies.regular",
|
|
4271
|
-
fontFamily: "bodies.regular",
|
|
4272
|
-
py: !multiline && reactNative.Platform.OS !== 'web' ? 0 : undefined,
|
|
4273
|
-
variant: variant,
|
|
4274
|
-
...props,
|
|
4275
|
-
onSubmitEditing: multiline ? () => null : onSubmitEditing
|
|
4276
|
-
}), right ? /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4277
|
-
position: "absolute",
|
|
4278
|
-
right: 0,
|
|
4279
|
-
top: 0,
|
|
4280
|
-
bottom: 0,
|
|
4281
|
-
justifyContent: "center",
|
|
4282
|
-
padding: theme.kitt.forms.input.rightContainer.padding,
|
|
4283
|
-
children: right
|
|
4284
|
-
}) : null]
|
|
4285
|
-
});
|
|
4286
|
-
});
|
|
4636
|
+
minDate.setSeconds(0);
|
|
4637
|
+
minDate.setMilliseconds(0);
|
|
4638
|
+
const isMinDateAfterNextValue = minDate.getTime() > nextValue.getTime();
|
|
4639
|
+
if (isMinDateAfterNextValue) {
|
|
4640
|
+
if (onFocus) onFocus();
|
|
4641
|
+
onChange(undefined);
|
|
4642
|
+
if (onBlur) onBlur();
|
|
4643
|
+
return;
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4646
|
+
if (maxDate) {
|
|
4647
|
+
maxDate.setMinutes(0);
|
|
4648
|
+
maxDate.setHours(0);
|
|
4649
|
+
maxDate.setSeconds(0);
|
|
4650
|
+
maxDate.setMilliseconds(0);
|
|
4651
|
+
const isMaxDateBeforeNextValue = nextValue.getTime() > maxDate.getTime();
|
|
4652
|
+
if (isMaxDateBeforeNextValue) {
|
|
4653
|
+
if (onFocus) onFocus();
|
|
4654
|
+
onChange(undefined);
|
|
4655
|
+
if (onBlur) onBlur();
|
|
4656
|
+
return;
|
|
4657
|
+
}
|
|
4658
|
+
}
|
|
4659
|
+
if (onFocus) onFocus();
|
|
4660
|
+
onChange(nextValue);
|
|
4661
|
+
if (onBlur) onBlur();
|
|
4662
|
+
}
|
|
4663
|
+
|
|
4664
|
+
function stringToNumber(text) {
|
|
4665
|
+
if (text.length === 0) return undefined;
|
|
4666
|
+
return parseInt(text, 10);
|
|
4667
|
+
}
|
|
4287
4668
|
|
|
4288
4669
|
function getCurrentInternalForcedState$1({
|
|
4289
4670
|
isDisabled,
|
|
@@ -4818,6 +5199,399 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
|
|
|
4818
5199
|
});
|
|
4819
5200
|
});
|
|
4820
5201
|
|
|
5202
|
+
const GoogleMapsApiKeyContext = /*#__PURE__*/React.createContext(undefined);
|
|
5203
|
+
function GoogleMapsApiKeyProvider({
|
|
5204
|
+
children,
|
|
5205
|
+
apiKey
|
|
5206
|
+
}) {
|
|
5207
|
+
return /*#__PURE__*/jsxRuntime.jsx(GoogleMapsApiKeyContext.Provider, {
|
|
5208
|
+
value: apiKey,
|
|
5209
|
+
children: children
|
|
5210
|
+
});
|
|
5211
|
+
}
|
|
5212
|
+
|
|
5213
|
+
function useGoogleMapApiKey() {
|
|
5214
|
+
const context = React.useContext(GoogleMapsApiKeyContext);
|
|
5215
|
+
if (!context) {
|
|
5216
|
+
throw new Error('<GoogleMapsApiKeyContext> missing in the react tree');
|
|
5217
|
+
}
|
|
5218
|
+
return context;
|
|
5219
|
+
}
|
|
5220
|
+
|
|
5221
|
+
function makeMapsApiUrl(resource, paramName, value, apiKey) {
|
|
5222
|
+
return `https://maps.googleapis.com/maps/api/${resource}/json?${paramName}=${encodeURIComponent(value)}&key=${apiKey}`;
|
|
5223
|
+
}
|
|
5224
|
+
|
|
5225
|
+
function useGoogleMapsApi() {
|
|
5226
|
+
const apiKey = useGoogleMapApiKey();
|
|
5227
|
+
const makeApiUrl = (resource, paramName, value) => {
|
|
5228
|
+
return makeMapsApiUrl(resource, paramName, value, apiKey);
|
|
5229
|
+
};
|
|
5230
|
+
const sharedFetchOptions = {
|
|
5231
|
+
method: 'GET',
|
|
5232
|
+
headers: {
|
|
5233
|
+
'Content-Type': 'application/json'
|
|
5234
|
+
}
|
|
5235
|
+
};
|
|
5236
|
+
return {
|
|
5237
|
+
autoComplete: {
|
|
5238
|
+
getPlacePredictions: async input => {
|
|
5239
|
+
try {
|
|
5240
|
+
const response = await fetch(makeApiUrl('place/autocomplete', 'input', input), sharedFetchOptions);
|
|
5241
|
+
const data = await response.json();
|
|
5242
|
+
if (data?.status !== 'OK') {
|
|
5243
|
+
return {
|
|
5244
|
+
status: data?.status,
|
|
5245
|
+
results: []
|
|
5246
|
+
};
|
|
5247
|
+
}
|
|
5248
|
+
return {
|
|
5249
|
+
results: data?.predictions,
|
|
5250
|
+
status: data?.status
|
|
5251
|
+
};
|
|
5252
|
+
} catch (error) {
|
|
5253
|
+
return {
|
|
5254
|
+
status: google.maps.places.PlacesServiceStatus.UNKNOWN_ERROR,
|
|
5255
|
+
results: []
|
|
5256
|
+
};
|
|
5257
|
+
}
|
|
5258
|
+
}
|
|
5259
|
+
},
|
|
5260
|
+
placesService: {
|
|
5261
|
+
getDetails: async placeId => {
|
|
5262
|
+
try {
|
|
5263
|
+
const response = await fetch(makeApiUrl('place/details', 'place_id', placeId), sharedFetchOptions);
|
|
5264
|
+
const data = await response.json();
|
|
5265
|
+
if (data?.status !== 'OK') {
|
|
5266
|
+
return {
|
|
5267
|
+
status: data?.status,
|
|
5268
|
+
result: undefined
|
|
5269
|
+
};
|
|
5270
|
+
}
|
|
5271
|
+
return {
|
|
5272
|
+
result: data?.result,
|
|
5273
|
+
status: data?.status
|
|
5274
|
+
};
|
|
5275
|
+
} catch (error) {
|
|
5276
|
+
return {
|
|
5277
|
+
status: google.maps.places.PlacesServiceStatus.UNKNOWN_ERROR,
|
|
5278
|
+
result: undefined
|
|
5279
|
+
};
|
|
5280
|
+
}
|
|
5281
|
+
}
|
|
5282
|
+
}
|
|
5283
|
+
};
|
|
5284
|
+
}
|
|
5285
|
+
|
|
5286
|
+
const googleMapsAutocompleteReducer = (state, action) => {
|
|
5287
|
+
switch (action.type) {
|
|
5288
|
+
case 'search-change':
|
|
5289
|
+
{
|
|
5290
|
+
return {
|
|
5291
|
+
...state,
|
|
5292
|
+
hasSearchError: false,
|
|
5293
|
+
isLoadingSearch: true
|
|
5294
|
+
};
|
|
5295
|
+
}
|
|
5296
|
+
case 'search-success':
|
|
5297
|
+
{
|
|
5298
|
+
return {
|
|
5299
|
+
...state,
|
|
5300
|
+
hasSearchError: false,
|
|
5301
|
+
isLoadingSearch: false,
|
|
5302
|
+
items: action.payload.results
|
|
5303
|
+
};
|
|
5304
|
+
}
|
|
5305
|
+
case 'search-error':
|
|
5306
|
+
{
|
|
5307
|
+
return {
|
|
5308
|
+
...state,
|
|
5309
|
+
hasSearchError: true,
|
|
5310
|
+
isLoadingSearch: false,
|
|
5311
|
+
items: []
|
|
5312
|
+
};
|
|
5313
|
+
}
|
|
5314
|
+
case 'select-result':
|
|
5315
|
+
{
|
|
5316
|
+
return {
|
|
5317
|
+
...state,
|
|
5318
|
+
hasSelectResultError: false,
|
|
5319
|
+
isLoadingResultDetails: true
|
|
5320
|
+
};
|
|
5321
|
+
}
|
|
5322
|
+
case 'select-result-success':
|
|
5323
|
+
{
|
|
5324
|
+
return {
|
|
5325
|
+
...state,
|
|
5326
|
+
hasSelectResultError: false,
|
|
5327
|
+
isLoadingResultDetails: false,
|
|
5328
|
+
currentSelectedValue: action.payload.result
|
|
5329
|
+
};
|
|
5330
|
+
}
|
|
5331
|
+
case 'select-result-error':
|
|
5332
|
+
{
|
|
5333
|
+
return {
|
|
5334
|
+
...state,
|
|
5335
|
+
hasSelectResultError: true,
|
|
5336
|
+
isLoadingResultDetails: false,
|
|
5337
|
+
currentSelectedValue: undefined
|
|
5338
|
+
};
|
|
5339
|
+
}
|
|
5340
|
+
default:
|
|
5341
|
+
return state;
|
|
5342
|
+
}
|
|
5343
|
+
};
|
|
5344
|
+
|
|
5345
|
+
function findComponentByType(typeName, components) {
|
|
5346
|
+
return components.find(component => component.types.includes(typeName));
|
|
5347
|
+
}
|
|
5348
|
+
const matchStreetNumberWithOriginalAddress = (streetNumber = '', address = '') => {
|
|
5349
|
+
const [, number = '', extension = ''] = / *(\d*[-/_]{0,1}\d*) *(bis|ter|quater|quinquies|sexies|septies|octies|novies|decies|[a-z])? /i.exec(address) || [];
|
|
5350
|
+
if (number) return `${number}${extension}`;
|
|
5351
|
+
return streetNumber;
|
|
5352
|
+
};
|
|
5353
|
+
const formatAddressFromGoogle = (placeResult, originalAddress) => {
|
|
5354
|
+
const {
|
|
5355
|
+
address_components: addressComponents = []
|
|
5356
|
+
} = placeResult;
|
|
5357
|
+
return {
|
|
5358
|
+
source: 'google',
|
|
5359
|
+
lat: placeResult.geometry?.location.lat(),
|
|
5360
|
+
lng: placeResult.geometry?.location.lng(),
|
|
5361
|
+
locality: findComponentByType('locality', addressComponents)?.long_name,
|
|
5362
|
+
subLocality: findComponentByType('sublocality', addressComponents)?.long_name,
|
|
5363
|
+
zipcode: findComponentByType('postal_code', addressComponents)?.long_name,
|
|
5364
|
+
streetName: findComponentByType('route', addressComponents)?.long_name,
|
|
5365
|
+
streetNumber: matchStreetNumberWithOriginalAddress(findComponentByType('street_number', addressComponents)?.long_name, originalAddress),
|
|
5366
|
+
country: findComponentByType('country', addressComponents)?.long_name,
|
|
5367
|
+
administrativeAreaLevel1: findComponentByType('administrative_area_level_1', addressComponents)?.long_name,
|
|
5368
|
+
administrativeAreaLevel2: findComponentByType('administrative_area_level_1', addressComponents)?.long_name
|
|
5369
|
+
};
|
|
5370
|
+
};
|
|
5371
|
+
|
|
5372
|
+
const GoogleMapsAutocompleteContext = /*#__PURE__*/React.createContext({
|
|
5373
|
+
state: {
|
|
5374
|
+
items: [],
|
|
5375
|
+
currentSelectedValue: undefined,
|
|
5376
|
+
isLoadingSearch: false,
|
|
5377
|
+
hasSearchError: false,
|
|
5378
|
+
hasSelectResultError: false,
|
|
5379
|
+
isLoadingResultDetails: false,
|
|
5380
|
+
shouldDisplayEmptyStateWhenNoResults: false
|
|
5381
|
+
},
|
|
5382
|
+
onInputChange: () => {
|
|
5383
|
+
return Promise.resolve();
|
|
5384
|
+
},
|
|
5385
|
+
onSelectItem: () => {}
|
|
5386
|
+
});
|
|
5387
|
+
function GoogleMapsAutocompleteProvider({
|
|
5388
|
+
children,
|
|
5389
|
+
minCharsToSearch = 3,
|
|
5390
|
+
debounceTimeout = 950
|
|
5391
|
+
}) {
|
|
5392
|
+
const mapsApi = useGoogleMapsApi();
|
|
5393
|
+
const searchResultsCache = React.useRef({});
|
|
5394
|
+
const resultDetailsCache = React.useRef({});
|
|
5395
|
+
const [state, dispatch] = React.useReducer(googleMapsAutocompleteReducer, {
|
|
5396
|
+
items: [],
|
|
5397
|
+
shouldDisplayEmptyStateWhenNoResults: false
|
|
5398
|
+
});
|
|
5399
|
+
const handleInputChange = useDebounce.useDebouncedCallback(React.useCallback(async value => {
|
|
5400
|
+
if (value.length < minCharsToSearch) return;
|
|
5401
|
+
dispatch({
|
|
5402
|
+
type: 'search-change'
|
|
5403
|
+
});
|
|
5404
|
+
|
|
5405
|
+
// If the user types the same value as the previous search, we don't need to call the API again
|
|
5406
|
+
const predictionsPromise = searchResultsCache.current[value] ? Promise.resolve({
|
|
5407
|
+
results: searchResultsCache.current[value],
|
|
5408
|
+
status: 'OK'
|
|
5409
|
+
}) : mapsApi.autoComplete.getPlacePredictions(value);
|
|
5410
|
+
try {
|
|
5411
|
+
const {
|
|
5412
|
+
results,
|
|
5413
|
+
status
|
|
5414
|
+
} = await predictionsPromise;
|
|
5415
|
+
if (status !== 'OK') {
|
|
5416
|
+
dispatch({
|
|
5417
|
+
type: 'search-error'
|
|
5418
|
+
});
|
|
5419
|
+
return;
|
|
5420
|
+
}
|
|
5421
|
+
|
|
5422
|
+
// We cache the results to avoid calling the API again if the user types the same value
|
|
5423
|
+
searchResultsCache.current[value] = results;
|
|
5424
|
+
dispatch({
|
|
5425
|
+
type: 'search-success',
|
|
5426
|
+
payload: {
|
|
5427
|
+
results
|
|
5428
|
+
}
|
|
5429
|
+
});
|
|
5430
|
+
} catch (error) {
|
|
5431
|
+
dispatch({
|
|
5432
|
+
type: 'search-error'
|
|
5433
|
+
});
|
|
5434
|
+
}
|
|
5435
|
+
}, [mapsApi.autoComplete, minCharsToSearch]), debounceTimeout);
|
|
5436
|
+
const handleSelectItem = React.useCallback(async (item, onChange) => {
|
|
5437
|
+
// This case should never happen but it's here to avoid a TS error
|
|
5438
|
+
if (!item?.place_id) {
|
|
5439
|
+
if (onChange) onChange(undefined);
|
|
5440
|
+
return;
|
|
5441
|
+
}
|
|
5442
|
+
dispatch({
|
|
5443
|
+
type: 'select-result'
|
|
5444
|
+
});
|
|
5445
|
+
try {
|
|
5446
|
+
// If we already have the details in cache, we don't need to fetch them again
|
|
5447
|
+
const placePromise = resultDetailsCache.current[item.place_id] ? Promise.resolve(resultDetailsCache.current[item.place_id]) : mapsApi.placesService.getDetails(item.place_id).then(({
|
|
5448
|
+
result
|
|
5449
|
+
}) => result);
|
|
5450
|
+
const place = await placePromise;
|
|
5451
|
+
if (!place) {
|
|
5452
|
+
dispatch({
|
|
5453
|
+
type: 'select-result-error'
|
|
5454
|
+
});
|
|
5455
|
+
if (onChange) onChange(undefined);
|
|
5456
|
+
return;
|
|
5457
|
+
}
|
|
5458
|
+
dispatch({
|
|
5459
|
+
type: 'select-result-success',
|
|
5460
|
+
payload: {
|
|
5461
|
+
result: place
|
|
5462
|
+
}
|
|
5463
|
+
});
|
|
5464
|
+
const formattedAddress = formatAddressFromGoogle(place, item.description);
|
|
5465
|
+
|
|
5466
|
+
// We cache the result details to avoid fetching them again if the user selects the same item
|
|
5467
|
+
resultDetailsCache.current[item.place_id] = place;
|
|
5468
|
+
if (onChange) onChange(formattedAddress);
|
|
5469
|
+
} catch (error) {
|
|
5470
|
+
dispatch({
|
|
5471
|
+
type: 'select-result-error'
|
|
5472
|
+
});
|
|
5473
|
+
if (onChange) onChange(undefined);
|
|
5474
|
+
}
|
|
5475
|
+
}, [mapsApi.placesService]);
|
|
5476
|
+
const api = React.useMemo(() => ({
|
|
5477
|
+
state,
|
|
5478
|
+
onSelectItem: handleSelectItem,
|
|
5479
|
+
onInputChange: handleInputChange
|
|
5480
|
+
}), [handleInputChange, handleSelectItem, state]);
|
|
5481
|
+
return /*#__PURE__*/jsxRuntime.jsx(GoogleMapsAutocompleteContext.Provider, {
|
|
5482
|
+
value: api,
|
|
5483
|
+
children: children
|
|
5484
|
+
});
|
|
5485
|
+
}
|
|
5486
|
+
|
|
5487
|
+
function useGoogleMapsAutocomplete() {
|
|
5488
|
+
const context = React.useContext(GoogleMapsAutocompleteContext);
|
|
5489
|
+
if (!context) {
|
|
5490
|
+
throw new Error('<GoogleMapsAutocompleteProvider> missing in the react tree');
|
|
5491
|
+
}
|
|
5492
|
+
return context;
|
|
5493
|
+
}
|
|
5494
|
+
|
|
5495
|
+
function InputAddressOption({
|
|
5496
|
+
item
|
|
5497
|
+
}) {
|
|
5498
|
+
const sharedTransform = {
|
|
5499
|
+
style: {
|
|
5500
|
+
transform: [{
|
|
5501
|
+
translateY: 4
|
|
5502
|
+
}]
|
|
5503
|
+
}
|
|
5504
|
+
};
|
|
5505
|
+
return /*#__PURE__*/jsxRuntime.jsx(Autocomplete.Option, {
|
|
5506
|
+
item: item,
|
|
5507
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(HStack, {
|
|
5508
|
+
space: "kitt.2",
|
|
5509
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(View, {
|
|
5510
|
+
_web: sharedTransform,
|
|
5511
|
+
_ios: sharedTransform,
|
|
5512
|
+
_android: sharedTransform,
|
|
5513
|
+
children: /*#__PURE__*/jsxRuntime.jsx(TypographyIcon, {
|
|
5514
|
+
icon: /*#__PURE__*/jsxRuntime.jsx(kittIcons.MapPinIcon, {}),
|
|
5515
|
+
color: "black"
|
|
5516
|
+
})
|
|
5517
|
+
}), /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
5518
|
+
flexShrink: 1,
|
|
5519
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(Typography.Text, {
|
|
5520
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Typography.Text, {
|
|
5521
|
+
variant: "bold",
|
|
5522
|
+
children: item.structured_formatting.main_text
|
|
5523
|
+
}), item.structured_formatting.secondary_text ? /*#__PURE__*/jsxRuntime.jsxs(Typography.Text, {
|
|
5524
|
+
color: "black-light",
|
|
5525
|
+
variant: "bold",
|
|
5526
|
+
children: [' ', item.structured_formatting.secondary_text]
|
|
5527
|
+
}) : null]
|
|
5528
|
+
})
|
|
5529
|
+
})]
|
|
5530
|
+
})
|
|
5531
|
+
});
|
|
5532
|
+
}
|
|
5533
|
+
|
|
5534
|
+
function defaultItemToString(item) {
|
|
5535
|
+
if (!item) return '';
|
|
5536
|
+
return item.structured_formatting.main_text;
|
|
5537
|
+
}
|
|
5538
|
+
|
|
5539
|
+
// This function takes AutocompleteAddress and return a valid google AutocompletePrediction
|
|
5540
|
+
function formatInitialValueToAutocompletePrediction(address, placeId) {
|
|
5541
|
+
return {
|
|
5542
|
+
place_id: placeId,
|
|
5543
|
+
description: '',
|
|
5544
|
+
reference: '',
|
|
5545
|
+
types: [],
|
|
5546
|
+
terms: [],
|
|
5547
|
+
matched_substrings: [],
|
|
5548
|
+
structured_formatting: {
|
|
5549
|
+
main_text: [address.streetName, address.streetNumber].filter(Boolean).join(' '),
|
|
5550
|
+
main_text_matched_substrings: [],
|
|
5551
|
+
secondary_text: [address.zipcode, address.locality, address.subLocality].filter(Boolean).join(' ')
|
|
5552
|
+
}
|
|
5553
|
+
};
|
|
5554
|
+
}
|
|
5555
|
+
|
|
5556
|
+
function InputAddress({
|
|
5557
|
+
initialValue,
|
|
5558
|
+
itemToString = defaultItemToString,
|
|
5559
|
+
errorElement,
|
|
5560
|
+
emptyResultsElement,
|
|
5561
|
+
onChange,
|
|
5562
|
+
...props
|
|
5563
|
+
}) {
|
|
5564
|
+
const {
|
|
5565
|
+
state,
|
|
5566
|
+
onInputChange,
|
|
5567
|
+
onSelectItem
|
|
5568
|
+
} = useGoogleMapsAutocomplete();
|
|
5569
|
+
|
|
5570
|
+
// place_id is a google field that is not available within an AutoCompleteAddress, so we need to add a fake one when handling initial values
|
|
5571
|
+
const formattedInitialValue = initialValue ? formatInitialValueToAutocompletePrediction(initialValue, 'initial-value-placeId') : undefined;
|
|
5572
|
+
return /*#__PURE__*/jsxRuntime.jsx(Autocomplete, {
|
|
5573
|
+
itemToString: itemToString,
|
|
5574
|
+
initialValue: formattedInitialValue,
|
|
5575
|
+
checkSelectedItem: (selectedItem, item) => selectedItem?.place_id === item.place_id,
|
|
5576
|
+
right: state.isLoadingSearch || state.isLoadingResultDetails ? /*#__PURE__*/jsxRuntime.jsx(Icon, {
|
|
5577
|
+
icon: /*#__PURE__*/jsxRuntime.jsx(LoaderIcon, {}),
|
|
5578
|
+
color: "kitt.black"
|
|
5579
|
+
}) : undefined,
|
|
5580
|
+
errorElement: state.hasSearchError || state.hasSelectResultError ? errorElement : null,
|
|
5581
|
+
emptyResultsElement: state.items.length === 0 ? emptyResultsElement : null,
|
|
5582
|
+
onInputChange: v => {
|
|
5583
|
+
onInputChange(v);
|
|
5584
|
+
},
|
|
5585
|
+
onChange: v => {
|
|
5586
|
+
onSelectItem(v, onChange);
|
|
5587
|
+
},
|
|
5588
|
+
children: state.items.map(item => /*#__PURE__*/jsxRuntime.jsx(InputAddressOption, {
|
|
5589
|
+
item: item
|
|
5590
|
+
}, item.place_id))
|
|
5591
|
+
});
|
|
5592
|
+
}
|
|
5593
|
+
InputAddress.Option = InputAddressOption;
|
|
5594
|
+
|
|
4821
5595
|
const InputEmail = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
4822
5596
|
return /*#__PURE__*/jsxRuntime.jsx(InputText, {
|
|
4823
5597
|
ref: ref,
|
|
@@ -4876,39 +5650,6 @@ function InputField({
|
|
|
4876
5650
|
});
|
|
4877
5651
|
}
|
|
4878
5652
|
|
|
4879
|
-
function getIconColor(state, disabled) {
|
|
4880
|
-
if (disabled) return 'black-light';
|
|
4881
|
-
switch (state) {
|
|
4882
|
-
case 'invalid':
|
|
4883
|
-
return 'danger';
|
|
4884
|
-
case 'valid':
|
|
4885
|
-
return 'success';
|
|
4886
|
-
default:
|
|
4887
|
-
return undefined;
|
|
4888
|
-
}
|
|
4889
|
-
}
|
|
4890
|
-
function InputIcon({
|
|
4891
|
-
icon,
|
|
4892
|
-
state,
|
|
4893
|
-
disabled
|
|
4894
|
-
}) {
|
|
4895
|
-
const theme = useTheme();
|
|
4896
|
-
const color = getIconColor(state, disabled);
|
|
4897
|
-
return /*#__PURE__*/jsxRuntime.jsx(TypographyIcon, {
|
|
4898
|
-
color: color,
|
|
4899
|
-
icon: icon,
|
|
4900
|
-
size: theme.kitt.forms.input.icon.size
|
|
4901
|
-
});
|
|
4902
|
-
}
|
|
4903
|
-
|
|
4904
|
-
function InputPressable({
|
|
4905
|
-
...props
|
|
4906
|
-
}) {
|
|
4907
|
-
return /*#__PURE__*/jsxRuntime.jsx(reactNative.Pressable, {
|
|
4908
|
-
...props
|
|
4909
|
-
});
|
|
4910
|
-
}
|
|
4911
|
-
|
|
4912
5653
|
const InputPassword = /*#__PURE__*/React.forwardRef(({
|
|
4913
5654
|
isPasswordDefaultVisible,
|
|
4914
5655
|
right,
|
|
@@ -6788,6 +7529,31 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
6788
7529
|
}
|
|
6789
7530
|
},
|
|
6790
7531
|
forms: {
|
|
7532
|
+
autocomplete: {
|
|
7533
|
+
option: {
|
|
7534
|
+
default: {
|
|
7535
|
+
backgroundColor: theme.forms.autocomplete.option.default.backgroundColor
|
|
7536
|
+
},
|
|
7537
|
+
hovered: {
|
|
7538
|
+
backgroundColor: theme.forms.autocomplete.option.hovered.backgroundColor
|
|
7539
|
+
},
|
|
7540
|
+
focused: {
|
|
7541
|
+
backgroundColor: theme.forms.autocomplete.option.focused.backgroundColor
|
|
7542
|
+
},
|
|
7543
|
+
selected: {
|
|
7544
|
+
backgroundColor: theme.forms.autocomplete.option.selected.backgroundColor
|
|
7545
|
+
},
|
|
7546
|
+
highlighted: {
|
|
7547
|
+
backgroundColor: theme.forms.autocomplete.option.highlighted.backgroundColor
|
|
7548
|
+
},
|
|
7549
|
+
pressed: {
|
|
7550
|
+
backgroundColor: theme.forms.autocomplete.option.pressed.backgroundColor
|
|
7551
|
+
}
|
|
7552
|
+
},
|
|
7553
|
+
optionsContainer: {
|
|
7554
|
+
backgroundColor: theme.forms.autocomplete.optionsContainer.backgroundColor
|
|
7555
|
+
}
|
|
7556
|
+
},
|
|
6791
7557
|
input: {
|
|
6792
7558
|
states: theme.forms.input.states
|
|
6793
7559
|
},
|
|
@@ -7012,6 +7778,11 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
7012
7778
|
borderRadius: theme.dialogModal.borderRadius
|
|
7013
7779
|
},
|
|
7014
7780
|
forms: {
|
|
7781
|
+
autocomplete: {
|
|
7782
|
+
optionsContainer: {
|
|
7783
|
+
borderRadius: theme.forms.autocomplete.optionsContainer.borderRadius
|
|
7784
|
+
}
|
|
7785
|
+
},
|
|
7015
7786
|
input: {
|
|
7016
7787
|
borderRadius: theme.forms.input.borderRadius
|
|
7017
7788
|
},
|
|
@@ -7270,6 +8041,11 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
7270
8041
|
minHeight: theme.feedbackMessage.minHeight
|
|
7271
8042
|
},
|
|
7272
8043
|
forms: {
|
|
8044
|
+
autocomplete: {
|
|
8045
|
+
option: {
|
|
8046
|
+
minHeight: theme.forms.autocomplete.option.minHeight
|
|
8047
|
+
}
|
|
8048
|
+
},
|
|
7273
8049
|
datePicker: {
|
|
7274
8050
|
minHeight: theme.forms.input.minHeight,
|
|
7275
8051
|
day: {
|
|
@@ -7375,6 +8151,11 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
7375
8151
|
overlayPadding: theme.dialogModal.overlayPadding
|
|
7376
8152
|
},
|
|
7377
8153
|
forms: {
|
|
8154
|
+
autocomplete: {
|
|
8155
|
+
option: {
|
|
8156
|
+
verticalPadding: theme.forms.autocomplete.option.verticalPadding
|
|
8157
|
+
}
|
|
8158
|
+
},
|
|
7378
8159
|
datePicker: {
|
|
7379
8160
|
padding: theme.forms.input.padding
|
|
7380
8161
|
},
|
|
@@ -7846,16 +8627,18 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
7846
8627
|
shadowRadius: theme.dialogModal.shadow.radius
|
|
7847
8628
|
}
|
|
7848
8629
|
},
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
8630
|
+
forms: {
|
|
8631
|
+
autocomplete: {
|
|
8632
|
+
optionsContainer: {
|
|
8633
|
+
shadow: {
|
|
8634
|
+
shadowColor: theme.forms.autocomplete.optionsContainer.shadow.color,
|
|
8635
|
+
shadowOffset: {
|
|
8636
|
+
width: theme.forms.autocomplete.optionsContainer.shadow.offsetX,
|
|
8637
|
+
height: theme.forms.autocomplete.optionsContainer.shadow.offsetY
|
|
8638
|
+
},
|
|
8639
|
+
shadowOpacity: theme.forms.autocomplete.optionsContainer.shadow.opacity,
|
|
8640
|
+
shadowRadius: theme.forms.autocomplete.optionsContainer.shadow.radius
|
|
8641
|
+
}
|
|
7859
8642
|
}
|
|
7860
8643
|
}
|
|
7861
8644
|
}
|
|
@@ -9122,10 +9905,12 @@ function BlockSection({
|
|
|
9122
9905
|
});
|
|
9123
9906
|
}
|
|
9124
9907
|
function DemoSection({
|
|
9125
|
-
children
|
|
9908
|
+
children,
|
|
9909
|
+
...props
|
|
9126
9910
|
}) {
|
|
9127
9911
|
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
9128
9912
|
marginBottom: "kitt.16",
|
|
9913
|
+
...props,
|
|
9129
9914
|
children: /*#__PURE__*/jsxRuntime.jsx(StorySection, {
|
|
9130
9915
|
internalIsDemoSection: true,
|
|
9131
9916
|
title: "Demo",
|
|
@@ -10071,6 +10856,7 @@ exports.useToken = nativeBase.useToken;
|
|
|
10071
10856
|
exports.useWindowSize = reactNative.useWindowDimensions;
|
|
10072
10857
|
exports.ActionCard = ActionCard;
|
|
10073
10858
|
exports.Actions = Actions;
|
|
10859
|
+
exports.Autocomplete = Autocomplete;
|
|
10074
10860
|
exports.Avatar = Avatar;
|
|
10075
10861
|
exports.BottomSheet = BottomSheet;
|
|
10076
10862
|
exports.Button = Button;
|
|
@@ -10086,11 +10872,14 @@ exports.ExternalLink = ExternalLink;
|
|
|
10086
10872
|
exports.FlatList = FlatList;
|
|
10087
10873
|
exports.Flex = Flex;
|
|
10088
10874
|
exports.FullscreenModal = FullscreenModal;
|
|
10875
|
+
exports.GoogleMapsApiKeyProvider = GoogleMapsApiKeyProvider;
|
|
10876
|
+
exports.GoogleMapsAutocompleteProvider = GoogleMapsAutocompleteProvider;
|
|
10089
10877
|
exports.HStack = HStack;
|
|
10090
10878
|
exports.Highlight = Highlight;
|
|
10091
10879
|
exports.Icon = Icon;
|
|
10092
10880
|
exports.IconButton = IconButton;
|
|
10093
10881
|
exports.Image = Image;
|
|
10882
|
+
exports.InputAddress = InputAddress;
|
|
10094
10883
|
exports.InputEmail = InputEmail;
|
|
10095
10884
|
exports.InputFeedback = InputFeedback;
|
|
10096
10885
|
exports.InputField = InputField;
|