@rxdrag/website-lib-core 0.0.62 → 0.0.64
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 +5 -5
- package/src/react/components/ContactForm/ContactForm.tsx +1 -1
- package/src/react/components/ContactForm/{FileUpload.tsx → FileUpload2.tsx} +2 -2
- package/src/react/components/ContactForm/Input2.tsx +3 -1
- package/src/react/components/ContactForm/Submit.tsx +4 -1
- package/src/react/components/ContactForm/TelInput.tsx +215 -0
- package/src/react/components/ContactForm/TelInput2.tsx +177 -0
- package/src/react/components/ContactForm/Textarea2.tsx +3 -1
- package/src/react/components/ContactForm/countryDialCodes.ts +243 -0
- package/src/react/components/ContactForm/factory.tsx +60 -49
- package/src/react/components/ContactForm/hooks/useInlineLabelPadding.ts +20 -0
- package/src/react/components/ContactForm/hooks/useTelControl.ts +81 -0
- package/src/react/components/ContactForm/index.ts +1 -1
- package/src/react/components/ContactForm/useVisitorInfo.ts +0 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.64",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts"
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@types/react-dom": "^19.1.0",
|
|
25
25
|
"eslint": "^7.32.0",
|
|
26
26
|
"typescript": "^5",
|
|
27
|
+
"@rxdrag/eslint-config-custom": "0.2.12",
|
|
27
28
|
"@rxdrag/tsconfig": "0.2.0",
|
|
28
|
-
"@rxdrag/slate-preview": "1.2.58"
|
|
29
|
-
"@rxdrag/eslint-config-custom": "0.2.12"
|
|
29
|
+
"@rxdrag/slate-preview": "1.2.58"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"clsx": "^2.1.0",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"lodash-es": "^4.17.21",
|
|
36
36
|
"react": "^19.1.0",
|
|
37
37
|
"react-dom": "^19.1.0",
|
|
38
|
-
"@rxdrag/
|
|
39
|
-
"@rxdrag/
|
|
38
|
+
"@rxdrag/entify-lib": "0.0.18",
|
|
39
|
+
"@rxdrag/rxcms-models": "0.3.89"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"astro": "^4.0.0 || ^5.0.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, useState } from "react";
|
|
2
2
|
import { Submit } from "./Submit";
|
|
3
|
-
import { type UploadedFile } from "./
|
|
3
|
+
import { type UploadedFile } from "./FileUpload2";
|
|
4
4
|
import clsx from "clsx";
|
|
5
5
|
import { modal } from "../../../controller";
|
|
6
6
|
import { encrypt } from "./funcs";
|
|
@@ -43,7 +43,7 @@ export type FileUploadProps = {
|
|
|
43
43
|
maxSize?: number; // 最大文件大小(字节),默认 5MB
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export const
|
|
46
|
+
export const FileUpload2 = forwardRef<HTMLInputElement, FileUploadProps>(
|
|
47
47
|
(props, ref) => {
|
|
48
48
|
const {
|
|
49
49
|
label,
|
|
@@ -320,7 +320,7 @@ export const FileUpload = forwardRef<HTMLInputElement, FileUploadProps>(
|
|
|
320
320
|
ref={labelRef}
|
|
321
321
|
htmlFor={name}
|
|
322
322
|
className={clsx(
|
|
323
|
-
"absolute left-3 top-1/2 -translate-y-1/2 mt-1
|
|
323
|
+
"absolute left-3 top-1/2 -translate-y-1/2 mt-1 opacity-70 text-sm pointer-events-none whitespace-nowrap z-10",
|
|
324
324
|
labelClassName
|
|
325
325
|
)}
|
|
326
326
|
>
|
|
@@ -7,6 +7,7 @@ export const Input2 = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
|
|
|
7
7
|
label,
|
|
8
8
|
name,
|
|
9
9
|
required,
|
|
10
|
+
requiredClassName,
|
|
10
11
|
className,
|
|
11
12
|
labelClassName,
|
|
12
13
|
inputClassName,
|
|
@@ -35,11 +36,12 @@ export const Input2 = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
|
|
|
35
36
|
ref={labelRef}
|
|
36
37
|
htmlFor={name}
|
|
37
38
|
className={clsx(
|
|
38
|
-
"absolute left-3 top-1/2 -translate-y-1/2 mt-1
|
|
39
|
+
"absolute left-3 top-1/2 -translate-y-1/2 mt-1 opacity-70 text-sm pointer-events-none whitespace-nowrap",
|
|
39
40
|
labelClassName
|
|
40
41
|
)}
|
|
41
42
|
>
|
|
42
43
|
{label}
|
|
44
|
+
{required ? <span className={requiredClassName}>*</span> : ""}
|
|
43
45
|
</label>
|
|
44
46
|
<input
|
|
45
47
|
ref={ref}
|
|
@@ -32,7 +32,10 @@ export const Submit: React.FC<SubmitProps> = (props) => {
|
|
|
32
32
|
>
|
|
33
33
|
{submitting && spinner}
|
|
34
34
|
{rawHtml ? (
|
|
35
|
-
<div
|
|
35
|
+
<div
|
|
36
|
+
style={{ display: "contents" }}
|
|
37
|
+
dangerouslySetInnerHTML={{ __html: rawHtml }}
|
|
38
|
+
/>
|
|
36
39
|
) : (
|
|
37
40
|
title
|
|
38
41
|
)}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { CountryDial } from "./countryDialCodes";
|
|
4
|
+
import { useTelControl } from "./hooks/useTelControl";
|
|
5
|
+
|
|
6
|
+
export interface TelInputProps
|
|
7
|
+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> {
|
|
8
|
+
label?: string;
|
|
9
|
+
name: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
requiredClassName?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
labelClassName?: string;
|
|
14
|
+
inputClassName?: string;
|
|
15
|
+
countries?: CountryDial[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const TelInput = forwardRef<HTMLInputElement, TelInputProps>(
|
|
19
|
+
(props, ref) => {
|
|
20
|
+
const {
|
|
21
|
+
label,
|
|
22
|
+
name,
|
|
23
|
+
required,
|
|
24
|
+
requiredClassName,
|
|
25
|
+
className,
|
|
26
|
+
labelClassName,
|
|
27
|
+
inputClassName,
|
|
28
|
+
countries,
|
|
29
|
+
placeholder,
|
|
30
|
+
value,
|
|
31
|
+
onChange,
|
|
32
|
+
} = props;
|
|
33
|
+
|
|
34
|
+
const { allCountries, selected, localNumber, onSelectCountry, onChangeLocal } =
|
|
35
|
+
useTelControl({ countries, name, value, onChange });
|
|
36
|
+
|
|
37
|
+
const [open, setOpen] = useState(false);
|
|
38
|
+
const [query, setQuery] = useState("");
|
|
39
|
+
const panelRef = useRef<HTMLDivElement | null>(null);
|
|
40
|
+
const buttonRef = useRef<HTMLButtonElement | null>(null);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const onDocClick = (e: MouseEvent) => {
|
|
44
|
+
const target = e.target as Node;
|
|
45
|
+
if (
|
|
46
|
+
open &&
|
|
47
|
+
panelRef.current &&
|
|
48
|
+
!panelRef.current.contains(target) &&
|
|
49
|
+
buttonRef.current &&
|
|
50
|
+
!buttonRef.current.contains(target)
|
|
51
|
+
) {
|
|
52
|
+
setOpen(false);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
document.addEventListener("mousedown", onDocClick);
|
|
56
|
+
return () => document.removeEventListener("mousedown", onDocClick);
|
|
57
|
+
}, [open]);
|
|
58
|
+
|
|
59
|
+
// 使用 useTelControl 负责解析与变更回传
|
|
60
|
+
|
|
61
|
+
const filtered: CountryDial[] = useMemo(() => {
|
|
62
|
+
if (!query) return allCountries;
|
|
63
|
+
const q = query.toLowerCase();
|
|
64
|
+
return allCountries.filter(
|
|
65
|
+
(c: CountryDial) =>
|
|
66
|
+
c.name.toLowerCase().includes(q) ||
|
|
67
|
+
(c.region && c.region.toLowerCase().includes(q)) ||
|
|
68
|
+
c.dialCode.replace("+", "").includes(q.replace("+", ""))
|
|
69
|
+
);
|
|
70
|
+
}, [allCountries, query]);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div className={clsx("w-full", className)}>
|
|
74
|
+
{label ? (
|
|
75
|
+
<label
|
|
76
|
+
htmlFor={name}
|
|
77
|
+
className={clsx(
|
|
78
|
+
"mb-1 inline-flex items-center text-sm text-gray-600",
|
|
79
|
+
labelClassName
|
|
80
|
+
)}
|
|
81
|
+
>
|
|
82
|
+
{label}
|
|
83
|
+
{required ? <span className={requiredClassName}>*</span> : null}
|
|
84
|
+
</label>
|
|
85
|
+
) : null}
|
|
86
|
+
|
|
87
|
+
<div
|
|
88
|
+
className={clsx(
|
|
89
|
+
"flex h-10 items-center gap-2 rounded-md focus-within:ring-2 focus-within:ring-primary-300 focus-within:ring-offset-0 bg-white",
|
|
90
|
+
inputClassName
|
|
91
|
+
)}
|
|
92
|
+
>
|
|
93
|
+
<div className="relative h-full">
|
|
94
|
+
<button
|
|
95
|
+
ref={buttonRef}
|
|
96
|
+
type="button"
|
|
97
|
+
aria-haspopup="listbox"
|
|
98
|
+
aria-expanded={open}
|
|
99
|
+
onClick={() => setOpen((v) => !v)}
|
|
100
|
+
className={
|
|
101
|
+
"h-full min-w-[200px] inline-flex items-center justify-between whitespace-nowrap rounded-md px-3 py-0 text-sm"
|
|
102
|
+
}
|
|
103
|
+
>
|
|
104
|
+
<span className="truncate text-left leading-tight">
|
|
105
|
+
{selected ? (
|
|
106
|
+
<>
|
|
107
|
+
<span className="font-medium">{selected.name}</span>
|
|
108
|
+
{selected.region ? (
|
|
109
|
+
<span className="text-gray-500">, {selected.region}</span>
|
|
110
|
+
) : null}
|
|
111
|
+
<span className="ml-1 text-gray-700">
|
|
112
|
+
{selected.dialCode}
|
|
113
|
+
</span>
|
|
114
|
+
</>
|
|
115
|
+
) : (
|
|
116
|
+
"Select Country/Region"
|
|
117
|
+
)}
|
|
118
|
+
</span>
|
|
119
|
+
<svg
|
|
120
|
+
className="ml-2 h-4 w-4 text-gray-500"
|
|
121
|
+
viewBox="0 0 20 20"
|
|
122
|
+
fill="currentColor"
|
|
123
|
+
aria-hidden="true"
|
|
124
|
+
>
|
|
125
|
+
<path
|
|
126
|
+
fillRule="evenodd"
|
|
127
|
+
d="M5.23 7.21a.75.75 0 011.06.02L10 11.085l3.71-3.855a.75.75 0 111.08 1.04l-4.24 4.41a.75.75 0 01-1.08 0L5.25 8.27a.75.75 0 01-.02-1.06z"
|
|
128
|
+
clipRule="evenodd"
|
|
129
|
+
/>
|
|
130
|
+
</svg>
|
|
131
|
+
</button>
|
|
132
|
+
|
|
133
|
+
{open ? (
|
|
134
|
+
<div
|
|
135
|
+
ref={panelRef}
|
|
136
|
+
className="absolute z-50 mt-2 w-[320px] rounded-md border border-gray-200 bg-white p-2 shadow-lg"
|
|
137
|
+
>
|
|
138
|
+
<div className="flex items-center gap-2 rounded-md border border-gray-200 px-2 py-1.5">
|
|
139
|
+
<input
|
|
140
|
+
value={query}
|
|
141
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
142
|
+
placeholder="Enter Country/Region"
|
|
143
|
+
className="h-8 w-full bg-transparent text-sm outline-none"
|
|
144
|
+
/>
|
|
145
|
+
<svg
|
|
146
|
+
className="h-4 w-4 text-gray-500"
|
|
147
|
+
viewBox="0 0 20 20"
|
|
148
|
+
fill="currentColor"
|
|
149
|
+
aria-hidden="true"
|
|
150
|
+
>
|
|
151
|
+
<path
|
|
152
|
+
fillRule="evenodd"
|
|
153
|
+
d="M8.5 3.5a5 5 0 013.996 8.1l3.202 3.203a.75.75 0 11-1.06 1.06l-3.203-3.202A5 5 0 118.5 3.5zm0 1.5a3.5 3.5 0 100 7 3.5 3.5 0 000-7z"
|
|
154
|
+
clipRule="evenodd"
|
|
155
|
+
/>
|
|
156
|
+
</svg>
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
<div className="mt-2 max-h-64 overflow-auto pr-1">
|
|
160
|
+
{filtered.map((c: CountryDial) => (
|
|
161
|
+
<button
|
|
162
|
+
key={c.code}
|
|
163
|
+
type="button"
|
|
164
|
+
onClick={() => {
|
|
165
|
+
onSelectCountry(c);
|
|
166
|
+
setOpen(false);
|
|
167
|
+
}}
|
|
168
|
+
className="flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm hover:bg-gray-50"
|
|
169
|
+
>
|
|
170
|
+
<span
|
|
171
|
+
className={clsx(
|
|
172
|
+
"inline-block h-3 w-3 rounded-full border",
|
|
173
|
+
selected?.code === c.code
|
|
174
|
+
? "border-primary-500 ring-4 ring-primary-200"
|
|
175
|
+
: "border-gray-400"
|
|
176
|
+
)}
|
|
177
|
+
></span>
|
|
178
|
+
<span className="flex-1 truncate">
|
|
179
|
+
{c.name}
|
|
180
|
+
{c.region ? (
|
|
181
|
+
<span className="text-gray-500">, {c.region}</span>
|
|
182
|
+
) : null}
|
|
183
|
+
</span>
|
|
184
|
+
<span className="text-gray-700">{c.dialCode}</span>
|
|
185
|
+
</button>
|
|
186
|
+
))}
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
) : null}
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
<input
|
|
193
|
+
ref={ref}
|
|
194
|
+
id={name}
|
|
195
|
+
name={name}
|
|
196
|
+
required={required}
|
|
197
|
+
placeholder={placeholder || "Phone number"}
|
|
198
|
+
inputMode="tel"
|
|
199
|
+
className={clsx("h-10 w-full px-3 py-0 text-sm leading-tight ring-0 outline-none rounded-md")}
|
|
200
|
+
value={localNumber}
|
|
201
|
+
onChange={(e) => {
|
|
202
|
+
const next = e.target.value;
|
|
203
|
+
onChangeLocal(next);
|
|
204
|
+
}}
|
|
205
|
+
autoComplete={name}
|
|
206
|
+
autoCorrect="off"
|
|
207
|
+
spellCheck={false}
|
|
208
|
+
/>
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
export default TelInput;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import type { CountryDial } from "./countryDialCodes";
|
|
4
|
+
import { useInlineLabelPadding } from "./hooks/useInlineLabelPadding";
|
|
5
|
+
import { useTelControl } from "./hooks/useTelControl";
|
|
6
|
+
|
|
7
|
+
export interface TelInputProps
|
|
8
|
+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> {
|
|
9
|
+
label?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
requiredClassName?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
labelClassName?: string;
|
|
15
|
+
inputClassName?: string;
|
|
16
|
+
countries?: CountryDial[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const TelInput2 = forwardRef<HTMLInputElement, TelInputProps>((props, ref) => {
|
|
20
|
+
const {
|
|
21
|
+
label,
|
|
22
|
+
name,
|
|
23
|
+
required,
|
|
24
|
+
requiredClassName,
|
|
25
|
+
className,
|
|
26
|
+
labelClassName,
|
|
27
|
+
inputClassName,
|
|
28
|
+
countries,
|
|
29
|
+
placeholder,
|
|
30
|
+
value,
|
|
31
|
+
onChange,
|
|
32
|
+
} = props;
|
|
33
|
+
|
|
34
|
+
const { labelRef, paddingLeft } = useInlineLabelPadding(16);
|
|
35
|
+
const {
|
|
36
|
+
allCountries,
|
|
37
|
+
selected,
|
|
38
|
+
localNumber,
|
|
39
|
+
onSelectCountry,
|
|
40
|
+
onChangeLocal,
|
|
41
|
+
} = useTelControl({ countries, name, value, onChange });
|
|
42
|
+
|
|
43
|
+
const [open, setOpen] = useState(false);
|
|
44
|
+
const [query, setQuery] = useState("");
|
|
45
|
+
const panelRef = useRef<HTMLDivElement | null>(null);
|
|
46
|
+
const buttonRef = useRef<HTMLButtonElement | null>(null);
|
|
47
|
+
|
|
48
|
+
const filtered = useMemo(() => {
|
|
49
|
+
if (!query) return allCountries;
|
|
50
|
+
const q = query.toLowerCase();
|
|
51
|
+
return allCountries.filter(
|
|
52
|
+
(c) =>
|
|
53
|
+
c.name.toLowerCase().includes(q) ||
|
|
54
|
+
(c.region && c.region.toLowerCase().includes(q)) ||
|
|
55
|
+
c.dialCode.replace("+", "").includes(q.replace("+", ""))
|
|
56
|
+
);
|
|
57
|
+
}, [allCountries, query]);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const onDocClick = (e: MouseEvent) => {
|
|
61
|
+
const target = e.target as Node;
|
|
62
|
+
if (
|
|
63
|
+
open &&
|
|
64
|
+
panelRef.current &&
|
|
65
|
+
!panelRef.current.contains(target) &&
|
|
66
|
+
buttonRef.current &&
|
|
67
|
+
!buttonRef.current.contains(target)
|
|
68
|
+
) {
|
|
69
|
+
setOpen(false);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
document.addEventListener("mousedown", onDocClick);
|
|
73
|
+
return () => document.removeEventListener("mousedown", onDocClick);
|
|
74
|
+
}, [open]);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div className={clsx("relative w-full", className)}>
|
|
78
|
+
<label
|
|
79
|
+
ref={labelRef}
|
|
80
|
+
htmlFor={name}
|
|
81
|
+
className={clsx(
|
|
82
|
+
"absolute left-3 top-1/2 -translate-y-1/2 mt-1 opacity-70 text-sm pointer-events-none whitespace-nowrap",
|
|
83
|
+
labelClassName
|
|
84
|
+
)}
|
|
85
|
+
>
|
|
86
|
+
{label}
|
|
87
|
+
{required ? <span className={requiredClassName}>*</span> : null}
|
|
88
|
+
</label>
|
|
89
|
+
|
|
90
|
+
<div
|
|
91
|
+
className={clsx(
|
|
92
|
+
"flex h-10 items-center gap-2 rounded-md shadow-sm focus-within:ring-2 focus-within:ring-primary-300",
|
|
93
|
+
inputClassName
|
|
94
|
+
)}
|
|
95
|
+
style={{ paddingLeft }}
|
|
96
|
+
>
|
|
97
|
+
<div className="relative h-full">
|
|
98
|
+
<button
|
|
99
|
+
ref={buttonRef}
|
|
100
|
+
type="button"
|
|
101
|
+
aria-haspopup="listbox"
|
|
102
|
+
aria-expanded={open}
|
|
103
|
+
onClick={() => setOpen((v) => !v)}
|
|
104
|
+
className={"h-full min-w-[100px] inline-flex items-center justify-between whitespace-nowrap rounded-md px-3 py-0 text-sm"}
|
|
105
|
+
>
|
|
106
|
+
<span className="truncate text-left leading-tight">
|
|
107
|
+
{selected ? (
|
|
108
|
+
<span className="font-medium">{selected.dialCode}</span>
|
|
109
|
+
) : (
|
|
110
|
+
<span className="text-gray-500">+ Code</span>
|
|
111
|
+
)}
|
|
112
|
+
</span>
|
|
113
|
+
<svg className="ml-2 h-4 w-4 text-gray-500" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
|
114
|
+
<path fillRule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.085l3.71-3.855a.75.75 0 111.08 1.04l-4.24 4.41a.75.75 0 01-1.08 0L5.25 8.27a.75.75 0 01-.02-1.06z" clipRule="evenodd" />
|
|
115
|
+
</svg>
|
|
116
|
+
</button>
|
|
117
|
+
|
|
118
|
+
{open ? (
|
|
119
|
+
<div ref={panelRef} className="absolute z-50 mt-2 w-[320px] rounded-md border border-gray-200 bg-white p-2 shadow-lg">
|
|
120
|
+
<div className="flex items-center gap-2 rounded-md border border-gray-200 px-2 py-1.5">
|
|
121
|
+
<input
|
|
122
|
+
value={query}
|
|
123
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
124
|
+
placeholder="Enter Country/Region"
|
|
125
|
+
className="h-8 w-full bg-transparent text-sm outline-none"
|
|
126
|
+
/>
|
|
127
|
+
<svg className="h-4 w-4 text-gray-500" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
|
128
|
+
<path fillRule="evenodd" d="M8.5 3.5a5 5 0 013.996 8.1l3.202 3.203a.75.75 0 11-1.06 1.06l-3.203-3.202A5 5 0 118.5 3.5zm0 1.5a3.5 3.5 0 100 7 3.5 3.5 0 000-7z" clipRule="evenodd" />
|
|
129
|
+
</svg>
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<div className="mt-2 max-h-64 overflow-auto pr-1">
|
|
133
|
+
{filtered.map((c) => (
|
|
134
|
+
<button
|
|
135
|
+
key={c.code}
|
|
136
|
+
type="button"
|
|
137
|
+
onClick={() => {
|
|
138
|
+
onSelectCountry(c);
|
|
139
|
+
setOpen(false);
|
|
140
|
+
}}
|
|
141
|
+
className="flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm hover:bg-gray-50"
|
|
142
|
+
>
|
|
143
|
+
<span className={clsx("inline-block h-3 w-3 rounded-full border", selected?.code === c.code ? "border-primary-500 ring-4 ring-primary-200" : "border-gray-400")}></span>
|
|
144
|
+
<span className="flex-1 truncate">
|
|
145
|
+
{c.name}
|
|
146
|
+
{c.region ? <span className="text-gray-500">, {c.region}</span> : null}
|
|
147
|
+
</span>
|
|
148
|
+
<span className="text-gray-700">{c.dialCode}</span>
|
|
149
|
+
</button>
|
|
150
|
+
))}
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
) : null}
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<input
|
|
157
|
+
ref={ref}
|
|
158
|
+
id={name}
|
|
159
|
+
name={name}
|
|
160
|
+
required={required}
|
|
161
|
+
placeholder={placeholder || "Phone number"}
|
|
162
|
+
inputMode="tel"
|
|
163
|
+
className={clsx(
|
|
164
|
+
"h-10 w-full appearance-none rounded-md border-0 bg-transparent px-3 py-0 text-sm leading-tight focus:outline-none",
|
|
165
|
+
)}
|
|
166
|
+
value={localNumber}
|
|
167
|
+
onChange={(e) => onChangeLocal(e.target.value)}
|
|
168
|
+
autoComplete={name}
|
|
169
|
+
autoCorrect="off"
|
|
170
|
+
spellCheck={false}
|
|
171
|
+
/>
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export default TelInput2;
|
|
@@ -7,6 +7,7 @@ export const Textarea2 = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
|
7
7
|
label,
|
|
8
8
|
name,
|
|
9
9
|
required,
|
|
10
|
+
requiredClassName,
|
|
10
11
|
labelClassName,
|
|
11
12
|
inputClassName,
|
|
12
13
|
className,
|
|
@@ -33,11 +34,12 @@ export const Textarea2 = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
|
33
34
|
<label
|
|
34
35
|
ref={labelRef}
|
|
35
36
|
htmlFor={name}
|
|
36
|
-
className={`absolute left-3 top-2
|
|
37
|
+
className={`absolute left-3 top-2 opacity-70 text-sm pointer-events-none ${
|
|
37
38
|
labelClassName || ""
|
|
38
39
|
}`}
|
|
39
40
|
>
|
|
40
41
|
{label}
|
|
42
|
+
{required ? <span className={requiredClassName}>*</span> : ""}
|
|
41
43
|
</label>
|
|
42
44
|
<textarea
|
|
43
45
|
ref={ref}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
export type CountryDial = {
|
|
2
|
+
code: string; // ISO 3166-1 alpha-2
|
|
3
|
+
name: string; // English name
|
|
4
|
+
region?: string; // Continent/region label
|
|
5
|
+
dialCode: string; // +NN
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Note: Names follow common English naming used in international forms.
|
|
9
|
+
// Region is a coarse grouping for search hints.
|
|
10
|
+
export const countries: CountryDial[] = [
|
|
11
|
+
{ code: "AF", name: "Afghanistan", region: "Asia", dialCode: "+93" },
|
|
12
|
+
{ code: "AL", name: "Albania", region: "Europe", dialCode: "+355" },
|
|
13
|
+
{ code: "DZ", name: "Algeria", region: "Africa", dialCode: "+213" },
|
|
14
|
+
{ code: "AS", name: "American Samoa", region: "Oceania", dialCode: "+1" },
|
|
15
|
+
{ code: "AD", name: "Andorra", region: "Europe", dialCode: "+376" },
|
|
16
|
+
{ code: "AO", name: "Angola", region: "Africa", dialCode: "+244" },
|
|
17
|
+
{ code: "AI", name: "Anguilla", region: "North America", dialCode: "+1" },
|
|
18
|
+
{ code: "AG", name: "Antigua and Barbuda", region: "North America", dialCode: "+1" },
|
|
19
|
+
{ code: "AR", name: "Argentina", region: "South America", dialCode: "+54" },
|
|
20
|
+
{ code: "AM", name: "Armenia", region: "Asia", dialCode: "+374" },
|
|
21
|
+
{ code: "AW", name: "Aruba", region: "North America", dialCode: "+297" },
|
|
22
|
+
{ code: "AU", name: "Australia", region: "Oceania", dialCode: "+61" },
|
|
23
|
+
{ code: "AT", name: "Austria", region: "Europe", dialCode: "+43" },
|
|
24
|
+
{ code: "AZ", name: "Azerbaijan", region: "Asia", dialCode: "+994" },
|
|
25
|
+
{ code: "BS", name: "Bahamas", region: "North America", dialCode: "+1" },
|
|
26
|
+
{ code: "BH", name: "Bahrain", region: "Asia", dialCode: "+973" },
|
|
27
|
+
{ code: "BD", name: "Bangladesh", region: "Asia", dialCode: "+880" },
|
|
28
|
+
{ code: "BB", name: "Barbados", region: "North America", dialCode: "+1" },
|
|
29
|
+
{ code: "BY", name: "Belarus", region: "Europe", dialCode: "+375" },
|
|
30
|
+
{ code: "BE", name: "Belgium", region: "Europe", dialCode: "+32" },
|
|
31
|
+
{ code: "BZ", name: "Belize", region: "North America", dialCode: "+501" },
|
|
32
|
+
{ code: "BJ", name: "Benin", region: "Africa", dialCode: "+229" },
|
|
33
|
+
{ code: "BM", name: "Bermuda", region: "North America", dialCode: "+1" },
|
|
34
|
+
{ code: "BT", name: "Bhutan", region: "Asia", dialCode: "+975" },
|
|
35
|
+
{ code: "BO", name: "Bolivia", region: "South America", dialCode: "+591" },
|
|
36
|
+
{ code: "BA", name: "Bosnia and Herzegovina", region: "Europe", dialCode: "+387" },
|
|
37
|
+
{ code: "BW", name: "Botswana", region: "Africa", dialCode: "+267" },
|
|
38
|
+
{ code: "BR", name: "Brazil", region: "South America", dialCode: "+55" },
|
|
39
|
+
{ code: "VG", name: "British Virgin Islands", region: "North America", dialCode: "+1" },
|
|
40
|
+
{ code: "BN", name: "Brunei", region: "Asia", dialCode: "+673" },
|
|
41
|
+
{ code: "BG", name: "Bulgaria", region: "Europe", dialCode: "+359" },
|
|
42
|
+
{ code: "BF", name: "Burkina Faso", region: "Africa", dialCode: "+226" },
|
|
43
|
+
{ code: "BI", name: "Burundi", region: "Africa", dialCode: "+257" },
|
|
44
|
+
{ code: "KH", name: "Cambodia", region: "Asia", dialCode: "+855" },
|
|
45
|
+
{ code: "CM", name: "Cameroon", region: "Africa", dialCode: "+237" },
|
|
46
|
+
{ code: "CA", name: "Canada", region: "North America", dialCode: "+1" },
|
|
47
|
+
{ code: "CV", name: "Cape Verde", region: "Africa", dialCode: "+238" },
|
|
48
|
+
{ code: "KY", name: "Cayman Islands", region: "North America", dialCode: "+1" },
|
|
49
|
+
{ code: "CF", name: "Central African Republic", region: "Africa", dialCode: "+236" },
|
|
50
|
+
{ code: "TD", name: "Chad", region: "Africa", dialCode: "+235" },
|
|
51
|
+
{ code: "CL", name: "Chile", region: "South America", dialCode: "+56" },
|
|
52
|
+
{ code: "CN", name: "China", region: "Asia", dialCode: "+86" },
|
|
53
|
+
{ code: "HK", name: "Hong Kong, China", region: "Asia", dialCode: "+852" },
|
|
54
|
+
{ code: "MO", name: "Macao, China", region: "Asia", dialCode: "+853" },
|
|
55
|
+
{ code: "TW", name: "Taiwan, China", region: "Asia", dialCode: "+886" },
|
|
56
|
+
{ code: "CO", name: "Colombia", region: "South America", dialCode: "+57" },
|
|
57
|
+
{ code: "KM", name: "Comoros", region: "Africa", dialCode: "+269" },
|
|
58
|
+
{ code: "CG", name: "Congo", region: "Africa", dialCode: "+242" },
|
|
59
|
+
{ code: "CD", name: "Congo (DRC)", region: "Africa", dialCode: "+243" },
|
|
60
|
+
{ code: "CR", name: "Costa Rica", region: "North America", dialCode: "+506" },
|
|
61
|
+
{ code: "CI", name: "Côte d’Ivoire", region: "Africa", dialCode: "+225" },
|
|
62
|
+
{ code: "HR", name: "Croatia", region: "Europe", dialCode: "+385" },
|
|
63
|
+
{ code: "CU", name: "Cuba", region: "North America", dialCode: "+53" },
|
|
64
|
+
{ code: "CY", name: "Cyprus", region: "Europe", dialCode: "+357" },
|
|
65
|
+
{ code: "CZ", name: "Czechia", region: "Europe", dialCode: "+420" },
|
|
66
|
+
{ code: "DK", name: "Denmark", region: "Europe", dialCode: "+45" },
|
|
67
|
+
{ code: "DJ", name: "Djibouti", region: "Africa", dialCode: "+253" },
|
|
68
|
+
{ code: "DM", name: "Dominica", region: "North America", dialCode: "+1" },
|
|
69
|
+
{ code: "DO", name: "Dominican Republic", region: "North America", dialCode: "+1" },
|
|
70
|
+
{ code: "EC", name: "Ecuador", region: "South America", dialCode: "+593" },
|
|
71
|
+
{ code: "EG", name: "Egypt", region: "Africa", dialCode: "+20" },
|
|
72
|
+
{ code: "SV", name: "El Salvador", region: "North America", dialCode: "+503" },
|
|
73
|
+
{ code: "GQ", name: "Equatorial Guinea", region: "Africa", dialCode: "+240" },
|
|
74
|
+
{ code: "ER", name: "Eritrea", region: "Africa", dialCode: "+291" },
|
|
75
|
+
{ code: "EE", name: "Estonia", region: "Europe", dialCode: "+372" },
|
|
76
|
+
{ code: "SZ", name: "Eswatini", region: "Africa", dialCode: "+268" },
|
|
77
|
+
{ code: "ET", name: "Ethiopia", region: "Africa", dialCode: "+251" },
|
|
78
|
+
{ code: "FO", name: "Faroe Islands", region: "Europe", dialCode: "+298" },
|
|
79
|
+
{ code: "FJ", name: "Fiji", region: "Oceania", dialCode: "+679" },
|
|
80
|
+
{ code: "FI", name: "Finland", region: "Europe", dialCode: "+358" },
|
|
81
|
+
{ code: "FR", name: "France", region: "Europe", dialCode: "+33" },
|
|
82
|
+
{ code: "GF", name: "French Guiana", region: "South America", dialCode: "+594" },
|
|
83
|
+
{ code: "PF", name: "French Polynesia", region: "Oceania", dialCode: "+689" },
|
|
84
|
+
{ code: "GA", name: "Gabon", region: "Africa", dialCode: "+241" },
|
|
85
|
+
{ code: "GM", name: "Gambia", region: "Africa", dialCode: "+220" },
|
|
86
|
+
{ code: "GE", name: "Georgia", region: "Asia", dialCode: "+995" },
|
|
87
|
+
{ code: "DE", name: "Germany", region: "Europe", dialCode: "+49" },
|
|
88
|
+
{ code: "GH", name: "Ghana", region: "Africa", dialCode: "+233" },
|
|
89
|
+
{ code: "GI", name: "Gibraltar", region: "Europe", dialCode: "+350" },
|
|
90
|
+
{ code: "GR", name: "Greece", region: "Europe", dialCode: "+30" },
|
|
91
|
+
{ code: "GL", name: "Greenland", region: "North America", dialCode: "+299" },
|
|
92
|
+
{ code: "GD", name: "Grenada", region: "North America", dialCode: "+1" },
|
|
93
|
+
{ code: "GP", name: "Guadeloupe", region: "North America", dialCode: "+590" },
|
|
94
|
+
{ code: "GU", name: "Guam", region: "Oceania", dialCode: "+1" },
|
|
95
|
+
{ code: "GT", name: "Guatemala", region: "North America", dialCode: "+502" },
|
|
96
|
+
{ code: "GG", name: "Guernsey", region: "Europe", dialCode: "+44" },
|
|
97
|
+
{ code: "GN", name: "Guinea", region: "Africa", dialCode: "+224" },
|
|
98
|
+
{ code: "GW", name: "Guinea-Bissau", region: "Africa", dialCode: "+245" },
|
|
99
|
+
{ code: "GY", name: "Guyana", region: "South America", dialCode: "+592" },
|
|
100
|
+
{ code: "HT", name: "Haiti", region: "North America", dialCode: "+509" },
|
|
101
|
+
{ code: "HN", name: "Honduras", region: "North America", dialCode: "+504" },
|
|
102
|
+
{ code: "HU", name: "Hungary", region: "Europe", dialCode: "+36" },
|
|
103
|
+
{ code: "IS", name: "Iceland", region: "Europe", dialCode: "+354" },
|
|
104
|
+
{ code: "IN", name: "India", region: "Asia", dialCode: "+91" },
|
|
105
|
+
{ code: "ID", name: "Indonesia", region: "Asia", dialCode: "+62" },
|
|
106
|
+
{ code: "IR", name: "Iran", region: "Asia", dialCode: "+98" },
|
|
107
|
+
{ code: "IQ", name: "Iraq", region: "Asia", dialCode: "+964" },
|
|
108
|
+
{ code: "IE", name: "Ireland", region: "Europe", dialCode: "+353" },
|
|
109
|
+
{ code: "IM", name: "Isle of Man", region: "Europe", dialCode: "+44" },
|
|
110
|
+
{ code: "IL", name: "Israel", region: "Asia", dialCode: "+972" },
|
|
111
|
+
{ code: "IT", name: "Italy", region: "Europe", dialCode: "+39" },
|
|
112
|
+
{ code: "JM", name: "Jamaica", region: "North America", dialCode: "+1" },
|
|
113
|
+
{ code: "JP", name: "Japan", region: "Asia", dialCode: "+81" },
|
|
114
|
+
{ code: "JE", name: "Jersey", region: "Europe", dialCode: "+44" },
|
|
115
|
+
{ code: "JO", name: "Jordan", region: "Asia", dialCode: "+962" },
|
|
116
|
+
{ code: "KZ", name: "Kazakhstan", region: "Asia", dialCode: "+7" },
|
|
117
|
+
{ code: "KE", name: "Kenya", region: "Africa", dialCode: "+254" },
|
|
118
|
+
{ code: "KI", name: "Kiribati", region: "Oceania", dialCode: "+686" },
|
|
119
|
+
{ code: "XK", name: "Kosovo", region: "Europe", dialCode: "+383" },
|
|
120
|
+
{ code: "KW", name: "Kuwait", region: "Asia", dialCode: "+965" },
|
|
121
|
+
{ code: "KG", name: "Kyrgyzstan", region: "Asia", dialCode: "+996" },
|
|
122
|
+
{ code: "LA", name: "Laos", region: "Asia", dialCode: "+856" },
|
|
123
|
+
{ code: "LV", name: "Latvia", region: "Europe", dialCode: "+371" },
|
|
124
|
+
{ code: "LB", name: "Lebanon", region: "Asia", dialCode: "+961" },
|
|
125
|
+
{ code: "LS", name: "Lesotho", region: "Africa", dialCode: "+266" },
|
|
126
|
+
{ code: "LR", name: "Liberia", region: "Africa", dialCode: "+231" },
|
|
127
|
+
{ code: "LY", name: "Libya", region: "Africa", dialCode: "+218" },
|
|
128
|
+
{ code: "LI", name: "Liechtenstein", region: "Europe", dialCode: "+423" },
|
|
129
|
+
{ code: "LT", name: "Lithuania", region: "Europe", dialCode: "+370" },
|
|
130
|
+
{ code: "LU", name: "Luxembourg", region: "Europe", dialCode: "+352" },
|
|
131
|
+
{ code: "MG", name: "Madagascar", region: "Africa", dialCode: "+261" },
|
|
132
|
+
{ code: "MW", name: "Malawi", region: "Africa", dialCode: "+265" },
|
|
133
|
+
{ code: "MY", name: "Malaysia", region: "Asia", dialCode: "+60" },
|
|
134
|
+
{ code: "MV", name: "Maldives", region: "Asia", dialCode: "+960" },
|
|
135
|
+
{ code: "ML", name: "Mali", region: "Africa", dialCode: "+223" },
|
|
136
|
+
{ code: "MT", name: "Malta", region: "Europe", dialCode: "+356" },
|
|
137
|
+
{ code: "MH", name: "Marshall Islands", region: "Oceania", dialCode: "+692" },
|
|
138
|
+
{ code: "MQ", name: "Martinique", region: "North America", dialCode: "+596" },
|
|
139
|
+
{ code: "MR", name: "Mauritania", region: "Africa", dialCode: "+222" },
|
|
140
|
+
{ code: "MU", name: "Mauritius", region: "Africa", dialCode: "+230" },
|
|
141
|
+
{ code: "YT", name: "Mayotte", region: "Africa", dialCode: "+262" },
|
|
142
|
+
{ code: "MX", name: "Mexico", region: "North America", dialCode: "+52" },
|
|
143
|
+
{ code: "FM", name: "Micronesia", region: "Oceania", dialCode: "+691" },
|
|
144
|
+
{ code: "MD", name: "Moldova", region: "Europe", dialCode: "+373" },
|
|
145
|
+
{ code: "MC", name: "Monaco", region: "Europe", dialCode: "+377" },
|
|
146
|
+
{ code: "MN", name: "Mongolia", region: "Asia", dialCode: "+976" },
|
|
147
|
+
{ code: "ME", name: "Montenegro", region: "Europe", dialCode: "+382" },
|
|
148
|
+
{ code: "MS", name: "Montserrat", region: "North America", dialCode: "+1" },
|
|
149
|
+
{ code: "MA", name: "Morocco", region: "Africa", dialCode: "+212" },
|
|
150
|
+
{ code: "MZ", name: "Mozambique", region: "Africa", dialCode: "+258" },
|
|
151
|
+
{ code: "MM", name: "Myanmar", region: "Asia", dialCode: "+95" },
|
|
152
|
+
{ code: "NA", name: "Namibia", region: "Africa", dialCode: "+264" },
|
|
153
|
+
{ code: "NR", name: "Nauru", region: "Oceania", dialCode: "+674" },
|
|
154
|
+
{ code: "NP", name: "Nepal", region: "Asia", dialCode: "+977" },
|
|
155
|
+
{ code: "NL", name: "Netherlands", region: "Europe", dialCode: "+31" },
|
|
156
|
+
{ code: "NC", name: "New Caledonia", region: "Oceania", dialCode: "+687" },
|
|
157
|
+
{ code: "NZ", name: "New Zealand", region: "Oceania", dialCode: "+64" },
|
|
158
|
+
{ code: "NI", name: "Nicaragua", region: "North America", dialCode: "+505" },
|
|
159
|
+
{ code: "NE", name: "Niger", region: "Africa", dialCode: "+227" },
|
|
160
|
+
{ code: "NG", name: "Nigeria", region: "Africa", dialCode: "+234" },
|
|
161
|
+
{ code: "NU", name: "Niue", region: "Oceania", dialCode: "+683" },
|
|
162
|
+
{ code: "NF", name: "Norfolk Island", region: "Oceania", dialCode: "+672" },
|
|
163
|
+
{ code: "KP", name: "North Korea", region: "Asia", dialCode: "+850" },
|
|
164
|
+
{ code: "MK", name: "North Macedonia", region: "Europe", dialCode: "+389" },
|
|
165
|
+
{ code: "MP", name: "Northern Mariana Islands", region: "Oceania", dialCode: "+1" },
|
|
166
|
+
{ code: "NO", name: "Norway", region: "Europe", dialCode: "+47" },
|
|
167
|
+
{ code: "OM", name: "Oman", region: "Asia", dialCode: "+968" },
|
|
168
|
+
{ code: "PK", name: "Pakistan", region: "Asia", dialCode: "+92" },
|
|
169
|
+
{ code: "PW", name: "Palau", region: "Oceania", dialCode: "+680" },
|
|
170
|
+
{ code: "PS", name: "Palestine", region: "Asia", dialCode: "+970" },
|
|
171
|
+
{ code: "PA", name: "Panama", region: "North America", dialCode: "+507" },
|
|
172
|
+
{ code: "PG", name: "Papua New Guinea", region: "Oceania", dialCode: "+675" },
|
|
173
|
+
{ code: "PY", name: "Paraguay", region: "South America", dialCode: "+595" },
|
|
174
|
+
{ code: "PE", name: "Peru", region: "South America", dialCode: "+51" },
|
|
175
|
+
{ code: "PH", name: "Philippines", region: "Asia", dialCode: "+63" },
|
|
176
|
+
{ code: "PL", name: "Poland", region: "Europe", dialCode: "+48" },
|
|
177
|
+
{ code: "PT", name: "Portugal", region: "Europe", dialCode: "+351" },
|
|
178
|
+
{ code: "PR", name: "Puerto Rico", region: "North America", dialCode: "+1" },
|
|
179
|
+
{ code: "QA", name: "Qatar", region: "Asia", dialCode: "+974" },
|
|
180
|
+
{ code: "RE", name: "Réunion", region: "Africa", dialCode: "+262" },
|
|
181
|
+
{ code: "RO", name: "Romania", region: "Europe", dialCode: "+40" },
|
|
182
|
+
{ code: "RU", name: "Russia", region: "Europe", dialCode: "+7" },
|
|
183
|
+
{ code: "RW", name: "Rwanda", region: "Africa", dialCode: "+250" },
|
|
184
|
+
{ code: "BL", name: "Saint Barthélemy", region: "North America", dialCode: "+590" },
|
|
185
|
+
{ code: "KN", name: "Saint Kitts and Nevis", region: "North America", dialCode: "+1" },
|
|
186
|
+
{ code: "LC", name: "Saint Lucia", region: "North America", dialCode: "+1" },
|
|
187
|
+
{ code: "MF", name: "Saint Martin", region: "North America", dialCode: "+590" },
|
|
188
|
+
{ code: "PM", name: "Saint Pierre and Miquelon", region: "North America", dialCode: "+508" },
|
|
189
|
+
{ code: "VC", name: "Saint Vincent and the Grenadines", region: "North America", dialCode: "+1" },
|
|
190
|
+
{ code: "WS", name: "Samoa", region: "Oceania", dialCode: "+685" },
|
|
191
|
+
{ code: "SM", name: "San Marino", region: "Europe", dialCode: "+378" },
|
|
192
|
+
{ code: "ST", name: "São Tomé and Príncipe", region: "Africa", dialCode: "+239" },
|
|
193
|
+
{ code: "SA", name: "Saudi Arabia", region: "Asia", dialCode: "+966" },
|
|
194
|
+
{ code: "SN", name: "Senegal", region: "Africa", dialCode: "+221" },
|
|
195
|
+
{ code: "RS", name: "Serbia", region: "Europe", dialCode: "+381" },
|
|
196
|
+
{ code: "SC", name: "Seychelles", region: "Africa", dialCode: "+248" },
|
|
197
|
+
{ code: "SL", name: "Sierra Leone", region: "Africa", dialCode: "+232" },
|
|
198
|
+
{ code: "SG", name: "Singapore", region: "Asia", dialCode: "+65" },
|
|
199
|
+
{ code: "SX", name: "Sint Maarten", region: "North America", dialCode: "+1" },
|
|
200
|
+
{ code: "SK", name: "Slovakia", region: "Europe", dialCode: "+421" },
|
|
201
|
+
{ code: "SI", name: "Slovenia", region: "Europe", dialCode: "+386" },
|
|
202
|
+
{ code: "SB", name: "Solomon Islands", region: "Oceania", dialCode: "+677" },
|
|
203
|
+
{ code: "SO", name: "Somalia", region: "Africa", dialCode: "+252" },
|
|
204
|
+
{ code: "ZA", name: "South Africa", region: "Africa", dialCode: "+27" },
|
|
205
|
+
{ code: "KR", name: "South Korea", region: "Asia", dialCode: "+82" },
|
|
206
|
+
{ code: "SS", name: "South Sudan", region: "Africa", dialCode: "+211" },
|
|
207
|
+
{ code: "ES", name: "Spain", region: "Europe", dialCode: "+34" },
|
|
208
|
+
{ code: "LK", name: "Sri Lanka", region: "Asia", dialCode: "+94" },
|
|
209
|
+
{ code: "SD", name: "Sudan", region: "Africa", dialCode: "+249" },
|
|
210
|
+
{ code: "SR", name: "Suriname", region: "South America", dialCode: "+597" },
|
|
211
|
+
{ code: "SE", name: "Sweden", region: "Europe", dialCode: "+46" },
|
|
212
|
+
{ code: "CH", name: "Switzerland", region: "Europe", dialCode: "+41" },
|
|
213
|
+
{ code: "SY", name: "Syria", region: "Asia", dialCode: "+963" },
|
|
214
|
+
{ code: "TJ", name: "Tajikistan", region: "Asia", dialCode: "+992" },
|
|
215
|
+
{ code: "TZ", name: "Tanzania", region: "Africa", dialCode: "+255" },
|
|
216
|
+
{ code: "TH", name: "Thailand", region: "Asia", dialCode: "+66" },
|
|
217
|
+
{ code: "TG", name: "Togo", region: "Africa", dialCode: "+228" },
|
|
218
|
+
{ code: "TK", name: "Tokelau", region: "Oceania", dialCode: "+690" },
|
|
219
|
+
{ code: "TO", name: "Tonga", region: "Oceania", dialCode: "+676" },
|
|
220
|
+
{ code: "TT", name: "Trinidad and Tobago", region: "North America", dialCode: "+1" },
|
|
221
|
+
{ code: "TN", name: "Tunisia", region: "Africa", dialCode: "+216" },
|
|
222
|
+
{ code: "TR", name: "Türkiye", region: "Europe", dialCode: "+90" },
|
|
223
|
+
{ code: "TM", name: "Turkmenistan", region: "Asia", dialCode: "+993" },
|
|
224
|
+
{ code: "TC", name: "Turks and Caicos Islands", region: "North America", dialCode: "+1" },
|
|
225
|
+
{ code: "TV", name: "Tuvalu", region: "Oceania", dialCode: "+688" },
|
|
226
|
+
{ code: "UG", name: "Uganda", region: "Africa", dialCode: "+256" },
|
|
227
|
+
{ code: "UA", name: "Ukraine", region: "Europe", dialCode: "+380" },
|
|
228
|
+
{ code: "AE", name: "United Arab Emirates", region: "Asia", dialCode: "+971" },
|
|
229
|
+
{ code: "GB", name: "United Kingdom", region: "Europe", dialCode: "+44" },
|
|
230
|
+
{ code: "US", name: "United States", region: "North America", dialCode: "+1" },
|
|
231
|
+
{ code: "UY", name: "Uruguay", region: "South America", dialCode: "+598" },
|
|
232
|
+
{ code: "UZ", name: "Uzbekistan", region: "Asia", dialCode: "+998" },
|
|
233
|
+
{ code: "VU", name: "Vanuatu", region: "Oceania", dialCode: "+678" },
|
|
234
|
+
{ code: "VA", name: "Vatican City", region: "Europe", dialCode: "+39" },
|
|
235
|
+
{ code: "VE", name: "Venezuela", region: "South America", dialCode: "+58" },
|
|
236
|
+
{ code: "VN", name: "Vietnam", region: "Asia", dialCode: "+84" },
|
|
237
|
+
{ code: "VI", name: "U.S. Virgin Islands", region: "North America", dialCode: "+1" },
|
|
238
|
+
{ code: "WF", name: "Wallis and Futuna", region: "Oceania", dialCode: "+681" },
|
|
239
|
+
{ code: "EH", name: "Western Sahara", region: "Africa", dialCode: "+212" },
|
|
240
|
+
{ code: "YE", name: "Yemen", region: "Asia", dialCode: "+967" },
|
|
241
|
+
{ code: "ZM", name: "Zambia", region: "Africa", dialCode: "+260" },
|
|
242
|
+
{ code: "ZW", name: "Zimbabwe", region: "Africa", dialCode: "+263" },
|
|
243
|
+
];
|
|
@@ -1,49 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Input } from "./Input";
|
|
3
|
-
import { Input2 } from "./Input2";
|
|
4
|
-
import { Textarea } from "./Textarea";
|
|
5
|
-
import { Textarea2 } from "./Textarea2";
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
case "
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return Input;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return Textarea;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
import { FileUpload2, FileUploadProps } from "./FileUpload2";
|
|
2
|
+
import { Input } from "./Input";
|
|
3
|
+
import { Input2 } from "./Input2";
|
|
4
|
+
import { Textarea } from "./Textarea";
|
|
5
|
+
import { Textarea2 } from "./Textarea2";
|
|
6
|
+
import TelInput from "./TelInput";
|
|
7
|
+
import TelInput2 from "./TelInput2";
|
|
8
|
+
import { FieldStyle } from "./types";
|
|
9
|
+
|
|
10
|
+
export const getControl = (controlName?: string, fieldStyle?: FieldStyle) => {
|
|
11
|
+
switch (controlName) {
|
|
12
|
+
case "Input":
|
|
13
|
+
return getInput(fieldStyle);
|
|
14
|
+
case "Textarea":
|
|
15
|
+
return getTextarea(fieldStyle);
|
|
16
|
+
case "TelInput":
|
|
17
|
+
return getTelInput(fieldStyle);
|
|
18
|
+
default:
|
|
19
|
+
return getInput(fieldStyle);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getInput = (fieldStyle?: FieldStyle) => {
|
|
24
|
+
if (fieldStyle === "default") {
|
|
25
|
+
return Input;
|
|
26
|
+
} else if (fieldStyle === "label-inline") {
|
|
27
|
+
return Input2;
|
|
28
|
+
} else {
|
|
29
|
+
return Input;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getTextarea = (fieldStyle?: FieldStyle) => {
|
|
34
|
+
if (fieldStyle === "default") {
|
|
35
|
+
return Textarea;
|
|
36
|
+
} else if (fieldStyle === "label-inline") {
|
|
37
|
+
return Textarea2;
|
|
38
|
+
} else {
|
|
39
|
+
return Textarea;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const getTelInput = (fieldStyle?: FieldStyle) => {
|
|
44
|
+
if (fieldStyle === "label-inline") {
|
|
45
|
+
return TelInput2;
|
|
46
|
+
}
|
|
47
|
+
return TelInput;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const getFileUpload = (
|
|
51
|
+
fieldStyle?: FieldStyle
|
|
52
|
+
): React.FC<FileUploadProps> => {
|
|
53
|
+
if (fieldStyle === "default") {
|
|
54
|
+
return FileUpload2;
|
|
55
|
+
} else if (fieldStyle === "label-inline") {
|
|
56
|
+
return FileUpload2;
|
|
57
|
+
} else {
|
|
58
|
+
return FileUpload2;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 计算内联标签布局所需的 paddingLeft(= label 宽度 + 额外间距)
|
|
5
|
+
* - 返回 labelRef 供 <label ref={labelRef} /> 绑定
|
|
6
|
+
* - 返回 paddingLeft 用于内层输入/容器 style
|
|
7
|
+
*/
|
|
8
|
+
export function useInlineLabelPadding(extraSpace: number = 16) {
|
|
9
|
+
const labelRef = useRef<HTMLLabelElement>(null);
|
|
10
|
+
const [paddingLeft, setPaddingLeft] = useState<string>("3.5rem");
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (labelRef.current) {
|
|
14
|
+
const width = labelRef.current.getBoundingClientRect().width;
|
|
15
|
+
setPaddingLeft(`${width + extraSpace}px`);
|
|
16
|
+
}
|
|
17
|
+
}, [extraSpace]);
|
|
18
|
+
|
|
19
|
+
return { labelRef, paddingLeft } as const;
|
|
20
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import type { CountryDial } from "../countryDialCodes";
|
|
3
|
+
import { countries as defaultCountries } from "../countryDialCodes";
|
|
4
|
+
|
|
5
|
+
export interface UseTelControlOptions {
|
|
6
|
+
countries?: CountryDial[];
|
|
7
|
+
name: string;
|
|
8
|
+
value?: string | number | readonly string[] | undefined;
|
|
9
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useTelControl({ countries, name, value, onChange }: UseTelControlOptions) {
|
|
13
|
+
const allCountries = useMemo<CountryDial[]>(() => countries || defaultCountries, [countries]);
|
|
14
|
+
|
|
15
|
+
const [selected, setSelected] = useState<CountryDial | null>(null);
|
|
16
|
+
const [localNumber, setLocalNumber] = useState<string>("");
|
|
17
|
+
|
|
18
|
+
const toStringValue = (val?: string | number | readonly string[]) => {
|
|
19
|
+
if (typeof val === "string") return val;
|
|
20
|
+
if (typeof val === "number") return String(val);
|
|
21
|
+
if (Array.isArray(val)) return val[0] ?? "";
|
|
22
|
+
return "";
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const s = toStringValue(value).trim();
|
|
27
|
+
const m = s.match(/^\+\d{1,4}/);
|
|
28
|
+
const dial = m ? m[0] : "";
|
|
29
|
+
const number = s.slice(dial.length).trimStart();
|
|
30
|
+
setLocalNumber(number || "");
|
|
31
|
+
if (dial) {
|
|
32
|
+
const found = allCountries.find((c) => c.dialCode === dial) || null;
|
|
33
|
+
setSelected(found);
|
|
34
|
+
} else {
|
|
35
|
+
setSelected(null);
|
|
36
|
+
}
|
|
37
|
+
}, [value, allCountries]);
|
|
38
|
+
|
|
39
|
+
const emitChange = (combined: string) => {
|
|
40
|
+
if (!onChange) return;
|
|
41
|
+
const evt = {
|
|
42
|
+
target: { value: combined, name } as unknown,
|
|
43
|
+
currentTarget: { value: combined, name } as unknown,
|
|
44
|
+
} as unknown as React.ChangeEvent<HTMLInputElement>;
|
|
45
|
+
onChange(evt);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const filtered = (query: string) => {
|
|
49
|
+
if (!query) return allCountries;
|
|
50
|
+
const q = query.toLowerCase();
|
|
51
|
+
return allCountries.filter(
|
|
52
|
+
(c) =>
|
|
53
|
+
c.name.toLowerCase().includes(q) ||
|
|
54
|
+
(c.region && c.region.toLowerCase().includes(q)) ||
|
|
55
|
+
c.dialCode.replace("+", "").includes(q.replace("+", ""))
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const onSelectCountry = (c: CountryDial) => {
|
|
60
|
+
setSelected(c);
|
|
61
|
+
const combined = `${c.dialCode} ${localNumber}`.trim();
|
|
62
|
+
emitChange(combined);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const onChangeLocal = (next: string) => {
|
|
66
|
+
setLocalNumber(next);
|
|
67
|
+
const combined = `${selected?.dialCode || ""} ${next}`.trim();
|
|
68
|
+
emitChange(combined);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
allCountries,
|
|
73
|
+
selected,
|
|
74
|
+
setSelected,
|
|
75
|
+
localNumber,
|
|
76
|
+
setLocalNumber,
|
|
77
|
+
filtered,
|
|
78
|
+
onSelectCountry,
|
|
79
|
+
onChangeLocal,
|
|
80
|
+
} as const;
|
|
81
|
+
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
export interface VisitorInfo {
|
|
4
|
-
visitorId: string | null;
|
|
5
|
-
sessionId: string | null;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function useVisitorInfo() {
|
|
9
|
-
const [visitorInfo, setVisitorInfo] = useState<VisitorInfo>({
|
|
10
|
-
visitorId: null,
|
|
11
|
-
sessionId: null,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
const getVisitorId = () => {
|
|
16
|
-
const match = document.cookie.match(/visitor_id=([^;]+)/);
|
|
17
|
-
return match ? match[1] : null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getSessionId = () => {
|
|
21
|
-
return sessionStorage.getItem("session_id");
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
setVisitorInfo({
|
|
25
|
-
visitorId: getVisitorId(),
|
|
26
|
-
sessionId: getSessionId(),
|
|
27
|
-
});
|
|
28
|
-
}, []);
|
|
29
|
-
|
|
30
|
-
return visitorInfo;
|
|
31
|
-
}
|