Skip to content

Commit 0267bfa

Browse files
committed
feat: add phone number formatting
1 parent a4e0982 commit 0267bfa

File tree

17 files changed

+924
-72
lines changed

17 files changed

+924
-72
lines changed

docs/.vitepress/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ declare module 'vue' {
1515
HomeSponsors: typeof import('./theme/components/HomeSponsors.vue')['default']
1616
HomeTeam: typeof import('./theme/components/HomeTeam.vue')['default']
1717
NumeralInputDemo: typeof import('./theme/components/vue-demo/NumeralInputDemo.vue')['default']
18+
PhoneInputDemo: typeof import('./theme/components/vue-demo/PhoneInputDemo.vue')['default']
1819
TeamMember: typeof import('./theme/components/TeamMember.vue')['default']
1920
TimeInputDemo: typeof import('./theme/components/vue-demo/TimeInputDemo.vue')['default']
2021
}

docs/.vitepress/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ const sidebar = [
6262
{
6363
text: 'Features',
6464
items: [
65+
{ text: 'Phone Formatting', link: '/features/phone' },
6566
{ text: 'Credit Card Formatting', link: '/features/credit-card' },
6667
{ text: 'Date Formatting', link: '/features/date' },
6768
{ text: 'Time Formatting', link: '/features/time' },
6869
{ text: 'Numerical Formatting', link: '/features/numeral' },
69-
{ text: 'Cursor Tracking', link: '/features/cursor' },
7070
],
7171
},
7272
{
@@ -76,8 +76,9 @@ const sidebar = [
7676
text: 'Vue Components',
7777
items: [
7878
{ text: 'Overview', link: '/vue/' },
79+
{ text: 'Phone Input', link: '/vue/phone' },
7980
{ text: 'Credit Card Input', link: '/vue/credit-card' },
80-
{ text: 'DateTime Input', link: '/vue/datetime' },
81+
{ text: 'Date Input', link: '/vue/date' },
8182
{ text: 'Time Input', link: '/vue/time' },
8283
{ text: 'Numeral Input', link: '/vue/numeral' },
8384
{ text: 'Places Autocomplete', link: '/vue/places-autocomplete' },
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<script setup lang="ts">
2+
import { PhoneInput } from 'ts-inputs-vue'
3+
import { computed, ref } from 'vue'
4+
5+
const phone = ref('')
6+
const delimiter = ref('-')
7+
const pattern = ref([3, 3, 4]) // Default US pattern: XXX-XXX-XXXX
8+
9+
const options = computed(() => ({
10+
delimiter: delimiter.value,
11+
pattern: pattern.value,
12+
}))
13+
14+
const formattedValue = computed(() => {
15+
if (!phone.value)
16+
return ''
17+
return phone.value
18+
})
19+
</script>
20+
21+
<template>
22+
<div class="demo-container">
23+
<div class="input-section">
24+
<div class="input-group">
25+
<label class="block text-sm font-medium text-gray-700">Phone Input</label>
26+
<PhoneInput
27+
v-model="phone"
28+
v-bind="options"
29+
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
30+
placeholder="Enter phone number"
31+
/>
32+
</div>
33+
34+
<div class="options-grid">
35+
<div class="option-group">
36+
<label class="block text-sm font-medium text-gray-700">Delimiter</label>
37+
<select
38+
v-model="delimiter"
39+
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
40+
>
41+
<option value="-">
42+
Hyphen (-)
43+
</option>
44+
<option value=" ">
45+
Space ( )
46+
</option>
47+
<option value=".">
48+
Dot (.)
49+
</option>
50+
</select>
51+
</div>
52+
53+
<div class="option-group">
54+
<label class="block text-sm font-medium text-gray-700">Pattern</label>
55+
<select
56+
v-model="pattern"
57+
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
58+
>
59+
<option :value="[3, 3, 4]">
60+
US (XXX-XXX-XXXX)
61+
</option>
62+
<option :value="[4, 3, 3]">
63+
UK (XXXX-XXX-XXX)
64+
</option>
65+
<option :value="[2, 4, 4]">
66+
France (XX-XXXX-XXXX)
67+
</option>
68+
<option :value="[3, 2, 2, 2]">
69+
Germany (XXX-XX-XX-XX)
70+
</option>
71+
</select>
72+
</div>
73+
</div>
74+
</div>
75+
76+
<div class="result-section">
77+
<h3 class="text-lg font-medium text-gray-900">
78+
Result
79+
</h3>
80+
<div class="mt-2">
81+
<div class="text-sm text-gray-500">
82+
Formatted Value:
83+
</div>
84+
<div class="mt-1 font-mono text-lg">
85+
{{ formattedValue }}
86+
</div>
87+
</div>
88+
</div>
89+
</div>
90+
</template>
91+
92+
<style scoped>
93+
.demo-container {
94+
@apply max-w-4xl mx-auto p-6 bg-white rounded-lg shadow;
95+
}
96+
97+
.input-section {
98+
@apply space-y-6;
99+
}
100+
101+
.options-grid {
102+
@apply grid grid-cols-1 md:grid-cols-2 gap-4;
103+
}
104+
105+
.option-group {
106+
@apply space-y-1;
107+
}
108+
109+
.result-section {
110+
@apply mt-6 p-4 bg-gray-50 rounded-lg;
111+
}
112+
</style>

0 commit comments

Comments
 (0)