-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var cc = { | ||
images: true, | ||
format: true, | ||
number: '4485148248332663', | ||
label: 'Credit Card: ', | ||
accepted: ['visa','mastercard'] | ||
}; | ||
|
||
var example = ( | ||
<UIToolkit.CreditCardNumber | ||
showImages={cc.images} | ||
formatInput={cc.format} | ||
defaultValue={cc.number} | ||
label={cc.label} | ||
accepted={cc.accepted} /> | ||
); | ||
|
||
React.render(example, mountNode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
.project | ||
dev/app.js | ||
node_modules |
33 changes: 33 additions & 0 deletions
33
src/components/credit-card-number/__tests__/creditcard-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** @jsx React.DOM */ | ||
|
||
jest.dontMock('../code/views/creditCardNumberView.jsx'); | ||
|
||
var React = require('react/addons'); | ||
var CreditCardNumberComponent = require('../code/views/creditCardNumberView.jsx'); | ||
var TestUtils = React.addons.TestUtils; | ||
|
||
describe('CreditCardNumberComponent', function() { | ||
|
||
it('is an element', function() { | ||
expect(TestUtils.isElement(<CreditCardNumberComponent />)).toBeTruthy(); | ||
}); | ||
|
||
it('should render a label', function() { | ||
var labelCheck = TestUtils.renderIntoDocument( | ||
<CreditCardNumberComponent label="Credit Card: " /> | ||
); | ||
|
||
var renderedLabel = TestUtils.findRenderedDOMComponentWithClass(labelCheck, 'credit-card-number-label'); | ||
expect(renderedLabel).toBeDefined(); | ||
}); | ||
|
||
it('should render credit card images', function() { | ||
var imagesCheck = TestUtils.renderIntoDocument( | ||
<CreditCardNumberComponent showImages /> | ||
); | ||
|
||
var renderedImages = TestUtils.findRenderedDOMComponentWithClass(imagesCheck, 'credit-card-images'); | ||
expect(renderedImages).toBeDefined(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./views/creditCardNumberView.jsx'); |
52 changes: 52 additions & 0 deletions
52
src/components/credit-card-number/code/templates/creditCardNumberTemplate.jsx
Large diffs are not rendered by default.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
src/components/credit-card-number/code/views/creditCardNumberView.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
var React = require('react'); | ||
|
||
module.exports = React.createClass({ | ||
|
||
propTypes: { | ||
accepted: React.PropTypes.array, | ||
cardNumber: React.PropTypes.string, | ||
cardType: React.PropTypes.oneOf(['amex', 'discover', 'mastercard', 'visa']), | ||
defaultValue: React.PropTypes.string, | ||
id: React.PropTypes.string, | ||
label: React.PropTypes.string, | ||
name: React.PropTypes.string | ||
}, | ||
|
||
getInitialState: function() { | ||
|
||
var card = this.updateCard(this.props.defaultValue); | ||
|
||
return { | ||
cardNumber: card.cardNumber || '', | ||
cardType: card.cardType || '' | ||
}; | ||
}, | ||
|
||
getDefaultProps: function() { | ||
return { | ||
accepted: ['amex', 'discover', 'mastercard', 'visa'], | ||
formatInput: false, | ||
id: 'credit-card-number', | ||
name: 'credit-card-number', | ||
placeHolder: '• • • • • • • • • • • • • • • •', | ||
showImages: false | ||
}; | ||
}, | ||
|
||
updateCard: function(cardNumber) { | ||
|
||
if(typeof cardNumber === 'undefined'){ | ||
return false; | ||
} | ||
|
||
var cardInfo = this.getCard(cardNumber); | ||
var formattedCard = (this.props.formatInput) ? cardNumber.replace(/(.{4})/g, '$1 ').trim() : cardNumber; | ||
|
||
var card = { | ||
cardNumber: formattedCard, | ||
cardType: cardInfo.type | ||
}; | ||
|
||
this.setState(card); | ||
|
||
return card; | ||
}, | ||
|
||
getCard: function(cardNumber) { | ||
|
||
var cards = [ | ||
{ | ||
type: 'amex', | ||
pattern: /^3[47]/, | ||
format: /(\d{1,4})(\d{1,6})?(\d{1,5})?/, | ||
length: [15] | ||
}, | ||
{ | ||
type: 'discover', | ||
pattern: /^(6011|65|64[4-9]|622)/, | ||
format: /(\d{1,4})/g, | ||
length: [16] | ||
}, | ||
{ | ||
type: 'mastercard', | ||
pattern: /^5[1-5]/, | ||
format: /(\d{1,4})/g, | ||
length: [16] | ||
}, | ||
{ | ||
type: 'visa', | ||
pattern: /^4/, | ||
format: /(\d{1,4})/g, | ||
length: [13, 14, 15, 16] | ||
} | ||
]; | ||
|
||
for (var i=0; i<cards.length; i++) { | ||
var card = cards[i]; | ||
if (card.pattern.test(cardNumber) && this.props.accepted.indexOf(card.type) > -1) | ||
{ | ||
return card; | ||
} | ||
} | ||
|
||
return { | ||
type: '' | ||
}; | ||
}, | ||
|
||
handleChange: function(e) { | ||
var cardNumber = e.target.value.replace(/\D/g, ''); | ||
this.updateCard(cardNumber); | ||
}, | ||
|
||
render: function() { | ||
return require('../templates/creditCardNumberTemplate.jsx')(this); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./code/index'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
if [ -z "$VARIANT" ]; then VARIANT=''; fi | ||
if [ -z "$TEMPLATE_LANG" ]; then TEMPLATE_LANG='en'; fi | ||
|
||
echo "Building package for demo. Variant: '$VARIANT', language: '$TEMPLATE_LANG'." | ||
|
||
browserify -t [ redirectify --dir "$VARIANT" ] -t reactify dev/example.jsx -o dev/ui-component-creditcard.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
if [ -z "$VARIANT" ]; then VARIANT=''; fi | ||
if [ -z "$TEMPLATE_LANG" ]; then TEMPLATE_LANG='en'; fi | ||
|
||
echo "Building package for demo. Variant: '$VARIANT', language: '$TEMPLATE_LANG'." | ||
|
||
browserify -t [ redirectify --dir "$VARIANT" ] -t reactify index.js --standalone ui-component-creditcard > dist/ui-component-creditcard-standalone.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters