I'll help you build a comprehensive credit card input component with all the requested features.
First, I'll install some necessary packages for icons and class name management, which are helpful for building robust UI components.
I'll create a utility file to handle all the card logic: detecting the card type from the prefix, formatting the card number with spaces, formatting the expiry date, and validating the fields.
I'll update the main CSS file to include some necessary classes for the 3D flipping effect. This will allow the card to smoothly rotate and show its back side when the user interacts with the CVV field.
Next, I'll build the CreditCardPreview component. This handles the visual representation of the credit card, including dynamic background gradients based on the detected card type, the smooth 3D flip animation, and a highlight box that moves to indicate the active input field.
Next, I'll create the CreditCardForm component. This component holds the input fields and handles the visual validation states (red for invalid, green for valid once filled out). It passes focus events up to the parent so the preview card knows which field to highlight or flip to.
Now, I'll update App.tsx to tie the form, the preview, and the logic utilities together. It will manage the application state, handling formatting updates from the form and passing them to the visual card preview.
I'll fix the minor linting error in App.tsx and update the index.html title to be appropriate for our application.
Let me quickly read index.html so I can update the title properly.
I will update the title in index.html to reflect the Secure Checkout page.
Now I will build the project to ensure there are no compilation errors and everything is ready to run.
I see that this environment is using Tailwind v4 which has a new syntax for its CSS file. I will update src/index.css to use the new @import "tailwindcss"; syntax and adjust our custom utilities.
I'll run the build process again to verify the Tailwind v4 syntax works.
I'll quickly do some minor cleanup to remove the unused React imports from the components to keep the code perfectly clean.
I will run a final build to confirm everything is pristine.
I have successfully created a complete, functional credit card input component with all the requested features:
- Live Card Preview: The visual card in the preview updates dynamically as you type in the form.
- Flip for CVV: Focusing the CVV input smoothly rotates the card 180 degrees using CSS 3D transforms to reveal the back.
- Card Type Detection: The card logo and gradient background automatically adapt based on the number prefix (Visa, Mastercard, Amex, Discover).
- Expiry Formatting: Automatically formats the expiry date (MM/YY) correctly and enforces input structure.
- Satisfying Validation States: The fields provide live feedback with smooth color transitions. Successfully validated fields show green borders with a checkmark, while errors are highlighted in red with an alert icon when leaving the input.
The project is built successfully and ready to use!
Files built: src/utils/cardUtils.ts, src/index.css, src/components/CreditCardPreview.tsx, src/components/CreditCardForm.tsx, src/App.tsx, index.html