felquis / react-credit-cards-2

Beautiful credit cards for your payment forms - community edition ⚡️
https://ovvwzkzry9.codesandbox.io/
MIT License
62 stars 9 forks source link

React Credit Cards 2 - Community Package

This repository is a hard-fork from the original react-credit-cards package. The main purpose is to update dependencies, make it usable with React 17 and 18 and clear installation warnings.

NPM BundleSize Travis Maintainability Test Coverage

A slick credit card component for React.

demo

Demo - CodeSandbox

Install

npm install --save react-credit-cards-2

Usage

import React, { useState } from 'react';
import Cards from 'react-credit-cards-2';

const PaymentForm = () => {
  const [state, setState] = useState({
    number: '',
    expiry: '',
    cvc: '',
    name: '',
    focus: '',
  });

  const handleInputChange = (evt) => {
    const { name, value } = evt.target;

    setState((prev) => ({ ...prev, [name]: value }));
  }

  const handleInputFocus = (evt) => {
    setState((prev) => ({ ...prev, focus: evt.target.name }));
  }

  return (
    <div>
      <Cards
        number={state.number}
        expiry={state.expiry}
        cvc={state.cvc}
        name={state.name}
        focused={state.focus}
      />
      <form>
        <input
          type="number"
          name="number"
          placeholder="Card Number"
          value={state.number}
          onChange={handleInputChange}
          onFocus={handleInputFocus}
        />
        ...
      </form>
    </div>
  );
}

export default PaymentForm;

If you are using SASS, import the CSS react-credit-cards-2/dist/lib/styles.scss

Or you can import the CSS:
import 'react-credit-cards-2/dist/es/styles-compiled.css';

Features

Props

* Required fields

SCSS options

Credit Card sizing

Credit Card fonts

Credit Card styling

Credit Card brands

Development

Here's how you can get started developing locally:

  1. Clone this repo and link it to your global node_modules:

    $ git clone https://github.com/felquis/react-credit-cards-2.git

    $ cd react-credit-cards-2

    $ npm install

    $ npm link

  2. Download the demo source from codesandbox.

  3. Unzip it to the desired directory.

  4. Install the dependencies

    $ cd react-credit-cards-demo

    $ npm install

    $ npm link react-credit-cards

  5. On the react-credit-cards directory, start the watcher:

    $ npm run watch

  6. On the react-credit-cards-demo directory, start the demo app:

    $ npm start

  7. 🎉 Done! The demo app will be running on: http://localhost:3000/. Your local changes should be automatically reflected there.

Check npm-link for detailed instructions.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process of contributing to the project.

Useful links

EBANK's test numbers
Adyen's test numbers
Worldpay's test card numbers
Brazilian cards patterns

LICENSE

This project is licensed under the MIT License.

Made with ❤️ at AMARO.
Maintained with ❤️ by the community