lite-phone-input 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 wp-sms
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # lite-phone-input
2
+
3
+ [![npm version](https://img.shields.io/npm/v/lite-phone-input.svg)](https://www.npmjs.com/package/lite-phone-input)
4
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/lite-phone-input)](https://bundlephobia.com/package/lite-phone-input)
5
+ [![license](https://img.shields.io/npm/l/lite-phone-input.svg)](./LICENSE)
6
+
7
+ Lightweight phone input with format-as-you-type, validation, and emoji flags. **~13KB gzipped total** — zero runtime dependencies.
8
+
9
+ ## Why lite-phone-input?
10
+
11
+ | | lite-phone-input | intl-tel-input |
12
+ |---|---|---|
13
+ | **JS bundle** | ~13KB (includes formatting + validation) | ~15KB + ~260KB utils |
14
+ | **Flag assets** | Emoji (0KB) | Webp sprites (30–66KB) |
15
+ | **Dependencies** | 0 | Flag sprites + optional utils |
16
+ | **Formatting** | Built-in | Requires utils bundle |
17
+ | **Validation** | Built-in | Requires utils bundle |
18
+
19
+ ## Features
20
+
21
+ - **~13KB gzipped** (JS + country data) — includes formatting AND validation
22
+ - **Emoji flags** computed from ISO code at runtime (zero image cost)
23
+ - **Format-as-you-type** with per-country masks (~240 countries)
24
+ - **Per-country length validation** with rich error data
25
+ - **TypeScript-first** with full type definitions
26
+ - **Framework adapters** — Vanilla JS, React, Preact
27
+ - **Accessible** — WCAG 2.1 AA, ARIA combobox pattern, keyboard navigation
28
+ - **SSR-safe** — no browser API calls at module level
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ npm install lite-phone-input
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ### Vanilla JS
39
+
40
+ ```js
41
+ import { PhoneInput } from 'lite-phone-input/vanilla';
42
+ import 'lite-phone-input/styles';
43
+
44
+ const phone = PhoneInput.mount(document.getElementById('phone'), {
45
+ defaultCountry: 'US',
46
+ separateDialCode: true,
47
+ onChange(e164, country, validation) {
48
+ console.log(e164); // '+12025551234'
49
+ console.log(country.code); // 'US'
50
+ console.log(validation.valid); // true
51
+ },
52
+ });
53
+ ```
54
+
55
+ ### React
56
+
57
+ ```jsx
58
+ import { useRef, useState } from 'react';
59
+ import { PhoneInput } from 'lite-phone-input/react';
60
+ import 'lite-phone-input/styles';
61
+
62
+ function MyForm() {
63
+ const [value, setValue] = useState('');
64
+ const phoneRef = useRef(null);
65
+
66
+ return (
67
+ <PhoneInput
68
+ ref={phoneRef}
69
+ defaultCountry="US"
70
+ separateDialCode
71
+ value={value}
72
+ onChange={(e164) => setValue(e164)}
73
+ name="phone"
74
+ aria-label="Phone number"
75
+ />
76
+ );
77
+ }
78
+ ```
79
+
80
+ ### Preact
81
+
82
+ ```jsx
83
+ import { PhoneInput } from 'lite-phone-input/preact';
84
+ import 'lite-phone-input/styles';
85
+ ```
86
+
87
+ Same API as React. Uses `preact/hooks` directly — no `preact/compat` required.
88
+
89
+ ### CDN / Script Tag
90
+
91
+ ```html
92
+ <link rel="stylesheet" href="https://unpkg.com/lite-phone-input/dist/styles.css">
93
+ <script src="https://unpkg.com/lite-phone-input/dist/vanilla/index.global.js"></script>
94
+ <script>
95
+ const phone = LitePhoneInput.PhoneInput.mount(document.getElementById('phone'), {
96
+ defaultCountry: 'US',
97
+ });
98
+ </script>
99
+ ```
100
+
101
+ ## Documentation
102
+
103
+ | Guide | Description |
104
+ |---|---|
105
+ | [Getting Started](docs/getting-started.md) | Installation and first render |
106
+ | [Vanilla JS Guide](docs/vanilla-guide.md) | Mounting, methods, callbacks |
107
+ | [React Guide](docs/react-guide.md) | Controlled/uncontrolled, form libraries |
108
+ | [Preact Guide](docs/preact-guide.md) | Preact-specific setup |
109
+ | [API Reference](docs/api-reference.md) | All options, methods, and types |
110
+ | [Styling & Theming](docs/styling.md) | CSS variables, BEM classes, dark mode |
111
+ | [Validation](docs/validation.md) | Validation model and error messages |
112
+ | [Form Integration](docs/form-integration.md) | Hidden inputs, RHF, Formik |
113
+ | [Core Utilities](docs/core-utilities.md) | Headless/server-side functions |
114
+ | [Accessibility](docs/accessibility.md) | ARIA patterns, keyboard navigation |
115
+ | [Advanced Topics](docs/advanced.md) | SSR, RTL, i18n, portals |
116
+ | [Migration from intl-tel-input](docs/migration-from-intl-tel-input.md) | Comparison and migration guide |
117
+
118
+ ## Browser Support
119
+
120
+ Chrome 80+, Firefox 80+, Safari 14+, Edge 80+. No IE support, no polyfills needed.
121
+
122
+ ## Contributing
123
+
124
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
125
+
126
+ ## Changelog
127
+
128
+ See [CHANGELOG.md](CHANGELOG.md) for release history.
129
+
130
+ ## License
131
+
132
+ [MIT](LICENSE)