import React, { Component } from "react"
import PropTypes from "prop-types"
import { connect } from "react-redux"
import { update as updateOptions } from "../../ducks/options"
import { Key } from "../../utils"
const stopPropagation = e => {
if (e.keyCode !== Key.ESC) {
e.stopPropagation()
}
}
BooleanOption.PropTypes = {
value: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired,
}
function BooleanOption({ value, onChange, ...props }) {
return (
)
}
StringOption.PropTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
}
function StringOption({ value, onChange, ...props }) {
return (
onChange(e.target.value)}
{...props}
/>
)
}
function Optional(Component) {
return function ({ onChange, ...props }) {
return onChange(x ? x : null)}
{...props}
/>
}
}
NumberOption.PropTypes = {
value: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired,
}
function NumberOption({ value, onChange, ...props }) {
return (
onChange(parseInt(e.target.value))}
{...props}
/>
)
}
ChoicesOption.PropTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
}
function ChoicesOption({ value, onChange, choices, ...props }) {
return (
)
}
StringSequenceOption.PropTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
}
function StringSequenceOption({ value, onChange, ...props }) {
const height = Math.max(value.length, 1)
return