@swan-io/lake 13.9.3 → 13.10.1
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/package.json
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ReactNode, Ref } from "react";
|
|
2
|
-
export type PhoneCountry = {
|
|
3
|
-
cca2: string;
|
|
4
|
-
idd: string;
|
|
5
|
-
};
|
|
6
|
-
export type InputPhoneNumberRef = {
|
|
7
|
-
focus: () => void;
|
|
8
|
-
blur: () => void;
|
|
9
|
-
};
|
|
10
|
-
type Props = {
|
|
11
|
-
ref?: Ref<InputPhoneNumberRef>;
|
|
12
|
-
id?: string;
|
|
13
|
-
country: PhoneCountry;
|
|
14
|
-
value: string;
|
|
15
|
-
error?: string;
|
|
16
|
-
valid?: boolean;
|
|
17
|
-
autofocus?: boolean;
|
|
18
|
-
disabled?: boolean;
|
|
19
|
-
readOnly?: boolean;
|
|
20
|
-
flag?: ReactNode;
|
|
21
|
-
countryList: (close: () => void) => ReactNode;
|
|
22
|
-
countryButtonAriaLabel?: string;
|
|
23
|
-
onChangeText?: (text: string) => void;
|
|
24
|
-
onSubmitEditing?: () => void;
|
|
25
|
-
onBlur?: () => void;
|
|
26
|
-
};
|
|
27
|
-
export declare const InputPhoneNumber: ({ ref, id, country, value, error, valid, autofocus, disabled, readOnly, flag, countryList, countryButtonAriaLabel, onChangeText, onSubmitEditing, onBlur, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useImperativeHandle, useRef } from "react";
|
|
3
|
-
import { Pressable, StyleSheet } from "react-native";
|
|
4
|
-
import { colors, radii, spacings } from "../constants/design";
|
|
5
|
-
import { useDisclosure } from "../hooks/useDisclosure";
|
|
6
|
-
import { isNotNullishOrEmpty } from "../utils/nullish";
|
|
7
|
-
import { Box } from "./Box";
|
|
8
|
-
import { Icon } from "./Icon";
|
|
9
|
-
import { LakeText } from "./LakeText";
|
|
10
|
-
import { LakeTextInput } from "./LakeTextInput";
|
|
11
|
-
import { Popover } from "./Popover";
|
|
12
|
-
import { Space } from "./Space";
|
|
13
|
-
const styles = StyleSheet.create({
|
|
14
|
-
idd: {
|
|
15
|
-
alignItems: "center",
|
|
16
|
-
backgroundColor: colors.gray[50],
|
|
17
|
-
borderColor: colors.gray[100],
|
|
18
|
-
borderTopLeftRadius: radii[4],
|
|
19
|
-
borderBottomLeftRadius: radii[4],
|
|
20
|
-
borderWidth: 1,
|
|
21
|
-
borderRightWidth: 0,
|
|
22
|
-
flexDirection: "row",
|
|
23
|
-
justifyContent: "center",
|
|
24
|
-
paddingLeft: spacings[16],
|
|
25
|
-
paddingRight: spacings[12],
|
|
26
|
-
transitionDuration: "150ms",
|
|
27
|
-
transitionProperty: "background-color",
|
|
28
|
-
},
|
|
29
|
-
iddPressed: { backgroundColor: colors.gray[100] },
|
|
30
|
-
iddErrored: { borderColor: colors.negative[500] },
|
|
31
|
-
iddDisabled: {
|
|
32
|
-
borderColor: colors.gray[50],
|
|
33
|
-
borderRightWidth: 1,
|
|
34
|
-
borderRightColor: colors.gray[100],
|
|
35
|
-
},
|
|
36
|
-
input: { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 },
|
|
37
|
-
});
|
|
38
|
-
export const InputPhoneNumber = ({ ref, id, country, value, error, valid = false, autofocus = false, disabled = false, readOnly = false, flag, countryList, countryButtonAriaLabel = "Select country", onChangeText, onSubmitEditing, onBlur, }) => {
|
|
39
|
-
const referenceRef = useRef(null);
|
|
40
|
-
const inputRef = useRef(null);
|
|
41
|
-
const [visible, { open, close }] = useDisclosure(false);
|
|
42
|
-
const handleChangeText = (text) => {
|
|
43
|
-
const clean = text.replace(/[^ +0-9-()]/g, "");
|
|
44
|
-
if (text === clean) {
|
|
45
|
-
onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(text);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (autofocus && inputRef.current) {
|
|
50
|
-
setTimeout(() => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 250);
|
|
51
|
-
}
|
|
52
|
-
}, [autofocus]);
|
|
53
|
-
useImperativeHandle(ref, () => ({ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); } }), []);
|
|
54
|
-
return (_jsxs(_Fragment, { children: [_jsx(Popover, { referenceRef: referenceRef, visible: visible, matchReferenceWidth: true, onDismiss: close, children: countryList(close) }), _jsxs(Box, { ref: referenceRef, direction: "row", children: [_jsxs(Pressable, { role: "button", disabled: visible || disabled || readOnly, onPress: open, "aria-label": countryButtonAriaLabel, style: ({ pressed }) => [
|
|
55
|
-
styles.idd,
|
|
56
|
-
!visible && pressed && styles.iddPressed,
|
|
57
|
-
(disabled || readOnly) && styles.iddDisabled,
|
|
58
|
-
isNotNullishOrEmpty(error) && styles.iddErrored,
|
|
59
|
-
], children: [flag, flag != null && _jsx(Space, { width: 8 }), _jsxs(LakeText, { color: colors.gray[600], numberOfLines: 1, userSelect: "none", variant: "smallSemibold", children: ["+", country.idd] }), _jsx(Space, { width: 8 }), _jsx(Icon, { name: "chevron-down-filled", color: colors.gray[600], size: 16 })] }), _jsx(LakeTextInput, { id: id, ref: inputRef, autoComplete: "tel", inputMode: "tel", rows: 1, hideErrors: true, value: value, valid: valid, error: error, disabled: disabled, readOnly: readOnly, onChangeText: handleChangeText, onSubmitEditing: onSubmitEditing, onBlur: onBlur, style: styles.input })] })] }));
|
|
60
|
-
};
|