SimpleInput.vue 1.9 KB

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