Skip to content

Commit

Permalink
Add Images and gif display
Browse files Browse the repository at this point in the history
  • Loading branch information
jasminmif committed Nov 9, 2019
1 parent e8be975 commit 8570453
Show file tree
Hide file tree
Showing 28 changed files with 62 additions and 23 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# react-interactive-paycard

Inspired from a vue project [vue-interactive-paycard](https://github.com/muhammederdem/vue-interactive-paycard), i decided to recreate the same on React as a part time fun project.
Inspired from a vue project [vue-interactive-paycard](https://github.com/muhammederdem/vue-interactive-paycard), I decided to recreate the same on React as a part time fun project.
I did some minor changes on the animations and optimizations on the code.

A fantastic credit card form with smooth and sweet micro-interactions. Includes number formatting, validation and automatic card type detection. Built with vuejs and also fully responsive
A fantastic credit card form with smooth and sweet micro-interactions. Includes number formatting, validation and automatic card type detection. Built with reactjs and also fully responsive

![](demo.gif)

## Libraries used

Expand Down
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/10.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/11.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/12.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/13.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/14.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/15.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/16.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/17.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/18.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/19.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/20.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/21.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/22.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/23.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/24.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/25.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/6.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/7.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/8.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-background/9.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 10 additions & 16 deletions src/screens/MainScreen/components/card/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import './styles.scss';
class Card extends Component {
constructor() {
super();

const backgroundImgname = this.cardBackgroundName();
this.state = {
style: {},
counter: 0
counter: 0,
backgroundImgname: backgroundImgname
};
}

// const [style, setStyle] = useState({});
// const [counter, setCounter] = useState(0);
cardType = () => {
const number = this.props.cardNumber;

Expand All @@ -41,6 +42,11 @@ class Card extends Component {
return 'visa'; // default type
};

cardBackgroundName = () => {
let random = Math.floor(Math.random() * 25 + 1);
return `${random}.jpeg`;
};

removeEmptySpaces = cardNumber => {
return cardNumber.replace(/\s+/g, '');
};
Expand Down Expand Up @@ -89,15 +95,6 @@ class Card extends Component {
return cardNumberArr;
}

// useEffect(() => {
// const style = outlineElementStyle(currentFocusedElm);
// setStyle(style);
// }, [currentFocusedElm]);

// useEffect(() => {
// setCounter(counter + 1);
// }, [cardMonth]);

render() {
let {
cardHolder,
Expand All @@ -116,9 +113,6 @@ class Card extends Component {
const cardHolderArr = cardHolder.split('');
const cardNumberArr = this.maskCardNumber(cardNumber);
cardCvv = cardCvv.split('');
// const cardNumberTrimmed = removeEmptySpaces(cardNumber.trim(' '));

// const { style } = this.state;

return (
<div className={'card-item ' + (isCardFlipped ? '-active' : '')}>
Expand All @@ -133,7 +127,7 @@ class Card extends Component {
<img
src={
process.env.PUBLIC_URL +
'/card-background/5.jpeg'
`/card-background/${this.state.backgroundImgname}`
}
className="card-item__bg"
/>
Expand Down
52 changes: 47 additions & 5 deletions src/screens/MainScreen/components/form/CForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class CForm extends Component {

const currentYear = new Date().getFullYear();
this.state = {
cardNumber: '',
cardMonth: '',
cardYear: '',
monthsArr: Array.from(new Array(12), (x, i) => {
Expand All @@ -26,14 +27,54 @@ class CForm extends Component {
handleFormChange = event => {
const { name, value } = event.target;

if (name === 'cardNumber') {
}

this.setState({ [name]: value });

this.updateMainState(name, value);
};

replaceMissingChars = cardNumber => {
let cardNumberTmp = '#### #### #### ####';
cardNumberTmp = cardNumberTmp.split('');
let cardNumberArr = cardNumber.split('');

let maskedCardNumber = [];
cardNumberTmp.forEach((val, index) => {
cardNumberArr[index]
? maskedCardNumber.push(cardNumberArr[index])
: maskedCardNumber.push(val);
});

return maskedCardNumber.join('');
};

onCardNumberChange = event => {
let { value, name } = event.target;
let cardNumber = value;
let cardNumberMaxLength = 19;
value = value.replace(/\D/g, '');
if (/^3[47]\d{0,13}$/.test(value)) {
cardNumber = value
.replace(/(\d{4})/, '$1 ')
.replace(/(\d{4}) (\d{6})/, '$1 $2 ');
cardNumberMaxLength = 17;
} else if (/^3(?:0[0-5]|[68]\d)\d{0,11}$/.test(value)) {
// diner's club, 14 digits
cardNumber = value
.replace(/(\d{4})/, '$1 ')
.replace(/(\d{4}) (\d{6})/, '$1 $2 ');
cardNumberMaxLength = 16;
} else if (/^\d{0,16}$/.test(value)) {
// regular cc number, 16 digits
cardNumber = value
.replace(/(\d{4})/, '$1 ')
.replace(/(\d{4}) (\d{4})/, '$1 $2 ')
.replace(/(\d{4}) (\d{4}) (\d{4})/, '$1 $2 $3 ');
cardNumberMaxLength = 19;
}

this.setState({ [name]: cardNumber.trimRight() });
this.updateMainState(name, cardNumber);
};

onCvvFocus = event => {
this.updateMainState('isCardFlipped', true);
};
Expand Down Expand Up @@ -68,11 +109,12 @@ class CForm extends Component {
name="cardNumber"
className="card-input__input"
autoComplete="off"
onChange={this.handleFormChange}
onChange={this.onCardNumberChange}
maxLength="19"
ref={cardNumberRef}
onFocus={e => onCardInputFocus(e, 'cardNumber')}
onBlur={onCardInputBlur}
value={this.state.cardNumber}
/>
</div>

Expand Down

0 comments on commit 8570453

Please sign in to comment.