-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathTypeahead.d.ts
98 lines (84 loc) · 1.89 KB
/
Typeahead.d.ts
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
/// <reference types="svelte" />
import { SvelteComponentTyped } from "svelte";
import { SearchProps } from "svelte-search/types/Search";
export type Item = string | number | Record<string, any>;
export interface FuzzyResult {
original: Item;
index: number;
score: number;
string: string;
}
export interface TypeaheadProps extends SearchProps {
/**
* @default "typeahead-" + Math.random().toString(36)
*/
id?: string;
/**
* @default ""
*/
value?: string;
/**
* @default []
*/
data?: Item[];
/**
* @default (item) => item
*/
extract?: (item: Item) => Item;
/**
* @default (item) => item
*/
selection?: (item: Item) => Item;
/**
* @default (item) => false
*/
disable?: (item: Item) => boolean;
/**
* @default (item) => false
*/
filter?: (item: Item) => boolean;
/**
* Set to `false` to prevent the first result from being selected
* @default true
*/
autoselect?: boolean;
/**
* Set to `keep` to keep the search field unchanged after select, set to `clear` to auto-clear search field
* @default "update"
*/
inputAfterSelect?: "update" | "clear" | "keep";
/**
* @default []
*/
results?: FuzzyResult[];
/**
* Set to `true` to re-focus the input after selecting a result
* @default false
*/
focusAfterSelect?: boolean;
}
export default class Typeahead extends SvelteComponentTyped<
TypeaheadProps,
{
select: CustomEvent<{
searched: string;
selected: Item;
selectedIndex: number;
original: Item;
originalIndex: number;
}>;
type: CustomEvent<string>;
clear: CustomEvent<any>;
input: WindowEventMap["input"];
change: WindowEventMap["change"];
focus: WindowEventMap["focus"];
blur: WindowEventMap["blur"];
keydown: WindowEventMap["keydown"];
},
{
default: {
result: FuzzyResult;
index: number;
};
}
> {}