This file contains hidden or 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 { registerStyles } from '@vaadin/vaadin-themable-mixin/register-styles.js'; | |
registerStyles('vaadin-combo-box-item', css` | |
.symbol { font-weight: bold } | |
.name { font-size: 0.8rem } | |
`); |
This file contains hidden or 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
<vaadin-combo-box | |
@filter-changed=${this.onStockSearchStringChanged} | |
.renderer=${this.renderSearchBoxItems} | |
id="stock-search" | |
label="Search for a stock symbol" | |
item-label-path="symbol"> | |
</vaadin-combo-box> | |
... |
This file contains hidden or 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
private searchApiURL = 'https://financialmodelingprep.com/api/v3/search?query=<query>&exchange=NASDAQ'; | |
private onStockSearchStringChanged(filterEvent: any) { | |
let searchString = filterEvent.detail.value; | |
if (!searchString) { | |
this.stockSearchBox.filteredItems = []; | |
return; | |
} | |
const url = this.searchApiURL.replace('<query>', searchString); |
This file contains hidden or 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 {LitElement, html, css, customElement, property, query} from 'lit-element'; | |
... | |
import '@vaadin/vaadin-combo-box'; | |
import '@vaadin/vaadin-button'; | |
import '@vaadin/vaadin-ordered-layout'; | |
... | |
@query("#stock-search") | |
private stockSearchBox: any; |
This file contains hidden or 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
:host { | |
display: flex; | |
flex-flow: column; | |
box-sizing: border-box; | |
padding: var(--lumo-space-l); | |
} |
This file contains hidden or 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
static get styles() { | |
return css` | |
.percentage { | |
color: green; | |
font-weight: bold; | |
} | |
.percentage.negative { | |
color: red; | |
} | |
`; |
This file contains hidden or 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
render() { | |
return html` | |
<vaadin-grid .items=${this.items}> | |
<vaadin-grid-column path="symbol"></vaadin-grid-column> | |
<vaadin-grid-column path="price"></vaadin-grid-column> | |
<vaadin-grid-column .renderer=${this.renderPercentage} header="Percentage change"></vaadin-grid-column> | |
</vaadin-grid> | |
`; | |
} |
This file contains hidden or 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
firstUpdated() { | |
this.updateGrid(); | |
} | |
private updateGrid() { | |
StockService.getStocks().then(stocks => { | |
let symbols = stocks.map(stock => stock.symbol).concat(','); | |
let url = this.stockAPIBaseUrl + symbols; | |
fetch(url) |
This file contains hidden or 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
@property({ type: Array }) | |
private items = []; | |
firstUpdated() { | |
StockService.getStocks().then(stocks => this.items = stocks); | |
} |
This file contains hidden or 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
render() { | |
return html` | |
<vaadin-grid .items=${this.items}> | |
<vaadin-grid-column path="symbol"></vaadin-grid-column> | |
</vaadin-grid> | |
`; | |
} |