// @flow import * as React from 'react'; import { FormField } from './form-field'; type FormPrice = { amount: ?number, currency: string, }; type Props = { price: FormPrice, onChange: FormPrice => void, placeholder: number, min: number, disabled: boolean, name: string, step: ?number, }; export class FormFieldPrice extends React.PureComponent { constructor(props: Props) { super(props); (this: any).handleAmountChange = this.handleAmountChange.bind(this); (this: any).handleCurrencyChange = this.handleCurrencyChange.bind(this); } handleAmountChange(event: SyntheticInputEvent<*>) { const { price, onChange } = this.props; const amount = event.target.value ? parseFloat(event.target.value) : undefined; onChange({ currency: price.currency, amount, }); } handleCurrencyChange(event: SyntheticInputEvent<*>) { const { price, onChange } = this.props; onChange({ currency: event.target.value, amount: price.amount, }); } render() { const { price, placeholder, min, disabled, name, step } = this.props; return ( e.preventDefault()} onChange={this.handleAmountChange} placeholder={placeholder || 5} disabled={disabled} step={step || 'any'} /> ); } } export default FormFieldPrice;