-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add intl-tel-input package for phone number input
- Loading branch information
1 parent
70149cd
commit e23b8ac
Showing
5 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
frontend/src/components/BasicInputs/BasicInputPhoneNumber.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<script setup lang="ts"> | ||
import { useVModel } from '@vueuse/core' | ||
import intlTelInput from 'intl-tel-input/intlTelInputWithUtils' | ||
import { onMounted, onUnmounted, ref } from 'vue' | ||
import useValidationModel from '../../composables/useValidationModel' | ||
import BasicFormGroup from './components/BasicFormGroup.vue' | ||
import { type BasicInputDefaultProps } from './defaultProps' | ||
const props = withDefaults( | ||
defineProps< | ||
BasicInputDefaultProps<string> & { | ||
inputClass?: string | ||
disableValidation?: boolean | ||
} | ||
>(), | ||
{ | ||
type: 'number', | ||
autocapitalize: 'off', | ||
inputClass: '', | ||
disableValidation: false, | ||
} | ||
) | ||
const emit = defineEmits<{ | ||
(event: 'update:modelValue', eventArgs: string | undefined): void | ||
(event: 'focus'): void | ||
(event: 'blur'): void | ||
}>() | ||
const { model, errorMessage } = props.disableValidation | ||
? { | ||
model: useVModel(props, 'modelValue', emit), | ||
errorMessage: undefined, | ||
} | ||
: useValidationModel(props, emit) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let intl: any = null | ||
const phone = ref() | ||
onMounted(async () => { | ||
// await import('intl-tel-input/build/js/utils.js') | ||
intl = intlTelInput(phone.value, { | ||
separateDialCode: true, | ||
strictMode: true, | ||
initialCountry: 'de', | ||
autoPlaceholder: 'off', | ||
}) | ||
}) | ||
onUnmounted(() => { | ||
intl?.destroy() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<BasicFormGroup | ||
:id="id" | ||
:name="name" | ||
:label="label" | ||
:required="required" | ||
:error-message="errorMessage" | ||
> | ||
<div class="intl-tel-wrapper"> | ||
<input | ||
:id="id || name || label" | ||
ref="phone" | ||
:value="model" | ||
type="tel" | ||
:placeholder="placeholder || label || name" | ||
:class="inputClass" | ||
:name="id || name || label" | ||
:disabled="disabled" | ||
/> | ||
</div> | ||
<template #label> | ||
<slot name="label"></slot> | ||
</template> | ||
</BasicFormGroup> | ||
</template> | ||
|
||
<style lang="scss"> | ||
@import 'intl-tel-input/build/css/intlTelInput.css'; | ||
.intl-tel-wrapper { | ||
.iti { | ||
@apply block w-full; | ||
.form-control { | ||
@apply block w-full; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.