FancyInput.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. v-bind:type='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', 'type'],
  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. margin-top: 0.25rem;
  47. margin-bottom: 0.5rem;
  48. @at-root #{&}__placeholder {
  49. position: absolute;
  50. top: 0.35rem;
  51. background-color: #fff;
  52. left: 0.35rem;
  53. color: $color__gray--darkest;
  54. pointer-events: none;
  55. transition: top 0.2s, font-size 0.2s;
  56. @at-root #{&}--active {
  57. top: -0.5rem;
  58. font-size: 0.75rem;
  59. transition: top 0.2s, font-size 0.2s;
  60. }
  61. }
  62. }
  63. </style>