ml-ui-lib 1.0.4 → 1.0.6
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/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/package.json +5 -6
- package/src/common.css +0 -27
- package/src/components/Alert/Alert.css +0 -56
- package/src/components/Alert/Alert.tsx +0 -27
- package/src/components/Button/Button.css +0 -24
- package/src/components/Button/Button.tsx +0 -20
- package/src/components/DatePicker/DatePicker.css +0 -103
- package/src/components/DatePicker/DatePicker.tsx +0 -158
- package/src/components/DatePicker2/DatePicker2.css +0 -113
- package/src/components/DatePicker2/DatePicker2.tsx +0 -179
- package/src/components/Dropdown/Dropdown.css +0 -84
- package/src/components/Dropdown/Dropdown.tsx +0 -76
- package/src/components/Input/Input.css +0 -36
- package/src/components/Input/Input.tsx +0 -24
- package/src/components/Modal/Modal.css +0 -81
- package/src/components/Modal/Modal.tsx +0 -63
- package/src/components/Modal/icons/error.png +0 -0
- package/src/components/PhoneInput/PhoneInput.css +0 -78
- package/src/components/PhoneInput/PhoneInput.tsx +0 -127
- package/src/declarations.d.ts +0 -14
- package/src/index.ts +0 -25
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
3
|
-
import "./PhoneInput.css";
|
|
4
|
-
|
|
5
|
-
interface CountryOption {
|
|
6
|
-
code: string;
|
|
7
|
-
country: string;
|
|
8
|
-
flag: string; // CDN URL or emoji
|
|
9
|
-
placeholder: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface PhoneInputProps {
|
|
13
|
-
value: string;
|
|
14
|
-
onChange: (formatted: string) => void;
|
|
15
|
-
country?: string;
|
|
16
|
-
onCountryChange?: (countryCode: string) => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const countryOptions: Record<string, CountryOption> = {
|
|
20
|
-
PH: {
|
|
21
|
-
code: "+63",
|
|
22
|
-
country: "Philippines",
|
|
23
|
-
flag: "https://flagcdn.com/w20/ph.png",
|
|
24
|
-
placeholder: "988 888 8888",
|
|
25
|
-
},
|
|
26
|
-
US: {
|
|
27
|
-
code: "+1",
|
|
28
|
-
country: "United States",
|
|
29
|
-
flag: "https://flagcdn.com/w20/us.png",
|
|
30
|
-
placeholder: "(000) 888 8888",
|
|
31
|
-
},
|
|
32
|
-
CA: {
|
|
33
|
-
code: "+1",
|
|
34
|
-
country: "Canada",
|
|
35
|
-
flag: "https://flagcdn.com/w20/ca.png",
|
|
36
|
-
placeholder: "000 888 8888",
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const PhoneInput: React.FC<PhoneInputProps> = ({
|
|
41
|
-
value,
|
|
42
|
-
onChange,
|
|
43
|
-
country = "PH",
|
|
44
|
-
onCountryChange,
|
|
45
|
-
}) => {
|
|
46
|
-
const [selectedCountry, setSelectedCountry] = useState<string>(country);
|
|
47
|
-
const [dropdownOpen, setDropdownOpen] = useState(false);
|
|
48
|
-
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
const handleClickOutside = (e: MouseEvent) => {
|
|
52
|
-
if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) {
|
|
53
|
-
setDropdownOpen(false);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
57
|
-
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
58
|
-
}, []);
|
|
59
|
-
|
|
60
|
-
const handleCountrySelect = (countryKey: string) => {
|
|
61
|
-
setSelectedCountry(countryKey);
|
|
62
|
-
setDropdownOpen(false);
|
|
63
|
-
onCountryChange?.(countryKey);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const formatPhone = (raw: string) => {
|
|
67
|
-
const digits = raw.replace(/\D/g, "");
|
|
68
|
-
if (selectedCountry === "PH") {
|
|
69
|
-
return digits.replace(/^(\d{3})(\d{3})(\d{0,4}).*/, "$1 $2 $3").trim();
|
|
70
|
-
}
|
|
71
|
-
if (selectedCountry === "US" || selectedCountry === "CA") {
|
|
72
|
-
return digits.replace(/^(\d{3})(\d{3})(\d{0,4}).*/, "($1) $2 $3").trim();
|
|
73
|
-
}
|
|
74
|
-
return digits;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
78
|
-
const formatted = formatPhone(e.target.value);
|
|
79
|
-
onChange(formatted);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<div className="phone-input-wrapper" ref={dropdownRef}>
|
|
84
|
-
{/* Country Selector */}
|
|
85
|
-
<div
|
|
86
|
-
className="country-dropdown"
|
|
87
|
-
onClick={() => setDropdownOpen(!dropdownOpen)}
|
|
88
|
-
>
|
|
89
|
-
<img
|
|
90
|
-
src={countryOptions[selectedCountry].flag}
|
|
91
|
-
alt={countryOptions[selectedCountry].country}
|
|
92
|
-
className="country-flag"
|
|
93
|
-
/>
|
|
94
|
-
<span className="country-code">{countryOptions[selectedCountry].code}</span>
|
|
95
|
-
</div>
|
|
96
|
-
|
|
97
|
-
{/* Dropdown Menu */}
|
|
98
|
-
{dropdownOpen && (
|
|
99
|
-
<div className="country-dropdown-menu">
|
|
100
|
-
{Object.entries(countryOptions).map(([key, { code, country, flag }]) => (
|
|
101
|
-
<div
|
|
102
|
-
key={key}
|
|
103
|
-
className="country-dropdown-item"
|
|
104
|
-
onClick={() => handleCountrySelect(key)}
|
|
105
|
-
>
|
|
106
|
-
<img src={flag} alt={country} className="country-flag" />
|
|
107
|
-
<span>{country}</span>
|
|
108
|
-
<span className="country-code-text">{code}</span>
|
|
109
|
-
</div>
|
|
110
|
-
))}
|
|
111
|
-
</div>
|
|
112
|
-
)}
|
|
113
|
-
|
|
114
|
-
{/* Input */}
|
|
115
|
-
<input
|
|
116
|
-
type="text"
|
|
117
|
-
value={value}
|
|
118
|
-
onChange={handleInputChange}
|
|
119
|
-
placeholder={countryOptions[selectedCountry].placeholder}
|
|
120
|
-
className="phone-input"
|
|
121
|
-
autoComplete="off"
|
|
122
|
-
/>
|
|
123
|
-
</div>
|
|
124
|
-
);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export default PhoneInput;
|
package/src/declarations.d.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import "./common.css";
|
|
2
|
-
|
|
3
|
-
export { Button } from "./components/Button/Button";
|
|
4
|
-
export type { ButtonProps } from "./components/Button/Button";
|
|
5
|
-
|
|
6
|
-
export { Modal } from "./components/Modal/Modal";
|
|
7
|
-
export type { ModalProps } from "./components/Modal/Modal";
|
|
8
|
-
|
|
9
|
-
export { Input } from "./components/Input/Input";
|
|
10
|
-
export type { InputProps } from "./components/Input/Input";
|
|
11
|
-
|
|
12
|
-
export { Alert } from "./components/Alert/Alert";
|
|
13
|
-
export type { AlertProps, AlertVariant } from "./components/Alert/Alert";
|
|
14
|
-
|
|
15
|
-
export { PhoneInput } from "./components/PhoneInput/PhoneInput";
|
|
16
|
-
export type { PhoneInputProps } from "./components/PhoneInput/PhoneInput";
|
|
17
|
-
|
|
18
|
-
export { Dropdown } from "./components/Dropdown/Dropdown";
|
|
19
|
-
export type { DropdownProps } from "./components/Dropdown/Dropdown";
|
|
20
|
-
|
|
21
|
-
export { DatePicker2 } from "./components/DatePicker2/DatePicker2";
|
|
22
|
-
export type { DatePicker2Props, DateValue } from "./components/DatePicker2/DatePicker2";
|
|
23
|
-
|
|
24
|
-
export { DatePicker } from "./components/DatePicker/DatePicker";
|
|
25
|
-
export type { DatePickerProps, DatePickerValue } from "./components/DatePicker/DatePicker";
|