|
| 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