// @flow import React from "react"; import { ListItem, ListItemIcon, ListItemSecondaryAction, ListItemText } from "material-ui/List"; import { renderIcon } from "utils/parseIconName"; import type { ControlUI, UIControl, UISlider } from "config/flowtypes"; // TODO: Use something else import Slider from "material-ui-old/Slider"; import MuiThemeProvider from "material-ui-old/styles/MuiThemeProvider"; import { Toggle, DropDown, Link, Section, Text, Progress } from "./UiItem"; export type UiItemListProps = { controls: Array, state: State, onChangeState: (topic: string, nextState: Actual) => void }; export default class UiItemList extends React.Component { constructor(props: UiItemListProps) { super(props); } render() { return this.props.controls.map((control, key) => { if (control.type == null) { throw new Error( "A control is missing the \"type\" parameter" ); } if (control.type === "section") { return this.renderControl(control); } return ( {control.icon == null || {renderIcon(control.icon, "mdi-24px")}} {this.renderControl(control)} ); }); } renderControl(control: ControlUI) { switch (control.type) { case "toggle": { return ; } case "dropDown": { return ; } case "section": { return
; } case "link": { return ; } case "slider": { return this.renderSlider(control); } case "text": { return ; } case "progress": { return ; } default: { throw new Error( `Unknown UI type "${control.type}" for "${control.text}" component` ); } } } getValue(control: UIControl) { const value = this.props.state[control.topic]; if (value == null) { throw new Error( `Unknown topic "${control.topic}" in ${control.type} "${control.text}"` ); } return value; } renderSlider(control: UISlider) { const value = this.getValue(control); const on = (dontApply: ?boolean) => () => { if (dontApply == null || dontApply === false) { this.props.onChangeState(control.topic, this.val); } }; return [ , { this.val = next; on(control.delayedApply)(); }} onDragStop={on(false)} style={{width: 100}} /> ]; } }