import React, { Component } from 'react'; import classNames from 'classnames'; import './style.css'; interface ContainerProps { value: string; onChange(event: EventTarget, value: any): void; } const MyContainer = (WrappedComponent: any) => class MyContainer extends Component { constructor(props: ContainerProps) { super(props); this.state = { name: this.props.value || '' }; this.onNameChange = this.onNameChange.bind(this); } onNameChange(event: any) { this.setState({ name: event.target.value }); if (this.props.onChange) { this.props.onChange(event, event.target.value); } } componentWillReceiveProps({ value }: ContainerProps) { if (value) { this.setState({ name: value }); } } render() { const newProps = { name: { value: this.state.name, onChange: this.onNameChange } }; return ; } }; interface InputProps { type: string; autoFocus: boolean; value: string; name: object; placeholder: string; onFocus(): void; onBlur(): void; } class Input extends Component { static defaultProps = { type: 'text' }; constructor(props: InputProps) { super(props); this.state = { focusState: false }; } focusCtrl(focusState: boolean) { this.setState({ focusState }); const { onBlur = () => { }, onFocus = () => { } } = this.props; focusState ? onFocus() : onBlur(); } render() { const { type, autoFocus } = this.props; const { focusState }: any = this.state; const focusClass = classNames({ 'focus-border': focusState, 'input-box': true }); return (
{type === 'text' ? ( ) : ( )}
); } } export default MyContainer(Input);