Skip to content

Commit 84424e7

Browse files
JesmoDeviOvergaard
authored andcommitted
add async options and data stories
1 parent 80eb776 commit 84424e7

File tree

2 files changed

+74
-5
lines changed

2 files changed

+74
-5
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { html, LitElement } from 'lit';
2+
import { customElement, property, state } from 'lit/decorators.js';
3+
4+
interface Fruit {
5+
name: string;
6+
value: string;
7+
}
8+
9+
const data: Array<Fruit> = [
10+
{ name: 'Apple', value: 'apple' },
11+
{ name: 'Orange', value: 'orange' },
12+
{ name: 'Banana', value: 'banana' },
13+
{ name: 'Pear', value: 'pear' },
14+
{ name: 'Grape', value: 'grape' },
15+
{ name: 'Strawberry', value: 'strawberry' },
16+
{ name: 'Watermelon', value: 'watermelon' },
17+
{ name: 'Pineapple', value: 'pineapple' },
18+
{ name: 'Coconut', value: 'coconut' },
19+
{ name: 'Mango', value: 'mango' },
20+
{ name: 'Papaya', value: 'papaya' },
21+
{ name: 'Kiwi', value: 'kiwi' },
22+
{ name: 'Avocado', value: 'avocado' },
23+
{ name: 'Pomegranate', value: 'pomegranate' },
24+
{ name: 'Cherry', value: 'cherry' },
25+
{ name: 'Lemon', value: 'lemon' },
26+
{ name: 'Lime', value: 'lime' },
27+
];
28+
29+
async function getFruits() {
30+
return Promise.resolve(data);
31+
}
32+
33+
@customElement('uui-combobox-async-options-example')
34+
export class UUIComboboxAsyncOptionsExampleElement extends LitElement {
35+
@state()
36+
_options: any[] = [];
37+
38+
connectedCallback() {
39+
super.connectedCallback();
40+
this._fetchData();
41+
}
42+
43+
private _fetchData = async () => {
44+
const response = await getFruits();
45+
this._options = [...response];
46+
};
47+
48+
@property()
49+
preselected = 'apple';
50+
51+
render() {
52+
return html`
53+
<uui-combobox value=${this.preselected}>
54+
<uui-combobox-list>
55+
${this._options.map(
56+
option =>
57+
html`<uui-combobox-list-option value="${option.value}"
58+
>${option.name}</uui-combobox-list-option
59+
>`
60+
)}
61+
</uui-combobox-list>
62+
</uui-combobox>
63+
`;
64+
}
65+
}

packages/uui-combobox/lib/uui-combobox.story.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import '.';
22
import './uui-combobox-async-example';
3+
import './uui-combobox-async-options-example';
34

45
import { Story } from '@storybook/web-components';
56
import { html } from 'lit-html';
@@ -23,6 +24,14 @@ export default {
2324
},
2425
};
2526

27+
export const AsyncOptions: Story = () =>
28+
html`
29+
<uui-combobox-async-options-example></uui-combobox-async-options-example>
30+
`;
31+
32+
export const AsyncData: Story = () =>
33+
html`<uui-combobox-async-example></uui-combobox-async-example>`;
34+
2635
const fruits = [
2736
'apple',
2837
'orange',
@@ -389,8 +398,3 @@ CountrySelect.args = {
389398
selected: 'DK',
390399
regions: RegionsAndCountries,
391400
};
392-
393-
/*
394-
export const AsyncData: Story = () =>
395-
html`<uui-combobox-async-example></uui-combobox-async-example>`;
396-
*/

0 commit comments

Comments
 (0)