svelte-multiselect 3.0.1 → 3.1.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/MultiSelect.svelte +23 -26
- package/MultiSelect.svelte.d.ts +10 -1
- package/package.json +18 -19
- package/readme.md +47 -9
package/MultiSelect.svelte
CHANGED
|
@@ -207,30 +207,23 @@ display above those of another following shortly after it -->
|
|
|
207
207
|
>
|
|
208
208
|
<ExpandIcon height="14pt" style="padding: 0 3pt 0 1pt;" />
|
|
209
209
|
<ul class="selected {ulSelectedClass}">
|
|
210
|
-
{#
|
|
211
|
-
<
|
|
212
|
-
{
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
<
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
>
|
|
228
|
-
<CrossIcon height="12pt" />
|
|
229
|
-
</button>
|
|
230
|
-
{/if}
|
|
231
|
-
</li>
|
|
232
|
-
{/each}
|
|
233
|
-
{/if}
|
|
210
|
+
{#each selected as option, idx}
|
|
211
|
+
<li class={liSelectedClass}>
|
|
212
|
+
<slot name="selectedRenderer" {option} {idx}>
|
|
213
|
+
{option.label}
|
|
214
|
+
</slot>
|
|
215
|
+
{#if !readonly}
|
|
216
|
+
<button
|
|
217
|
+
on:mouseup|stopPropagation={() => remove(option.label)}
|
|
218
|
+
on:keydown={handleEnterAndSpaceKeys(() => remove(option.label))}
|
|
219
|
+
type="button"
|
|
220
|
+
title="{removeBtnTitle} {option.label}"
|
|
221
|
+
>
|
|
222
|
+
<CrossIcon height="12pt" />
|
|
223
|
+
</button>
|
|
224
|
+
{/if}
|
|
225
|
+
</li>
|
|
226
|
+
{/each}
|
|
234
227
|
<input
|
|
235
228
|
bind:this={input}
|
|
236
229
|
autocomplete="off"
|
|
@@ -265,7 +258,9 @@ display above those of another following shortly after it -->
|
|
|
265
258
|
class:hidden={!showOptions}
|
|
266
259
|
transition:fly|local={{ duration: 300, y: 40 }}
|
|
267
260
|
>
|
|
268
|
-
{#each matchingOptions as
|
|
261
|
+
{#each matchingOptions as option, idx}
|
|
262
|
+
{@const { label, disabled, title = null, selectedTitle } = option}
|
|
263
|
+
{@const { disabledTitle = defaultDisabledTitle } = option}
|
|
269
264
|
<li
|
|
270
265
|
on:mouseup|preventDefault|stopPropagation
|
|
271
266
|
on:mousedown|preventDefault|stopPropagation={() => {
|
|
@@ -278,7 +273,9 @@ display above those of another following shortly after it -->
|
|
|
278
273
|
title={disabled ? disabledTitle : (isSelected(label) && selectedTitle) || title}
|
|
279
274
|
class={liOptionClass}
|
|
280
275
|
>
|
|
281
|
-
{
|
|
276
|
+
<slot name="optionRenderer" {option} {idx}>
|
|
277
|
+
{option.label}
|
|
278
|
+
</slot>
|
|
282
279
|
</li>
|
|
283
280
|
{:else}
|
|
284
281
|
{noOptionsMsg}
|
package/MultiSelect.svelte.d.ts
CHANGED
|
@@ -29,7 +29,16 @@ declare const __propDef: {
|
|
|
29
29
|
} & {
|
|
30
30
|
[evt: string]: CustomEvent<any>;
|
|
31
31
|
};
|
|
32
|
-
slots: {
|
|
32
|
+
slots: {
|
|
33
|
+
selectedRenderer: {
|
|
34
|
+
option: Option;
|
|
35
|
+
idx: any;
|
|
36
|
+
};
|
|
37
|
+
optionRenderer: {
|
|
38
|
+
option: Option;
|
|
39
|
+
idx: any;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
33
42
|
};
|
|
34
43
|
export declare type MultiSelectProps = typeof __propDef.props;
|
|
35
44
|
export declare type MultiSelectEvents = typeof __propDef.events;
|
package/package.json
CHANGED
|
@@ -5,33 +5,32 @@
|
|
|
5
5
|
"homepage": "https://svelte-multiselect.netlify.app",
|
|
6
6
|
"repository": "https://github.com/janosh/svelte-multiselect",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "3.0
|
|
8
|
+
"version": "3.1.0",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"svelte": "
|
|
11
|
-
"bugs":
|
|
12
|
-
"url": "https://github.com/janosh/svelte-multiselect/issues"
|
|
13
|
-
},
|
|
10
|
+
"svelte": "index.js",
|
|
11
|
+
"bugs": "https://github.com/janosh/svelte-multiselect/issues",
|
|
14
12
|
"devDependencies": {
|
|
15
|
-
"@sveltejs/adapter-static": "^1.0.0-next.
|
|
16
|
-
"@sveltejs/kit": "^1.0.0-next.
|
|
17
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
18
|
-
"@typescript-eslint/parser": "^5.
|
|
19
|
-
"eslint": "^8.
|
|
20
|
-
"eslint-plugin-svelte3": "^3.
|
|
13
|
+
"@sveltejs/adapter-static": "^1.0.0-next.26",
|
|
14
|
+
"@sveltejs/kit": "^1.0.0-next.239",
|
|
15
|
+
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
|
16
|
+
"@typescript-eslint/parser": "^5.10.0",
|
|
17
|
+
"eslint": "^8.7.0",
|
|
18
|
+
"eslint-plugin-svelte3": "^3.4.0",
|
|
21
19
|
"hastscript": "^7.0.2",
|
|
22
20
|
"mdsvex": "^0.9.8",
|
|
23
21
|
"prettier": "^2.5.1",
|
|
24
|
-
"prettier-plugin-svelte": "^2.
|
|
22
|
+
"prettier-plugin-svelte": "^2.6.0",
|
|
25
23
|
"rehype-autolink-headings": "^6.1.1",
|
|
26
24
|
"rehype-slug": "^5.0.1",
|
|
27
|
-
"svelte": "^3.
|
|
28
|
-
"svelte-check": "^2.
|
|
29
|
-
"svelte-
|
|
30
|
-
"svelte-
|
|
31
|
-
"
|
|
25
|
+
"svelte": "^3.46.2",
|
|
26
|
+
"svelte-check": "^2.3.0",
|
|
27
|
+
"svelte-github-corner": "^0.1.0",
|
|
28
|
+
"svelte-preprocess": "^4.10.2",
|
|
29
|
+
"svelte-toc": "^0.2.2",
|
|
30
|
+
"svelte2tsx": "^0.4.14",
|
|
32
31
|
"tslib": "^2.3.1",
|
|
33
|
-
"typescript": "^4.5.
|
|
34
|
-
"vite": "^2.7.
|
|
32
|
+
"typescript": "^4.5.5",
|
|
33
|
+
"vite": "^2.7.13"
|
|
35
34
|
},
|
|
36
35
|
"keywords": [
|
|
37
36
|
"svelte",
|
package/readme.md
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<h1 align="center">Svelte MultiSelect</h1>
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/janosh/svelte-toc/main/static/favicon.svg" alt="Svelte MultiSelect" height=60>
|
|
3
|
+
<br> Svelte MultiSelect
|
|
4
|
+
</h1>
|
|
8
5
|
|
|
9
6
|
<h4 align="center">
|
|
10
7
|
|
|
@@ -14,14 +11,16 @@
|
|
|
14
11
|
|
|
15
12
|
</h4>
|
|
16
13
|
|
|
14
|
+
<div class="hide-in-docs">
|
|
15
|
+
|
|
17
16
|
**[Live demo](https://svelte-multiselect.netlify.app)**.
|
|
18
17
|
|
|
19
18
|
</div>
|
|
20
19
|
|
|
21
|
-
<!-- remove above in docs -->
|
|
22
|
-
|
|
23
20
|
**Keyboard-friendly, zero-dependency multi-select Svelte component.**
|
|
24
21
|
|
|
22
|
+
<slot />
|
|
23
|
+
|
|
25
24
|
## Key Features
|
|
26
25
|
|
|
27
26
|
- **Single / multiple select:** pass `maxSelect={1}` prop to only allow one selection
|
|
@@ -105,6 +104,26 @@ Full list of props/bindable variables for this component:
|
|
|
105
104
|
|
|
106
105
|
</div>
|
|
107
106
|
|
|
107
|
+
## Slots
|
|
108
|
+
|
|
109
|
+
`MultiSelect.svelte` accepts two named slots
|
|
110
|
+
|
|
111
|
+
- `slot="optionRenderer"`
|
|
112
|
+
- `slot="selectedRenderer"`
|
|
113
|
+
|
|
114
|
+
to customize rendering individual options in the dropdown and the list of selected tags, respectively. Each renderer receives the full `option` object along with the zero-indexed position (`idx`) in its list, both available via the `let:` directive:
|
|
115
|
+
|
|
116
|
+
```svelte
|
|
117
|
+
<MultiSelect options={[`Banana`, `Watermelon`, `Apple`, `Dates`, `Mango`]}>
|
|
118
|
+
<span let:idx let:option slot="optionRenderer">
|
|
119
|
+
{idx + 1}. {option.label} {option.label === `Mango` ? `🎉` : ``}</span
|
|
120
|
+
>
|
|
121
|
+
<span let:idx let:option slot="selectedRenderer">
|
|
122
|
+
#️⃣ {idx + 1} {option.label}</span
|
|
123
|
+
>
|
|
124
|
+
</MultiSelect>
|
|
125
|
+
```
|
|
126
|
+
|
|
108
127
|
## Events
|
|
109
128
|
|
|
110
129
|
`MultiSelect.svelte` dispatches the following events:
|
|
@@ -131,6 +150,25 @@ Full list of props/bindable variables for this component:
|
|
|
131
150
|
/>
|
|
132
151
|
```
|
|
133
152
|
|
|
153
|
+
## TypeScript
|
|
154
|
+
|
|
155
|
+
TypeScript users can import the types used for internal type safety for external use as well:
|
|
156
|
+
|
|
157
|
+
```svelte
|
|
158
|
+
<script lang="ts">
|
|
159
|
+
import MultiSelect, {
|
|
160
|
+
Option,
|
|
161
|
+
Primitive,
|
|
162
|
+
ProtoOption,
|
|
163
|
+
} from 'svelte-multiselect'
|
|
164
|
+
|
|
165
|
+
const myOptions: Option[] = [
|
|
166
|
+
{ label: 'foo', value: 42 },
|
|
167
|
+
{ label: 'bar', value: 69 },
|
|
168
|
+
]
|
|
169
|
+
</script>
|
|
170
|
+
```
|
|
171
|
+
|
|
134
172
|
## Styling
|
|
135
173
|
|
|
136
174
|
There are 3 ways to style this component.
|