SimpleInput.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div
  3. :class="[
  4. 'nana-simple-input',
  5. focusState ? 'focus' : '',
  6. ]"
  7. >
  8. <div class="prefix">
  9. <slot name="prefix"/>
  10. </div>
  11. <input
  12. :placeholder="placeholder"
  13. v-bind="$attrs"
  14. class="nana-input-text"
  15. :value="modelValue"
  16. @input="(e: Event) => emit('update:modelValue', (e.target as HTMLInputElement).value)"
  17. @focus="handleFocus"
  18. @blur="handleBlur"
  19. @keydown.enter="emit('search')"
  20. />
  21. <div class="suffix">
  22. <slot name="suffix"/>
  23. </div>
  24. </div>
  25. </template>
  26. <script setup lang="ts">
  27. import { ref } from 'vue';
  28. defineProps({
  29. modelValue: {
  30. type: String,
  31. default: '',
  32. },
  33. placeholder: {
  34. type: String,
  35. default: '',
  36. },
  37. })
  38. const focusState = ref(false)
  39. const emit = defineEmits([ 'update:modelValue', 'focus', 'blur', 'search' ])
  40. function handleFocus() {
  41. focusState.value = true;
  42. emit('focus');
  43. }
  44. function handleBlur() {
  45. focusState.value = false;
  46. emit('blur');
  47. }
  48. </script>
  49. <style lang="scss">
  50. @use "@/assets/scss/colors.scss" as *;
  51. .nana-simple-input {
  52. display: flex;
  53. flex-direction: row;
  54. align-items: center;
  55. justify-content: space-between;
  56. padding: 6px 10px;
  57. border-radius: 10px;
  58. background-color: $box-color;
  59. border: 1px solid $border-default-color;
  60. &.focus {
  61. border-color: $border-active-color;
  62. }
  63. input {
  64. font-size: 1rem;
  65. color: $text-color;
  66. border: none;
  67. outline: none;
  68. background-color: transparent;
  69. }
  70. .prefix {
  71. margin-right: 6px;
  72. img {
  73. width: 24px;
  74. height: 24px;
  75. vertical-align: middle;
  76. }
  77. }
  78. .suffix {
  79. margin-left: 10px;
  80. margin-right: 10px;
  81. }
  82. .icon {
  83. width: 24px;
  84. height: 24px;
  85. }
  86. &.dark {
  87. background-color: $box-dark-trans-color;
  88. border: 1px solid $border-dark-color;
  89. .nana-input-text {
  90. color: $text-color-light;
  91. &::placeholder {
  92. color: $text-second-color-light;
  93. }
  94. }
  95. }
  96. }
  97. .nana-input-text {
  98. color: $text-color;
  99. font-size: 26px;
  100. }
  101. </style>