|
| 1 | +<template lang="jade"> |
| 2 | +section.start |
| 3 | + .center-vertically |
| 4 | + h1.typo__h1 |
| 5 | + img.logo(src="../static/vue-logo.png") |
| 6 | + | Vue-multiselect |
| 7 | + small.version (v2.0.0-beta) |
| 8 | + h3.typo__h3 The most complete selecting solution for |
| 9 | + = ' ' |
| 10 | + a.typo__link(href="http://vuejs.org" target="_BLANK") Vue.js |
| 11 | + |
| 12 | + .grid__row.grid__row--centered |
| 13 | + .grid__column.grid__unit--md-6 |
| 14 | + .multiselect-example__container |
| 15 | + multiselect( |
| 16 | + :options="options", |
| 17 | + :selected="selected", |
| 18 | + :multiple="multiple", |
| 19 | + :searchable="searchable", |
| 20 | + :show-labels="true", |
| 21 | + :limit="3", |
| 22 | + :taggable="true", |
| 23 | + @tag="onTagging" |
| 24 | + @update="afterChange", |
| 25 | + placeholder="Select option", |
| 26 | + select-label="Enter to select" |
| 27 | + ) |
| 28 | + span(slot="noResult"). |
| 29 | + Tag not found. Press semi-colon <kbd>;</kbd> to create a tag from search query. |
| 30 | + .grid__row.start__list |
| 31 | + .grid__column.grid__unit--md-6.list |
| 32 | + ul.list__ul |
| 33 | + li.typo__li Single / multi select |
| 34 | + li.typo__li Dropdowns |
| 35 | + li.typo__li: a.typo__link(href="#search") Searchable |
| 36 | + li.typo__li: a.typo__link(href="#tagging") Tagging |
| 37 | + li.typo__li: a.typo__link(href="#action") Action dispatcher |
| 38 | + .grid__column.grid__unit--md-6.list |
| 39 | + ul.list__ul |
| 40 | + li.typo__li Vuex support by default |
| 41 | + li.typo__li: a.typo__link(href="#ajax") Ajax options |
| 42 | + li.typo__li: a.typo__link(href="#custom") Fully configurable |
| 43 | + li.typo__li +99% test coverage |
| 44 | + li.typo__li No dependencies |
| 45 | + |
| 46 | + .grid__row.grid__row--centered |
| 47 | + .grid__column.utils--center |
| 48 | + a.button.button--large.button--secondary.button--github(href="https://github.com/monterail/vue-multiselect" target="_BLANK") View on GitHub |
| 49 | + a.button.button--large(href="#getting-started") Getting started & examples |
| 50 | +</template> |
| 51 | + |
| 52 | +<script> |
| 53 | +import countries from './data/countries.json' |
| 54 | +import Multiselect from '../src/Multiselect' |
| 55 | +
|
| 56 | +function throttle (callback, limit) { |
| 57 | + var wait = false |
| 58 | + return function () { |
| 59 | + if (!wait) { |
| 60 | + callback.call() |
| 61 | + wait = true |
| 62 | + setTimeout(function () { |
| 63 | + wait = false |
| 64 | + }, limit) |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | +
|
| 69 | +const SL = ', 100%, 85%' |
| 70 | +
|
| 71 | +export default { |
| 72 | + components: { |
| 73 | + Multiselect |
| 74 | + }, |
| 75 | + data () { |
| 76 | + return { |
| 77 | + options: ['Select option', 'options', 'selected', 'mulitple', 'label', 'searchable', 'clearOnSelect', 'hideSelected', 'maxHeight', 'allowEmpty', 'showLabels', 'onChange', 'touched'], |
| 78 | + selected: ['Select option'], |
| 79 | + source: [ |
| 80 | + { name: 'Vue.js', language: 'JavaScript' }, |
| 81 | + { name: 'Rails', language: 'Ruby' }, |
| 82 | + { name: 'Sinatra', language: 'Ruby' }, |
| 83 | + { name: 'Laravel', language: 'PHP' }, |
| 84 | + { name: 'Phoenix', language: 'Elixir' } |
| 85 | + ], |
| 86 | + value: { name: 'Vue.js', language: 'Javascript' }, |
| 87 | + valuePrimitive: 'showLabels', |
| 88 | + multiValue: [{ name: 'Vue.js', language: 'Javascript' }], |
| 89 | + multiple: true, |
| 90 | + taggingOptions: [{ name: 'Vue.js', code: 'vu' }, { name: 'Javascript', code: 'js' }, { name: 'Monterail', code: 'pl' }, { name: 'Open Source', code: 'os' }], |
| 91 | + taggingSelected: [], |
| 92 | + searchable: true, |
| 93 | + placeholder: 'Select props', |
| 94 | + countries: [], |
| 95 | + selectedCountries: [], |
| 96 | + actions: ['alert', 'console.log', 'scrollTop'], |
| 97 | + action: null, |
| 98 | + isTouched: false, |
| 99 | + exampleValue6: [], |
| 100 | + isLoading: false, |
| 101 | + isNavSticky: false, |
| 102 | + firstColor: Math.floor(Math.random() * 255), |
| 103 | + secondColor: Math.floor(Math.random() * 255) |
| 104 | + } |
| 105 | + }, |
| 106 | + computed: { |
| 107 | + gradient () { |
| 108 | + return { |
| 109 | + background: `linear-gradient(to left bottom, hsl(${this.firstColor + SL}) 0%, hsl(${this.secondColor + SL}) 100%)` |
| 110 | + } |
| 111 | + }, |
| 112 | + isInvalid () { |
| 113 | + return this.isTouched && this.exampleValue6.length === 0 |
| 114 | + } |
| 115 | + }, |
| 116 | + methods: { |
| 117 | + asyncFind (query) { |
| 118 | + if (query.length === 0) { |
| 119 | + this.countries = [] |
| 120 | + } else { |
| 121 | + this.isLoading = true |
| 122 | + setTimeout(() => { |
| 123 | + this.countries = countries.filter((element, index, array) => { |
| 124 | + return element.name.toLowerCase().includes(query.toLowerCase()) |
| 125 | + }) |
| 126 | + this.isLoading = false |
| 127 | + }, 1000) |
| 128 | + } |
| 129 | + }, |
| 130 | + asyncUpdate (newVal) { |
| 131 | + this.selectedCountries = newVal |
| 132 | + }, |
| 133 | + afterChange (selectValue) { |
| 134 | + this.selected = selectValue |
| 135 | + }, |
| 136 | + onTagging (newTag) { |
| 137 | + this.options.push(newTag) |
| 138 | + this.selected.push(newTag) |
| 139 | + }, |
| 140 | + onClose (val) { |
| 141 | + console.log('close: ', val) |
| 142 | + }, |
| 143 | + addTag (newTag) { |
| 144 | + const tag = { |
| 145 | + name: newTag, |
| 146 | + code: newTag.substring(0, 2) + Math.floor((Math.random() * 10000000)) |
| 147 | + } |
| 148 | + this.taggingOptions.push(tag) |
| 149 | + this.taggingSelected.push(tag) |
| 150 | + }, |
| 151 | + updateSelectedTagging (value) { |
| 152 | + console.log('@tag: ', value) |
| 153 | + this.taggingSelected = value |
| 154 | + }, |
| 155 | + dispatchAction (actionName) { |
| 156 | + switch (actionName) { |
| 157 | + case 'alert': |
| 158 | + window.alert('You just dispatched "alert" action!') |
| 159 | + break |
| 160 | + case 'console.log': |
| 161 | + console.log('You just dispatched "console.log" action!') |
| 162 | + break |
| 163 | + case 'scrollTop': |
| 164 | + window.scrollTo(0, 0) |
| 165 | + break |
| 166 | + } |
| 167 | + }, |
| 168 | + updateExampleValue (value) { |
| 169 | + console.log('@update: ', value) |
| 170 | + this.exampleValue6 = value |
| 171 | + }, |
| 172 | + onTouch () { |
| 173 | + this.isTouched = true |
| 174 | + }, |
| 175 | + updateValue (value) { |
| 176 | + console.log('@update: ', value) |
| 177 | + this.value = value |
| 178 | + }, |
| 179 | + updateMultiValue (value) { |
| 180 | + console.log('@update: ', value) |
| 181 | + this.multiValue = value |
| 182 | + }, |
| 183 | + updateValuePrimitive (value) { |
| 184 | + console.log('@update: ', value) |
| 185 | + this.valuePrimitive = value |
| 186 | + }, |
| 187 | + nameWithLang ({ name, language }) { |
| 188 | + return `${name} — [${language}]` |
| 189 | + }, |
| 190 | + onSelect (option) { |
| 191 | + console.log('@select: ', option) |
| 192 | + }, |
| 193 | + onRemove (option) { |
| 194 | + console.log('@remove: ', option) |
| 195 | + }, |
| 196 | + adjustNav () { |
| 197 | + this.isNavSticky = window.scrollY > window.innerHeight |
| 198 | + } |
| 199 | + // calculateNavPositions () { |
| 200 | + // /*eslint-disable */ |
| 201 | + // for (let position of this.navPositions) { |
| 202 | + // const elem = document.getElementById(position[0]) |
| 203 | + // if (elem) position[1] = elem.offsetTop - 200 |
| 204 | + // } |
| 205 | + // this.navPositions = this.navPositions.sort((a, b) => a[1] - b[1]) |
| 206 | + // /*eslint-enable */ |
| 207 | + // } |
| 208 | + }, |
| 209 | + mounted () { |
| 210 | + this.adjustNav() |
| 211 | + window.addEventListener('scroll', throttle(this.adjustNav, 50)) |
| 212 | + } |
| 213 | +} |
| 214 | +</script> |
| 215 | + |
| 216 | +<style lang="sass"> |
| 217 | + @import "./docs.scss" |
| 218 | +</style> |
0 commit comments