@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
|
@@ -10,13 +10,19 @@ const reactPortal = require('react-portal');
|
|
|
10
10
|
const reactTransitionGroup = require('react-transition-group');
|
|
11
11
|
const reactNative = require('react-native');
|
|
12
12
|
const twemojiParser = require('twemoji-parser');
|
|
13
|
+
const Downshift = require('downshift');
|
|
14
|
+
const useDebounce = require('use-debounce');
|
|
15
|
+
const jsApiLoader = require('@googlemaps/js-api-loader');
|
|
13
16
|
const libphonenumberJs = require('libphonenumber-js');
|
|
14
17
|
const reactNativeSafeAreaContext = require('react-native-safe-area-context');
|
|
15
18
|
const reactDom = require('@floating-ui/react-dom');
|
|
16
|
-
const downshift = require('downshift');
|
|
17
19
|
const usehooksTs = require('usehooks-ts');
|
|
18
20
|
const addons = require('@storybook/addons');
|
|
19
21
|
|
|
22
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
23
|
+
|
|
24
|
+
const Downshift__default = /*#__PURE__*/_interopDefaultLegacy(Downshift);
|
|
25
|
+
|
|
20
26
|
const View = nativeBase.View;
|
|
21
27
|
const ScrollView = nativeBase.ScrollView;
|
|
22
28
|
const Pressable = nativeBase.Pressable;
|
|
@@ -735,6 +741,42 @@ const feedbackMessage = {
|
|
|
735
741
|
}
|
|
736
742
|
};
|
|
737
743
|
|
|
744
|
+
const autocomplete = {
|
|
745
|
+
option: {
|
|
746
|
+
verticalPadding: 2,
|
|
747
|
+
minHeight: 40,
|
|
748
|
+
default: {
|
|
749
|
+
backgroundColor: colors.white
|
|
750
|
+
},
|
|
751
|
+
hovered: {
|
|
752
|
+
backgroundColor: lateOceanColorPalette.black50
|
|
753
|
+
},
|
|
754
|
+
focused: {
|
|
755
|
+
backgroundColor: lateOceanColorPalette.black50
|
|
756
|
+
},
|
|
757
|
+
selected: {
|
|
758
|
+
backgroundColor: lateOceanColorPalette.black50
|
|
759
|
+
},
|
|
760
|
+
highlighted: {
|
|
761
|
+
backgroundColor: lateOceanColorPalette.black50
|
|
762
|
+
},
|
|
763
|
+
pressed: {
|
|
764
|
+
backgroundColor: lateOceanColorPalette.black100
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
optionsContainer: {
|
|
768
|
+
borderRadius: 10,
|
|
769
|
+
backgroundColor: colors.white,
|
|
770
|
+
shadow: {
|
|
771
|
+
color: colors.black,
|
|
772
|
+
offsetX: 0,
|
|
773
|
+
offsetY: 10,
|
|
774
|
+
opacity: 0.15,
|
|
775
|
+
radius: 20
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
|
|
738
780
|
const checkbox = {
|
|
739
781
|
borderWidth: 2,
|
|
740
782
|
borderRadius: 5,
|
|
@@ -1034,6 +1076,7 @@ const timePicker = {
|
|
|
1034
1076
|
};
|
|
1035
1077
|
|
|
1036
1078
|
const forms = {
|
|
1079
|
+
autocomplete,
|
|
1037
1080
|
datePicker,
|
|
1038
1081
|
input,
|
|
1039
1082
|
radio,
|
|
@@ -2910,7 +2953,7 @@ CardModal.Header = CardModalHeader;
|
|
|
2910
2953
|
CardModal.Footer = CardModalFooter;
|
|
2911
2954
|
CardModal.ModalBehaviour = CardModalBehaviour;
|
|
2912
2955
|
|
|
2913
|
-
function getBackgroundColor$
|
|
2956
|
+
function getBackgroundColor$5({
|
|
2914
2957
|
isDisabled,
|
|
2915
2958
|
isSelected,
|
|
2916
2959
|
isHovered,
|
|
@@ -2943,7 +2986,7 @@ function AnimatedChoiceItemView({
|
|
|
2943
2986
|
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
2944
2987
|
position: "relative",
|
|
2945
2988
|
borderRadius: getBorderRadius(variant),
|
|
2946
|
-
backgroundColor: getBackgroundColor$
|
|
2989
|
+
backgroundColor: getBackgroundColor$5({
|
|
2947
2990
|
isDisabled,
|
|
2948
2991
|
isSelected,
|
|
2949
2992
|
isHovered,
|
|
@@ -3436,6 +3479,395 @@ function ExternalLink({
|
|
|
3436
3479
|
});
|
|
3437
3480
|
}
|
|
3438
3481
|
|
|
3482
|
+
function getIconColor(state, disabled) {
|
|
3483
|
+
if (disabled) return 'black-light';
|
|
3484
|
+
switch (state) {
|
|
3485
|
+
case 'invalid':
|
|
3486
|
+
return 'danger';
|
|
3487
|
+
case 'valid':
|
|
3488
|
+
return 'success';
|
|
3489
|
+
default:
|
|
3490
|
+
return undefined;
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
function InputIcon({
|
|
3494
|
+
icon,
|
|
3495
|
+
state,
|
|
3496
|
+
disabled
|
|
3497
|
+
}) {
|
|
3498
|
+
const theme = useTheme();
|
|
3499
|
+
const color = getIconColor(state, disabled);
|
|
3500
|
+
return /*#__PURE__*/jsxRuntime.jsx(TypographyIcon, {
|
|
3501
|
+
color: color,
|
|
3502
|
+
icon: icon,
|
|
3503
|
+
size: theme.kitt.forms.input.icon.size
|
|
3504
|
+
});
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
function InputPressable({
|
|
3508
|
+
...props
|
|
3509
|
+
}) {
|
|
3510
|
+
return /*#__PURE__*/jsxRuntime.jsx(reactNative.Pressable, {
|
|
3511
|
+
...props
|
|
3512
|
+
});
|
|
3513
|
+
}
|
|
3514
|
+
|
|
3515
|
+
const inputTextContainer = "kitt-u_inputTextContainer_i1encr9g";
|
|
3516
|
+
function InputTextContainer(props) {
|
|
3517
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
3518
|
+
className: inputTextContainer,
|
|
3519
|
+
...props
|
|
3520
|
+
});
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
const InputText = /*#__PURE__*/react.forwardRef(({
|
|
3524
|
+
id,
|
|
3525
|
+
right,
|
|
3526
|
+
state: formState,
|
|
3527
|
+
variant = 'outline',
|
|
3528
|
+
internalForceState,
|
|
3529
|
+
disabled = false,
|
|
3530
|
+
autoCorrect = true,
|
|
3531
|
+
textContentType = 'none',
|
|
3532
|
+
autoComplete = 'off',
|
|
3533
|
+
keyboardType = 'default',
|
|
3534
|
+
multiline,
|
|
3535
|
+
onSubmitEditing,
|
|
3536
|
+
...props
|
|
3537
|
+
}, ref) => {
|
|
3538
|
+
const theme = useTheme();
|
|
3539
|
+
const fontSizeForNativeBase = createNativeBaseFontSize({
|
|
3540
|
+
base: 'body'
|
|
3541
|
+
});
|
|
3542
|
+
return /*#__PURE__*/jsxRuntime.jsxs(InputTextContainer, {
|
|
3543
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(nativeBase.Input, {
|
|
3544
|
+
ref: ref,
|
|
3545
|
+
multiline: multiline,
|
|
3546
|
+
nativeID: id,
|
|
3547
|
+
isDisabled: internalForceState ? internalForceState === 'disabled' : disabled,
|
|
3548
|
+
isHovered: internalForceState ? internalForceState === 'hover' : undefined,
|
|
3549
|
+
isFocused: internalForceState ? internalForceState === 'focus' : undefined,
|
|
3550
|
+
keyboardType: keyboardType,
|
|
3551
|
+
autoComplete: autoComplete,
|
|
3552
|
+
autoCorrect: autoCorrect,
|
|
3553
|
+
textContentType: textContentType,
|
|
3554
|
+
fontSize: fontSizeForNativeBase,
|
|
3555
|
+
lineHeight:
|
|
3556
|
+
// On basic text input, we set the line-height to zero for iOS to fix vertical text alignment
|
|
3557
|
+
// This is a iOS only fix since having 0 as a line-height value breaks text inputs on Android
|
|
3558
|
+
fontSizeForNativeBase,
|
|
3559
|
+
fontWeight: "bodies.regular",
|
|
3560
|
+
fontFamily: "bodies.regular",
|
|
3561
|
+
py: !multiline && "web" !== 'web' ? 0 : undefined,
|
|
3562
|
+
variant: variant,
|
|
3563
|
+
...props,
|
|
3564
|
+
onSubmitEditing: multiline ? () => null : onSubmitEditing
|
|
3565
|
+
}), right ? /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
3566
|
+
position: "absolute",
|
|
3567
|
+
right: 0,
|
|
3568
|
+
top: 0,
|
|
3569
|
+
bottom: 0,
|
|
3570
|
+
justifyContent: "center",
|
|
3571
|
+
padding: theme.kitt.forms.input.rightContainer.padding,
|
|
3572
|
+
children: right
|
|
3573
|
+
}) : null]
|
|
3574
|
+
});
|
|
3575
|
+
});
|
|
3576
|
+
|
|
3577
|
+
function getBackgroundColor$4({
|
|
3578
|
+
isSelected,
|
|
3579
|
+
isHighlighted,
|
|
3580
|
+
isPressed,
|
|
3581
|
+
isHovered,
|
|
3582
|
+
isFocused
|
|
3583
|
+
}) {
|
|
3584
|
+
const baseKey = 'kitt.forms.autocomplete.option';
|
|
3585
|
+
if (isHighlighted) {
|
|
3586
|
+
return `${baseKey}.highlighted.backgroundColor`;
|
|
3587
|
+
}
|
|
3588
|
+
if (isPressed) {
|
|
3589
|
+
return `${baseKey}.pressed.backgroundColor`;
|
|
3590
|
+
}
|
|
3591
|
+
if (isHovered) {
|
|
3592
|
+
return `${baseKey}.hovered.backgroundColor`;
|
|
3593
|
+
}
|
|
3594
|
+
if (isFocused) {
|
|
3595
|
+
return `${baseKey}.focused.backgroundColor`;
|
|
3596
|
+
}
|
|
3597
|
+
if (isSelected) {
|
|
3598
|
+
return `${baseKey}.selected.backgroundColor`;
|
|
3599
|
+
}
|
|
3600
|
+
return `${baseKey}.default.backgroundColor`;
|
|
3601
|
+
}
|
|
3602
|
+
function AutocompleteItem({
|
|
3603
|
+
children,
|
|
3604
|
+
isSelected,
|
|
3605
|
+
isHighlighted,
|
|
3606
|
+
isHovered,
|
|
3607
|
+
isFocused,
|
|
3608
|
+
isPressed
|
|
3609
|
+
}) {
|
|
3610
|
+
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
3611
|
+
justifyContent: "center",
|
|
3612
|
+
width: "100%",
|
|
3613
|
+
minHeight: "kitt.forms.autocomplete.option.minHeight",
|
|
3614
|
+
borderRadius: "kitt.1",
|
|
3615
|
+
padding: "kitt.1",
|
|
3616
|
+
backgroundColor: getBackgroundColor$4({
|
|
3617
|
+
isSelected,
|
|
3618
|
+
isHighlighted,
|
|
3619
|
+
isPressed,
|
|
3620
|
+
isHovered,
|
|
3621
|
+
isFocused
|
|
3622
|
+
}),
|
|
3623
|
+
children: children
|
|
3624
|
+
});
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
function AutocompleteItemsListContainer({
|
|
3628
|
+
testID,
|
|
3629
|
+
children,
|
|
3630
|
+
zIndex = 1000
|
|
3631
|
+
}) {
|
|
3632
|
+
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
3633
|
+
testID: testID,
|
|
3634
|
+
zIndex: zIndex,
|
|
3635
|
+
top: "kitt.2",
|
|
3636
|
+
left: 0,
|
|
3637
|
+
position: "absolute",
|
|
3638
|
+
flexGrow: 1,
|
|
3639
|
+
width: "100%",
|
|
3640
|
+
paddingY: "kitt.2",
|
|
3641
|
+
borderRadius: "kitt.forms.autocomplete.optionsContainer.borderRadius",
|
|
3642
|
+
backgroundColor: "kitt.forms.autocomplete.optionsContainer.backgroundColor",
|
|
3643
|
+
shadow: "kitt.forms.autocomplete.optionsContainer.shadow",
|
|
3644
|
+
_android: {
|
|
3645
|
+
style: {
|
|
3646
|
+
elevation: 2
|
|
3647
|
+
}
|
|
3648
|
+
},
|
|
3649
|
+
children: children
|
|
3650
|
+
});
|
|
3651
|
+
}
|
|
3652
|
+
|
|
3653
|
+
function AutocompleteOption({
|
|
3654
|
+
children,
|
|
3655
|
+
...props
|
|
3656
|
+
}) {
|
|
3657
|
+
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
3658
|
+
paddingX: {
|
|
3659
|
+
base: 'kitt.2',
|
|
3660
|
+
small: 'kitt.4'
|
|
3661
|
+
},
|
|
3662
|
+
paddingY: "kitt.forms.autocomplete.option.verticalPadding",
|
|
3663
|
+
...props,
|
|
3664
|
+
children: children
|
|
3665
|
+
});
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
function isReactElement(element) {
|
|
3669
|
+
return typeof element === 'object' && element !== null && 'type' in element && 'props' in element;
|
|
3670
|
+
}
|
|
3671
|
+
function Autocomplete({
|
|
3672
|
+
children,
|
|
3673
|
+
name,
|
|
3674
|
+
disabled,
|
|
3675
|
+
placeholder,
|
|
3676
|
+
isInitialOpen,
|
|
3677
|
+
initialValue,
|
|
3678
|
+
containerProps,
|
|
3679
|
+
filterItemBasedOnCurrentInputValue,
|
|
3680
|
+
checkSelectedItem,
|
|
3681
|
+
itemToString,
|
|
3682
|
+
right,
|
|
3683
|
+
onChange,
|
|
3684
|
+
onFocus,
|
|
3685
|
+
onBlur,
|
|
3686
|
+
onInputChange,
|
|
3687
|
+
onSelectItem,
|
|
3688
|
+
/**
|
|
3689
|
+
* @description web only callback
|
|
3690
|
+
*/
|
|
3691
|
+
onOuterPress,
|
|
3692
|
+
errorElement,
|
|
3693
|
+
emptyResultsElement,
|
|
3694
|
+
inputTestID = 'kitt.Autocomplete.inputText',
|
|
3695
|
+
listContainerTestID = 'kitt.Autocomplete.listContainer',
|
|
3696
|
+
zIndex = 1000,
|
|
3697
|
+
...props
|
|
3698
|
+
}) {
|
|
3699
|
+
const childrenArray = react.Children.toArray(children);
|
|
3700
|
+
const items = childrenArray.filter(isReactElement).map(child => ({
|
|
3701
|
+
child,
|
|
3702
|
+
item: child.props.item
|
|
3703
|
+
}));
|
|
3704
|
+
return /*#__PURE__*/jsxRuntime.jsx(Downshift__default, {
|
|
3705
|
+
defaultIsOpen: isInitialOpen,
|
|
3706
|
+
initialSelectedItem: initialValue,
|
|
3707
|
+
initialInputValue: initialValue ? itemToString(initialValue) : undefined,
|
|
3708
|
+
itemToString: item => {
|
|
3709
|
+
// Prevents returning null values
|
|
3710
|
+
if (!itemToString) return '';
|
|
3711
|
+
return itemToString(item || undefined);
|
|
3712
|
+
},
|
|
3713
|
+
stateReducer: (state, changes) => {
|
|
3714
|
+
switch (changes.type) {
|
|
3715
|
+
case Downshift__default.stateChangeTypes.changeInput:
|
|
3716
|
+
return {
|
|
3717
|
+
...changes,
|
|
3718
|
+
selectedItem: null
|
|
3719
|
+
};
|
|
3720
|
+
default:
|
|
3721
|
+
return changes;
|
|
3722
|
+
}
|
|
3723
|
+
},
|
|
3724
|
+
onChange: (selectedItem, stateAndHelpers) => {
|
|
3725
|
+
if (onChange) {
|
|
3726
|
+
onChange(selectedItem, stateAndHelpers);
|
|
3727
|
+
}
|
|
3728
|
+
},
|
|
3729
|
+
onSelect: onSelectItem,
|
|
3730
|
+
onOuterClick: onOuterPress,
|
|
3731
|
+
onInputValueChange: onInputChange,
|
|
3732
|
+
children: ({
|
|
3733
|
+
getRootProps,
|
|
3734
|
+
getInputProps,
|
|
3735
|
+
getMenuProps,
|
|
3736
|
+
getItemProps,
|
|
3737
|
+
getToggleButtonProps,
|
|
3738
|
+
isOpen,
|
|
3739
|
+
inputValue,
|
|
3740
|
+
highlightedIndex,
|
|
3741
|
+
selectedItem,
|
|
3742
|
+
openMenu
|
|
3743
|
+
}) => {
|
|
3744
|
+
const shouldSuppressRefError = "web" !== 'web';
|
|
3745
|
+
const rootProps = getRootProps(undefined, {
|
|
3746
|
+
suppressRefError: shouldSuppressRefError
|
|
3747
|
+
});
|
|
3748
|
+
const menuProps = getMenuProps(undefined, {
|
|
3749
|
+
suppressRefError: shouldSuppressRefError
|
|
3750
|
+
});
|
|
3751
|
+
const {
|
|
3752
|
+
onClick: onClickToggle,
|
|
3753
|
+
onPress: onPressToggle,
|
|
3754
|
+
...toggleProps
|
|
3755
|
+
} = getToggleButtonProps({
|
|
3756
|
+
disabled
|
|
3757
|
+
});
|
|
3758
|
+
const {
|
|
3759
|
+
onKeyDown,
|
|
3760
|
+
onFocus: onSearchInputFocus,
|
|
3761
|
+
onBlur: onSearchInputBlur,
|
|
3762
|
+
onChange: onSearchInputChange,
|
|
3763
|
+
...inputProps
|
|
3764
|
+
} = getInputProps({
|
|
3765
|
+
placeholder,
|
|
3766
|
+
disabled
|
|
3767
|
+
});
|
|
3768
|
+
const hasCurrentSearch = inputValue && inputValue.length > 0;
|
|
3769
|
+
const currentItems = hasCurrentSearch && filterItemBasedOnCurrentInputValue ? items.filter(({
|
|
3770
|
+
item
|
|
3771
|
+
}) => {
|
|
3772
|
+
if (!filterItemBasedOnCurrentInputValue) return true;
|
|
3773
|
+
return filterItemBasedOnCurrentInputValue(item, inputValue || '');
|
|
3774
|
+
}) : items;
|
|
3775
|
+
|
|
3776
|
+
// 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
|
|
3777
|
+
const isCurrentlyOpen = isOpen ? currentItems.length > 0 || !!errorElement || !!emptyResultsElement : false;
|
|
3778
|
+
const canDisplayCollapseButton = currentItems.length > 0 || !!errorElement || !!emptyResultsElement;
|
|
3779
|
+
return /*#__PURE__*/jsxRuntime.jsxs(View, {
|
|
3780
|
+
...rootProps,
|
|
3781
|
+
...containerProps,
|
|
3782
|
+
zIndex: zIndex,
|
|
3783
|
+
position: "relative",
|
|
3784
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(InputText, {
|
|
3785
|
+
...inputProps,
|
|
3786
|
+
...props,
|
|
3787
|
+
name: name,
|
|
3788
|
+
testID: inputTestID,
|
|
3789
|
+
right: right || (canDisplayCollapseButton ? /*#__PURE__*/jsxRuntime.jsx(InputPressable, {
|
|
3790
|
+
...toggleProps,
|
|
3791
|
+
testID: "kitt.Autocomplete.listToggle",
|
|
3792
|
+
hitSlop: 40,
|
|
3793
|
+
onPress: e => {
|
|
3794
|
+
onClickToggle(e);
|
|
3795
|
+
},
|
|
3796
|
+
children: /*#__PURE__*/jsxRuntime.jsx(InputIcon, {
|
|
3797
|
+
icon: isCurrentlyOpen ? /*#__PURE__*/jsxRuntime.jsx(kittIcons.ArrowUpIcon, {}) : /*#__PURE__*/jsxRuntime.jsx(kittIcons.ArrowDownIcon, {})
|
|
3798
|
+
})
|
|
3799
|
+
}) : null),
|
|
3800
|
+
onFocus: e => {
|
|
3801
|
+
openMenu();
|
|
3802
|
+
/** @ts-expect-error onFocus wants web events */
|
|
3803
|
+
if (onSearchInputFocus) onSearchInputFocus(e);
|
|
3804
|
+
if (onFocus) onFocus(e);
|
|
3805
|
+
},
|
|
3806
|
+
onBlur: e => {
|
|
3807
|
+
/** @ts-expect-error onBlur wants web events */
|
|
3808
|
+
if (onSearchInputBlur) onSearchInputBlur(e);
|
|
3809
|
+
if (onBlur) onBlur(e);
|
|
3810
|
+
}
|
|
3811
|
+
/** @ts-expect-error onSearchInputChange wants web events */,
|
|
3812
|
+
onChange: onSearchInputChange
|
|
3813
|
+
/** @ts-expect-error onKeyDown wants web events */,
|
|
3814
|
+
onKeyPress: onKeyDown
|
|
3815
|
+
}), /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
3816
|
+
...menuProps,
|
|
3817
|
+
position: "relative",
|
|
3818
|
+
children: isCurrentlyOpen ? /*#__PURE__*/jsxRuntime.jsxs(AutocompleteItemsListContainer, {
|
|
3819
|
+
testID: listContainerTestID,
|
|
3820
|
+
children: [currentItems.map(({
|
|
3821
|
+
child,
|
|
3822
|
+
item
|
|
3823
|
+
}, index) => {
|
|
3824
|
+
const {
|
|
3825
|
+
onClick,
|
|
3826
|
+
onPress,
|
|
3827
|
+
role,
|
|
3828
|
+
'aria-selected': ariaSelected,
|
|
3829
|
+
...itemProps
|
|
3830
|
+
} = getItemProps({
|
|
3831
|
+
item,
|
|
3832
|
+
index
|
|
3833
|
+
});
|
|
3834
|
+
return /*#__PURE__*/jsxRuntime.jsx(Pressable, {
|
|
3835
|
+
...itemProps,
|
|
3836
|
+
accessibilityRole: role,
|
|
3837
|
+
accessibilityState: {
|
|
3838
|
+
selected: ariaSelected
|
|
3839
|
+
},
|
|
3840
|
+
disabled: disabled,
|
|
3841
|
+
onPress: e => {
|
|
3842
|
+
if (onClick) onClick(e);
|
|
3843
|
+
},
|
|
3844
|
+
children: ({
|
|
3845
|
+
isHovered,
|
|
3846
|
+
isFocused,
|
|
3847
|
+
isPressed
|
|
3848
|
+
}) => /*#__PURE__*/jsxRuntime.jsx(AutocompleteItem, {
|
|
3849
|
+
item: item,
|
|
3850
|
+
isHighlighted: highlightedIndex === index,
|
|
3851
|
+
isHovered: isHovered,
|
|
3852
|
+
isFocused: isFocused,
|
|
3853
|
+
isPressed: isPressed,
|
|
3854
|
+
isSelected: checkSelectedItem(selectedItem || undefined, item),
|
|
3855
|
+
children: child
|
|
3856
|
+
})
|
|
3857
|
+
}, itemProps.id);
|
|
3858
|
+
}), errorElement, emptyResultsElement]
|
|
3859
|
+
}) : null
|
|
3860
|
+
})]
|
|
3861
|
+
});
|
|
3862
|
+
}
|
|
3863
|
+
});
|
|
3864
|
+
}
|
|
3865
|
+
Autocomplete.Option = AutocompleteOption;
|
|
3866
|
+
/**
|
|
3867
|
+
* @description: This is exported for testing purposes only
|
|
3868
|
+
*/
|
|
3869
|
+
Autocomplete.UnsafeInternalItem = AutocompleteItem;
|
|
3870
|
+
|
|
3439
3871
|
function getBackgroundColor$3({
|
|
3440
3872
|
isDisabled,
|
|
3441
3873
|
isPressed,
|
|
@@ -3746,68 +4178,6 @@ function stringToNumber(text) {
|
|
|
3746
4178
|
return parseInt(text, 10);
|
|
3747
4179
|
}
|
|
3748
4180
|
|
|
3749
|
-
const inputTextContainer = "kitt-u_inputTextContainer_i1encr9g";
|
|
3750
|
-
function InputTextContainer(props) {
|
|
3751
|
-
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
3752
|
-
className: inputTextContainer,
|
|
3753
|
-
...props
|
|
3754
|
-
});
|
|
3755
|
-
}
|
|
3756
|
-
|
|
3757
|
-
const InputText = /*#__PURE__*/react.forwardRef(({
|
|
3758
|
-
id,
|
|
3759
|
-
right,
|
|
3760
|
-
state: formState,
|
|
3761
|
-
variant = 'outline',
|
|
3762
|
-
internalForceState,
|
|
3763
|
-
disabled = false,
|
|
3764
|
-
autoCorrect = true,
|
|
3765
|
-
textContentType = 'none',
|
|
3766
|
-
autoComplete = 'off',
|
|
3767
|
-
keyboardType = 'default',
|
|
3768
|
-
multiline,
|
|
3769
|
-
onSubmitEditing,
|
|
3770
|
-
...props
|
|
3771
|
-
}, ref) => {
|
|
3772
|
-
const theme = useTheme();
|
|
3773
|
-
const fontSizeForNativeBase = createNativeBaseFontSize({
|
|
3774
|
-
base: 'body'
|
|
3775
|
-
});
|
|
3776
|
-
return /*#__PURE__*/jsxRuntime.jsxs(InputTextContainer, {
|
|
3777
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(nativeBase.Input, {
|
|
3778
|
-
ref: ref,
|
|
3779
|
-
multiline: multiline,
|
|
3780
|
-
nativeID: id,
|
|
3781
|
-
isDisabled: internalForceState ? internalForceState === 'disabled' : disabled,
|
|
3782
|
-
isHovered: internalForceState ? internalForceState === 'hover' : undefined,
|
|
3783
|
-
isFocused: internalForceState ? internalForceState === 'focus' : undefined,
|
|
3784
|
-
keyboardType: keyboardType,
|
|
3785
|
-
autoComplete: autoComplete,
|
|
3786
|
-
autoCorrect: autoCorrect,
|
|
3787
|
-
textContentType: textContentType,
|
|
3788
|
-
fontSize: fontSizeForNativeBase,
|
|
3789
|
-
lineHeight:
|
|
3790
|
-
// On basic text input, we set the line-height to zero for iOS to fix vertical text alignment
|
|
3791
|
-
// This is a iOS only fix since having 0 as a line-height value breaks text inputs on Android
|
|
3792
|
-
fontSizeForNativeBase,
|
|
3793
|
-
fontWeight: "bodies.regular",
|
|
3794
|
-
fontFamily: "bodies.regular",
|
|
3795
|
-
py: !multiline && "web" !== 'web' ? 0 : undefined,
|
|
3796
|
-
variant: variant,
|
|
3797
|
-
...props,
|
|
3798
|
-
onSubmitEditing: multiline ? () => null : onSubmitEditing
|
|
3799
|
-
}), right ? /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
3800
|
-
position: "absolute",
|
|
3801
|
-
right: 0,
|
|
3802
|
-
top: 0,
|
|
3803
|
-
bottom: 0,
|
|
3804
|
-
justifyContent: "center",
|
|
3805
|
-
padding: theme.kitt.forms.input.rightContainer.padding,
|
|
3806
|
-
children: right
|
|
3807
|
-
}) : null]
|
|
3808
|
-
});
|
|
3809
|
-
});
|
|
3810
|
-
|
|
3811
4181
|
function getCurrentInternalForcedState$1({
|
|
3812
4182
|
isDisabled,
|
|
3813
4183
|
isHoveredInternal,
|
|
@@ -4030,6 +4400,402 @@ const DatePicker = /*#__PURE__*/react.forwardRef(({
|
|
|
4030
4400
|
});
|
|
4031
4401
|
});
|
|
4032
4402
|
|
|
4403
|
+
const GoogleMapsApiKeyContext = /*#__PURE__*/react.createContext(undefined);
|
|
4404
|
+
function GoogleMapsApiKeyProvider({
|
|
4405
|
+
children,
|
|
4406
|
+
apiKey
|
|
4407
|
+
}) {
|
|
4408
|
+
return /*#__PURE__*/jsxRuntime.jsx(GoogleMapsApiKeyContext.Provider, {
|
|
4409
|
+
value: apiKey,
|
|
4410
|
+
children: children
|
|
4411
|
+
});
|
|
4412
|
+
}
|
|
4413
|
+
|
|
4414
|
+
function useGoogleMapApiKey() {
|
|
4415
|
+
const context = react.useContext(GoogleMapsApiKeyContext);
|
|
4416
|
+
if (!context) {
|
|
4417
|
+
throw new Error('<GoogleMapsApiKeyContext> missing in the react tree');
|
|
4418
|
+
}
|
|
4419
|
+
return context;
|
|
4420
|
+
}
|
|
4421
|
+
|
|
4422
|
+
function useGoogleMapsApi() {
|
|
4423
|
+
const apiKey = useGoogleMapApiKey();
|
|
4424
|
+
const autoCompleteServiceInstanceRef = react.useRef(null);
|
|
4425
|
+
const placesServiceInstanceRef = react.useRef(null);
|
|
4426
|
+
react.useEffect(() => {
|
|
4427
|
+
if (autoCompleteServiceInstanceRef.current && placesServiceInstanceRef.current) return;
|
|
4428
|
+
const loader = new jsApiLoader.Loader({
|
|
4429
|
+
apiKey,
|
|
4430
|
+
libraries: ['places']
|
|
4431
|
+
});
|
|
4432
|
+
(async function () {
|
|
4433
|
+
try {
|
|
4434
|
+
const placeApi = await loader.importLibrary('places');
|
|
4435
|
+
autoCompleteServiceInstanceRef.current = new placeApi.AutocompleteService();
|
|
4436
|
+
placesServiceInstanceRef.current = new placeApi.PlacesService(document.createElement('div'));
|
|
4437
|
+
} catch (error) {
|
|
4438
|
+
console.error(error);
|
|
4439
|
+
}
|
|
4440
|
+
})();
|
|
4441
|
+
}, [apiKey]);
|
|
4442
|
+
return {
|
|
4443
|
+
autoComplete: {
|
|
4444
|
+
getPlacePredictions: input => {
|
|
4445
|
+
const promise = new Promise(resolve => {
|
|
4446
|
+
autoCompleteServiceInstanceRef.current?.getPlacePredictions({
|
|
4447
|
+
input
|
|
4448
|
+
}, (predictions, status) => {
|
|
4449
|
+
if (status !== google.maps.places.PlacesServiceStatus.OK) {
|
|
4450
|
+
resolve({
|
|
4451
|
+
status,
|
|
4452
|
+
results: []
|
|
4453
|
+
});
|
|
4454
|
+
return;
|
|
4455
|
+
}
|
|
4456
|
+
resolve({
|
|
4457
|
+
results: predictions,
|
|
4458
|
+
status
|
|
4459
|
+
});
|
|
4460
|
+
});
|
|
4461
|
+
});
|
|
4462
|
+
return promise;
|
|
4463
|
+
}
|
|
4464
|
+
},
|
|
4465
|
+
placesService: {
|
|
4466
|
+
getDetails: placeId => {
|
|
4467
|
+
const promise = new Promise(resolve => {
|
|
4468
|
+
placesServiceInstanceRef.current?.getDetails({
|
|
4469
|
+
placeId
|
|
4470
|
+
}, (place, status) => {
|
|
4471
|
+
if (status !== google.maps.places.PlacesServiceStatus.OK) {
|
|
4472
|
+
resolve({
|
|
4473
|
+
status,
|
|
4474
|
+
result: undefined
|
|
4475
|
+
});
|
|
4476
|
+
return;
|
|
4477
|
+
}
|
|
4478
|
+
resolve({
|
|
4479
|
+
result: place,
|
|
4480
|
+
status
|
|
4481
|
+
});
|
|
4482
|
+
});
|
|
4483
|
+
});
|
|
4484
|
+
return promise;
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
};
|
|
4488
|
+
}
|
|
4489
|
+
|
|
4490
|
+
const googleMapsAutocompleteReducer = (state, action) => {
|
|
4491
|
+
switch (action.type) {
|
|
4492
|
+
case 'search-change':
|
|
4493
|
+
{
|
|
4494
|
+
return {
|
|
4495
|
+
...state,
|
|
4496
|
+
hasSearchError: false,
|
|
4497
|
+
isLoadingSearch: true
|
|
4498
|
+
};
|
|
4499
|
+
}
|
|
4500
|
+
case 'search-success':
|
|
4501
|
+
{
|
|
4502
|
+
return {
|
|
4503
|
+
...state,
|
|
4504
|
+
hasSearchError: false,
|
|
4505
|
+
isLoadingSearch: false,
|
|
4506
|
+
items: action.payload.results
|
|
4507
|
+
};
|
|
4508
|
+
}
|
|
4509
|
+
case 'search-error':
|
|
4510
|
+
{
|
|
4511
|
+
return {
|
|
4512
|
+
...state,
|
|
4513
|
+
hasSearchError: true,
|
|
4514
|
+
isLoadingSearch: false,
|
|
4515
|
+
items: []
|
|
4516
|
+
};
|
|
4517
|
+
}
|
|
4518
|
+
case 'select-result':
|
|
4519
|
+
{
|
|
4520
|
+
return {
|
|
4521
|
+
...state,
|
|
4522
|
+
hasSelectResultError: false,
|
|
4523
|
+
isLoadingResultDetails: true
|
|
4524
|
+
};
|
|
4525
|
+
}
|
|
4526
|
+
case 'select-result-success':
|
|
4527
|
+
{
|
|
4528
|
+
return {
|
|
4529
|
+
...state,
|
|
4530
|
+
hasSelectResultError: false,
|
|
4531
|
+
isLoadingResultDetails: false,
|
|
4532
|
+
currentSelectedValue: action.payload.result
|
|
4533
|
+
};
|
|
4534
|
+
}
|
|
4535
|
+
case 'select-result-error':
|
|
4536
|
+
{
|
|
4537
|
+
return {
|
|
4538
|
+
...state,
|
|
4539
|
+
hasSelectResultError: true,
|
|
4540
|
+
isLoadingResultDetails: false,
|
|
4541
|
+
currentSelectedValue: undefined
|
|
4542
|
+
};
|
|
4543
|
+
}
|
|
4544
|
+
default:
|
|
4545
|
+
return state;
|
|
4546
|
+
}
|
|
4547
|
+
};
|
|
4548
|
+
|
|
4549
|
+
function findComponentByType(typeName, components) {
|
|
4550
|
+
return components.find(component => component.types.includes(typeName));
|
|
4551
|
+
}
|
|
4552
|
+
const matchStreetNumberWithOriginalAddress = (streetNumber = '', address = '') => {
|
|
4553
|
+
const [, number = '', extension = ''] = / *(\d*[-/_]{0,1}\d*) *(bis|ter|quater|quinquies|sexies|septies|octies|novies|decies|[a-z])? /i.exec(address) || [];
|
|
4554
|
+
if (number) return `${number}${extension}`;
|
|
4555
|
+
return streetNumber;
|
|
4556
|
+
};
|
|
4557
|
+
const formatAddressFromGoogle = (placeResult, originalAddress) => {
|
|
4558
|
+
const {
|
|
4559
|
+
address_components: addressComponents = []
|
|
4560
|
+
} = placeResult;
|
|
4561
|
+
return {
|
|
4562
|
+
source: 'google',
|
|
4563
|
+
lat: placeResult.geometry?.location.lat(),
|
|
4564
|
+
lng: placeResult.geometry?.location.lng(),
|
|
4565
|
+
locality: findComponentByType('locality', addressComponents)?.long_name,
|
|
4566
|
+
subLocality: findComponentByType('sublocality', addressComponents)?.long_name,
|
|
4567
|
+
zipcode: findComponentByType('postal_code', addressComponents)?.long_name,
|
|
4568
|
+
streetName: findComponentByType('route', addressComponents)?.long_name,
|
|
4569
|
+
streetNumber: matchStreetNumberWithOriginalAddress(findComponentByType('street_number', addressComponents)?.long_name, originalAddress),
|
|
4570
|
+
country: findComponentByType('country', addressComponents)?.long_name,
|
|
4571
|
+
administrativeAreaLevel1: findComponentByType('administrative_area_level_1', addressComponents)?.long_name,
|
|
4572
|
+
administrativeAreaLevel2: findComponentByType('administrative_area_level_1', addressComponents)?.long_name
|
|
4573
|
+
};
|
|
4574
|
+
};
|
|
4575
|
+
|
|
4576
|
+
const GoogleMapsAutocompleteContext = /*#__PURE__*/react.createContext({
|
|
4577
|
+
state: {
|
|
4578
|
+
items: [],
|
|
4579
|
+
currentSelectedValue: undefined,
|
|
4580
|
+
isLoadingSearch: false,
|
|
4581
|
+
hasSearchError: false,
|
|
4582
|
+
hasSelectResultError: false,
|
|
4583
|
+
isLoadingResultDetails: false,
|
|
4584
|
+
shouldDisplayEmptyStateWhenNoResults: false
|
|
4585
|
+
},
|
|
4586
|
+
onInputChange: () => {
|
|
4587
|
+
return Promise.resolve();
|
|
4588
|
+
},
|
|
4589
|
+
onSelectItem: () => {}
|
|
4590
|
+
});
|
|
4591
|
+
function GoogleMapsAutocompleteProvider({
|
|
4592
|
+
children,
|
|
4593
|
+
minCharsToSearch = 3,
|
|
4594
|
+
debounceTimeout = 950
|
|
4595
|
+
}) {
|
|
4596
|
+
const mapsApi = useGoogleMapsApi();
|
|
4597
|
+
const searchResultsCache = react.useRef({});
|
|
4598
|
+
const resultDetailsCache = react.useRef({});
|
|
4599
|
+
const [state, dispatch] = react.useReducer(googleMapsAutocompleteReducer, {
|
|
4600
|
+
items: [],
|
|
4601
|
+
shouldDisplayEmptyStateWhenNoResults: false
|
|
4602
|
+
});
|
|
4603
|
+
const handleInputChange = useDebounce.useDebouncedCallback(react.useCallback(async value => {
|
|
4604
|
+
if (value.length < minCharsToSearch) return;
|
|
4605
|
+
dispatch({
|
|
4606
|
+
type: 'search-change'
|
|
4607
|
+
});
|
|
4608
|
+
|
|
4609
|
+
// If the user types the same value as the previous search, we don't need to call the API again
|
|
4610
|
+
const predictionsPromise = searchResultsCache.current[value] ? Promise.resolve({
|
|
4611
|
+
results: searchResultsCache.current[value],
|
|
4612
|
+
status: 'OK'
|
|
4613
|
+
}) : mapsApi.autoComplete.getPlacePredictions(value);
|
|
4614
|
+
try {
|
|
4615
|
+
const {
|
|
4616
|
+
results,
|
|
4617
|
+
status
|
|
4618
|
+
} = await predictionsPromise;
|
|
4619
|
+
if (status !== 'OK') {
|
|
4620
|
+
dispatch({
|
|
4621
|
+
type: 'search-error'
|
|
4622
|
+
});
|
|
4623
|
+
return;
|
|
4624
|
+
}
|
|
4625
|
+
|
|
4626
|
+
// We cache the results to avoid calling the API again if the user types the same value
|
|
4627
|
+
searchResultsCache.current[value] = results;
|
|
4628
|
+
dispatch({
|
|
4629
|
+
type: 'search-success',
|
|
4630
|
+
payload: {
|
|
4631
|
+
results
|
|
4632
|
+
}
|
|
4633
|
+
});
|
|
4634
|
+
} catch (error) {
|
|
4635
|
+
dispatch({
|
|
4636
|
+
type: 'search-error'
|
|
4637
|
+
});
|
|
4638
|
+
}
|
|
4639
|
+
}, [mapsApi.autoComplete, minCharsToSearch]), debounceTimeout);
|
|
4640
|
+
const handleSelectItem = react.useCallback(async (item, onChange) => {
|
|
4641
|
+
// This case should never happen but it's here to avoid a TS error
|
|
4642
|
+
if (!item?.place_id) {
|
|
4643
|
+
if (onChange) onChange(undefined);
|
|
4644
|
+
return;
|
|
4645
|
+
}
|
|
4646
|
+
dispatch({
|
|
4647
|
+
type: 'select-result'
|
|
4648
|
+
});
|
|
4649
|
+
try {
|
|
4650
|
+
// If we already have the details in cache, we don't need to fetch them again
|
|
4651
|
+
const placePromise = resultDetailsCache.current[item.place_id] ? Promise.resolve(resultDetailsCache.current[item.place_id]) : mapsApi.placesService.getDetails(item.place_id).then(({
|
|
4652
|
+
result
|
|
4653
|
+
}) => result);
|
|
4654
|
+
const place = await placePromise;
|
|
4655
|
+
if (!place) {
|
|
4656
|
+
dispatch({
|
|
4657
|
+
type: 'select-result-error'
|
|
4658
|
+
});
|
|
4659
|
+
if (onChange) onChange(undefined);
|
|
4660
|
+
return;
|
|
4661
|
+
}
|
|
4662
|
+
dispatch({
|
|
4663
|
+
type: 'select-result-success',
|
|
4664
|
+
payload: {
|
|
4665
|
+
result: place
|
|
4666
|
+
}
|
|
4667
|
+
});
|
|
4668
|
+
const formattedAddress = formatAddressFromGoogle(place, item.description);
|
|
4669
|
+
|
|
4670
|
+
// We cache the result details to avoid fetching them again if the user selects the same item
|
|
4671
|
+
resultDetailsCache.current[item.place_id] = place;
|
|
4672
|
+
if (onChange) onChange(formattedAddress);
|
|
4673
|
+
} catch (error) {
|
|
4674
|
+
dispatch({
|
|
4675
|
+
type: 'select-result-error'
|
|
4676
|
+
});
|
|
4677
|
+
if (onChange) onChange(undefined);
|
|
4678
|
+
}
|
|
4679
|
+
}, [mapsApi.placesService]);
|
|
4680
|
+
const api = react.useMemo(() => ({
|
|
4681
|
+
state,
|
|
4682
|
+
onSelectItem: handleSelectItem,
|
|
4683
|
+
onInputChange: handleInputChange
|
|
4684
|
+
}), [handleInputChange, handleSelectItem, state]);
|
|
4685
|
+
return /*#__PURE__*/jsxRuntime.jsx(GoogleMapsAutocompleteContext.Provider, {
|
|
4686
|
+
value: api,
|
|
4687
|
+
children: children
|
|
4688
|
+
});
|
|
4689
|
+
}
|
|
4690
|
+
|
|
4691
|
+
function useGoogleMapsAutocomplete() {
|
|
4692
|
+
const context = react.useContext(GoogleMapsAutocompleteContext);
|
|
4693
|
+
if (!context) {
|
|
4694
|
+
throw new Error('<GoogleMapsAutocompleteProvider> missing in the react tree');
|
|
4695
|
+
}
|
|
4696
|
+
return context;
|
|
4697
|
+
}
|
|
4698
|
+
|
|
4699
|
+
function InputAddressOption({
|
|
4700
|
+
item
|
|
4701
|
+
}) {
|
|
4702
|
+
const sharedTransform = {
|
|
4703
|
+
style: {
|
|
4704
|
+
transform: [{
|
|
4705
|
+
translateY: 4
|
|
4706
|
+
}]
|
|
4707
|
+
}
|
|
4708
|
+
};
|
|
4709
|
+
return /*#__PURE__*/jsxRuntime.jsx(Autocomplete.Option, {
|
|
4710
|
+
item: item,
|
|
4711
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(HStack, {
|
|
4712
|
+
space: "kitt.2",
|
|
4713
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4714
|
+
_web: sharedTransform,
|
|
4715
|
+
_ios: sharedTransform,
|
|
4716
|
+
_android: sharedTransform,
|
|
4717
|
+
children: /*#__PURE__*/jsxRuntime.jsx(TypographyIcon, {
|
|
4718
|
+
icon: /*#__PURE__*/jsxRuntime.jsx(kittIcons.MapPinIcon, {}),
|
|
4719
|
+
color: "black"
|
|
4720
|
+
})
|
|
4721
|
+
}), /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
4722
|
+
flexShrink: 1,
|
|
4723
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(Typography.Text, {
|
|
4724
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Typography.Text, {
|
|
4725
|
+
variant: "bold",
|
|
4726
|
+
children: item.structured_formatting.main_text
|
|
4727
|
+
}), item.structured_formatting.secondary_text ? /*#__PURE__*/jsxRuntime.jsxs(Typography.Text, {
|
|
4728
|
+
color: "black-light",
|
|
4729
|
+
variant: "bold",
|
|
4730
|
+
children: [' ', item.structured_formatting.secondary_text]
|
|
4731
|
+
}) : null]
|
|
4732
|
+
})
|
|
4733
|
+
})]
|
|
4734
|
+
})
|
|
4735
|
+
});
|
|
4736
|
+
}
|
|
4737
|
+
|
|
4738
|
+
function defaultItemToString(item) {
|
|
4739
|
+
if (!item) return '';
|
|
4740
|
+
return item.structured_formatting.main_text;
|
|
4741
|
+
}
|
|
4742
|
+
|
|
4743
|
+
// This function takes AutocompleteAddress and return a valid google AutocompletePrediction
|
|
4744
|
+
function formatInitialValueToAutocompletePrediction(address, placeId) {
|
|
4745
|
+
return {
|
|
4746
|
+
place_id: placeId,
|
|
4747
|
+
description: '',
|
|
4748
|
+
reference: '',
|
|
4749
|
+
types: [],
|
|
4750
|
+
terms: [],
|
|
4751
|
+
matched_substrings: [],
|
|
4752
|
+
structured_formatting: {
|
|
4753
|
+
main_text: [address.streetName, address.streetNumber].filter(Boolean).join(' '),
|
|
4754
|
+
main_text_matched_substrings: [],
|
|
4755
|
+
secondary_text: [address.zipcode, address.locality, address.subLocality].filter(Boolean).join(' ')
|
|
4756
|
+
}
|
|
4757
|
+
};
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4760
|
+
function InputAddress({
|
|
4761
|
+
initialValue,
|
|
4762
|
+
itemToString = defaultItemToString,
|
|
4763
|
+
errorElement,
|
|
4764
|
+
emptyResultsElement,
|
|
4765
|
+
onChange,
|
|
4766
|
+
...props
|
|
4767
|
+
}) {
|
|
4768
|
+
const {
|
|
4769
|
+
state,
|
|
4770
|
+
onInputChange,
|
|
4771
|
+
onSelectItem
|
|
4772
|
+
} = useGoogleMapsAutocomplete();
|
|
4773
|
+
|
|
4774
|
+
// 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
|
|
4775
|
+
const formattedInitialValue = initialValue ? formatInitialValueToAutocompletePrediction(initialValue, 'initial-value-placeId') : undefined;
|
|
4776
|
+
return /*#__PURE__*/jsxRuntime.jsx(Autocomplete, {
|
|
4777
|
+
itemToString: itemToString,
|
|
4778
|
+
initialValue: formattedInitialValue,
|
|
4779
|
+
checkSelectedItem: (selectedItem, item) => selectedItem?.place_id === item.place_id,
|
|
4780
|
+
right: state.isLoadingSearch || state.isLoadingResultDetails ? /*#__PURE__*/jsxRuntime.jsx(Icon, {
|
|
4781
|
+
icon: /*#__PURE__*/jsxRuntime.jsx(LoaderIcon, {}),
|
|
4782
|
+
color: "kitt.black"
|
|
4783
|
+
}) : undefined,
|
|
4784
|
+
errorElement: state.hasSearchError || state.hasSelectResultError ? errorElement : null,
|
|
4785
|
+
emptyResultsElement: state.items.length === 0 ? emptyResultsElement : null,
|
|
4786
|
+
onInputChange: v => {
|
|
4787
|
+
onInputChange(v);
|
|
4788
|
+
},
|
|
4789
|
+
onChange: v => {
|
|
4790
|
+
onSelectItem(v, onChange);
|
|
4791
|
+
},
|
|
4792
|
+
children: state.items.map(item => /*#__PURE__*/jsxRuntime.jsx(InputAddressOption, {
|
|
4793
|
+
item: item
|
|
4794
|
+
}, item.place_id))
|
|
4795
|
+
});
|
|
4796
|
+
}
|
|
4797
|
+
InputAddress.Option = InputAddressOption;
|
|
4798
|
+
|
|
4033
4799
|
const InputEmail = /*#__PURE__*/react.forwardRef((props, ref) => {
|
|
4034
4800
|
return /*#__PURE__*/jsxRuntime.jsx(InputText, {
|
|
4035
4801
|
ref: ref,
|
|
@@ -4088,39 +4854,6 @@ function InputField({
|
|
|
4088
4854
|
});
|
|
4089
4855
|
}
|
|
4090
4856
|
|
|
4091
|
-
function getIconColor(state, disabled) {
|
|
4092
|
-
if (disabled) return 'black-light';
|
|
4093
|
-
switch (state) {
|
|
4094
|
-
case 'invalid':
|
|
4095
|
-
return 'danger';
|
|
4096
|
-
case 'valid':
|
|
4097
|
-
return 'success';
|
|
4098
|
-
default:
|
|
4099
|
-
return undefined;
|
|
4100
|
-
}
|
|
4101
|
-
}
|
|
4102
|
-
function InputIcon({
|
|
4103
|
-
icon,
|
|
4104
|
-
state,
|
|
4105
|
-
disabled
|
|
4106
|
-
}) {
|
|
4107
|
-
const theme = useTheme();
|
|
4108
|
-
const color = getIconColor(state, disabled);
|
|
4109
|
-
return /*#__PURE__*/jsxRuntime.jsx(TypographyIcon, {
|
|
4110
|
-
color: color,
|
|
4111
|
-
icon: icon,
|
|
4112
|
-
size: theme.kitt.forms.input.icon.size
|
|
4113
|
-
});
|
|
4114
|
-
}
|
|
4115
|
-
|
|
4116
|
-
function InputPressable({
|
|
4117
|
-
...props
|
|
4118
|
-
}) {
|
|
4119
|
-
return /*#__PURE__*/jsxRuntime.jsx(reactNative.Pressable, {
|
|
4120
|
-
...props
|
|
4121
|
-
});
|
|
4122
|
-
}
|
|
4123
|
-
|
|
4124
4857
|
const InputPassword = /*#__PURE__*/react.forwardRef(({
|
|
4125
4858
|
isPasswordDefaultVisible,
|
|
4126
4859
|
right,
|
|
@@ -5821,6 +6554,31 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
5821
6554
|
}
|
|
5822
6555
|
},
|
|
5823
6556
|
forms: {
|
|
6557
|
+
autocomplete: {
|
|
6558
|
+
option: {
|
|
6559
|
+
default: {
|
|
6560
|
+
backgroundColor: theme.forms.autocomplete.option.default.backgroundColor
|
|
6561
|
+
},
|
|
6562
|
+
hovered: {
|
|
6563
|
+
backgroundColor: theme.forms.autocomplete.option.hovered.backgroundColor
|
|
6564
|
+
},
|
|
6565
|
+
focused: {
|
|
6566
|
+
backgroundColor: theme.forms.autocomplete.option.focused.backgroundColor
|
|
6567
|
+
},
|
|
6568
|
+
selected: {
|
|
6569
|
+
backgroundColor: theme.forms.autocomplete.option.selected.backgroundColor
|
|
6570
|
+
},
|
|
6571
|
+
highlighted: {
|
|
6572
|
+
backgroundColor: theme.forms.autocomplete.option.highlighted.backgroundColor
|
|
6573
|
+
},
|
|
6574
|
+
pressed: {
|
|
6575
|
+
backgroundColor: theme.forms.autocomplete.option.pressed.backgroundColor
|
|
6576
|
+
}
|
|
6577
|
+
},
|
|
6578
|
+
optionsContainer: {
|
|
6579
|
+
backgroundColor: theme.forms.autocomplete.optionsContainer.backgroundColor
|
|
6580
|
+
}
|
|
6581
|
+
},
|
|
5824
6582
|
input: {
|
|
5825
6583
|
states: theme.forms.input.states
|
|
5826
6584
|
},
|
|
@@ -6045,6 +6803,11 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
6045
6803
|
borderRadius: theme.dialogModal.borderRadius
|
|
6046
6804
|
},
|
|
6047
6805
|
forms: {
|
|
6806
|
+
autocomplete: {
|
|
6807
|
+
optionsContainer: {
|
|
6808
|
+
borderRadius: theme.forms.autocomplete.optionsContainer.borderRadius
|
|
6809
|
+
}
|
|
6810
|
+
},
|
|
6048
6811
|
input: {
|
|
6049
6812
|
borderRadius: theme.forms.input.borderRadius
|
|
6050
6813
|
},
|
|
@@ -6303,6 +7066,11 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
6303
7066
|
minHeight: theme.feedbackMessage.minHeight
|
|
6304
7067
|
},
|
|
6305
7068
|
forms: {
|
|
7069
|
+
autocomplete: {
|
|
7070
|
+
option: {
|
|
7071
|
+
minHeight: theme.forms.autocomplete.option.minHeight
|
|
7072
|
+
}
|
|
7073
|
+
},
|
|
6306
7074
|
datePicker: {
|
|
6307
7075
|
minHeight: theme.forms.input.minHeight,
|
|
6308
7076
|
day: {
|
|
@@ -6408,6 +7176,11 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
6408
7176
|
overlayPadding: theme.dialogModal.overlayPadding
|
|
6409
7177
|
},
|
|
6410
7178
|
forms: {
|
|
7179
|
+
autocomplete: {
|
|
7180
|
+
option: {
|
|
7181
|
+
verticalPadding: theme.forms.autocomplete.option.verticalPadding
|
|
7182
|
+
}
|
|
7183
|
+
},
|
|
6411
7184
|
datePicker: {
|
|
6412
7185
|
padding: theme.forms.input.padding
|
|
6413
7186
|
},
|
|
@@ -6879,16 +7652,18 @@ function createKittNativeBaseCustomTheme(theme, appTheme) {
|
|
|
6879
7652
|
shadowRadius: theme.dialogModal.shadow.radius
|
|
6880
7653
|
}
|
|
6881
7654
|
},
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
7655
|
+
forms: {
|
|
7656
|
+
autocomplete: {
|
|
7657
|
+
optionsContainer: {
|
|
7658
|
+
shadow: {
|
|
7659
|
+
shadowColor: theme.forms.autocomplete.optionsContainer.shadow.color,
|
|
7660
|
+
shadowOffset: {
|
|
7661
|
+
width: theme.forms.autocomplete.optionsContainer.shadow.offsetX,
|
|
7662
|
+
height: theme.forms.autocomplete.optionsContainer.shadow.offsetY
|
|
7663
|
+
},
|
|
7664
|
+
shadowOpacity: theme.forms.autocomplete.optionsContainer.shadow.opacity,
|
|
7665
|
+
shadowRadius: theme.forms.autocomplete.optionsContainer.shadow.radius
|
|
7666
|
+
}
|
|
6892
7667
|
}
|
|
6893
7668
|
}
|
|
6894
7669
|
}
|
|
@@ -7288,7 +8063,7 @@ function webUseSelectReducer(state, actionAndChanges, options) {
|
|
|
7288
8063
|
changes
|
|
7289
8064
|
} = actionAndChanges;
|
|
7290
8065
|
switch (type) {
|
|
7291
|
-
case
|
|
8066
|
+
case Downshift.useSelect.stateChangeTypes.ItemClick:
|
|
7292
8067
|
if (!options.keepOpenOnChange) return changes;
|
|
7293
8068
|
return {
|
|
7294
8069
|
...changes,
|
|
@@ -7323,7 +8098,7 @@ function Picker({
|
|
|
7323
8098
|
getMenuProps,
|
|
7324
8099
|
highlightedIndex,
|
|
7325
8100
|
getItemProps
|
|
7326
|
-
} =
|
|
8101
|
+
} = Downshift.useSelect({
|
|
7327
8102
|
items,
|
|
7328
8103
|
initialSelectedItem: initialValueIndex > -1 ? items[initialValueIndex] : undefined,
|
|
7329
8104
|
initialIsOpen: isInitialOpen,
|
|
@@ -8002,10 +8777,12 @@ function BlockSection({
|
|
|
8002
8777
|
});
|
|
8003
8778
|
}
|
|
8004
8779
|
function DemoSection({
|
|
8005
|
-
children
|
|
8780
|
+
children,
|
|
8781
|
+
...props
|
|
8006
8782
|
}) {
|
|
8007
8783
|
return /*#__PURE__*/jsxRuntime.jsx(View, {
|
|
8008
8784
|
marginBottom: "kitt.16",
|
|
8785
|
+
...props,
|
|
8009
8786
|
children: /*#__PURE__*/jsxRuntime.jsx(StorySection, {
|
|
8010
8787
|
internalIsDemoSection: true,
|
|
8011
8788
|
title: "Demo",
|
|
@@ -8909,6 +9686,7 @@ exports.useToken = nativeBase.useToken;
|
|
|
8909
9686
|
exports.useWindowSize = reactNative.useWindowDimensions;
|
|
8910
9687
|
exports.ActionCard = ActionCard;
|
|
8911
9688
|
exports.Actions = Actions;
|
|
9689
|
+
exports.Autocomplete = Autocomplete;
|
|
8912
9690
|
exports.Avatar = Avatar;
|
|
8913
9691
|
exports.BottomSheet = BottomSheet;
|
|
8914
9692
|
exports.Button = Button;
|
|
@@ -8924,11 +9702,14 @@ exports.ExternalLink = ExternalLink;
|
|
|
8924
9702
|
exports.FlatList = FlatList;
|
|
8925
9703
|
exports.Flex = Flex;
|
|
8926
9704
|
exports.FullscreenModal = FullscreenModal;
|
|
9705
|
+
exports.GoogleMapsApiKeyProvider = GoogleMapsApiKeyProvider;
|
|
9706
|
+
exports.GoogleMapsAutocompleteProvider = GoogleMapsAutocompleteProvider;
|
|
8927
9707
|
exports.HStack = HStack;
|
|
8928
9708
|
exports.Highlight = Highlight;
|
|
8929
9709
|
exports.Icon = Icon;
|
|
8930
9710
|
exports.IconButton = IconButton;
|
|
8931
9711
|
exports.Image = Image;
|
|
9712
|
+
exports.InputAddress = InputAddress;
|
|
8932
9713
|
exports.InputEmail = InputEmail;
|
|
8933
9714
|
exports.InputFeedback = InputFeedback;
|
|
8934
9715
|
exports.InputField = InputField;
|