FancyInput.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class='fancy_input'>
  3. <div
  4. class='fancy_input__error'
  5. :class='{"fancy_input__error--show": error }'
  6. >
  7. {{error}}
  8. </div>
  9. <div
  10. class='fancy_input__placeholder'
  11. :class='{"fancy_input__placeholder--active": active || value.length}'
  12. >
  13. {{placeholder}}
  14. </div>
  15. <input
  16. v-bind:type='type || "text"'
  17. class='input'
  18. v-bind:value='value'
  19. v-bind:style='{width: width || "10rem"}'
  20. v-on:input='updateValue($event.target.value)'
  21. @focus='addActive'
  22. @blur='removeActive'
  23. >
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'FancyInput',
  29. props: ['value', 'placeholder', 'width', 'type', 'error'],
  30. data () {
  31. return {
  32. active: false
  33. }
  34. },
  35. methods: {
  36. updateValue (val) {
  37. this.$emit('input', val);
  38. },
  39. addActive () {
  40. this.active = true;
  41. },
  42. removeActive () {
  43. this.active = false;
  44. }
  45. }
  46. }
  47. </script>
  48. <style lang='scss' scoped>
  49. @import '../assets/scss/variables.scss';
  50. .fancy_input {
  51. position: relative;
  52. margin-top: 0.25rem;
  53. margin-bottom: 0.5rem;
  54. @at-root #{&}__placeholder {
  55. position: absolute;
  56. top: 0.35rem;
  57. background-color: #fff;
  58. left: 0.35rem;
  59. color: $color__gray--darkest;
  60. pointer-events: none;
  61. transition: top 0.2s, font-size 0.2s;
  62. @at-root #{&}--active {
  63. top: -0.5rem;
  64. font-size: 0.75rem;
  65. transition: top 0.2s, font-size 0.2s;
  66. }
  67. }
  68. @at-root #{&}__error {
  69. position: absolute;
  70. background-color: #ffeff1;
  71. border: 0.125rem solid #D32F2F;
  72. font-size: 0.9rem;
  73. padding: 0.1rem 0.25rem;
  74. top: 0.2125rem;
  75. left: calc(100% + 0.25rem);
  76. white-space: nowrap;
  77. &:first-letter{ text-transform: capitalize; }
  78. opacity: 0;
  79. pointer-events: none;
  80. margin-top: -1rem;
  81. transition: opacity 0.2s, margin-top 0.2s;
  82. @at-root #{&}--show {
  83. opacity: 1;
  84. pointer-events: all;
  85. margin-top: 0;
  86. transition: opacity 0.2s, margin-top 0.2s;
  87. }
  88. &::after {
  89. content: '';
  90. position: relative;
  91. width: 0;
  92. height: 0;
  93. display: inline-block;
  94. right: calc(100% + 0.3rem);
  95. border-top: 0.3rem solid transparent;
  96. border-bottom: 0.3rem solid transparent;
  97. border-right: 0.3rem solid #D32F2F;
  98. }
  99. }
  100. }
  101. </style>