Skip to content

Instantly share code, notes, and snippets.

@odoe
Created April 19, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/6b5cb11a93f7064e643e8d2fe7dfd67c to your computer and use it in GitHub Desktop.
Save odoe/6b5cb11a93f7064e643e8d2fe7dfd67c to your computer and use it in GitHub Desktop.
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