SimpleInput.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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: 10px 15px;
  57. background-color: $box-color;
  58. border: 1px solid $border-default-color;
  59. &.focus {
  60. border-color: $border-active-color;
  61. }
  62. input {
  63. font-size: 1rem;
  64. color: $text-color;
  65. border: none;
  66. outline: none;
  67. background-color: transparent;
  68. }
  69. .prefix {
  70. margin-right: 6px;
  71. img {
  72. width: 24px;
  73. height: 24px;
  74. vertical-align: middle;
  75. }
  76. }
  77. .suffix {
  78. margin-left: 10px;
  79. margin-right: 10px;
  80. }
  81. &.dark {
  82. background-color: $box-dark-trans-color;
  83. border: 1px solid $border-dark-color;
  84. .nana-input-text {
  85. color: $text-color-light;
  86. &::placeholder {
  87. color: $text-second-color-light;
  88. }
  89. }
  90. }
  91. }
  92. .nana-input-text {
  93. color: $text-color;
  94. font-size: 26px;
  95. }
  96. </style>