Code Monkey home page Code Monkey logo

ngx-card's Introduction

ngx-card npm version npm License: MIT

Build Status Codacy Badge

Angular 2+ wrapper for card.js

card

https://ihym.github.io/ngx-card/

Installation

Install through npm:

npm install --save ngx-card

If you use SystemJS to load your files, you should adjust your configuration to point our UMD bundle:

map: {
  ...
  'ngx-card/ngx-card': 'node_modules/ngx-card/bundles/ngx-card.umd.js'
}

Dependencies

This library depends on https://github.com/jessepollak/card (tested with 2.3.0). We don't ship with the library, but you have to take care of including it in your page. There are various ways to achieve this, for example by adding this at the end of your <body>:

<script src="https://unpkg.com/[email protected]/dist/card.js"></script>

API

[card]

Input

  • container: any: A selector or DOM element for the form where users will be entering their information

  • card-width: number: default 350px

  • messages: any = {validDate: 'valid\ndate', monthYear: 'mm/yyyy'}: Strings for translation

  • placeholders: any = {number: '•••• •••• •••• ••••', name: 'Full Name', expiry: '••/••', cvc: '•••'}: Placeholders for rendered fields

  • masks: any;

  • formatting: boolean = true;

  • debug: boolean = false: If true, will log helpful messages for setting up Card

[card-number]

[card-name]

[card-expiry]

[card-cvc]

Usage

Once installed you need to import our main module into yours. You should end up with code similar to this:

import {MyComponent} from '...';
import {CardModule} from 'ngx-card/ngx-card';

@NgModule({
  imports: [..., CardModule],
  declarations: [MyComponent, ...],
})
export class MyModule {}

Modify slightly your form by adding the correct directives in your form elements.

You can have multiple form elements that render to a single field (i.e. you have a first and last name input).

To use ngx-card with this functionality, just rearrange your form elements in the correct order and add the proper directives. For example,

<div class="card-container"></div>
<form card
  container=".card-container"
  card-width="500"
  [messages]="messages"
  [placeholders]="placeholders"
  [masks]="masks"
  formatting="false"
  debug="true">

  <input type="text" name="number" card-number/>
  <input type="text" name="first-name" card-name/>
  <input type="text" name="last-name" card-name/>
  <input type="text" name="expiry" card-expiry/>
  <input type="text" name="cvc" card-cvc/>
</form>

Contribute

Build

npm run build

If you want to watch your source files for changes and build every time use:

npm start

Note: Generated output is placed into the node_modules/ngx-card folder.

Demo

The best way to see your changes in action, is to use our demo page locally. Run:

npm run demo

which will create a development server accessible through http:localhost:1111. In conjunction with npm start in another command tab you have a fully working environment!

All demo resources can be found in the /demo folder.


MIT © Vasilis Diakomanolis

ngx-card's People

Contributors

ihym avatar jbagaresgaray avatar kenfire avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.