App.jsx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
import React, { useState } from "react"; import Cards from "react-credit-cards"; import "react-credit-cards/es/styles-compiled.css"; import { Form, Button, Container, Row, Col } from "react-bootstrap"; import "bootstrap/dist/css/bootstrap.min.css"; function App() { const [formData, setFormData] = useState({ cvc: "", expiry: "", focus: "", name: "", number: "", }); const handleInputFocus = (e) => { setFormData((prevData) => ({ ...prevData, focus: e.target.name, })); }; const handleInputChange = (e) => { const { name, value } = e.target; setFormData((prevData) => ({ ...prevData, [name]: value, })); }; return ( <Container className="mt-5"> <Row className="justify-content-center"> <Col md={6} sm={12}> <div className="mb-4"> <Cards cvc={formData.cvc} expiry={formData.expiry} focused={formData.focus} name={formData.name} number={formData.number} /> </div> <Form> <Form.Group className="mb-3"> <Form.Control type="tel" name="number" placeholder="Card Number" value={formData.number} onChange={handleInputChange} onFocus={handleInputFocus} /> </Form.Group> <Form.Group controlId="formName" className="mb-3"> <Form.Control type="text" name="name" placeholder="Name" value={formData.name} onChange={handleInputChange} onFocus={handleInputFocus} /> </Form.Group> <Row> <Col md={6}> <Form.Group controlId="formExpiry" className="mb-3"> <Form.Control type="text" name="expiry" placeholder="MM/YY" value={formData.expiry} onChange={handleInputChange} onFocus={handleInputFocus} /> </Form.Group> </Col> <Col md={6}> <Form.Group controlId="formCVC" className="mb-3"> <Form.Control type="tel" name="cvc" placeholder="CVC" value={formData.cvc} onChange={handleInputChange} onFocus={handleInputFocus} /> </Form.Group> </Col> </Row> <Button variant="primary" type="submit" className="w-100"> Submit Payment </Button> </Form> </Col> </Row> </Container> ); } export default App; |