-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(picker): add optional message for empty search result
fix #307
- Loading branch information
1 parent
63f7ef2
commit 2b4e4a7
Showing
4 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Component, h, State } from '@stencil/core'; | ||
import { ListItem } from '../../interface'; | ||
|
||
const NETWORK_DELAY = 500; | ||
|
||
@Component({ | ||
tag: 'limel-example-picker-empty-suggestions', | ||
shadow: true, | ||
styleUrl: 'picker.scss', | ||
}) | ||
export class PickerExample { | ||
private allItems: Array<ListItem<number>> = [ | ||
{ text: 'Admiral Swiggins', value: 1 }, | ||
{ text: 'Ayla', value: 2 }, | ||
{ text: 'Clunk', value: 3 }, | ||
{ text: 'Coco', value: 4 }, | ||
{ text: 'Derpl', value: 5 }, | ||
{ text: 'Froggy G', value: 6 }, | ||
{ text: 'Gnaw', value: 7 }, | ||
{ text: 'Lonestar', value: 8 }, | ||
{ text: 'Leon', value: 9 }, | ||
{ text: 'Raelynn', value: 10 }, | ||
{ text: 'Skølldir', value: 11 }, | ||
{ text: 'Voltar', value: 12 }, | ||
{ text: 'Yuri', value: 13 }, | ||
]; | ||
|
||
@State() | ||
private selectedItem: ListItem<number>; | ||
|
||
constructor() { | ||
this.search = this.search.bind(this); | ||
this.onChange = this.onChange.bind(this); | ||
} | ||
|
||
public render() { | ||
return [ | ||
<limel-picker | ||
label="Favorite awesomenaut" | ||
value={this.selectedItem} | ||
searcher={this.search} | ||
emptyResultMessage="No results" | ||
onChange={this.onChange} | ||
onInteract={this.onInteract} | ||
/>, | ||
<p> | ||
Value: <code>{JSON.stringify(this.selectedItem)}</code> | ||
</p>, | ||
]; | ||
} | ||
|
||
private search(query: string): Promise<ListItem[]> { | ||
return new Promise(resolve => { | ||
if (query === '') { | ||
// Simulate some network delay | ||
setTimeout(() => { | ||
resolve([]); | ||
}, NETWORK_DELAY); | ||
} | ||
// Simulate some network delay | ||
setTimeout(() => { | ||
const filteredItems = this.allItems.filter(item => { | ||
return item.text | ||
.toLowerCase() | ||
.includes(query.toLowerCase()); | ||
}); | ||
resolve(filteredItems); | ||
}, NETWORK_DELAY); | ||
}); | ||
} | ||
|
||
private onChange(event: CustomEvent<ListItem<number>>) { | ||
this.selectedItem = event.detail; | ||
} | ||
|
||
private onInteract(event) { | ||
console.log('Value interacted with:', event.detail); | ||
} | ||
} |