AppInputNumber.vue 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. type: {
  13. type: String,
  14. default: 'text',
  15. },
  16. mode: {
  17. type: String,
  18. default: 'decimal',
  19. },
  20. incrementButtonClass: {
  21. type: String,
  22. default: null,
  23. },
  24. decrementButtonClass: {
  25. type: String,
  26. default: null,
  27. },
  28. incrementButtonIcon: {
  29. type: String,
  30. default: 'pi pi-angle-up',
  31. },
  32. decrementButtonIcon: {
  33. type: String,
  34. default: 'pi pi-angle-down',
  35. },
  36. showButtons: {
  37. type: Boolean,
  38. default: false,
  39. },
  40. buttonLayout: {
  41. type: String,
  42. default: 'stacked',
  43. },
  44. min: {
  45. type: Number,
  46. default: null,
  47. },
  48. max: {
  49. type: Number,
  50. default: null,
  51. },
  52. step: {
  53. type: Number,
  54. default: 1,
  55. },
  56. prefix: {
  57. type: String,
  58. default: null,
  59. },
  60. suffix: {
  61. type: String,
  62. default: null,
  63. },
  64. placeholder: {
  65. type: String,
  66. required: true,
  67. },
  68. useGrouping: {
  69. type: Boolean,
  70. default: true,
  71. },
  72. modelValue: {
  73. type: Number,
  74. default: null,
  75. },
  76. error: {
  77. type: String,
  78. default: null,
  79. },
  80. })
  81. defineEmits(['update:modelValue', 'blur'])
  82. const isError = computed(() => (props.error ? true : false))
  83. const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
  84. const ariaDescribedbyLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-') + '-help')
  85. </script>
  86. <template>
  87. <div class="field">
  88. <label :for="forLabel">{{ label }}</label>
  89. <InputNumber
  90. class="w-full"
  91. input-class="w-full"
  92. :class="{ 'p-invalid': isError }"
  93. :id="forLabel"
  94. :aria-describedby="ariaDescribedbyLabel"
  95. :type="type"
  96. :placeholder="placeholder"
  97. :model-value="modelValue"
  98. :disabled="disabled"
  99. :prefix="prefix"
  100. :suffix="suffix"
  101. :step="step"
  102. :min="min"
  103. :max="max"
  104. :mode="mode"
  105. :use-grouping="useGrouping"
  106. :show-buttons="showButtons"
  107. :button-layout="buttonLayout"
  108. :increment-button-class="incrementButtonClass"
  109. :decrement-button-class="decrementButtonClass"
  110. :increment-button-icon="incrementButtonIcon"
  111. :decrement-button-icon="decrementButtonIcon"
  112. @input="$emit('update:modelValue', $event.value)"
  113. @blur="$emit('blur', $event.value)"
  114. />
  115. <small v-if="error" :id="ariaDescribedbyLabel" :class="{ 'p-error': isError }">
  116. {{ error }}
  117. </small>
  118. </div>
  119. </template>