SearchBox.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div
  3. class='search_box'
  4. tabindex='0'
  5. @keydown.enter='goToSearch'
  6. >
  7. <input
  8. class='search_box__field'
  9. :class='{ "search_box__field--header": headerBar }'
  10. :placeholder='placeholder || "Search this forum"'
  11. v-model='searchField'
  12. >
  13. <button
  14. class='search_box__button'
  15. @click='goToSearch'
  16. >
  17. <span class='fa fa-search'></span>
  18. </button>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'SearchBox',
  24. props: ['placeholder', 'header-bar'],
  25. data () {
  26. return {
  27. searchField: ''
  28. }
  29. },
  30. methods: {
  31. goToSearch () {
  32. if(this.searchField.trim().length) {
  33. this.$router.push("/search/" + this.searchField)
  34. }
  35. }
  36. }
  37. }
  38. </script>
  39. <style lang='scss' scoped>
  40. @import '../assets/scss/variables.scss';
  41. @import '../assets/scss/elementStyles.scss';
  42. .search_box {
  43. border: thin solid $color__gray--darkest;
  44. border-right: 0;
  45. border-radius: 0.25rem;
  46. outline: none;
  47. display: inline-block;
  48. overflow: hidden;
  49. @at-root #{&}__field {
  50. outline: none;
  51. height: 100%;
  52. padding: 0 0.5rem;
  53. border: 0;
  54. transition: width 0.2s;
  55. @include text;
  56. color: $color__text--primary;
  57. @include placeholder {
  58. @include text;
  59. color: $color__darkgray--primary;
  60. }
  61. }
  62. @at-root #{&}__button {
  63. @extend .button;
  64. border: 0;
  65. border-right: thin solid $color__gray--darkest;
  66. border-radius: 0 0.125rem 0.125rem 0;
  67. &:hover, &:active {
  68. border-color: $color__gray--darkest;
  69. }
  70. }
  71. }
  72. @media (max-width: 950px) and (min-width: $breakpoint--tablet) {
  73. .search_box__field--header {
  74. width: 4rem;
  75. }
  76. }
  77. </style>