forked from umbraco/Umbraco.UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuui-combobox-async-options-example.ts
65 lines (57 loc) · 1.68 KB
/
uui-combobox-async-options-example.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
import { html, LitElement } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
interface Fruit {
name: string;
value: string;
}
const data: Array<Fruit> = [
{ name: 'Apple', value: 'apple' },
{ name: 'Orange', value: 'orange' },
{ name: 'Banana', value: 'banana' },
{ name: 'Pear', value: 'pear' },
{ name: 'Grape', value: 'grape' },
{ name: 'Strawberry', value: 'strawberry' },
{ name: 'Watermelon', value: 'watermelon' },
{ name: 'Pineapple', value: 'pineapple' },
{ name: 'Coconut', value: 'coconut' },
{ name: 'Mango', value: 'mango' },
{ name: 'Papaya', value: 'papaya' },
{ name: 'Kiwi', value: 'kiwi' },
{ name: 'Avocado', value: 'avocado' },
{ name: 'Pomegranate', value: 'pomegranate' },
{ name: 'Cherry', value: 'cherry' },
{ name: 'Lemon', value: 'lemon' },
{ name: 'Lime', value: 'lime' },
];
async function getFruits() {
return Promise.resolve(data);
}
@customElement('uui-combobox-async-options-example')
export class UUIComboboxAsyncOptionsExampleElement extends LitElement {
@state()
_options: any[] = [];
connectedCallback() {
super.connectedCallback();
this._fetchData();
}
private _fetchData = async () => {
const response = await getFruits();
this._options = [...response];
};
@property()
preselected = 'apple';
render() {
return html`
<uui-combobox value=${this.preselected}>
<uui-combobox-list>
${this._options.map(
option =>
html`<uui-combobox-list-option value="${option.value}"
>${option.name}</uui-combobox-list-option
>`
)}
</uui-combobox-list>
</uui-combobox>
`;
}
}