AmAddressFormField.vue
1 week ago
AmAttachmentFormField.vue
1 week ago
AmCheckboxFormField.vue
1 week ago
AmContentFormField.vue
1 week ago
AmDatePickerFormField.vue
1 week ago
AmInputFormField.vue
1 week ago
AmPhoneFormField.vue
1 week ago
AmRadioFormField.vue
1 week ago
AmSelectFormField.vue
1 week ago
AmSocialButton.vue
1 week ago
AmPhoneFormField.vue
175 lines
| 1 | <template> |
| 2 | <el-form-item |
| 3 | v-if="props.visible" |
| 4 | ref="formFieldRef" |
| 5 | class="am-ff__item" |
| 6 | :prop="props.itemName" |
| 7 | :label-position="props.labelPosition" |
| 8 | :style="cssVars" |
| 9 | style="z-index: 10" |
| 10 | > |
| 11 | <template #label> |
| 12 | <span class="am-ff__item-label" v-html="props.label" /> |
| 13 | </template> |
| 14 | <AmInputPhone |
| 15 | :key="`phone-${props.refreshTrigger}`" |
| 16 | v-model="model" |
| 17 | v-model:country-code="countryCode" |
| 18 | :placeholder="props.placeholder" |
| 19 | :validation-error="true" |
| 20 | :error="props.phoneError" |
| 21 | :disabled="props.disabled" |
| 22 | :phone-input-attributes="{ name: props.itemName }" |
| 23 | style="position: relative" |
| 24 | @data="handleData" |
| 25 | > |
| 26 | <template v-if="props.noResultsLabel" #no-results> |
| 27 | {{ props.noResultsLabel }} |
| 28 | </template> |
| 29 | </AmInputPhone> |
| 30 | <template v-if="props.errorMessage" #error> |
| 31 | <span class="el-form-item__error"> |
| 32 | {{ props.errorMessage }} |
| 33 | </span> |
| 34 | </template> |
| 35 | <div v-if="props.isWhatsApp" class="am-whatsapp-opt-in-text"> |
| 36 | {{ props.whatsAppLabel }} |
| 37 | </div> |
| 38 | </el-form-item> |
| 39 | </template> |
| 40 | |
| 41 | <script setup> |
| 42 | // * _components |
| 43 | import AmInputPhone from '../../_components/input-phone/AmInputPhone.vue' |
| 44 | |
| 45 | // * Import from Vue |
| 46 | import { computed, inject, ref, toRefs } from 'vue' |
| 47 | |
| 48 | // * Composables |
| 49 | import { useColorTransparency } from '../../../assets/js/common/colorManipulation' |
| 50 | |
| 51 | // * Form Item Props |
| 52 | let props = defineProps({ |
| 53 | modelValue: { |
| 54 | type: [String, Number, Object, Array], |
| 55 | required: true, |
| 56 | }, |
| 57 | countryCode: { |
| 58 | type: String, |
| 59 | default: '', |
| 60 | }, |
| 61 | itemName: { |
| 62 | type: String, |
| 63 | required: true, |
| 64 | }, |
| 65 | label: { |
| 66 | type: String, |
| 67 | }, |
| 68 | whatsAppLabel: { |
| 69 | type: String, |
| 70 | }, |
| 71 | labelPosition: { |
| 72 | type: String, |
| 73 | default: 'top', |
| 74 | }, |
| 75 | placeholder: { |
| 76 | type: String, |
| 77 | }, |
| 78 | phoneError: { |
| 79 | type: Boolean, |
| 80 | default: false, |
| 81 | }, |
| 82 | visible: { |
| 83 | type: Boolean, |
| 84 | default: true, |
| 85 | }, |
| 86 | defaultCode: { |
| 87 | type: String, |
| 88 | default: '', |
| 89 | }, |
| 90 | isWhatsApp: { |
| 91 | type: [Boolean, String, Number], |
| 92 | default: false, |
| 93 | }, |
| 94 | disabled: { |
| 95 | type: Boolean, |
| 96 | default: false, |
| 97 | }, |
| 98 | errorMessage: { |
| 99 | type: String, |
| 100 | default: '', |
| 101 | }, |
| 102 | noResultsLabel: { |
| 103 | type: String, |
| 104 | default: '', |
| 105 | }, |
| 106 | refreshTrigger: { |
| 107 | type: Number, |
| 108 | default: 0, |
| 109 | }, |
| 110 | }) |
| 111 | |
| 112 | // * Define Emits |
| 113 | const emits = defineEmits(['update:modelValue', 'update:countryCode', 'handlePhoneData']) |
| 114 | |
| 115 | // * Component model |
| 116 | let { modelValue } = toRefs(props) |
| 117 | let model = computed({ |
| 118 | get: () => modelValue.value, |
| 119 | set: (val) => { |
| 120 | emits('update:modelValue', val ? val : '') |
| 121 | }, |
| 122 | }) |
| 123 | |
| 124 | const countryCode = computed({ |
| 125 | get: () => props.countryCode, |
| 126 | set: (val) => { |
| 127 | emits('update:countryCode', val) |
| 128 | }, |
| 129 | }) |
| 130 | |
| 131 | function handleData(val) { |
| 132 | emits('handlePhoneData', val) |
| 133 | } |
| 134 | |
| 135 | // * Colors |
| 136 | let amColors = inject('amColors') |
| 137 | let cssVars = computed(() => { |
| 138 | return { |
| 139 | // is - Info Step, wa - WhatsApp |
| 140 | '--am-c-is-wa-text': useColorTransparency(amColors.value.colorMainText, 0.5), |
| 141 | // ! Inline styles need to be removed |
| 142 | 'margin-bottom': props.isWhatsApp && !props.phoneError ? '10px' : '24px', |
| 143 | } |
| 144 | }) |
| 145 | |
| 146 | let formFieldRef = ref(null) |
| 147 | |
| 148 | defineExpose({ |
| 149 | formFieldRef, |
| 150 | }) |
| 151 | </script> |
| 152 | |
| 153 | <script> |
| 154 | export default { |
| 155 | name: 'PhoneFormField', |
| 156 | } |
| 157 | </script> |
| 158 | |
| 159 | <style lang="scss"> |
| 160 | .amelia-v2-booking { |
| 161 | #amelia-container { |
| 162 | .am-fs__info-form__item, |
| 163 | .am-ff__item { |
| 164 | .am-whatsapp-opt-in-text { |
| 165 | color: var(--am-c-is-wa-text); |
| 166 | font-weight: 400; |
| 167 | font-size: 10px; |
| 168 | line-height: 16px; |
| 169 | word-break: break-word; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | </style> |
| 175 |