@bity/preact-base-components
Advanced tools
Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "@bity/preact-base-components", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -10,4 +10,3 @@ import { h, Component } from 'preact'; | ||
this.state = { | ||
isDirty: false, | ||
value | ||
isDirty: false | ||
}; | ||
@@ -20,20 +19,10 @@ this.onInput = this.onInput.bind(this); | ||
const { | ||
onInput = () => {} | ||
} = this.props; | ||
const { | ||
value = '' | ||
} = event.target; | ||
this.processInputValue(value); | ||
onInput(value, undefined, USER_TYPING); | ||
} | ||
processInputValue(value) { | ||
const { | ||
onInput = () => {}, | ||
validators = [] | ||
} = this.props; | ||
const isValid = validators.reduce((result, validator) => result && validator.checker(value), true); | ||
onInput(value, isValid); | ||
this.setState({ | ||
value, | ||
isValid | ||
}); | ||
} | ||
onBlur(e) { | ||
@@ -45,26 +34,16 @@ const { | ||
isDirty: true | ||
}, () => { | ||
onBlur(e); | ||
}); | ||
onBlur(e); | ||
} | ||
componentDidMount() { | ||
const { | ||
value = '' | ||
} = this.state; | ||
const { | ||
onInput = () => {} | ||
} = this.props; | ||
if (value) { | ||
this.processInputValue(value); | ||
} else { | ||
// mark freshly rendered field as invalid | ||
onInput('', false); | ||
componentDidUpdate(prevProps, prevState) { | ||
if (this.props.value != prevProps.value) { | ||
const { | ||
onInput = () => {} | ||
} = this.props; | ||
onInput(this.props.value); | ||
} | ||
} | ||
componentWillReceiveProps(nextProps, nextState) { | ||
this.state.value = nextProps.value; | ||
} | ||
render() { | ||
@@ -79,7 +58,7 @@ const { | ||
validators = [], | ||
onKeyPress | ||
onKeyPress, | ||
value = '' | ||
} = this.props; | ||
const { | ||
isDirty, | ||
value | ||
isDirty | ||
} = this.state; | ||
@@ -86,0 +65,0 @@ return h("div", null, !rows && h("input", { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15366
514