2020-04-26 11:36:41 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
import {
|
|
|
|
Component, InputHTMLAttributes,
|
2020-04-26 22:41:06 +02:00
|
|
|
SyntheticEvent,
|
2020-04-26 11:36:41 +02:00
|
|
|
} from 'react';
|
|
|
|
|
|
|
|
export interface SubmitInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
|
|
type?: 'text' | 'number';
|
|
|
|
initialValue?: string;
|
|
|
|
onSubmitValue: (value: string) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface SubmitInputState {
|
|
|
|
value: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SubmitInput extends Component<SubmitInputProps, SubmitInputState> {
|
|
|
|
state: SubmitInputState = {
|
2020-04-26 22:41:06 +02:00
|
|
|
value: '',
|
2020-04-26 11:36:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: SubmitInputProps) {
|
|
|
|
super(props);
|
|
|
|
this.state.value = props.initialValue || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit = (event: SyntheticEvent<any>) => {
|
|
|
|
event.preventDefault();
|
|
|
|
this.props.onSubmitValue(this.state.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <form onSubmit={this.onSubmit}>
|
|
|
|
<input value={this.state.value}
|
2020-04-26 22:41:06 +02:00
|
|
|
{...this.props}
|
2020-04-26 11:36:41 +02:00
|
|
|
onChange={event => this.setState({value: event.currentTarget.value})}/>
|
|
|
|
</form>;
|
|
|
|
}
|
|
|
|
}
|