1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. type: {
  17. type: String,
  18. default: 'text',
  19. },
  20. error: {
  21. type: String,
  22. default: null,
  23. },
  24. modelValue: null,
  25. })
  26. defineEmits(['update:modelValue'])
  27. const isError = computed(() => (props.error ? true : false))
  28. const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
  29. const ariaDescribedbyLabel = computed(
  30. () => props.label.toLowerCase().replace(/\s+/g, '-') + '-help'
  31. )
  32. </script>
  33. <template>
  34. <div class="field">
  35. <label :for="forLabel">{{ label }}</label>
  36. <InputText
  37. class="w-full"
  38. :class="{ 'p-invalid': isError }"
  39. :type="type"
  40. :id="forLabel"
  41. :aria-describedby="ariaDescribedbyLabel"
  42. :model-value="modelValue"
  43. :placeholder="placeholder"
  44. :value="modelValue"
  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>