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.
@@ -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;
@@ -1,14 +0,0 @@
1
- declare module "*.png" {
2
- const value: string;
3
- export default value;
4
- }
5
-
6
- declare module "*.jpg" {
7
- const value: string;
8
- export default value;
9
- }
10
-
11
- declare module "*.svg" {
12
- const value: string;
13
- export default value;
14
- }
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";