AppPassword.vue 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <script setup>
  2. import { computed } from 'vue'
  3. const props = defineProps({
  4. label: {
  5. type: String,
  6. required: true,
  7. },
  8. disabled: {
  9. type: Boolean,
  10. default: false,
  11. },
  12. placeholder: {
  13. type: String,
  14. required: true,
  15. },
  16. error: {
  17. type: String,
  18. default: null,
  19. },
  20. modelValue: null,
  21. })
  22. defineEmits(['update:modelValue'])
  23. const isError = computed(() => (props.error ? true : false))
  24. const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
  25. const ariaDescribedbyLabel = computed(
  26. () => props.label.toLowerCase().replace(/\s+/g, '-') + '-help'
  27. )
  28. </script>
  29. <template>
  30. <div class="field">
  31. <label :for="forLabel">{{ label }}</label>
  32. <Password
  33. class="w-full"
  34. input-class="w-full"
  35. :disabled="disabled"
  36. :id="forLabel"
  37. :placeholder="placeholder"
  38. :aria-describedby="ariaDescribedbyLabel"
  39. :toggleMask="true"
  40. :value="modelValue"
  41. :model-value="modelValue"
  42. @input="$emit('update:modelValue', $event.target.value)"
  43. />
  44. <small
  45. v-if="error"
  46. :id="ariaDescribedbyLabel"
  47. :class="{ 'p-error': isError }"
  48. >
  49. {{ error }}
  50. </small>
  51. </div>
  52. </template>