import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Card } from 'react-bootstrap';
export default class Widget extends Component {
constructor(props) {
super(props)
this.state = {
title: this.props.title,
value: this.props.value,
unit: this.props.unit,
icon: this.props.icon,
avg: this.props.avg,
max: this.props.max,
failed: this.props.failed,
}
}
componentDidUpdate = () => {
if(this.props.title != this.state.title || this.props.value != this.state.value || this.props.unit != this.state.unit || this.props.icon != this.state.icon || this.props.avg != this.state.avg || this.props.max != this.state.max || this.props.failed != this.state.failed) {
this.setState({
title: this.props.title,
value: this.props.value,
unit: this.props.unit,
icon: this.props.icon,
avg: this.props.avg,
max: this.props.max,
failed: this.props.failed,
});
}
}
render() {
var title = this.state.title;
var value = this.state.value;
var unit = this.state.unit;
var icon = this.state.icon;
var max = this.state.max;
var avg = this.state.avg;
var failed = Boolean(Number(this.state.failed));
switch(icon) {
case 'ping':
icon = ;
break;
case 'dl':
icon = ;
break;
case 'ul':
icon = ;
break;
}
return (
{title}
{icon}
{(!failed) ? value : }
{unit} (current)
);
}
}
if (document.getElementById('Widget')) {
ReactDOM.render(, document.getElementById('Widget'));
}