-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): separate class and template exports
- Loading branch information
Showing
3 changed files
with
61 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright IBM Corp. 2023 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { LitElement } from 'lit'; | ||
import { SearchTypeaheadAPI } from '../../../services/SearchTypeahead/index.js'; | ||
|
||
/** | ||
* Input component using search typeahead api | ||
*/ | ||
export default class testInput extends LitElement { | ||
static properties = { | ||
searchResults: { attribute: false }, | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
this.searchResults; | ||
} | ||
|
||
async getResults(searchQuery) { | ||
const response = await SearchTypeaheadAPI.getResults(searchQuery); | ||
return response.map((res) => res[0]); | ||
} | ||
|
||
_handleInput(event) { | ||
const { value } = event.target; | ||
this.getResults(value).then((res) => { | ||
this.searchResults = res; | ||
}); | ||
} | ||
} |
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,20 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright IBM Corp. 2023 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import { html } from 'lit'; | ||
|
||
export function testInputTemplate(cls) { | ||
const { _handleInput: handleInput } = cls; | ||
return html`<div> | ||
<label>Search typeahead</label> | ||
<input type="text" @input="${handleInput}" /> | ||
${cls.searchResults | ||
? cls.searchResults.map((result) => html`<p>${result}</p>`) | ||
: undefined} | ||
</div>`; | ||
} |
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