import TextField from '@material-ui/core/TextField'; /** * @param error 是否是错误 * @param fullWidth 是否全部宽度 * @param placeholder 说明文字 * @param remark 追加说明 * @param multiline 是否是多行属性. * @param required 是否必填 * @param type 类型 * @param name 当前属性值. * @param disabled 是否可用 * @param inputProps : {min:16, max:33 }, 限制最大最小值 * @param onChange 更新处理方法 */ class JInput extends React.Component { constructor(props){ super(props); this.state={ value:'', inputProps:{ min:0, } } } static getDerivedStateFromProps(nextProps) { if (nextProps && null != nextProps && undefined != nextProps.onChange) { return { value : nextProps.value || '', inputProps : nextProps.inputProps || { min:0, }, } } return null; } onChange = (evt)=>{ const fix =evt.target.value; console.log(fix) const {onChange,name} = this.props; if(onChange) onChange(fix,name); else this.setState({value:fix}); } render() { const { error, fullWidth = true, placeholder = 'placeholder', type = "text",disabled=false,required=false, remark, multiline = false,style } = this.props; const {value,inputProps} = this.state; return (<TextField inputProps={inputProps} label={placeholder} fullWidth={fullWidth} error={error} type={type} required={required} size="small" disabled={disabled} value={value} onChange={this.onChange} multiline={multiline} helperText={remark} variant="outlined" style={style} />); } } export default JInput;
import TextField from '@material-ui/core/TextField'; /** * @param error 是否是错误 * @param fullWidth 是否全部宽度 * @param placeholder 说明文字 * @param remark 追加说明 * @param multiline 是否是多行属性. * @param required 是否必填 * @param type 类型 * @param name 当前属性值. * @param disabled 是否可用 * @param inputProps : {min:16, max:33 }, 限制最大最小值 * @param onChange 更新处理方法 */ class JInput extends React.Component { constructor(props){ super(props); this.state={ value:'', inputProps:{ min:0, } } } static getDerivedStateFromProps(nextProps) { if (nextProps && null != nextProps && undefined != nextProps.onChange) { return { value : nextProps.value || '', inputProps : nextProps.inputProps || { min:0, }, } } return null; } onChange = (evt)=>{ const fix =evt.target.value; console.log(fix) const {onChange,name} = this.props; if(onChange) onChange(fix,name); else this.setState({value:fix}); } render() { const { error, fullWidth = true, placeholder = 'placeholder', type = "text",disabled=false,required=false, remark, multiline = false,style } = this.props; const {value,inputProps} = this.state; return (<TextField inputProps={inputProps} label={placeholder} fullWidth={fullWidth} error={error} type={type} required={required} size="small" disabled={disabled} value={value} onChange={this.onChange} multiline={multiline} helperText={remark} variant="outlined" style={style} />); } } export default JInput;