Skip to content

Instantly share code, notes, and snippets.

@alanbsmith
Created January 15, 2018 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanbsmith/205a9bd497ef38419882a300a9ecac86 to your computer and use it in GitHub Desktop.
Save alanbsmith/205a9bd497ef38419882a300a9ecac86 to your computer and use it in GitHub Desktop.
// src/components/App/index.js
...
class App extends Component {
constructor(props) {
super(props);
this.state = {
inputError: false,
phoneNumber: ""
};
}
handleChange(phoneNumber) {
this.setState({
phoneNumber
});
}
render() {
const { inputError, phoneNumber } = this.state;
const inputFieldClasses = classNames('phone-input__field', {
error: inputError,
});
const submitBtnClasses = classNames('phone-input__submit', {
disabled: !phoneNumber.length || inputError,
});
return (
<div className="phone-input">
<label className="phone-input__label">phone number</label>
<input
className={inputFieldClasses}
onChange={e => this.handleChange(e.target.value)}
placeholder="(202) 224-3121"
type="text"
value={phoneNumber}
/>
<div className="phone-input__warning">
{this.state.inputError && 'invalid input'}
</div>
<button
className={submitBtnClasses}
disabled={!phoneNumber.length || inputError}
>
submit
</button>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment