Skip to content

Commit

Permalink
Merge pull request #186 from appfolio/addCreditCardInput
Browse files Browse the repository at this point in the history
gt - Refactor CreditCard components
  • Loading branch information
gthomas-appfolio authored Apr 13, 2017
2 parents 37c4b05 + 5355e0c commit c039743
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 342 deletions.
13 changes: 8 additions & 5 deletions src/components/CreditCardExpiration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ export default class CreditCardExpiration extends Component {

render() {
return (
<Row>
<Col xs={12} sm={6}>
<Row className="no-gutters">
<Col xs={7} sm={8}>
<Select
name={this.props.monthName}
placeholder="Month" value={this.props.month}
options={monthOptions} onChange={this.onMonthSelection}
placeholder="Month"
value={this.props.month}
options={monthOptions}
onChange={this.onMonthSelection}
className="pr-3"
/>
</Col>
<Col xs={12} sm={6}>
<Col xs={5} sm={4}>
<Select
name={this.props.yearName}
placeholder="Year" value={this.props.year}
Expand Down
182 changes: 0 additions & 182 deletions src/components/CreditCardForm.js

This file was deleted.

29 changes: 18 additions & 11 deletions src/components/CreditCardInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,37 @@ export default class CreditCardInput extends Component {
return (
<Row>
<Col xs={12} sm={6}>
<Row>
<Col xs={8}>
<ValidatedFormGroup label="Card Number" error={errors.cardNumber}>
<Row className="no-gutters">
<Col xs={9} sm={10}>
<ValidatedFormGroup className="pr-3" error={errors.cardNumber}>
<CreditCardNumber
value={cardNumber} placeholder="Card Number"
value={cardNumber}
placeholder="Card Number"
onChange={this.handleCardNumberChange}
/>
</ValidatedFormGroup>
</Col>
<Col xs={4}>
<ValidatedFormGroup label="CVV" error={errors.cardCVV}>
<Col xs={3} sm={2}>
<ValidatedFormGroup error={errors.cardCVV}>
<PatternInput
name="cardCVV" placeholder="CVV" type="text" value={cardCVV}
pattern={/^[0-9]{0,5}$/} onChange={this.handleCardCVVChange}
name="cardCVV"
placeholder="CVV"
type="text"
value={cardCVV}
pattern={/^[0-9]{0,5}$/}
onChange={this.handleCardCVVChange}
/>
</ValidatedFormGroup>
</Col>
</Row>
</Col>
<Col xs={12} sm={6}>
<ValidatedFormGroup label="Card Expiration" error={errors.expiration}>
<ValidatedFormGroup error={errors.expiration}>
<CreditCardExpiration
month={month} monthName="expiration"
year={year} yearName="expiration"
month={month}
monthName="expiration"
year={year}
yearName="expiration"
onChange={this.handleCardExpirationChange}
/>
</ValidatedFormGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/components/CreditCardNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class CreditCardNumber extends Component {
/>
{cardType &&
<InputGroupAddon>
<Icon name={cardType} />
<Icon name={cardType} size="lg" />
</InputGroupAddon>
}
</InputGroup>
Expand All @@ -99,7 +99,7 @@ export default class CreditCardNumber extends Component {

CreditCardNumber.defaultProps = {
allowedBrands: Object.keys(TYPES),
placeholder: 'Credit Card Number...',
placeholder: 'Credit Card Number',
restrictInput: false,
value: '',

Expand Down
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import BoundFormRow from './components/BoundFormRow';
import Close from './components/Close.js';
import CreditCardNumber from './components/CreditCardNumber.js';
import CreditCardExpiration from './components/CreditCardExpiration.js';
import CreditCardForm from './components/CreditCardForm.js';
import CreditCardInput from './components/CreditCardInput.js';
import CurrencyInput from './components/CurrencyInput.js';
import Datapair from './components/Datapair.js';
Expand Down Expand Up @@ -171,7 +170,6 @@ export {
Close,
CreditCardNumber,
CreditCardExpiration,
CreditCardForm,
CreditCardInput,
CurrencyInput,
Datapair,
Expand Down
10 changes: 0 additions & 10 deletions stories/CreditCardExpiration.js

This file was deleted.

22 changes: 0 additions & 22 deletions stories/CreditCardForm.js

This file was deleted.

32 changes: 32 additions & 0 deletions stories/CreditCardInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { CreditCardExpiration, CreditCardInput, CreditCardNumber } from '../src';
import { storiesOf } from '@kadira/storybook';
import { array, number, text } from '@kadira/storybook-addon-knobs';

const TODAY = new Date();

storiesOf('CreditCardInput', module)
.addWithInfo('Live example', () => (
<CreditCardInput
cardNumber={text('cardNumber', '4111 1111 1111 1111')}
cardCVV={text('cardCVV', '12345')}
expirationMonth={number('expirationMonth', TODAY.getMonth() + 1)}
expirationYear={number('expirationYear', TODAY.getFullYear() + 1)}
/>
))
.addWithInfo('CreditCardExpiration', () => (
<CreditCardExpiration />
))
.addWithInfo('CreditCardNumber', () => (
<CreditCardNumber
value={text('value', '4111111111111111')}
allowedBrands={array('allowedBrands', [
'american-express',
'diners-club',
'master-card',
'discover',
'jcb',
'visa'
])}
/>
));
28 changes: 0 additions & 28 deletions stories/CreditCardNumber.js

This file was deleted.

Loading

0 comments on commit c039743

Please sign in to comment.