-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (33 loc) · 814 Bytes
/
index.js
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
import Component from './lib/index.svelte';
export default (element, options = {}) => {
const {
htmlClassNamespace = '',
decorateOption = (node) => {},
decorateInputEvent = (listener) => listener,
onOptionSelect = (event, value, meta) => {},
onQueryInput = (query) => Promise.resolve([]),
onFocus = (currentResults) => Promise.resolve([])
} = options;
const value = element.value;
const instance = new Component({
target: element.parentElement,
elementToHandle: element,
data: {
value: value,
fixedValue: value,
elementClassName: element.className,
htmlClassNamespace,
decorateOption,
decorateInputEvent,
onOptionSelect,
onQueryInput,
onFocus
}
});
return {
destroy: () => {
instance.set({ isComponentActive: false });
instance.destroy();
}
};
};