|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import { CreditCardType } from 'ts-inputs' |
3 | | -import { BaseInput, CreditCardInput } from 'ts-inputs-vue' |
| 3 | +import { BaseInput } from 'ts-inputs-vue' |
4 | 4 | import { computed, ref } from 'vue' |
5 | 5 |
|
6 | | -const baseInputCardNumber = ref('') |
7 | | -const creditCardInputNumber = ref('') |
| 6 | +const cardNumber = ref('') |
| 7 | +const delimiter = ref(' ') |
8 | 8 | const cardType = ref<CreditCardType | null>(null) |
9 | 9 |
|
| 10 | +const creditCardOptions = computed(() => ({ |
| 11 | + delimiter: delimiter.value, |
| 12 | +})) |
| 13 | +
|
10 | 14 | function handleCardTypeChange(type: CreditCardType) { |
11 | 15 | cardType.value = type |
12 | 16 | } |
@@ -45,83 +49,70 @@ const cardTypeName = computed(() => { |
45 | 49 |
|
46 | 50 | <template> |
47 | 51 | <div class="demo-container"> |
48 | | - <div class="demo-section"> |
49 | | - <h3>Using BaseInput</h3> |
50 | | - <div class="input-wrapper"> |
| 52 | + <div class="input-section"> |
| 53 | + <div class="input-group"> |
| 54 | + <label class="block text-sm font-medium text-gray-700">Credit Card Input</label> |
51 | 55 | <BaseInput |
52 | | - v-model="baseInputCardNumber" |
| 56 | + v-model="cardNumber" |
53 | 57 | type="credit-card" |
54 | | - class-name="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6" |
| 58 | + :credit-card-options="creditCardOptions" |
| 59 | + class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" |
55 | 60 | placeholder="Enter card number" |
56 | 61 | @card-type="handleCardTypeChange" |
57 | 62 | /> |
58 | 63 | </div> |
59 | | - </div> |
60 | 64 |
|
61 | | - <div class="demo-section"> |
62 | | - <h3>Using CreditCardInput</h3> |
63 | | - <div class="input-wrapper"> |
64 | | - <CreditCardInput |
65 | | - v-model="creditCardInputNumber" |
66 | | - class-name="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6" |
67 | | - placeholder="Enter card number" |
68 | | - @card-type="handleCardTypeChange" |
69 | | - /> |
| 65 | + <div class="options-grid"> |
| 66 | + <div class="option-group"> |
| 67 | + <label class="block text-sm font-medium text-gray-700">Delimiter</label> |
| 68 | + <select |
| 69 | + v-model="delimiter" |
| 70 | + class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" |
| 71 | + > |
| 72 | + <option value=" "> |
| 73 | + Space ( ) |
| 74 | + </option> |
| 75 | + <option value="-"> |
| 76 | + Hyphen (-) |
| 77 | + </option> |
| 78 | + <option value="."> |
| 79 | + Dot (.) |
| 80 | + </option> |
| 81 | + </select> |
| 82 | + </div> |
70 | 83 | </div> |
71 | 84 | </div> |
72 | 85 |
|
73 | | - <div v-if="cardType" class="card-info"> |
74 | | - <img v-if="cardIcon" :src="cardIcon" :alt="cardTypeName" class="card-icon"> |
75 | | - <span class="card-type">{{ cardTypeName }}</span> |
| 86 | + <div v-if="cardType" class="result-section"> |
| 87 | + <h3 class="text-lg font-medium text-gray-900"> |
| 88 | + Card Information |
| 89 | + </h3> |
| 90 | + <div class="mt-2 flex items-center gap-2"> |
| 91 | + <img v-if="cardIcon" :src="cardIcon" :alt="cardTypeName" class="w-6 h-6"> |
| 92 | + <span class="text-sm text-gray-500">{{ cardTypeName }}</span> |
| 93 | + </div> |
76 | 94 | </div> |
77 | 95 | </div> |
78 | 96 | </template> |
79 | 97 |
|
80 | 98 | <style scoped> |
81 | 99 | .demo-container { |
82 | | - display: flex; |
83 | | - flex-direction: column; |
84 | | - gap: 2rem; |
85 | | - padding: 1rem; |
86 | | - max-width: 600px; |
87 | | - margin: 0 auto; |
88 | | -} |
89 | | -
|
90 | | -.demo-section { |
91 | | - display: flex; |
92 | | - flex-direction: column; |
93 | | - gap: 0.5rem; |
94 | | -} |
95 | | -
|
96 | | -.demo-section h3 { |
97 | | - font-size: 1.125rem; |
98 | | - font-weight: 600; |
99 | | - color: #374151; |
| 100 | + @apply max-w-4xl mx-auto p-6 bg-white rounded-lg shadow; |
100 | 101 | } |
101 | 102 |
|
102 | | -.input-wrapper { |
103 | | - position: relative; |
| 103 | +.input-section { |
| 104 | + @apply space-y-6; |
104 | 105 | } |
105 | 106 |
|
106 | | -.card-info { |
107 | | - display: flex; |
108 | | - align-items: center; |
109 | | - gap: 0.5rem; |
110 | | - padding: 0.5rem; |
111 | | - background-color: #f3f4f6; |
112 | | - border-radius: 0.375rem; |
113 | | - margin-top: 1rem; |
| 107 | +.options-grid { |
| 108 | + @apply grid grid-cols-1 md:grid-cols-2 gap-4; |
114 | 109 | } |
115 | 110 |
|
116 | | -.card-icon { |
117 | | - width: 24px; |
118 | | - height: 24px; |
119 | | - object-fit: contain; |
| 111 | +.option-group { |
| 112 | + @apply space-y-1; |
120 | 113 | } |
121 | 114 |
|
122 | | -.card-type { |
123 | | - font-size: 0.875rem; |
124 | | - color: #4b5563; |
125 | | - font-weight: 500; |
| 115 | +.result-section { |
| 116 | + @apply mt-6 p-4 bg-gray-50 rounded-lg; |
126 | 117 | } |
127 | 118 | </style> |
0 commit comments