Created
April 19, 2019 14:24
-
-
Save odoe/6b5cb11a93f7064e643e8d2fe7dfd67c to your computer and use it in GitHub Desktop.
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
import { tsx } from "@dojo/framework/widget-core/tsx"; | |
import { WidgetBase } from "@dojo/framework/widget-core/WidgetBase"; | |
import { watch } from "@dojo/framework/widget-core/decorators/watch"; | |
import Listbox from "@dojo/widgets/listbox"; | |
import TextArea from "@dojo/widgets/text-area"; | |
import theme from "@dojo/themes/dojo"; | |
import * as css from "./styles/APIExplorer.m.css"; | |
import { ExplorerProperties, Item } from "../interfaces"; | |
export class APIExplorer extends WidgetBase<ExplorerProperties> { | |
@watch() index = 0; | |
@watch() label = ""; | |
onAttach() { | |
this.properties.fetchAllResults(); | |
} | |
protected render() { | |
return ( | |
<div classes={css.root}> | |
<Listbox | |
theme={theme} | |
key="listbox1" | |
activeIndex={this.index} | |
widgetId="listbox1" | |
optionData={this.properties.items} | |
getOptionLabel={(option: Item) => option.label} | |
getOptionSelected={(option: Item) => option.label === this.label} | |
onActiveIndexChange={(index: number) => { | |
this.index = index; | |
}} | |
onOptionSelect={(option: Item, index: number) => { | |
this.label = option.label; | |
this.properties.fetchData(option); | |
}} | |
/> | |
<TextArea rows={15} theme={theme} value={this.properties.result} /> | |
</div> | |
); | |
} | |
} | |
// src/interfaces.ts | |
export interface ExplorerProperties { | |
items: Item[]; | |
result: string; | |
fetchAllResults: () => void; | |
fetchData: (item: Item) => void; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment