FormTextarea.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <script setup>
  2. import { useIdGenerator } from '@/composables/helpers'
  3. defineOptions({
  4. inheritAttrs: false
  5. })
  6. const props = defineProps({
  7. modelValue: [String, Number, Boolean],
  8. label: {
  9. type: String,
  10. default: ''
  11. },
  12. fieldName: {
  13. type: String,
  14. default: '',
  15. required: true
  16. },
  17. fieldError: [String],
  18. placeholder: {
  19. type: String,
  20. default: ''
  21. },
  22. help: {
  23. type: String,
  24. default: ''
  25. },
  26. size: {
  27. type: String,
  28. default: ''
  29. },
  30. hasOffset: {
  31. type: Boolean,
  32. default: false
  33. },
  34. isDisabled: {
  35. type: Boolean,
  36. default: false
  37. },
  38. maxLength: {
  39. type: Number,
  40. default: null
  41. },
  42. isIndented: Boolean,
  43. })
  44. const { inputId } = useIdGenerator(props.inputType, props.fieldName)
  45. </script>
  46. <template>
  47. <div class="mb-3" :class="{ 'pt-3' : hasOffset, 'is-flex' : isIndented }">
  48. <div v-if="isIndented" class="mx-2 pr-1" :style="{ 'opacity': isDisabled ? '0.5' : '1' }">
  49. <FontAwesomeIcon class="has-text-grey" :icon="['fas', 'chevron-right']" transform="rotate-135"/>
  50. </div>
  51. <div class="field" :class="{ 'is-flex-grow-5' : isIndented }">
  52. <label :for="inputId" class="label" v-html="$t(label)"></label>
  53. <div class="control" :class="{ 'has-icons-left' : leftIcon, 'has-icons-right': rightIcon }">
  54. <textarea
  55. :disabled="isDisabled"
  56. :id="inputId"
  57. class="textarea"
  58. :class="size"
  59. :value="modelValue"
  60. :placeholder="placeholder"
  61. v-bind="$attrs"
  62. v-on:input="$emit('update:modelValue', $event.target.value)"
  63. v-on:change="$emit('change:modelValue', $event.target.value)"
  64. :maxlength="maxLength"
  65. />
  66. </div>
  67. <FieldError v-if="fieldError != undefined" :error="fieldError" :field="fieldName" />
  68. <p class="help" v-html="$t(help)" v-if="help"></p>
  69. </div>
  70. </div>
  71. </template>