FancyInput.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div class='fancy_input'>
  3. <div
  4. class='fancy_input__placeholder'
  5. :class='{"fancy_input__placeholder--active": active || value.length}'
  6. >
  7. {{placeholder}}
  8. </div>
  9. <input
  10. type='text'
  11. class='input'
  12. v-bind:value='value'
  13. v-bind:style='{width: width || "10rem"}'
  14. v-on:input='updateValue($event.target.value)'
  15. @focus='addActive'
  16. @blur='removeActive'
  17. >
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'FancyInput',
  23. props: ['value', 'placeholder', 'width'],
  24. data () {
  25. return {
  26. active: false
  27. }
  28. },
  29. methods: {
  30. updateValue (val) {
  31. this.$emit('input', val);
  32. },
  33. addActive () {
  34. this.active = true;
  35. },
  36. removeActive () {
  37. this.active = false;
  38. }
  39. }
  40. }
  41. </script>
  42. <style lang='scss' scoped>
  43. @import '../assets/scss/variables.scss';
  44. .fancy_input {
  45. position: relative;
  46. @at-root #{&}__placeholder {
  47. position: absolute;
  48. top: 0.35rem;
  49. background-color: #fff;
  50. left: 0.35rem;
  51. color: $color__gray--darkest;
  52. pointer-events: none;
  53. transition: top 0.2s, font-size 0.2s;
  54. @at-root #{&}--active {
  55. top: -0.5rem;
  56. font-size: 0.75rem;
  57. transition: top 0.2s, font-size 0.2s;
  58. }
  59. }
  60. }
  61. </style>