Created
February 3, 2020 14:24
-
-
Save indreklasn/354817b008c55deb56f10f989f580713 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Cards from 'react-credit-cards'; | |
export default class PaymentForm extends React.Component { | |
state = { | |
cvc: '', | |
expiry: '', | |
focus: '', | |
name: '', | |
number: '', | |
}; | |
handleInputFocus = (e) => { | |
this.setState({ focus: e.target.name }); | |
} | |
handleInputChange = (e) => { | |
const { name, value } = e.target; | |
this.setState({ [name]: value }); | |
} | |
render() { | |
return ( | |
<div id="PaymentForm"> | |
<Cards | |
cvc={this.state.cvc} | |
expiry={this.state.expiry} | |
focused={this.state.focus} | |
name={this.state.name} | |
number={this.state.number} | |
/> | |
<form> | |
<input | |
type="tel" | |
name="number" | |
placeholder="Card Number" | |
onChange={this.handleInputChange} | |
onFocus={this.handleInputFocus} | |
/> | |
... | |
</form> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment