UiInput.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="inline-block input-ui">
  3. <label class="relative">
  4. <span
  5. v-if="label"
  6. class="text-sm dark:text-gray-200 text-gray-600 mb-1 ml-1"
  7. >
  8. {{ label }}
  9. </span>
  10. <div class="flex items-center">
  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-autofocus="autofocus"
  20. v-bind="{
  21. readonly: disabled || readonly || null,
  22. placeholder,
  23. type,
  24. autofocus,
  25. min,
  26. max,
  27. }"
  28. :class="{
  29. 'opacity-75 pointer-events-none': disabled,
  30. 'pl-10': prependIcon || $slots.prepend,
  31. }"
  32. :value="modelValue"
  33. class="py-2 px-4 rounded-lg w-full bg-input bg-transparent transition"
  34. @keydown="$emit('keydown', $event)"
  35. @input="emitValue"
  36. />
  37. </div>
  38. </label>
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. props: {
  44. modelModifiers: {
  45. default: () => ({}),
  46. },
  47. disabled: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. readonly: {
  52. type: Boolean,
  53. default: false,
  54. },
  55. autofocus: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. modelValue: {
  60. type: [String, Number],
  61. default: '',
  62. },
  63. prependIcon: {
  64. type: String,
  65. default: '',
  66. },
  67. label: {
  68. type: String,
  69. default: '',
  70. },
  71. type: {
  72. type: String,
  73. default: 'text',
  74. },
  75. placeholder: {
  76. type: String,
  77. default: '',
  78. },
  79. max: {
  80. type: [String, Number],
  81. default: null,
  82. },
  83. min: {
  84. type: [String, Number],
  85. default: null,
  86. },
  87. },
  88. emits: ['update:modelValue', 'change', 'keydown'],
  89. setup(props, { emit }) {
  90. function emitValue(event) {
  91. let { value } = event.target;
  92. if (props.modelModifiers.lowercase) {
  93. value = value.toLocaleLowerCase();
  94. }
  95. emit('update:modelValue', value);
  96. emit('change', value);
  97. }
  98. return {
  99. emitValue,
  100. };
  101. },
  102. };
  103. </script>