@blocklet/payment-react 1.18.55 → 1.19.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/es/checkout/donate.d.ts +1 -15
- package/es/checkout/donate.js +301 -189
- package/es/checkout/form.d.ts +1 -15
- package/es/checkout/form.js +5 -13
- package/es/checkout/table.js +3 -3
- package/es/components/blockchain/gas.d.ts +1 -5
- package/es/components/blockchain/gas.js +10 -2
- package/es/components/blockchain/tx.d.ts +1 -8
- package/es/components/blockchain/tx.js +28 -7
- package/es/components/confirm.d.ts +1 -10
- package/es/components/confirm.js +4 -10
- package/es/components/country-select.d.ts +3 -2
- package/es/components/country-select.js +375 -352
- package/es/components/input.d.ts +11 -20
- package/es/components/input.js +46 -43
- package/es/components/lazy-loader.js +1 -2
- package/es/components/link.d.ts +2 -9
- package/es/components/link.js +9 -6
- package/es/components/livemode.d.ts +2 -8
- package/es/components/livemode.js +1 -5
- package/es/components/loading-button.d.ts +6 -1
- package/es/components/loading-button.js +56 -66
- package/es/components/over-due-invoice-payment.d.ts +0 -18
- package/es/components/over-due-invoice-payment.js +138 -95
- package/es/components/payment-beneficiaries.d.ts +2 -7
- package/es/components/payment-beneficiaries.js +86 -40
- package/es/components/pricing-item.d.ts +0 -5
- package/es/components/pricing-item.js +1 -4
- package/es/components/pricing-table.d.ts +2 -10
- package/es/components/pricing-table.js +8 -7
- package/es/components/resume-subscription.d.ts +0 -10
- package/es/components/resume-subscription.js +42 -21
- package/es/components/truncated-text.d.ts +2 -9
- package/es/components/truncated-text.js +0 -5
- package/es/contexts/donate.d.ts +0 -7
- package/es/contexts/donate.js +10 -8
- package/es/contexts/payment.d.ts +1 -4
- package/es/contexts/payment.js +7 -2
- package/es/history/invoice/list.d.ts +2 -18
- package/es/history/invoice/list.js +151 -73
- package/es/history/payment/list.js +115 -38
- package/es/hooks/keyboard.d.ts +1 -1
- package/es/hooks/keyboard.js +2 -4
- package/es/libs/cached-request.js +2 -4
- package/es/libs/phone-validator.js +1 -2
- package/es/libs/util.js +2 -4
- package/es/libs/validator.js +2 -4
- package/es/payment/amount.d.ts +2 -7
- package/es/payment/amount.js +1 -5
- package/es/payment/donation-form.d.ts +2 -10
- package/es/payment/donation-form.js +196 -160
- package/es/payment/error.d.ts +2 -8
- package/es/payment/error.js +40 -20
- package/es/payment/footer.d.ts +2 -3
- package/es/payment/footer.js +19 -6
- package/es/payment/form/addon.js +14 -4
- package/es/payment/form/address.d.ts +2 -9
- package/es/payment/form/address.js +3 -6
- package/es/payment/form/currency.js +45 -25
- package/es/payment/form/index.d.ts +2 -8
- package/es/payment/form/index.js +107 -65
- package/es/payment/form/phone.js +2 -4
- package/es/payment/form/stripe/form.d.ts +2 -8
- package/es/payment/form/stripe/form.js +1 -3
- package/es/payment/header.js +38 -16
- package/es/payment/index.d.ts +2 -9
- package/es/payment/index.js +5 -14
- package/es/payment/product-card.d.ts +2 -11
- package/es/payment/product-card.js +84 -50
- package/es/payment/product-donation.js +175 -114
- package/es/payment/product-item.d.ts +2 -9
- package/es/payment/product-item.js +185 -142
- package/es/payment/product-skeleton.js +2 -2
- package/es/payment/skeleton/donation.js +27 -7
- package/es/payment/skeleton/overview.js +22 -2
- package/es/payment/skeleton/payment.js +33 -5
- package/es/payment/success.d.ts +2 -9
- package/es/payment/success.js +41 -14
- package/es/payment/summary.d.ts +2 -17
- package/es/payment/summary.js +184 -111
- package/es/theme/index.d.ts +0 -5
- package/es/theme/index.js +2 -5
- package/es/theme/typography.d.ts +2 -2
- package/lib/checkout/donate.d.ts +1 -15
- package/lib/checkout/donate.js +75 -54
- package/lib/checkout/form.d.ts +1 -15
- package/lib/checkout/form.js +7 -15
- package/lib/checkout/table.js +4 -4
- package/lib/components/blockchain/gas.d.ts +1 -5
- package/lib/components/blockchain/gas.js +3 -2
- package/lib/components/blockchain/tx.d.ts +1 -8
- package/lib/components/blockchain/tx.js +11 -7
- package/lib/components/confirm.d.ts +1 -10
- package/lib/components/confirm.js +5 -11
- package/lib/components/country-select.d.ts +3 -2
- package/lib/components/country-select.js +23 -22
- package/lib/components/input.d.ts +11 -20
- package/lib/components/input.js +20 -23
- package/lib/components/lazy-loader.js +1 -1
- package/lib/components/link.d.ts +2 -9
- package/lib/components/link.js +3 -8
- package/lib/components/livemode.d.ts +2 -8
- package/lib/components/livemode.js +3 -7
- package/lib/components/loading-button.d.ts +6 -1
- package/lib/components/loading-button.js +9 -17
- package/lib/components/over-due-invoice-payment.d.ts +0 -18
- package/lib/components/over-due-invoice-payment.js +31 -33
- package/lib/components/payment-beneficiaries.d.ts +2 -7
- package/lib/components/payment-beneficiaries.js +12 -11
- package/lib/components/pricing-item.d.ts +0 -5
- package/lib/components/pricing-item.js +2 -5
- package/lib/components/pricing-table.d.ts +2 -10
- package/lib/components/pricing-table.js +5 -11
- package/lib/components/resume-subscription.d.ts +0 -10
- package/lib/components/resume-subscription.js +16 -16
- package/lib/components/table.js +1 -1
- package/lib/components/truncated-text.d.ts +2 -9
- package/lib/components/truncated-text.js +1 -6
- package/lib/contexts/donate.d.ts +0 -7
- package/lib/contexts/donate.js +4 -7
- package/lib/contexts/payment.d.ts +1 -4
- package/lib/contexts/payment.js +4 -7
- package/lib/history/invoice/list.d.ts +2 -18
- package/lib/history/invoice/list.js +49 -37
- package/lib/history/payment/list.js +30 -16
- package/lib/hooks/keyboard.d.ts +1 -1
- package/lib/hooks/mobile.js +1 -1
- package/lib/hooks/subscription.js +1 -1
- package/lib/index.js +2 -2
- package/lib/libs/api.js +1 -1
- package/lib/libs/dayjs.js +1 -1
- package/lib/libs/phone-validator.js +0 -2
- package/lib/libs/theme.js +1 -1
- package/lib/libs/util.js +1 -1
- package/lib/libs/validator.js +1 -1
- package/lib/locales/en.js +1 -1
- package/lib/locales/index.js +1 -1
- package/lib/locales/zh.js +1 -1
- package/lib/payment/amount.d.ts +2 -7
- package/lib/payment/amount.js +2 -6
- package/lib/payment/donation-form.d.ts +2 -10
- package/lib/payment/donation-form.js +33 -38
- package/lib/payment/error.d.ts +2 -8
- package/lib/payment/error.js +11 -13
- package/lib/payment/footer.d.ts +2 -3
- package/lib/payment/footer.js +5 -5
- package/lib/payment/form/addon.js +5 -3
- package/lib/payment/form/address.d.ts +2 -9
- package/lib/payment/form/address.js +5 -8
- package/lib/payment/form/currency.js +3 -3
- package/lib/payment/form/index.d.ts +2 -8
- package/lib/payment/form/index.js +19 -15
- package/lib/payment/form/phone.js +1 -1
- package/lib/payment/form/stripe/form.d.ts +2 -8
- package/lib/payment/form/stripe/form.js +3 -6
- package/lib/payment/header.js +8 -4
- package/lib/payment/index.d.ts +2 -9
- package/lib/payment/index.js +7 -16
- package/lib/payment/product-card.d.ts +2 -11
- package/lib/payment/product-card.js +13 -20
- package/lib/payment/product-donation.js +71 -66
- package/lib/payment/product-item.d.ts +2 -9
- package/lib/payment/product-item.js +24 -25
- package/lib/payment/product-skeleton.js +2 -2
- package/lib/payment/skeleton/donation.js +8 -4
- package/lib/payment/skeleton/overview.js +6 -2
- package/lib/payment/skeleton/payment.js +9 -3
- package/lib/payment/success.d.ts +2 -9
- package/lib/payment/success.js +12 -15
- package/lib/payment/summary.d.ts +2 -17
- package/lib/payment/summary.js +44 -45
- package/lib/theme/index.d.ts +0 -5
- package/lib/theme/index.js +2 -5
- package/lib/theme/typography.d.ts +2 -2
- package/package.json +40 -40
- package/src/checkout/donate.tsx +103 -35
- package/src/checkout/form.tsx +5 -14
- package/src/checkout/table.tsx +3 -3
- package/src/components/blockchain/gas.tsx +5 -3
- package/src/components/blockchain/tx.tsx +22 -8
- package/src/components/confirm.tsx +4 -11
- package/src/components/country-select.tsx +391 -378
- package/src/components/input.tsx +49 -45
- package/src/components/link.tsx +9 -7
- package/src/components/livemode.tsx +2 -6
- package/src/components/loading-button.tsx +63 -76
- package/src/components/over-due-invoice-payment.tsx +43 -28
- package/src/components/payment-beneficiaries.tsx +33 -14
- package/src/components/pricing-item.tsx +1 -4
- package/src/components/pricing-table.tsx +8 -8
- package/src/components/resume-subscription.tsx +20 -14
- package/src/components/table.tsx +2 -2
- package/src/components/truncated-text.tsx +0 -6
- package/src/contexts/donate.tsx +6 -7
- package/src/contexts/payment.tsx +7 -3
- package/src/history/invoice/list.tsx +74 -35
- package/src/history/payment/list.tsx +53 -16
- package/src/hooks/keyboard.ts +1 -1
- package/src/payment/amount.tsx +1 -6
- package/src/payment/donation-form.tsx +47 -29
- package/src/payment/error.tsx +16 -8
- package/src/payment/footer.tsx +11 -3
- package/src/payment/form/addon.tsx +6 -1
- package/src/payment/form/address.tsx +3 -7
- package/src/payment/form/currency.tsx +12 -2
- package/src/payment/form/index.tsx +30 -12
- package/src/payment/form/stripe/form.tsx +1 -5
- package/src/payment/header.tsx +14 -2
- package/src/payment/index.tsx +10 -21
- package/src/payment/product-card.tsx +41 -18
- package/src/payment/product-donation.tsx +85 -47
- package/src/payment/product-item.tsx +46 -24
- package/src/payment/product-skeleton.tsx +3 -2
- package/src/payment/skeleton/donation.tsx +12 -2
- package/src/payment/skeleton/overview.tsx +12 -2
- package/src/payment/skeleton/payment.tsx +16 -3
- package/src/payment/success.tsx +26 -15
- package/src/payment/summary.tsx +74 -42
- package/src/theme/index.tsx +5 -8
- package/src/theme/typography.ts +2 -2
|
@@ -1,388 +1,411 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo,
|
|
2
|
+
import { useMemo, useState, useEffect, useRef } from "react";
|
|
3
3
|
import { Box, MenuItem, Typography, TextField, Dialog, DialogContent, IconButton, Select, Slide } from "@mui/material";
|
|
4
4
|
import { useFormContext } from "react-hook-form";
|
|
5
5
|
import { FlagEmoji, defaultCountries, parseCountry } from "react-international-phone";
|
|
6
6
|
import { useMobile } from "../hooks/mobile.js";
|
|
7
|
-
|
|
7
|
+
function Transition({ ref, ...props }) {
|
|
8
8
|
return /* @__PURE__ */ jsx(Slide, { direction: "up", ref, timeout: 200, ...props });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return () => {
|
|
31
|
-
window.removeEventListener("resize", handleResize);
|
|
32
|
-
};
|
|
33
|
-
}, [open]);
|
|
34
|
-
const scrollToTop = () => {
|
|
35
|
-
if (listRef.current) {
|
|
36
|
-
listRef.current.scrollTop = 0;
|
|
37
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export default function CountrySelect({
|
|
11
|
+
ref = void 0,
|
|
12
|
+
value,
|
|
13
|
+
onChange,
|
|
14
|
+
name,
|
|
15
|
+
sx = {},
|
|
16
|
+
showDialCode = false
|
|
17
|
+
}) {
|
|
18
|
+
const { setValue } = useFormContext();
|
|
19
|
+
const [open, setOpen] = useState(false);
|
|
20
|
+
const [searchText, setSearchText] = useState("");
|
|
21
|
+
const inputRef = useRef(null);
|
|
22
|
+
const menuRef = useRef(null);
|
|
23
|
+
const listRef = useRef(null);
|
|
24
|
+
const [focusedIndex, setFocusedIndex] = useState(-1);
|
|
25
|
+
const itemHeightRef = useRef(40);
|
|
26
|
+
const { isMobile } = useMobile();
|
|
27
|
+
const measuredRef = useRef(false);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!open) return () => {
|
|
38
30
|
};
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
return;
|
|
42
|
-
const items = listRef.current.querySelectorAll(".MuiMenuItem-root");
|
|
43
|
-
if (items.length > 0) {
|
|
44
|
-
const firstItem = items[0];
|
|
45
|
-
if (firstItem.offsetHeight > 0) {
|
|
46
|
-
itemHeightRef.current = firstItem.offsetHeight;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
31
|
+
const handleResize = () => {
|
|
32
|
+
measuredRef.current = false;
|
|
49
33
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (open && !measuredRef.current) {
|
|
54
|
-
measureItemHeight();
|
|
55
|
-
measuredRef.current = true;
|
|
56
|
-
}
|
|
57
|
-
const listHeight = listRef.current.clientHeight;
|
|
58
|
-
const targetPosition = index * itemHeightRef.current;
|
|
59
|
-
if (index < 2) {
|
|
60
|
-
listRef.current.scrollTop = 0;
|
|
61
|
-
} else if (index > filteredCountries.length - 3) {
|
|
62
|
-
listRef.current.scrollTop = listRef.current.scrollHeight - listHeight;
|
|
63
|
-
} else {
|
|
64
|
-
const scrollPosition = targetPosition - listHeight / 2 + itemHeightRef.current / 2;
|
|
65
|
-
listRef.current.scrollTop = Math.max(0, scrollPosition);
|
|
66
|
-
}
|
|
34
|
+
window.addEventListener("resize", handleResize);
|
|
35
|
+
return () => {
|
|
36
|
+
window.removeEventListener("resize", handleResize);
|
|
67
37
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
38
|
+
}, [open]);
|
|
39
|
+
const scrollToTop = () => {
|
|
40
|
+
if (listRef.current) {
|
|
41
|
+
listRef.current.scrollTop = 0;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const measureItemHeight = () => {
|
|
45
|
+
if (!listRef.current || !open) return;
|
|
46
|
+
const items = listRef.current.querySelectorAll(".MuiMenuItem-root");
|
|
47
|
+
if (items.length > 0) {
|
|
48
|
+
const firstItem = items[0];
|
|
49
|
+
if (firstItem.offsetHeight > 0) {
|
|
50
|
+
itemHeightRef.current = firstItem.offsetHeight;
|
|
80
51
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const controlScrollPosition = (index) => {
|
|
55
|
+
if (!listRef.current) return;
|
|
56
|
+
if (open && !measuredRef.current) {
|
|
57
|
+
measureItemHeight();
|
|
58
|
+
measuredRef.current = true;
|
|
59
|
+
}
|
|
60
|
+
const listHeight = listRef.current.clientHeight;
|
|
61
|
+
const targetPosition = index * itemHeightRef.current;
|
|
62
|
+
if (index < 2) {
|
|
63
|
+
listRef.current.scrollTop = 0;
|
|
64
|
+
} else if (index > filteredCountries.length - 3) {
|
|
65
|
+
listRef.current.scrollTop = listRef.current.scrollHeight - listHeight;
|
|
66
|
+
} else {
|
|
67
|
+
const scrollPosition = targetPosition - listHeight / 2 + itemHeightRef.current / 2;
|
|
68
|
+
listRef.current.scrollTop = Math.max(0, scrollPosition);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
let timeout = null;
|
|
73
|
+
if (open) {
|
|
74
|
+
timeout = setTimeout(() => {
|
|
75
|
+
scrollToTop();
|
|
76
|
+
if (!isMobile && inputRef.current) {
|
|
77
|
+
inputRef.current.focus();
|
|
84
78
|
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!searchText)
|
|
89
|
-
return defaultCountries;
|
|
90
|
-
return defaultCountries.filter((c) => {
|
|
91
|
-
const parsed = parseCountry(c);
|
|
92
|
-
return parsed.name.toLowerCase().includes(searchText.toLowerCase()) || parsed.iso2.toLowerCase().includes(searchText.toLowerCase()) || `+${parsed.dialCode}`.includes(searchText);
|
|
93
|
-
});
|
|
94
|
-
}, [searchText]);
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
scrollToTop();
|
|
79
|
+
}, 100);
|
|
80
|
+
} else {
|
|
81
|
+
setSearchText("");
|
|
97
82
|
setFocusedIndex(-1);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
timeout = setTimeout(() => {
|
|
103
|
-
controlScrollPosition(focusedIndex);
|
|
104
|
-
}, 10);
|
|
83
|
+
}
|
|
84
|
+
return () => {
|
|
85
|
+
if (timeout) {
|
|
86
|
+
clearTimeout(timeout);
|
|
105
87
|
}
|
|
106
|
-
return () => {
|
|
107
|
-
if (timeout) {
|
|
108
|
-
clearTimeout(timeout);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}, [focusedIndex, filteredCountries.length]);
|
|
112
|
-
const countryDetail = useMemo(() => {
|
|
113
|
-
const item = defaultCountries.find((v) => v[1] === value);
|
|
114
|
-
return value && item ? parseCountry(item) : { name: "" };
|
|
115
|
-
}, [value]);
|
|
116
|
-
const handleCountryClick = (code) => {
|
|
117
|
-
onChange(code);
|
|
118
|
-
setValue(name, code);
|
|
119
|
-
setOpen(false);
|
|
120
|
-
};
|
|
121
|
-
const handleSearchChange = (e) => {
|
|
122
|
-
e.stopPropagation();
|
|
123
|
-
setSearchText(e.target.value);
|
|
124
88
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
89
|
+
}, [open, isMobile]);
|
|
90
|
+
const filteredCountries = useMemo(() => {
|
|
91
|
+
if (!searchText) return defaultCountries;
|
|
92
|
+
return defaultCountries.filter((c) => {
|
|
93
|
+
const parsed = parseCountry(c);
|
|
94
|
+
return parsed.name.toLowerCase().includes(searchText.toLowerCase()) || parsed.iso2.toLowerCase().includes(searchText.toLowerCase()) || `+${parsed.dialCode}`.includes(searchText);
|
|
95
|
+
});
|
|
96
|
+
}, [searchText]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
scrollToTop();
|
|
99
|
+
setFocusedIndex(-1);
|
|
100
|
+
}, [searchText]);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
let timeout = null;
|
|
103
|
+
if (focusedIndex >= 0) {
|
|
104
|
+
timeout = setTimeout(() => {
|
|
105
|
+
controlScrollPosition(focusedIndex);
|
|
106
|
+
}, 10);
|
|
107
|
+
}
|
|
108
|
+
return () => {
|
|
109
|
+
if (timeout) {
|
|
110
|
+
clearTimeout(timeout);
|
|
130
111
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
112
|
+
};
|
|
113
|
+
}, [focusedIndex, filteredCountries.length]);
|
|
114
|
+
const countryDetail = useMemo(() => {
|
|
115
|
+
const item = defaultCountries.find((v) => v[1] === value);
|
|
116
|
+
return value && item ? parseCountry(item) : { name: "" };
|
|
117
|
+
}, [value]);
|
|
118
|
+
const handleCountryClick = (code) => {
|
|
119
|
+
onChange(code);
|
|
120
|
+
setValue(name, code);
|
|
121
|
+
setOpen(false);
|
|
122
|
+
};
|
|
123
|
+
const handleSearchChange = (e) => {
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
setSearchText(e.target.value);
|
|
126
|
+
};
|
|
127
|
+
const handleKeyDown = (e) => {
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
if (e.key === "Escape") {
|
|
130
|
+
setOpen(false);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const handleNavigation = (direction) => {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
setFocusedIndex((prev) => {
|
|
136
|
+
if (direction === "next") {
|
|
137
|
+
if (prev === -1) return 0;
|
|
138
|
+
return prev >= filteredCountries.length - 1 ? 0 : prev + 1;
|
|
139
|
+
}
|
|
140
|
+
if (prev === -1) return filteredCountries.length - 1;
|
|
141
|
+
return prev <= 0 ? filteredCountries.length - 1 : prev - 1;
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
if (e.key === "Tab") {
|
|
145
|
+
handleNavigation(e.shiftKey ? "prev" : "next");
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (e.key === "ArrowDown") {
|
|
149
|
+
handleNavigation("next");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (e.key === "ArrowUp") {
|
|
153
|
+
handleNavigation("prev");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (e.key === "Enter" && focusedIndex >= 0 && focusedIndex < filteredCountries.length) {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
const country = parseCountry(filteredCountries[focusedIndex]);
|
|
159
|
+
handleCountryClick(country.iso2);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const countryListContent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
163
|
+
/* @__PURE__ */ jsx(
|
|
164
|
+
Box,
|
|
165
|
+
{
|
|
166
|
+
sx: {
|
|
167
|
+
position: "sticky",
|
|
168
|
+
top: 0,
|
|
169
|
+
zIndex: 1,
|
|
170
|
+
bgcolor: "background.paper",
|
|
171
|
+
p: 1
|
|
172
|
+
},
|
|
173
|
+
onClick: (e) => {
|
|
174
|
+
e.stopPropagation();
|
|
175
|
+
},
|
|
176
|
+
children: /* @__PURE__ */ jsx(
|
|
177
|
+
TextField,
|
|
178
|
+
{
|
|
179
|
+
inputRef,
|
|
180
|
+
autoFocus: !isMobile,
|
|
181
|
+
fullWidth: true,
|
|
182
|
+
placeholder: "Search country...",
|
|
183
|
+
value: searchText,
|
|
184
|
+
onChange: handleSearchChange,
|
|
185
|
+
onKeyDown: handleKeyDown,
|
|
186
|
+
onClick: (e) => e.stopPropagation(),
|
|
187
|
+
size: "small",
|
|
188
|
+
variant: "outlined"
|
|
138
189
|
}
|
|
139
|
-
|
|
140
|
-
return filteredCountries.length - 1;
|
|
141
|
-
return prev <= 0 ? filteredCountries.length - 1 : prev - 1;
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
if (e.key === "Tab") {
|
|
145
|
-
handleNavigation(e.shiftKey ? "prev" : "next");
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (e.key === "ArrowDown") {
|
|
149
|
-
handleNavigation("next");
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
if (e.key === "ArrowUp") {
|
|
153
|
-
handleNavigation("prev");
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (e.key === "Enter" && focusedIndex >= 0 && focusedIndex < filteredCountries.length) {
|
|
157
|
-
e.preventDefault();
|
|
158
|
-
const country = parseCountry(filteredCountries[focusedIndex]);
|
|
159
|
-
handleCountryClick(country.iso2);
|
|
190
|
+
)
|
|
160
191
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
192
|
+
),
|
|
193
|
+
/* @__PURE__ */ jsx(
|
|
194
|
+
Box,
|
|
195
|
+
{
|
|
196
|
+
ref: listRef,
|
|
197
|
+
sx: {
|
|
198
|
+
flex: 1,
|
|
199
|
+
overflowY: "auto",
|
|
200
|
+
overflowX: "hidden",
|
|
201
|
+
maxHeight: isMobile ? "calc(60vh - 80px)" : "calc(300px - 65px)",
|
|
202
|
+
scrollBehavior: "smooth"
|
|
203
|
+
},
|
|
204
|
+
children: filteredCountries.length > 0 ? filteredCountries.map((c, index) => {
|
|
205
|
+
const parsed = parseCountry(c);
|
|
206
|
+
const isFocused = index === focusedIndex;
|
|
207
|
+
return /* @__PURE__ */ jsxs(
|
|
208
|
+
MenuItem,
|
|
178
209
|
{
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
size: "small",
|
|
188
|
-
variant: "outlined"
|
|
189
|
-
}
|
|
190
|
-
)
|
|
191
|
-
}
|
|
192
|
-
),
|
|
193
|
-
/* @__PURE__ */ jsx(
|
|
194
|
-
Box,
|
|
195
|
-
{
|
|
196
|
-
ref: listRef,
|
|
197
|
-
sx: {
|
|
198
|
-
flex: 1,
|
|
199
|
-
overflowY: "auto",
|
|
200
|
-
overflowX: "hidden",
|
|
201
|
-
maxHeight: isMobile ? "calc(60vh - 80px)" : "calc(300px - 65px)",
|
|
202
|
-
scrollBehavior: "smooth"
|
|
203
|
-
},
|
|
204
|
-
children: filteredCountries.length > 0 ? filteredCountries.map((c, index) => {
|
|
205
|
-
const parsed = parseCountry(c);
|
|
206
|
-
const isFocused = index === focusedIndex;
|
|
207
|
-
return /* @__PURE__ */ jsxs(
|
|
208
|
-
MenuItem,
|
|
209
|
-
{
|
|
210
|
-
value: parsed.iso2,
|
|
211
|
-
selected: parsed.iso2 === value,
|
|
212
|
-
onClick: () => handleCountryClick(parsed.iso2),
|
|
213
|
-
sx: {
|
|
214
|
-
display: "flex",
|
|
215
|
-
alignItems: "center",
|
|
216
|
-
"&.Mui-selected": {
|
|
217
|
-
backgroundColor: "primary.lighter"
|
|
218
|
-
},
|
|
219
|
-
"&:hover": {
|
|
220
|
-
backgroundColor: "grey.100"
|
|
221
|
-
},
|
|
222
|
-
...isFocused ? {
|
|
223
|
-
backgroundColor: "grey.100",
|
|
224
|
-
outline: "none"
|
|
225
|
-
} : {}
|
|
210
|
+
value: parsed.iso2,
|
|
211
|
+
selected: parsed.iso2 === value,
|
|
212
|
+
onClick: () => handleCountryClick(parsed.iso2),
|
|
213
|
+
sx: {
|
|
214
|
+
display: "flex",
|
|
215
|
+
alignItems: "center",
|
|
216
|
+
"&.Mui-selected": {
|
|
217
|
+
backgroundColor: "primary.lighter"
|
|
226
218
|
},
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
"&:hover": {
|
|
220
|
+
backgroundColor: "grey.100"
|
|
221
|
+
},
|
|
222
|
+
...isFocused ? {
|
|
223
|
+
backgroundColor: "grey.100",
|
|
224
|
+
outline: "none"
|
|
225
|
+
} : {}
|
|
232
226
|
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
MenuProps: {
|
|
248
|
-
style: {
|
|
249
|
-
maxHeight: "300px",
|
|
250
|
-
top: "10px"
|
|
251
|
-
},
|
|
252
|
-
anchorOrigin: {
|
|
253
|
-
vertical: "bottom",
|
|
254
|
-
horizontal: "left"
|
|
227
|
+
children: [
|
|
228
|
+
/* @__PURE__ */ jsx(FlagEmoji, { iso2: parsed.iso2, style: { marginRight: "8px" } }),
|
|
229
|
+
/* @__PURE__ */ jsx(Typography, { children: parsed.name }),
|
|
230
|
+
showDialCode && /* @__PURE__ */ jsx(
|
|
231
|
+
Typography,
|
|
232
|
+
{
|
|
233
|
+
sx: {
|
|
234
|
+
color: "text.secondary",
|
|
235
|
+
ml: 1
|
|
236
|
+
},
|
|
237
|
+
children: `+${parsed.dialCode}`
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
]
|
|
255
241
|
},
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
242
|
+
parsed.iso2
|
|
243
|
+
);
|
|
244
|
+
}) : /* @__PURE__ */ jsx(MenuItem, { disabled: true, children: /* @__PURE__ */ jsx(
|
|
245
|
+
Typography,
|
|
246
|
+
{
|
|
247
|
+
sx: {
|
|
248
|
+
color: "text.secondary"
|
|
259
249
|
},
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
250
|
+
children: "No countries found"
|
|
251
|
+
}
|
|
252
|
+
) })
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
] });
|
|
256
|
+
if (!isMobile) {
|
|
257
|
+
return /* @__PURE__ */ jsx(
|
|
258
|
+
Select,
|
|
259
|
+
{
|
|
260
|
+
ref,
|
|
261
|
+
open,
|
|
262
|
+
onOpen: () => setOpen(true),
|
|
263
|
+
onClose: () => setOpen(false),
|
|
264
|
+
MenuProps: {
|
|
265
|
+
style: {
|
|
266
|
+
maxHeight: "300px",
|
|
267
|
+
top: "10px"
|
|
268
|
+
},
|
|
269
|
+
anchorOrigin: {
|
|
270
|
+
vertical: "bottom",
|
|
271
|
+
horizontal: "left"
|
|
272
|
+
},
|
|
273
|
+
transformOrigin: {
|
|
274
|
+
vertical: "top",
|
|
275
|
+
horizontal: "left"
|
|
276
|
+
},
|
|
277
|
+
PaperProps: {
|
|
278
|
+
ref: menuRef,
|
|
279
|
+
sx: {
|
|
280
|
+
display: "flex",
|
|
281
|
+
"& .MuiList-root": {
|
|
282
|
+
pt: 0,
|
|
263
283
|
display: "flex",
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
display: "flex",
|
|
267
|
-
flexDirection: "column",
|
|
268
|
-
overflowY: "hidden"
|
|
269
|
-
}
|
|
284
|
+
flexDirection: "column",
|
|
285
|
+
overflowY: "hidden"
|
|
270
286
|
}
|
|
271
287
|
}
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
sx: {
|
|
291
|
+
width: "100%",
|
|
292
|
+
minWidth: "60px",
|
|
293
|
+
fieldset: {
|
|
294
|
+
display: "none"
|
|
272
295
|
},
|
|
273
|
-
|
|
274
|
-
width: "100%",
|
|
275
|
-
minWidth: "60px",
|
|
296
|
+
'&.Mui-focused:has(div[aria-expanded="false"])': {
|
|
276
297
|
fieldset: {
|
|
277
|
-
display: "
|
|
278
|
-
}
|
|
279
|
-
'&.Mui-focused:has(div[aria-expanded="false"])': {
|
|
280
|
-
fieldset: {
|
|
281
|
-
display: "block"
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
".MuiSelect-select": {
|
|
285
|
-
padding: "8px",
|
|
286
|
-
paddingRight: "24px !important"
|
|
287
|
-
},
|
|
288
|
-
svg: {
|
|
289
|
-
right: 0
|
|
290
|
-
},
|
|
291
|
-
".MuiMenuItem-root": {
|
|
292
|
-
justifyContent: "flex-start"
|
|
293
|
-
},
|
|
294
|
-
...sx
|
|
298
|
+
display: "block"
|
|
299
|
+
}
|
|
295
300
|
},
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
setValue(name, e.target.value);
|
|
301
|
+
".MuiSelect-select": {
|
|
302
|
+
padding: "8px",
|
|
303
|
+
paddingRight: "24px !important"
|
|
300
304
|
},
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
305
|
+
svg: {
|
|
306
|
+
right: 0
|
|
307
|
+
},
|
|
308
|
+
".MuiMenuItem-root": {
|
|
309
|
+
justifyContent: "flex-start"
|
|
310
|
+
},
|
|
311
|
+
...sx
|
|
312
|
+
},
|
|
313
|
+
value,
|
|
314
|
+
onChange: (e) => {
|
|
315
|
+
onChange(e.target.value);
|
|
316
|
+
setValue(name, e.target.value);
|
|
317
|
+
},
|
|
318
|
+
renderValue: (code) => /* @__PURE__ */ jsxs(
|
|
319
|
+
Box,
|
|
320
|
+
{
|
|
321
|
+
sx: {
|
|
322
|
+
display: "flex",
|
|
323
|
+
alignItems: "center",
|
|
324
|
+
flexWrap: "nowrap",
|
|
325
|
+
gap: 0.5,
|
|
326
|
+
cursor: "pointer"
|
|
327
|
+
},
|
|
328
|
+
children: [
|
|
329
|
+
/* @__PURE__ */ jsx(FlagEmoji, { iso2: code, style: { display: "flex" } }),
|
|
330
|
+
/* @__PURE__ */ jsx(Typography, { children: countryDetail?.name })
|
|
331
|
+
]
|
|
332
|
+
}
|
|
333
|
+
),
|
|
334
|
+
children: countryListContent
|
|
335
|
+
}
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
return /* @__PURE__ */ jsxs(Box, { ref, sx: { ...sx }, children: [
|
|
339
|
+
/* @__PURE__ */ jsxs(
|
|
340
|
+
Box,
|
|
341
|
+
{
|
|
342
|
+
onClick: () => setOpen(true),
|
|
343
|
+
sx: {
|
|
314
344
|
display: "flex",
|
|
315
345
|
alignItems: "center",
|
|
316
346
|
flexWrap: "nowrap",
|
|
317
347
|
gap: 0.5,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
"
|
|
328
|
-
|
|
329
|
-
outline: "none"
|
|
330
|
-
},
|
|
331
|
-
touchAction: "manipulation"
|
|
348
|
+
cursor: "pointer",
|
|
349
|
+
padding: "8px",
|
|
350
|
+
paddingRight: "24px",
|
|
351
|
+
position: "relative",
|
|
352
|
+
border: "none",
|
|
353
|
+
"-webkit-tap-highlight-color": "transparent",
|
|
354
|
+
userSelect: "none",
|
|
355
|
+
background: "none",
|
|
356
|
+
"&:hover, &:focus, &:active": {
|
|
357
|
+
backgroundColor: "transparent",
|
|
358
|
+
outline: "none"
|
|
332
359
|
},
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
360
|
+
touchAction: "manipulation"
|
|
361
|
+
},
|
|
362
|
+
children: [
|
|
363
|
+
/* @__PURE__ */ jsx(FlagEmoji, { iso2: value, style: { display: "flex" } }),
|
|
364
|
+
/* @__PURE__ */ jsx(Typography, { children: countryDetail?.name }),
|
|
365
|
+
/* @__PURE__ */ jsx(
|
|
366
|
+
Box,
|
|
367
|
+
{
|
|
368
|
+
sx: {
|
|
369
|
+
position: "absolute",
|
|
370
|
+
right: "8px",
|
|
371
|
+
width: 0,
|
|
372
|
+
height: 0,
|
|
373
|
+
borderLeft: "5px solid transparent",
|
|
374
|
+
borderRight: "5px solid transparent",
|
|
375
|
+
borderTop: "5px solid currentColor"
|
|
348
376
|
}
|
|
349
|
-
)
|
|
350
|
-
]
|
|
351
|
-
}
|
|
352
|
-
),
|
|
353
|
-
/* @__PURE__ */ jsxs(
|
|
354
|
-
Dialog,
|
|
355
|
-
{
|
|
356
|
-
open,
|
|
357
|
-
onClose: () => setOpen(false),
|
|
358
|
-
fullWidth: true,
|
|
359
|
-
maxWidth: "xs",
|
|
360
|
-
TransitionComponent: Transition,
|
|
361
|
-
PaperProps: {
|
|
362
|
-
sx: {
|
|
363
|
-
position: "absolute",
|
|
364
|
-
bottom: 0,
|
|
365
|
-
m: 0,
|
|
366
|
-
p: 0,
|
|
367
|
-
borderBottomLeftRadius: 0,
|
|
368
|
-
borderBottomRightRadius: 0,
|
|
369
|
-
width: "100%"
|
|
370
377
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
378
|
+
)
|
|
379
|
+
]
|
|
380
|
+
}
|
|
381
|
+
),
|
|
382
|
+
/* @__PURE__ */ jsxs(
|
|
383
|
+
Dialog,
|
|
384
|
+
{
|
|
385
|
+
open,
|
|
386
|
+
onClose: () => setOpen(false),
|
|
387
|
+
fullWidth: true,
|
|
388
|
+
maxWidth: "xs",
|
|
389
|
+
TransitionComponent: Transition,
|
|
390
|
+
PaperProps: {
|
|
391
|
+
sx: {
|
|
392
|
+
position: "absolute",
|
|
393
|
+
bottom: 0,
|
|
394
|
+
m: 0,
|
|
395
|
+
p: 0,
|
|
396
|
+
borderBottomLeftRadius: 0,
|
|
397
|
+
borderBottomRightRadius: 0,
|
|
398
|
+
width: "100%"
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
children: [
|
|
402
|
+
/* @__PURE__ */ jsxs(Box, { sx: { p: 2, display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
|
|
403
|
+
/* @__PURE__ */ jsx(Typography, { variant: "h6", children: "Select Country" }),
|
|
404
|
+
/* @__PURE__ */ jsx(IconButton, { edge: "end", onClick: () => setOpen(false), sx: { "-webkit-tap-highlight-color": "transparent" }, children: "\u2715" })
|
|
405
|
+
] }),
|
|
406
|
+
/* @__PURE__ */ jsx(DialogContent, { sx: { "&.MuiDialogContent-root": { p: 0 } }, children: countryListContent })
|
|
407
|
+
]
|
|
408
|
+
}
|
|
409
|
+
)
|
|
410
|
+
] });
|
|
411
|
+
}
|