AppInputText.vue 1.2KB

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