UiInput.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="inline-block input-ui">
  3. <label
  4. v-if="label || $slots.label"
  5. :for="componentId"
  6. class="text-sm dark:text-gray-200 text-gray-600 ml-1 inline-block leading-none"
  7. >
  8. <slot name="label">{{ label }}</slot>
  9. </label>
  10. <div class="flex items-center relative w-full">
  11. <slot name="prepend">
  12. <v-remixicon
  13. v-if="prependIcon"
  14. class="ml-2 dark:text-gray-200 text-gray-600 absolute left-0"
  15. :name="prependIcon"
  16. ></v-remixicon>
  17. </slot>
  18. <input
  19. v-bind="{
  20. readonly: disabled || readonly || null,
  21. placeholder,
  22. type,
  23. autocomplete,
  24. autofocus,
  25. min,
  26. max,
  27. list,
  28. }"
  29. :id="componentId"
  30. v-autofocus="autofocus"
  31. :class="[
  32. inputClass,
  33. {
  34. 'opacity-75 pointer-events-none': disabled,
  35. 'pl-10': prependIcon || $slots.prepend,
  36. 'appearance-none': list,
  37. },
  38. ]"
  39. :value="modelValue"
  40. class="py-2 px-4 rounded-lg w-full bg-input bg-transparent transition"
  41. @keydown="$emit('keydown', $event)"
  42. @keyup="$emit('keyup', $event)"
  43. @blur="$emit('blur', $event)"
  44. @focus="$emit('focus', $event)"
  45. @input="emitValue"
  46. />
  47. <slot name="append" />
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import { useComponentId } from '@/composable/componentId';
  53. /* eslint-disable vue/require-prop-types */
  54. export default {
  55. props: {
  56. modelModifiers: {
  57. default: () => ({}),
  58. },
  59. disabled: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. readonly: {
  64. type: Boolean,
  65. default: false,
  66. },
  67. autofocus: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. modelValue: {
  72. type: [String, Number],
  73. default: '',
  74. },
  75. inputClass: {
  76. type: String,
  77. default: '',
  78. },
  79. prependIcon: {
  80. type: String,
  81. default: '',
  82. },
  83. label: {
  84. type: String,
  85. default: '',
  86. },
  87. list: {
  88. type: String,
  89. default: null,
  90. },
  91. type: {
  92. type: String,
  93. default: 'text',
  94. },
  95. placeholder: {
  96. type: String,
  97. default: '',
  98. },
  99. max: {
  100. type: [String, Number],
  101. default: null,
  102. },
  103. min: {
  104. type: [String, Number],
  105. default: null,
  106. },
  107. autocomplete: {
  108. type: String,
  109. default: null,
  110. },
  111. },
  112. emits: ['update:modelValue', 'change', 'keydown', 'blur', 'keyup', 'focus'],
  113. setup(props, { emit }) {
  114. const componentId = useComponentId('ui-input');
  115. function emitValue(event) {
  116. let { value } = event.target;
  117. if (props.modelModifiers.lowercase) {
  118. value = value.toLocaleLowerCase();
  119. } else if (props.modelModifiers.number) {
  120. value = +value;
  121. }
  122. emit('update:modelValue', value);
  123. emit('change', value);
  124. }
  125. return {
  126. emitValue,
  127. componentId,
  128. };
  129. },
  130. };
  131. </script>