import * as React from "react"; import { Saucer } from "../ticker/saucer"; import { Color } from "../interfaces"; import { colors } from "../util"; interface ColorPickerProps { current: Color; onChange?: (color: Color) => any; } interface ColorPickerState { isHovered: boolean; } export class ColorPicker extends React.Component { constructor(props: ColorPickerProps) { super(props); this.state = { isHovered: false }; } /** The output of this function is what the user will see when the color circle is hovered over. */ isHovered() { let actual = this.props.current; let cb = this.props.onChange || function(){ }; function littleCircle(color: Color, key: number) { let style = { margin: "4px" }; if (color === actual) { style["border"] = "3px solid #666"; } function colorChange() { cb(color); } return
; } return
{colors.map(littleCircle)}
; } /** This is what the user sees when the circle is not hovered over. */ notHovered() { return
; } render() { let Comp = (this.state.isHovered ? this.isHovered.bind(this) : this.notHovered); return
{ this.setState({ isHovered: true }); } } onMouseLeave={() => { this.setState({ isHovered: false }); } } >
; }; }