You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
4.6 KiB

  1. <template>
  2. <div class="picker-wrap">
  3. <!-- <pre style="position: fixed; z-index: 500; right: 0; top: 7rem; font-size: 0.6rem; color: orange;">
  4. {{ selectedAirport }}
  5. </pre> -->
  6. <label for="">
  7. {{ leg }}
  8. </label>
  9. <v-select
  10. :value="selectedAirportComp"
  11. label="iata"
  12. :options="airports"
  13. :filter-by="filterBy"
  14. :components="{OpenIndicator, Deselect}"
  15. @input="changeAirport"
  16. >
  17. <template #no-options="{ search, searching }">
  18. <template v-if="searching">
  19. No results found for <em>{{ search }}</em>.
  20. </template>
  21. <em
  22. v-else
  23. style="opacity: 0.5;"
  24. >
  25. Start typing to search for an airport.
  26. </em>
  27. </template>
  28. <template #selected-option="option">
  29. <div class="picker-item">
  30. <div class="picker-item__section">
  31. <div class="picker-item__iata">
  32. {{ option.iata }}
  33. </div>
  34. </div>
  35. <div class="picker-item__section">
  36. <div class="picker-item__name">
  37. {{ option.name }}
  38. </div>
  39. <div class="picker-item__muni">
  40. {{ option.municipality }}
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <template #option="option">
  46. <div class="picker-item">
  47. <div class="picker-item__section">
  48. <div class="picker-item__iata">
  49. {{ option.iata }}
  50. </div>
  51. </div>
  52. <div class="picker-item__section">
  53. <div class="picker-item__name">
  54. {{ option.name }}
  55. </div>
  56. <div class="picker-item__muni">
  57. {{ option.municipality }}
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <template #search="{ events, attributes }">
  63. <input
  64. :placeholder="placeholder"
  65. type="search"
  66. class="vs__search"
  67. v-bind="attributes"
  68. v-on="events"
  69. >
  70. </template>
  71. </v-select>
  72. </div>
  73. </template>
  74. <script>
  75. import OpenIndicator from './OpenIndicator.vue'
  76. import Deselect from './Deselect.vue'
  77. export default {
  78. // ClearButton,
  79. props: {
  80. airports: {
  81. type: [Array],
  82. default () {
  83. return []
  84. }
  85. },
  86. selectedAirport: {
  87. type: [Object],
  88. default () {
  89. return {
  90. iata: '',
  91. lat: '',
  92. long: '',
  93. icon: '',
  94. name: '',
  95. municipality: '',
  96. type: '',
  97. search: ''
  98. }
  99. }
  100. },
  101. leg: {
  102. type: [String],
  103. default () {
  104. return ''
  105. }
  106. }
  107. },
  108. data: () => ({
  109. OpenIndicator,
  110. mountains: [],
  111. filterBy: (option, label, search) => {
  112. const temp = search.toLowerCase()
  113. return option.search.toLowerCase().includes(temp)
  114. }
  115. }),
  116. computed: {
  117. Deselect () {
  118. return this.selectedAirportComp.iata ? Deselect : ''
  119. },
  120. selectedAirportComp () {
  121. return {
  122. iata: this.selectedAirport.iata,
  123. lat: this.selectedAirport.lat,
  124. long: this.selectedAirport.long,
  125. icon: this.selectedAirport.icon,
  126. name: this.selectedAirport.name,
  127. municipality: this.selectedAirport.municipality,
  128. type: this.selectedAirport.type,
  129. search: this.selectedAirport.search,
  130. label: this.selectedAirport.label
  131. }
  132. },
  133. placeholder () {
  134. return (this.selectedAirport.iata) ? '' : 'town, airport, or iata'
  135. }
  136. },
  137. methods: {
  138. changeAirport (value) {
  139. if (value) {
  140. this.$emit('select-airport', value)
  141. } else {
  142. this.$emit('deselect-airport', value)
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style>
  149. html {
  150. color: black;
  151. }
  152. .picker-wrap {
  153. margin: 1rem;
  154. position: relative;
  155. }
  156. .picker-wrap:last-of-type {
  157. margin-top: 0;
  158. }
  159. .picker-wrap .vs__search {
  160. font-size: 3rem !important;
  161. padding: 0.5rem;
  162. }
  163. .vs__search::placeholder {
  164. color: #bbb;
  165. }
  166. .vs__dropdown-toggle {
  167. background: #eee;
  168. border: 0;
  169. border-radius: 3rem;
  170. padding-right: 1rem;
  171. padding-left: 1rem;
  172. }
  173. .picker-item {
  174. padding: 0.5rem;
  175. display: flex;
  176. flex-direction: row;
  177. align-items: center;
  178. }
  179. .picker-item__name {
  180. font-size: 1rem;
  181. }
  182. .picker-item__muni {
  183. color: #007fff;
  184. }
  185. .picker-item__iata {
  186. font-size: 3rem;
  187. margin-right: 1rem;
  188. }
  189. .vs--single .vs__selected {
  190. position: absolute;
  191. }
  192. </style>
  193. <style scoped>
  194. label {
  195. display: block;
  196. color: black;
  197. position: absolute;
  198. z-index: 1;
  199. text-transform: uppercase;
  200. font-weight: 300;
  201. top: 0.3rem;
  202. left: 2rem;
  203. letter-spacing: 0.13rem;
  204. font-size: 0.8rem;
  205. }
  206. </style>