Now with sliders!

Seriously, someone really should clean this mess of code up soon
This commit is contained in:
uwap 2017-09-17 05:35:20 +02:00
parent d121928df6
commit efc5af37ce
3 changed files with 45 additions and 2 deletions

View file

@ -3,6 +3,7 @@ import React from "react";
import Toggle from "material-ui/Toggle";
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';
import Slider from 'material-ui/Slider';
import Config from "./config";
import R from "ramda";
@ -72,3 +73,19 @@ export const dropDown = (state: State, props: ControlUI) => (
{R.values(R.mapObjIndexed(dropDownItem(props.topic), props.options))}
</SelectField>
);
const onSliderChange = (state: State, props: ControlUI) =>
(event, value) => {
if (state.mqtt != null) {
state.mqtt.publish(Config.topics[props.topic].command, value.toString());
}
};
export const slider = (state: State, props: ControlUI) => (
<Slider value={state.values[props.topic]}
min={props.min == null ? 0 : props.min}
max={props.max == null ? 1 : props.max}
step={props.step == null ? 1 : props.step}
onChange={onSliderChange(state, props)}
/>
);