npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@repay/react-credit-card

v1.0.7

Published

Credit card display in React

Downloads

211

Readme

@repay/react-credit-card

Coverage 100% CircleCI

A port of Card by @jessepollak and re-write of react-credit-card by @JohnyDays. We chose not to fork because it's a full re-write in TypeScript but the API is almost identical to react-credit-card

View the demo

Installation and Usage

Install via npm or yarn using the command-line

npm install @repay/react-credit-card
// OR
yarn add @repay/react-credit-card

Importing the CSS

You can import the CSS directly into some bundled CSS using the import directive.

@import "@repay/react-credit-card/dist/react-credit-card.css";

If using Webpack or some other bundler along with a css toolchain, you can import this into your JavaScript code.

import "@repay/react-credit-card/dist/react-credit-card.css";

If using css-modules, you will need to override this to import the styles as global: example for webpack to override css-modules.

import "!style-loader!css-loader?sourceMap!@repay/react-credit-card/dist/react-credit-card.css";

Using the Card

// see stories/Examples.stories.tsx
import Card from "@repay/react-credit-card";

export default function CreditCardForm() {
  const [values, setValues] = React.useState({
    name: "",
    number: "",
    expiration: "",
    cvc: ""
  });
  const handleChange = React.useCallback(
    event => {
      const { name, value } = event.target;
      setValues(v => ({ ...v, [name]: value }));
    },
    [setValues]
  );

  const [focused, setFocus] = React.useState<FOCUS_TYPE | undefined>(undefined);
  const handleFocus = React.useCallback(
    event => setFocus(event.target.name as FOCUS_TYPE),
    [setFocus]
  );
  const handleBlur = React.useCallback(() => setFocus(undefined), [setFocus]);

  return (
    <form>
      <div style={styles}>
        <fieldset>
          <label>Name on card</label>
          <input
            name="name"
            onChange={handleChange}
            onFocus={handleFocus}
            onBlur={handleBlur}
            value={values.name}
          />
        </fieldset>
        <fieldset>
          <label>Card Number</label>
          <input
            name="number"
            onChange={handleChange}
            onFocus={handleFocus}
            onBlur={handleBlur}
            value={values.number}
          />
        </fieldset>
        <fieldset>
          <label>Expiration</label>
          <input
            name="expiration"
            placeholder="MM/YY"
            onChange={handleChange}
            onFocus={handleFocus}
            onBlur={handleBlur}
            value={values.expiration}
          />
        </fieldset>
        <fieldset style={{ marginBottom: "20px" }}>
          <label>CVC</label>
          <input
            name="cvc"
            onChange={handleChange}
            onFocus={handleFocus}
            onBlur={handleBlur}
            value={values.cvc}
          />
        </fieldset>
        <ReactCreditCard {...values} focused={focused} />
      </div>
    </form>
  );
}

Dev Environment Setup

  1. Clone this repository into your local filesystem.
  2. Run the command yarn install to install the necessary dev dependencies.
  3. Run the command yarn dev to spin up the storybook dev environment. This allows you to easily see the credit card component, and use it as you modify.

General Commands

  • yarn tdd: Runs the test suite in watch mode, which will trigger tests to re-run when changes are made.
  • yarn test: runs the full test suite, TypeScript checks, and validates formatting; then documents current coverage
  • yarn fmt: tries to automatically fixes formatting or errors to fix others
  • yarn build: builds the distributable package into the dist/ folder

Publishing

yarn test:ci
yarn build
yarn publish