1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | 4× 1× 3× 31× 17× 3× 2× 2× 12× 8× 7× 4× 4× 1× 7× 5× 1× 4× 2× 1× 1× 8× 8× 2× 2× 8× 8× 1× 1× 1× 1× 159× 159× 72× 72× 84× 1× 83× 21× 72× 87× 113× 37× 32× 81× 1× 2× 6× 1× 5× 5× 6× 6× 1× 1× 2× 2× 19× 19× 19× 36× 3× 33× 4× 19× 35× 48× 1× 48× 48× 5× 48× 53× 38× 33× 5× 15× 50× 25× 25× 12× 13× | // <style> // .v-select.dropdown { // position: relative; // } // // .v-select .open-indicator { // position: absolute; // bottom: 6px; // right: 10px; // display: inline-block; // cursor: pointer; // pointer-events: all; // transition: all 150ms cubic-bezier(1.000, -0.115, 0.975, 0.855); // transition-timing-function: cubic-bezier(1.000, -0.115, 0.975, 0.855); // } // // .v-select .open-indicator:before { // border-color: rgba(60,60,60,.5); // border-style: solid; // border-width: 0.25em 0.25em 0 0; // content: ''; // display: inline-block; // height: 10px; // width: 10px; // vertical-align: top; // transform: rotate(133deg); // transition: all 150ms cubic-bezier(1.000, -0.115, 0.975, 0.855); // transition-timing-function: cubic-bezier(1.000, -0.115, 0.975, 0.855); // } // // .v-select.open .open-indicator { // bottom: 1px; // } // // .v-select.open .open-indicator:before { // transform: rotate(315deg); // } // // .v-select .dropdown-toggle { // display: block; // padding: 0; // background: none; // border: 1px solid rgba(60,60,60,.26); // border-radius: 4px; // white-space: normal; // } // // .v-select.searchable .dropdown-toggle { // cursor: text; // } // // .v-select.open .dropdown-toggle { // border-bottom: none; // border-bottom-left-radius: 0; // border-bottom-right-radius: 0; // } // // .v-select > .dropdown-menu { // margin: 0; // width: 100%; // overflow-y: auto; // border-top: none; // border-top-left-radius: 0; // border-top-right-radius: 0; // } // // .v-select .selected-tag { // color: #333; // background-color: #f0f0f0; // border: 1px solid #ccc; // border-radius: 4px; // height: 26px; // margin: 4px 1px 0px 3px; // padding: 0 0.25em; // float: left; // line-height: 1.7em; // } // // .v-select .selected-tag .close { // float: none; // margin-right: 0; // font-size: 20px; // } // // .v-select input[type=search], // .v-select input[type=search]:focus { // display: inline-block; // border: none; // outline: none; // margin: 0; // padding: 0 .5em; // width: 10em; // max-width: 100%; // background: none; // position: relative; // box-shadow: none; // float: left; // clear: none; // } // // .v-select input[type=search]:disabled { // cursor: pointer; // } // // .v-select li a { // cursor: pointer; // } // // .v-select .active a { // background: rgba(50,50,50,.1); // color: #333; // } // // .v-select .highlight a, // .v-select li:hover > a { // background: #f0f0f0; // color: #333; // } // </style> // // <template> // <div class="dropdown v-select" :class="dropdownClasses"> // <div v-el:toggle @mousedown.prevent="toggleDropdown" class="dropdown-toggle clearfix" type="button"> // <span class="form-control" v-if="!searchable && isValueEmpty"> // {{ placeholder }} // </span> // // <span class="selected-tag" v-for="option in valueAsArray"> // {{ getOptionLabel(option) }} // <button v-if="multiple" @click="select(option)" type="button" class="close"> // <span aria-hidden="true">×</span> // </button> // </span> // // <input // v-el:search // v-show="searchable" // v-model="search" // @keydown.delete="maybeDeleteValue" // @keyup.esc="onEscape" // @keyup.up.prevent="typeAheadUp" // @keyup.down.prevent="typeAheadDown" // @keyup.enter.prevent="typeAheadSelect" // @blur="open = false" // @focus="open = true" // type="search" // class="form-control" // :placeholder="searchPlaceholder" // :style="{ width: isValueEmpty ? '100%' : 'auto' }" // > // // <i v-el:open-indicator role="presentation" class="open-indicator"></i> // </div> // // <ul v-show="open" v-el:dropdown-menu :transition="transition" :style="{ 'max-height': maxHeight }" class="dropdown-menu animated"> // <li v-for="option in filteredOptions" track-by="$index" :class="{ active: isOptionSelected(option), highlight: $index === typeAheadPointer }" @mouseover="typeAheadPointer = $index"> // <a @mousedown.prevent="select(option)"> // {{ getOptionLabel(option) }} // </a> // </li> // <li transition="fade" v-if="!filteredOptions.length" class="divider"></li> // <li transition="fade" v-if="!filteredOptions.length" class="text-center"> // <slot name="no-options">Sorry, no matching options.</slot> // </li> // </ul> // </div> // </template> // // // <script type="text/babel"> export default { props: { /** * Contains the currently selected value. Very similar to a * `value` attribute on an <input>. In most cases, you'll want * to set this as a two-way binding, using :value.sync. However, * this will not work with Vuex, in which case you'll need to use * the onChange callback property. * @type {Object||String||null} */ value: { default: null }, /** * An array of strings or objects to be used as dropdown choices. * If you are using an array of objects, vue-select will look for * a `label` key (ex. [{label: 'This is Foo', value: 'foo'}]). A * custom label key can be set with the `label` prop. * @type {Object} */ options: { type: Array, default() { return [] }, }, /** * Sets the max-height property on the dropdown list. * @deprecated * @type {String} */ maxHeight: { type: String, default: '400px' }, /** * Enable/disable filtering the options. * @type {Boolean} */ searchable: { type: Boolean, default: true }, /** * Equivalent to the `multiple` attribute on a `<select>` input. * @type {Object} */ multiple: { type: Boolean, default: false }, /** * Equivalent to the `placeholder` attribute on an `<input>`. * @type {Object} */ placeholder: { type: String, default: '' }, /** * Sets a Vue transition property on the `.dropdown-menu`. vue-select * does not include CSS for transitions, you'll need to add them yourself. * @type {String} */ transition: { type: String, default: 'expand' }, /** * Enables/disables clearing the search text when an option is selected. * @type {Boolean} */ clearSearchOnSelect: { type: Boolean, default: true }, /** * Tells vue-select what key to use when generating option * labels when each `option` is an object. * @type {String} */ label: { type: String, default: 'label' }, /** * An optional callback function that is called each time the selected * value(s) change. When integrating with Vuex, use this callback to trigger * an action, rather than using :value.sync to retreive the selected value. * @type {Function} * @default {null} */ onChange: Function, /** * Enable/disable creating options from searchInput. * @type {Boolean} */ taggable: { type: Boolean, default: false }, /** * When true, newly created tags will be added to * the options list. * @type {Boolean} */ pushTags: { type: Boolean, default: false }, /** * User defined function for adding Options * @type {Function} */ createOption: { type: Function, default: function (newOption) { if (typeof this.options[0] === 'object') { return {[this.label]: newOption} } return newOption } } }, data() { return { search: '', open: false, typeAheadPointer: -1, } }, watch: { value(val, old) { this.onChange && val !== old ? this.onChange(val) : null }, options() { if (!this.taggable) { this.$set('value', this.multiple ? [] : null) } }, multiple( val ) { this.$set('value', val ? [] : null) }, filteredOptions() { this.typeAheadPointer = 0 }, }, methods: { /** * Select a given option. * @param {Object||String} option * @return {void} */ select(option) { if (!this.isOptionSelected(option)) { if (this.taggable && !this.optionExists(option)) { option = this.createOption(option) if( this.pushTags ) { this.options.push(option) } } if (this.multiple) { if (!this.value) { this.$set('value', [option]) } else { this.value.push(option) } } else { this.value = option } } else { Eif (this.multiple) { this.value.$remove(option) } } this.onAfterSelect(option) }, /** * Called from this.select after each selection. * @param {Object||String} option * @return {void} */ onAfterSelect(option) { if (!this.multiple) { this.open = !this.open this.$els.search.blur() } Eif( this.clearSearchOnSelect ) { this.search = '' } }, /** * Toggle the visibility of the dropdown menu. * @param {Event} e * @return {void} */ toggleDropdown(e) { Eif( e.target === this.$els.openIndicator || e.target === this.$els.search || e.target === this.$els.toggle || e.target === this.$el ) { Iif( this.open ) { this.$els.search.blur() // dropdown will close on blur } else { this.open = true this.$els.search.focus() } } }, /** * Check if the given option is currently selected. * @param {Object||String} option * @return {Boolean} True when selected || False otherwise */ isOptionSelected( option ) { if( this.multiple && this.value ) { let selected = false this.value.forEach(opt => { if( typeof opt === 'object' && opt[this.label] === option ) { selected = true } else if( opt === option ) { selected = true } }) return selected } return this.value === option }, /** * If the selected option has option['value'] return it. * Otherwise, return the entire option. * @param {Object||String} option * @return {Object||String} * @deprecated will be removed in 1.0.8 */ getOptionValue( option ) { if( typeof option === 'object' && option.value ) { return option.value; } return option; }, /** * Generate the option label text. If {option} * is an object, return option[this.label]. * * @param {Object || String} option * @return {String} */ getOptionLabel( option ) { if( typeof option === 'object' ) { if( this.label && option[this.label] ) { return option[this.label] } } return option; }, /** * Move the typeAheadPointer visually up the list by * subtracting the current index by one. * @return {void} */ typeAheadUp() { Eif (this.typeAheadPointer > 0) this.typeAheadPointer-- }, /** * Move the typeAheadPointer visually down the list by * adding the current index by one. * @return {void} */ typeAheadDown() { if (this.typeAheadPointer < this.filteredOptions.length - 1) this.typeAheadPointer++ }, /** * Select the option at the current typeAheadPointer position. * Optionally clear the search input on selection. * @return {void} */ typeAheadSelect() { if( this.filteredOptions[ this.typeAheadPointer ] ) { this.select( this.filteredOptions[ this.typeAheadPointer ] ); } else Eif (this.taggable && this.search.length){ this.select(this.search) } Eif( this.clearSearchOnSelect ) { this.search = ""; } }, /** * If there is any text in the search input, remove it. * Otherwise, blur the search input to close the dropdown. * @return {[type]} [description] */ onEscape() { Iif( ! this.search.length ) { this.$els.search.blur() } else { this.search = '' } }, /** * Delete the value on Delete keypress when there is no * text in the search input, & there's tags to delete * @return {this.value} */ maybeDeleteValue() { Eif( ! this.$els.search.value.length && this.value ) { return this.multiple ? this.value.pop() : this.$set('value', null) } }, /** * Determine if an option exists * within this.options array. * * @param {Object || String} option * @return {boolean} */ optionExists(option) { let exists = false this.options.forEach(opt => { if( typeof opt === 'object' && opt[this.label] === option ) { exists = true } else if( opt === option ) { exists = true } }) return exists } }, computed: { /** * Classes to be output on .dropdown * @return {Object} */ dropdownClasses() { return { open: this.open, searchable: this.searchable } }, /** * Return the placeholder string if it's set * & there is no value selected. * @return {String} Placeholder text */ searchPlaceholder() { if( this.isValueEmpty && this.placeholder ) { return this.placeholder; } }, /** * The currently displayed options, filtered * by the search elements value. If tagging * true, the search text will be prepended * if it doesn't already exist. * * @return {array} */ filteredOptions() { let options = this.$options.filters.filterBy(this.options, this.search) if (this.taggable && this.search.length && !this.optionExists(this.search)) { options.unshift(this.search) } return options }, /** * Check if there aren't any options selected. * @return {Boolean} */ isValueEmpty() { if( this.value ) { if( typeof this.value === 'object' ) { return ! Object.keys(this.value).length } return ! this.value.length } return true; }, /** * Return the current value in array format. * @return {Array} */ valueAsArray() { if( this.multiple ) { return this.value } else if (this.value) { return [this.value] } return [] } } } // </script> /* generated by vue-loader */ |