UiInput.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. }"
  26. class="py-2 px-4 rounded-lg w-full bg-input bg-transparent transition"
  27. :class="{
  28. 'opacity-75 pointer-events-none': disabled,
  29. 'pl-10': prependIcon || $slots.prepend,
  30. }"
  31. :value="modelValue"
  32. @keydown="$emit('keydown', $event)"
  33. @input="emitValue"
  34. />
  35. </div>
  36. </label>
  37. </div>
  38. </template>
  39. <script>
  40. export default {
  41. props: {
  42. modelModifiers: {
  43. default: () => ({}),
  44. },
  45. disabled: {
  46. type: Boolean,
  47. default: false,
  48. },
  49. readonly: {
  50. type: Boolean,
  51. default: false,
  52. },
  53. autofocus: {
  54. type: Boolean,
  55. default: false,
  56. },
  57. modelValue: {
  58. type: String,
  59. default: '',
  60. },
  61. prependIcon: {
  62. type: String,
  63. default: '',
  64. },
  65. label: {
  66. type: String,
  67. default: '',
  68. },
  69. type: {
  70. type: String,
  71. default: 'text',
  72. },
  73. placeholder: {
  74. type: String,
  75. default: '',
  76. },
  77. },
  78. emits: ['update:modelValue', 'change', 'keydown'],
  79. setup(props, { emit }) {
  80. function emitValue(event) {
  81. let { value } = event.target;
  82. if (props.modelModifiers.lowercase) {
  83. value = value.toLocaleLowerCase();
  84. }
  85. emit('update:modelValue', value);
  86. emit('change', value);
  87. }
  88. return {
  89. emitValue,
  90. };
  91. },
  92. };
  93. </script>