slim-select 2.0.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/render.d.ts +10 -3
- package/dist/select.d.ts +6 -6
- package/dist/settings.d.ts +0 -3
- package/dist/slimselect.cjs.js +202 -67
- package/dist/slimselect.css +1 -1
- package/dist/slimselect.css.map +1 -1
- package/dist/slimselect.es.js +202 -67
- package/dist/slimselect.global.js +202 -67
- package/dist/slimselect.js +202 -67
- package/dist/slimselect.min.js +1 -1
- package/dist/slimselect.umd.js +202 -67
- package/dist/slimselect.umd.min.js +1 -1
- package/dist/store.d.ts +5 -0
- package/docs/assets/data.js +7 -3
- package/docs/assets/home.css +1 -1
- package/docs/assets/home.js +1 -1
- package/docs/assets/index.css +1 -1
- package/docs/assets/index.js +7 -7
- package/docs/assets/index2.js +119 -35
- package/docs/assets/index3.js +39 -23
- package/docs/assets/index4.js +1 -1
- package/docs/assets/index5.js +147 -9
- package/docs/assets/install.js +4 -4
- package/docs/assets/selects.js +1 -1
- package/package.json +11 -3
- package/src/docs/app.vue +6 -5
- package/src/docs/{images → assets/images}/check-mark.svg +0 -0
- package/src/docs/{images → assets/images}/chrome.svg +0 -0
- package/src/docs/{images → assets/images}/firefox.svg +0 -0
- package/src/docs/{images → assets/images}/github.png +0 -0
- package/src/docs/{images → assets/images}/ie.svg +0 -0
- package/src/docs/{images → assets/images}/npm.png +0 -0
- package/src/docs/{images → assets/images}/opera.svg +0 -0
- package/src/docs/{images → assets/images}/safari.svg +0 -0
- package/src/docs/assets/scss/misc.scss +7 -0
- package/src/docs/env.d.ts +1 -0
- package/src/docs/pages/data.vue +4 -0
- package/src/docs/pages/events/addable.vue +22 -6
- package/src/docs/pages/events/before_after_change.vue +15 -1
- package/src/docs/pages/events/search.vue +31 -16
- package/src/docs/pages/frameworks/vue.vue +375 -7
- package/src/docs/pages/home.vue +104 -57
- package/src/docs/pages/methods/get_data.vue +2 -1
- package/src/docs/pages/methods/open_close.vue +1 -1
- package/src/docs/pages/settings/closable.vue +128 -0
- package/src/docs/pages/settings/index.vue +6 -3
- package/src/docs/pages/settings/select_all.vue +88 -0
- package/src/slim-select/index.ts +4 -2
- package/src/slim-select/render.ts +247 -59
- package/src/slim-select/rollup.config.mjs +5 -0
- package/src/slim-select/select.ts +48 -31
- package/src/slim-select/settings.ts +0 -4
- package/src/slim-select/slimselect.scss +112 -11
- package/src/slim-select/store.ts +19 -1
- package/src/vue/README.md +48 -0
- package/src/vue/dist/slimselectvue.es.js +1752 -0
- package/src/vue/dist/slimselectvue.global.js +1755 -0
- package/src/vue/dist/slimselectvue.ssr.js +1754 -0
- package/src/vue/hello.ts +5 -0
- package/src/vue/package.json +28 -0
- package/src/vue/rollup.config.mjs +44 -0
- package/src/vue/slimselect.vue +39 -5
- package/src/vue/tsconfig.json +14 -0
- package/src/docs/pages/settings/select_by_group.vue +0 -46
package/src/docs/pages/data.vue
CHANGED
|
@@ -49,6 +49,8 @@ export default defineComponent({
|
|
|
49
49
|
<code class="language-javascript">
|
|
50
50
|
var optgroup = {
|
|
51
51
|
label: 'label', // Required
|
|
52
|
+
selectAll: false, // Optional - default false
|
|
53
|
+
closabel: 'off', // Optional - default 'off' - 'off', 'open', 'close'
|
|
52
54
|
options: [] // Required - value is an array of options
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -57,7 +59,9 @@ export default defineComponent({
|
|
|
57
59
|
value: 'value', // Optional - value will be set by text if not set
|
|
58
60
|
html: '<b>Html</b>', // Optional - will be used for display purposes if set
|
|
59
61
|
selected: false, // Optional - default is false
|
|
62
|
+
display: true, // Optional - default is true
|
|
60
63
|
disabled: false, // Optional - default is false
|
|
64
|
+
mandatory: false, // Optional - default is false
|
|
61
65
|
placeholder: false, // Optional - default is false
|
|
62
66
|
class: '', // Optional - default is not set
|
|
63
67
|
style: '', // Optional - default is not set
|
|
@@ -10,7 +10,10 @@ export default defineComponent({
|
|
|
10
10
|
select: this.$refs.addableSingle as HTMLSelectElement,
|
|
11
11
|
events: {
|
|
12
12
|
addable: (value: string) => {
|
|
13
|
-
return
|
|
13
|
+
return {
|
|
14
|
+
text: value,
|
|
15
|
+
value: value.toLowerCase(),
|
|
16
|
+
}
|
|
14
17
|
},
|
|
15
18
|
},
|
|
16
19
|
})
|
|
@@ -19,10 +22,14 @@ export default defineComponent({
|
|
|
19
22
|
select: this.$refs.addableMultiple as HTMLSelectElement,
|
|
20
23
|
events: {
|
|
21
24
|
addable: (value: string) => {
|
|
22
|
-
return {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
resolve({
|
|
28
|
+
text: value,
|
|
29
|
+
value: value,
|
|
30
|
+
})
|
|
31
|
+
}, 100)
|
|
32
|
+
})
|
|
26
33
|
},
|
|
27
34
|
},
|
|
28
35
|
})
|
|
@@ -65,11 +72,20 @@ export default defineComponent({
|
|
|
65
72
|
// Return the value string
|
|
66
73
|
return value // Optional - value alteration // ex: value.toLowerCase()
|
|
67
74
|
|
|
68
|
-
// Optional - Return a valid data object.
|
|
75
|
+
// Optional - Return a valid data object.
|
|
76
|
+
// See methods/setData for list of valid options
|
|
69
77
|
return {
|
|
70
78
|
text: value,
|
|
71
79
|
value: value.toLowerCase()
|
|
72
80
|
}
|
|
81
|
+
|
|
82
|
+
// Optional - Return a promise with either a string or data object
|
|
83
|
+
return new Promise((resolve) => {
|
|
84
|
+
resolve({
|
|
85
|
+
text: value,
|
|
86
|
+
value: value,
|
|
87
|
+
})
|
|
88
|
+
})
|
|
73
89
|
}
|
|
74
90
|
}
|
|
75
91
|
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { defineComponent } from 'vue'
|
|
3
3
|
|
|
4
|
-
import SlimSelect
|
|
4
|
+
import SlimSelect from '../../../slim-select'
|
|
5
|
+
import { DataArray } from '../../../slim-select/store'
|
|
5
6
|
|
|
6
7
|
export default defineComponent({
|
|
7
8
|
name: 'BeforeAfterChange',
|
|
@@ -16,9 +17,13 @@ export default defineComponent({
|
|
|
16
17
|
mounted() {
|
|
17
18
|
new SlimSelect({
|
|
18
19
|
select: this.$refs.beforeChangeSingle as HTMLSelectElement,
|
|
20
|
+
settings: {
|
|
21
|
+
allowDeselect: true,
|
|
22
|
+
},
|
|
19
23
|
events: {
|
|
20
24
|
beforeChange: (newValue: DataArray, oldValue: DataArray) => {
|
|
21
25
|
this.beforeChangeSingle = oldValue
|
|
26
|
+
return true
|
|
22
27
|
},
|
|
23
28
|
},
|
|
24
29
|
})
|
|
@@ -35,6 +40,9 @@ export default defineComponent({
|
|
|
35
40
|
|
|
36
41
|
new SlimSelect({
|
|
37
42
|
select: this.$refs.afterChangeSingle as HTMLSelectElement,
|
|
43
|
+
settings: {
|
|
44
|
+
allowDeselect: true,
|
|
45
|
+
},
|
|
38
46
|
events: {
|
|
39
47
|
afterChange: (value: DataArray) => {
|
|
40
48
|
this.afterChangeSingle = value
|
|
@@ -63,11 +71,16 @@ export default defineComponent({
|
|
|
63
71
|
Returning nothing or true will allow it to continue as normal.
|
|
64
72
|
</p>
|
|
65
73
|
|
|
74
|
+
<div class="alert info">
|
|
75
|
+
Be sure to return true to allow for the change to happen. False or nothing to cancel change.
|
|
76
|
+
</div>
|
|
77
|
+
|
|
66
78
|
<div v-if="beforeChangeSingle">
|
|
67
79
|
<strong>Before change: {{ beforeChangeSingle }}</strong>
|
|
68
80
|
</div>
|
|
69
81
|
|
|
70
82
|
<select ref="beforeChangeSingle">
|
|
83
|
+
<option data-placeholder="true">Select Option</option>
|
|
71
84
|
<option value="value1">Value 1</option>
|
|
72
85
|
<option value="value2">Value 2</option>
|
|
73
86
|
<option value="value3">Value 3</option>
|
|
@@ -108,6 +121,7 @@ export default defineComponent({
|
|
|
108
121
|
</div>
|
|
109
122
|
|
|
110
123
|
<select ref="afterChangeSingle">
|
|
124
|
+
<option data-placeholder="true">Select Option</option>
|
|
111
125
|
<option value="value1">Value 1</option>
|
|
112
126
|
<option value="value2">Value 2</option>
|
|
113
127
|
<option value="value3">Value 3</option>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { onMounted, Ref, ref } from 'vue'
|
|
3
3
|
|
|
4
|
-
import SlimSelect
|
|
4
|
+
import SlimSelect from '../../../slim-select'
|
|
5
|
+
import { DataArray, Option } from '../../../slim-select/store'
|
|
5
6
|
|
|
6
7
|
interface Person {
|
|
7
8
|
first_name: string
|
|
@@ -59,7 +60,7 @@ onMounted(() => {
|
|
|
59
60
|
})
|
|
60
61
|
})
|
|
61
62
|
|
|
62
|
-
function searchPromise(search: string,
|
|
63
|
+
function searchPromise(search: string, currentData: DataArray): Promise<Option[]> {
|
|
63
64
|
return new Promise((resolve, reject) => {
|
|
64
65
|
if (search.length < 2) {
|
|
65
66
|
return reject('Search must be at least 2 characters')
|
|
@@ -76,13 +77,20 @@ function searchPromise(search: string, selectedData: DataArray): Promise<Option[
|
|
|
76
77
|
return reject('No results found')
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
// Take the results and create an array of options excluding any that are already selected in currentData
|
|
81
|
+
const options = results
|
|
82
|
+
.filter((person) => {
|
|
83
|
+
return !currentData.some((data) => {
|
|
84
|
+
// check if option has a value property
|
|
85
|
+
return data instanceof Option && data.value === `${person.first_name} ${person.last_name}`
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
.map((person) => {
|
|
89
|
+
return {
|
|
90
|
+
text: `${person.first_name} ${person.last_name}`,
|
|
91
|
+
value: `${person.first_name} ${person.last_name}`,
|
|
92
|
+
} as Option
|
|
93
|
+
})
|
|
86
94
|
|
|
87
95
|
// Simulate a slow search
|
|
88
96
|
setTimeout(() => {
|
|
@@ -134,13 +142,20 @@ function searchPromise(search: string, selectedData: DataArray): Promise<Option[
|
|
|
134
142
|
})
|
|
135
143
|
.then((response) => response.json())
|
|
136
144
|
.then((data) => {
|
|
137
|
-
// Take data and
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
// Take the data and create an array of options
|
|
146
|
+
// excluding any that are already selected in currentData
|
|
147
|
+
const options = data
|
|
148
|
+
.filter((person) => {
|
|
149
|
+
return !currentData.some((optionData) => {
|
|
150
|
+
return optionData.value === `${person.first_name} ${person.last_name}`
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
.map((person) => {
|
|
154
|
+
return {
|
|
155
|
+
text: `${person.first_name} ${person.last_name}`,
|
|
156
|
+
value: `${person.first_name} ${person.last_name}`,
|
|
157
|
+
}
|
|
158
|
+
})
|
|
144
159
|
|
|
145
160
|
resolve(options)
|
|
146
161
|
})
|
|
@@ -1,39 +1,407 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { defineComponent } from 'vue'
|
|
3
3
|
|
|
4
|
+
// We need to import from the root of the package
|
|
5
|
+
// Because if we use @slim-select/vue then we loose
|
|
6
|
+
// hot reloading of the file changes
|
|
7
|
+
import SlimSelectJS from '../../../slim-select'
|
|
4
8
|
import SlimSelect from '../../../vue/slimselect.vue'
|
|
9
|
+
import Settings from '../../../slim-select/settings'
|
|
10
|
+
import { Option, OptionOptional } from '../../../slim-select/store'
|
|
11
|
+
import { Events } from '../../../slim-select'
|
|
12
|
+
|
|
13
|
+
interface Person {
|
|
14
|
+
id: string
|
|
15
|
+
first_name: string
|
|
16
|
+
last_name: string
|
|
17
|
+
selected: number
|
|
18
|
+
}
|
|
5
19
|
|
|
6
20
|
export default defineComponent({
|
|
7
21
|
name: 'Vue',
|
|
8
22
|
components: {
|
|
9
23
|
SlimSelect,
|
|
10
24
|
},
|
|
25
|
+
data() {
|
|
26
|
+
return {
|
|
27
|
+
settings: {
|
|
28
|
+
showSearch: false,
|
|
29
|
+
} as Settings,
|
|
30
|
+
data: [
|
|
31
|
+
{ value: 'value1', text: 'Value 1' },
|
|
32
|
+
{ value: 'value2', text: 'Value 2' },
|
|
33
|
+
{ value: 'value3', text: 'Value 3' },
|
|
34
|
+
],
|
|
35
|
+
dynamicData: [] as OptionOptional[],
|
|
36
|
+
afterChangeData: [] as OptionOptional[],
|
|
37
|
+
events: {
|
|
38
|
+
afterChange: this.afterChange,
|
|
39
|
+
} as Events,
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
mounted() {
|
|
43
|
+
// Show the original select for debugging
|
|
44
|
+
// const randomComponent = this.$refs.randomDynamic as any
|
|
45
|
+
// const randomSlim = randomComponent.getSlimSelect()
|
|
46
|
+
// randomSlim.select.showUI()
|
|
47
|
+
},
|
|
48
|
+
methods: {
|
|
49
|
+
changeData() {
|
|
50
|
+
const dataSingle = this.$refs.dataSingle as any
|
|
51
|
+
const dataSingleSlim = dataSingle.getSlimSelect() as SlimSelectJS
|
|
52
|
+
dataSingleSlim.open()
|
|
53
|
+
const dataMultiple = this.$refs.dataMultiple as any
|
|
54
|
+
const dataMultipleSlim = dataMultiple.getSlimSelect() as SlimSelectJS
|
|
55
|
+
dataMultipleSlim.open()
|
|
56
|
+
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
this.data = [
|
|
59
|
+
{ value: 'value4', text: 'Value 4' },
|
|
60
|
+
{ value: 'value5', text: 'Value 5' },
|
|
61
|
+
{ value: 'value6', text: 'Value 6' },
|
|
62
|
+
]
|
|
63
|
+
}, 500)
|
|
64
|
+
},
|
|
65
|
+
afterChange(newVal: Option[]) {
|
|
66
|
+
this.afterChangeData = newVal
|
|
67
|
+
},
|
|
68
|
+
randomDynamicData() {
|
|
69
|
+
// Go fetch some gofakeit data via post to json
|
|
70
|
+
fetch('https://api.gofakeit.com/json', {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
},
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
type: 'array',
|
|
77
|
+
rowcount: 20,
|
|
78
|
+
indent: false,
|
|
79
|
+
fields: [
|
|
80
|
+
{
|
|
81
|
+
name: 'key',
|
|
82
|
+
function: 'password',
|
|
83
|
+
params: {
|
|
84
|
+
lower: true,
|
|
85
|
+
upper: true,
|
|
86
|
+
numeric: true,
|
|
87
|
+
special: false,
|
|
88
|
+
space: false,
|
|
89
|
+
length: 10,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{ name: 'first_name', function: 'firstname', params: {} },
|
|
93
|
+
{ name: 'last_name', function: 'lastname', params: {} },
|
|
94
|
+
{ name: 'selected', function: 'number', params: { min: 1, max: 10 } },
|
|
95
|
+
],
|
|
96
|
+
}),
|
|
97
|
+
})
|
|
98
|
+
.then((response) => response.json())
|
|
99
|
+
.then((data: Person[]) => {
|
|
100
|
+
// Map the data to the format slim select expects
|
|
101
|
+
this.dynamicData = data.map((person: Person) => {
|
|
102
|
+
return {
|
|
103
|
+
id: person.id,
|
|
104
|
+
text: `${person.first_name} ${person.last_name}`,
|
|
105
|
+
value: `${person.first_name} ${person.last_name}`,
|
|
106
|
+
selected: person.selected >= 8,
|
|
107
|
+
} as OptionOptional
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
},
|
|
111
|
+
},
|
|
11
112
|
})
|
|
12
113
|
</script>
|
|
13
114
|
|
|
14
115
|
<template>
|
|
15
|
-
<div id="
|
|
116
|
+
<div id="vue" class="content">
|
|
16
117
|
<h2 class="header">Vue</h2>
|
|
17
118
|
|
|
119
|
+
<h3>Install</h3>
|
|
120
|
+
<p>The vue component is in a sub package under SlimSelect</p>
|
|
121
|
+
<pre>
|
|
122
|
+
<code class="language-bash">
|
|
123
|
+
npm install @slim-select/vue
|
|
124
|
+
</code>
|
|
125
|
+
</pre>
|
|
126
|
+
<br />
|
|
127
|
+
|
|
128
|
+
<h3>Simple example</h3>
|
|
18
129
|
<div class="row">
|
|
19
130
|
<SlimSelect>
|
|
20
131
|
<option value="1">Option 1</option>
|
|
21
132
|
<option value="2">Option 2</option>
|
|
22
133
|
<option value="3">Option 3</option>
|
|
23
134
|
</SlimSelect>
|
|
135
|
+
|
|
136
|
+
<SlimSelect multiple>
|
|
137
|
+
<option value="1">Option 1</option>
|
|
138
|
+
<option value="2">Option 2</option>
|
|
139
|
+
<option value="3">Option 3</option>
|
|
140
|
+
</SlimSelect>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<pre>
|
|
144
|
+
<code class="language-javascript">
|
|
145
|
+
import { defineComponent } from 'vue'
|
|
146
|
+
import SlimSelect from '@slim-select/vue'
|
|
147
|
+
|
|
148
|
+
export default defineComponent({
|
|
149
|
+
components: {
|
|
150
|
+
SlimSelect,
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
</code>
|
|
154
|
+
</pre>
|
|
155
|
+
|
|
156
|
+
<pre>
|
|
157
|
+
<code class="language-html">
|
|
158
|
+
<SlimSelect>
|
|
159
|
+
<option value="1">Option 1</option>
|
|
160
|
+
<option value="2">Option 2</option>
|
|
161
|
+
<option value="3">Option 3</option>
|
|
162
|
+
</SlimSelect>
|
|
163
|
+
|
|
164
|
+
<SlimSelect multiple>
|
|
165
|
+
<option value="1">Option 1</option>
|
|
166
|
+
<option value="2">Option 2</option>
|
|
167
|
+
<option value="3">Option 3</option>
|
|
168
|
+
</SlimSelect>
|
|
169
|
+
</code>
|
|
170
|
+
</pre>
|
|
171
|
+
|
|
172
|
+
<br />
|
|
173
|
+
<div class="separator"></div>
|
|
174
|
+
<br />
|
|
175
|
+
|
|
176
|
+
<h3>Settings</h3>
|
|
177
|
+
<p>
|
|
178
|
+
Settings just like its passed as an object in normal SlimSelct will also be passed as an object to the component
|
|
179
|
+
prop
|
|
180
|
+
</p>
|
|
181
|
+
|
|
182
|
+
<div class="row">
|
|
183
|
+
<SlimSelect :settings="settings">
|
|
184
|
+
<option value="1">Option 1</option>
|
|
185
|
+
<option value="2">Option 2</option>
|
|
186
|
+
<option value="3">Option 3</option>
|
|
187
|
+
</SlimSelect>
|
|
188
|
+
|
|
189
|
+
<SlimSelect :settings="settings" multiple>
|
|
190
|
+
<option value="1">Option 1</option>
|
|
191
|
+
<option value="2">Option 2</option>
|
|
192
|
+
<option value="3">Option 3</option>
|
|
193
|
+
</SlimSelect>
|
|
194
|
+
</div>
|
|
195
|
+
|
|
196
|
+
<pre>
|
|
197
|
+
<code class="language-javascript">
|
|
198
|
+
import { defineComponent } from 'vue'
|
|
199
|
+
import SlimSelect from '@slim-select/vue'
|
|
200
|
+
|
|
201
|
+
export default defineComponent({
|
|
202
|
+
components: {
|
|
203
|
+
SlimSelect,
|
|
204
|
+
},
|
|
205
|
+
data() {
|
|
206
|
+
return {
|
|
207
|
+
settings: {
|
|
208
|
+
showSearch: false,
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
})
|
|
213
|
+
</code>
|
|
214
|
+
</pre>
|
|
215
|
+
|
|
216
|
+
<pre>
|
|
217
|
+
<code class="language-html">
|
|
218
|
+
<SlimSelect :settings="settings">
|
|
219
|
+
<option value="1">Option 1</option>
|
|
220
|
+
<option value="2">Option 2</option>
|
|
221
|
+
<option value="3">Option 3</option>
|
|
222
|
+
</SlimSelect>
|
|
223
|
+
|
|
224
|
+
<SlimSelect :settings="settings" multiple>
|
|
225
|
+
<option value="1">Option 1</option>
|
|
226
|
+
<option value="2">Option 2</option>
|
|
227
|
+
<option value="3">Option 3</option>
|
|
228
|
+
</SlimSelect>
|
|
229
|
+
</code>
|
|
230
|
+
</pre>
|
|
231
|
+
|
|
232
|
+
<br />
|
|
233
|
+
<div class="separator"></div>
|
|
234
|
+
<br />
|
|
235
|
+
|
|
236
|
+
<h3>Data</h3>
|
|
237
|
+
<p>
|
|
238
|
+
Data just like its passed as an array in normal SlimSelct will also be passed as an array to the component prop.
|
|
239
|
+
</p>
|
|
240
|
+
<div class="alert info">
|
|
241
|
+
You may pass data as a prop if you would like. But you can also have reactive options that when options change the
|
|
242
|
+
select will update as well. See Reactivity below for more info.
|
|
243
|
+
</div>
|
|
244
|
+
|
|
245
|
+
<div class="row">
|
|
246
|
+
<div class="btn info" @click="changeData">Change data</div>
|
|
247
|
+
<SlimSelect ref="dataSingle" :data="data" />
|
|
248
|
+
<SlimSelect ref="dataMultiple" :data="data" multiple />
|
|
249
|
+
</div>
|
|
250
|
+
|
|
251
|
+
<pre>
|
|
252
|
+
<code class="language-javascript">
|
|
253
|
+
import { defineComponent } from 'vue'
|
|
254
|
+
import SlimSelect from '@slim-select/vue'
|
|
255
|
+
|
|
256
|
+
export default defineComponent({
|
|
257
|
+
components: {
|
|
258
|
+
SlimSelect,
|
|
259
|
+
},
|
|
260
|
+
data() {
|
|
261
|
+
return {
|
|
262
|
+
data: [
|
|
263
|
+
{ value: 'value1', text: 'Value 1' },
|
|
264
|
+
{ value: 'value2', text: 'Value 2' },
|
|
265
|
+
{ value: 'value3', text: 'Value 3' },
|
|
266
|
+
],
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
})
|
|
270
|
+
</code>
|
|
271
|
+
</pre>
|
|
272
|
+
|
|
273
|
+
<pre>
|
|
274
|
+
<code class="language-html">
|
|
275
|
+
<SlimSelect :data="data" />
|
|
276
|
+
|
|
277
|
+
<SlimSelect :data="data" multiple />
|
|
278
|
+
</code>
|
|
279
|
+
</pre>
|
|
280
|
+
|
|
281
|
+
<br />
|
|
282
|
+
<div class="separator"></div>
|
|
283
|
+
<br />
|
|
284
|
+
|
|
285
|
+
<h3>Events</h3>
|
|
286
|
+
<p>
|
|
287
|
+
Events just like its passed as an object in normal SlimSelct will also be passed as an object to the component
|
|
288
|
+
prop.
|
|
289
|
+
</p>
|
|
290
|
+
|
|
291
|
+
<div v-if="afterChangeData.length"><strong>afterChange:</strong> {{ afterChangeData }}</div>
|
|
292
|
+
<div class="row">
|
|
293
|
+
<SlimSelect :events="events">
|
|
294
|
+
<option value="1">Option 1</option>
|
|
295
|
+
<option value="2">Option 2</option>
|
|
296
|
+
<option value="3">Option 3</option>
|
|
297
|
+
</SlimSelect>
|
|
298
|
+
|
|
299
|
+
<SlimSelect :events="events" multiple>
|
|
300
|
+
<option value="1">Option 1</option>
|
|
301
|
+
<option value="2">Option 2</option>
|
|
302
|
+
<option value="3">Option 3</option>
|
|
303
|
+
</SlimSelect>
|
|
304
|
+
</div>
|
|
305
|
+
|
|
306
|
+
<pre>
|
|
307
|
+
<code class="language-javascript">
|
|
308
|
+
import { defineComponent } from 'vue'
|
|
309
|
+
import SlimSelect from '@slim-select/vue'
|
|
310
|
+
|
|
311
|
+
export default defineComponent({
|
|
312
|
+
components: {
|
|
313
|
+
SlimSelect,
|
|
314
|
+
},
|
|
315
|
+
data() {
|
|
316
|
+
return {
|
|
317
|
+
events: {
|
|
318
|
+
afterChange: this.afterChange,
|
|
319
|
+
},
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
methods: {
|
|
323
|
+
afterChange(newVal) {
|
|
324
|
+
console.log(newVal)
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
})
|
|
328
|
+
</code>
|
|
329
|
+
</pre>
|
|
330
|
+
|
|
331
|
+
<pre>
|
|
332
|
+
<code class="language-html">
|
|
333
|
+
<SlimSelect :events="events">
|
|
334
|
+
<option value="1">Option 1</option>
|
|
335
|
+
<option value="2">Option 2</option>
|
|
336
|
+
<option value="3">Option 3</option>
|
|
337
|
+
</SlimSelect>
|
|
338
|
+
|
|
339
|
+
<SlimSelect :events="events" multiple>
|
|
340
|
+
<option value="1">Option 1</option>
|
|
341
|
+
<option value="2">Option 2</option>
|
|
342
|
+
<option value="3">Option 3</option>
|
|
343
|
+
</SlimSelect>
|
|
344
|
+
</code>
|
|
345
|
+
</pre>
|
|
346
|
+
|
|
347
|
+
<br />
|
|
348
|
+
<div class="separator"></div>
|
|
349
|
+
<br />
|
|
350
|
+
|
|
351
|
+
<h3>Reactivity</h3>
|
|
352
|
+
<p>
|
|
353
|
+
Slim select will look out for any options changes that happen to the select options and SlimSelect will update
|
|
354
|
+
accordingly. This is done via mutation observers.
|
|
355
|
+
</p>
|
|
356
|
+
|
|
357
|
+
<div class="row">
|
|
358
|
+
<div class="btn info" @click="randomDynamicData">Change data</div>
|
|
359
|
+
<SlimSelect ref="randomDynamic">
|
|
360
|
+
<option v-for="d in dynamicData" :key="d.id" :value="d.value" :selected="d.selected">{{ d.text }}</option>
|
|
361
|
+
</SlimSelect>
|
|
362
|
+
|
|
363
|
+
<SlimSelect multiple>
|
|
364
|
+
<option v-for="d in dynamicData" :value="d.value" :selected="d.selected">{{ d.text }}</option>
|
|
365
|
+
</SlimSelect>
|
|
24
366
|
</div>
|
|
25
367
|
|
|
26
368
|
<pre>
|
|
27
369
|
<code class="language-javascript">
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
370
|
+
import { defineComponent } from 'vue'
|
|
371
|
+
import SlimSelect from '@slim-select/vue'
|
|
372
|
+
|
|
373
|
+
export default defineComponent({
|
|
374
|
+
components: {
|
|
375
|
+
SlimSelect,
|
|
376
|
+
},
|
|
377
|
+
data() {
|
|
378
|
+
return {
|
|
379
|
+
dynamicData: []
|
|
33
380
|
}
|
|
34
|
-
}
|
|
381
|
+
},
|
|
382
|
+
methods: {
|
|
383
|
+
changeData() {
|
|
384
|
+
this.dynamicData = [
|
|
385
|
+
{ id: 1, value: 1, text: 'Option 1', selected: true },
|
|
386
|
+
{ id: 2, value: 2, text: 'Option 2', selected: false },
|
|
387
|
+
{ id: 3, value: 3, text: 'Option 3', selected: false },
|
|
388
|
+
]
|
|
389
|
+
},
|
|
390
|
+
},
|
|
35
391
|
})
|
|
36
392
|
</code>
|
|
37
393
|
</pre>
|
|
394
|
+
|
|
395
|
+
<pre>
|
|
396
|
+
<code class="language-html">
|
|
397
|
+
<SlimSelect :events="events">
|
|
398
|
+
<option v-for="d in dynamicData" :key="d.id" :value="d.value" :selected="d.selected">{{ d.text }}</option>
|
|
399
|
+
</SlimSelect>
|
|
400
|
+
|
|
401
|
+
<SlimSelect :events="events" multiple>
|
|
402
|
+
<option v-for="d in dynamicData" :value="d.value" :selected="d.selected">{{ d.text }}</option>
|
|
403
|
+
</SlimSelect>
|
|
404
|
+
</code>
|
|
405
|
+
</pre>
|
|
38
406
|
</div>
|
|
39
407
|
</template>
|