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.

221 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. filterBy: (option, label, search) => {
  111. const temp = search.toLowerCase()
  112. return option.search.toLowerCase().includes(temp)
  113. }
  114. }),
  115. computed: {
  116. Deselect () {
  117. return this.selectedAirportComp.iata ? Deselect : ''
  118. },
  119. selectedAirportComp () {
  120. return {
  121. iata: this.selectedAirport.iata,
  122. lat: this.selectedAirport.lat,
  123. long: this.selectedAirport.long,
  124. icon: this.selectedAirport.icon,
  125. name: this.selectedAirport.name,
  126. municipality: this.selectedAirport.municipality,
  127. type: this.selectedAirport.type,
  128. search: this.selectedAirport.search,
  129. label: this.selectedAirport.label
  130. }
  131. },
  132. placeholder () {
  133. return (this.selectedAirport.iata) ? '' : 'town, airport, or iata'
  134. }
  135. },
  136. methods: {
  137. changeAirport (value) {
  138. if (value) {
  139. this.$emit('select-airport', value)
  140. } else {
  141. this.$emit('deselect-airport', value)
  142. }
  143. }
  144. }
  145. }
  146. </script>
  147. <style>
  148. html {
  149. color: black;
  150. }
  151. .picker-wrap {
  152. margin: 1rem;
  153. position: relative;
  154. }
  155. .picker-wrap:last-of-type {
  156. margin-top: 0;
  157. }
  158. .picker-wrap .vs__search {
  159. font-size: 3rem !important;
  160. padding: 0.5rem;
  161. }
  162. .vs__search::placeholder {
  163. color: #bbb;
  164. }
  165. .vs__dropdown-toggle {
  166. background: #eee;
  167. border: 0;
  168. border-radius: 3rem;
  169. padding-right: 1rem;
  170. padding-left: 1rem;
  171. }
  172. .picker-item {
  173. padding: 0.5rem;
  174. display: flex;
  175. flex-direction: row;
  176. align-items: center;
  177. }
  178. .picker-item__name {
  179. font-size: 1rem;
  180. }
  181. .picker-item__muni {
  182. color: #007fff;
  183. }
  184. .picker-item__iata {
  185. font-size: 3rem;
  186. margin-right: 1rem;
  187. }
  188. .vs--single .vs__selected {
  189. position: absolute;
  190. }
  191. </style>
  192. <style scoped>
  193. label {
  194. display: block;
  195. color: black;
  196. position: absolute;
  197. z-index: 1;
  198. text-transform: uppercase;
  199. font-weight: 300;
  200. top: 0.3rem;
  201. left: 2rem;
  202. letter-spacing: 0.13rem;
  203. font-size: 0.8rem;
  204. }
  205. </style>