Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sbycrosz committed Jul 15, 2024
1 parent 552ab6a commit 6d17474
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 70 deletions.
128 changes: 65 additions & 63 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* eslint-disable react-native/no-inline-styles */
import { useState } from 'react';
import { ScrollView, Switch, Text, View } from 'react-native';
import {
Platform,
ScrollView,
StyleSheet,
Switch,
Text,
View,
} from 'react-native';
import {
CreditCardView,
CreditCardInput,
Expand All @@ -10,6 +16,45 @@ import {
type ValidationState,
} from 'react-native-credit-card-input';

const s = StyleSheet.create({
container: {
width: '100%',
maxWidth: 600,
marginHorizontal: 'auto',
backgroundColor: '#f0f0f0',
borderRadius: 10,
marginTop: 60,
},
switch: {
alignSelf: 'center',
marginTop: 20,
marginBottom: 20,
},
cardView: {
alignSelf: 'center',
marginTop: 15,
},
cardInput: {
marginTop: 15,
borderColor: '#fff',
borderTopWidth: 1,
borderBottomWidth: 1,
},
infoContainer: {
margin: 20,
padding: 20,
backgroundColor: '#dfdfdf',
borderRadius: 5,
},
info: {
fontFamily: Platform.select({
ios: 'Courier',
android: 'monospace',
web: 'monospace',
}),
},
});

const toStatusIcon = (status?: ValidationState) =>
status === 'valid' ? '✅' : status === 'invalid' ? '❌' : '❓';

Expand All @@ -21,111 +66,68 @@ export default function Example() {
const [formData, setFormData] = useState<CreditCardFormData>();

return (
<ScrollView
contentContainerStyle={{
width: '100%',
maxWidth: 600,
marginHorizontal: 'auto',
backgroundColor: '#f0f0f0',
borderRadius: 10,
marginTop: 60,
}}
>
<View
style={{
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
<ScrollView contentContainerStyle={s.container}>
<Switch
style={s.switch}
onValueChange={(v) => {
setUseLiteInput(v);
setFormData(undefined);
}}
>
<Switch
style={{
alignSelf: 'center',
marginTop: 20,
marginBottom: 20,
}}
onValueChange={(v) => {
setUseLiteInput(v);
setFormData(undefined);
}}
value={useLiteInput}
/>
</View>
value={useLiteInput}
/>

<CreditCardView
focusedField={focusedField}
type={formData?.values.type}
number={formData?.values.number}
expiry={formData?.values.expiry}
cvc={formData?.values.cvc}
style={{
alignSelf: 'center',
marginTop: 15,
}}
style={s.cardView}
/>

{useLiteInput ? (
<LiteCreditCardInput
autoFocus
style={{
marginTop: 15,
borderColor: '#fff',
borderTopWidth: 1,
borderBottomWidth: 1,
}}
inputStyle={{ color: 'black' }}
placeholderColor={'darkgray'}
style={s.cardInput}
onChange={setFormData}
onFocusField={setFocusedField}
/>
) : (
<CreditCardInput
autoFocus
style={{
marginTop: 15,
}}
labelStyle={{ color: 'black' }}
inputStyle={{ color: '#333' }}
placeholderColor={'darkgray'}
style={s.cardInput}
onChange={setFormData}
onFocusField={setFocusedField}
/>
)}

<View
style={{
margin: 20,
padding: 20,
backgroundColor: '#dfdfdf',
borderRadius: 5,
}}
>
<Text style={{ fontFamily: 'courier' }}>
<View style={s.infoContainer}>
<Text style={s.info}>
{formData?.valid
? '✅ Possibly valid card'
: '❌ Invalid/Incomplete card'}
</Text>

<Text style={{ fontFamily: 'courier' }}>
<Text style={s.info}>
{toStatusIcon(formData?.status.number)}
{' Number\t: '}
{formData?.values.number}
</Text>

<Text style={{ fontFamily: 'courier' }}>
<Text style={s.info}>
{toStatusIcon(formData?.status.expiry)}
{' Expiry\t: '}
{formData?.values.expiry}
</Text>

<Text style={{ fontFamily: 'courier' }}>
<Text style={s.info}>
{toStatusIcon(formData?.status.cvc)}
{' Cvc \t: '}
{formData?.values.cvc}
</Text>

<Text style={{ fontFamily: 'courier' }}>
{'ℹ️ Type\t: '}
<Text style={s.info}>
{'ℹ️ Type \t: '}
{formData?.values.type}
</Text>
</View>
Expand Down
6 changes: 2 additions & 4 deletions src/CreditCardInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Props {
style?: ViewStyle;
labelStyle?: TextStyle;
inputStyle?: TextStyle;
placeholderColor: string;
placeholderColor?: string;
labels?: {
number: string;
expiry: string;
Expand Down Expand Up @@ -59,7 +59,6 @@ const s = StyleSheet.create({
input: {
height: 40,
fontSize: 16,
color: 'darkgray',
borderBottomColor: 'darkgray',
borderBottomWidth: 1,
// @ts-expect-error outlineWidth is used to hide the text-input outline on react-native-web
Expand All @@ -68,7 +67,6 @@ const s = StyleSheet.create({
inputLabel: {
fontSize: 14,
fontWeight: 600,
color: 'black',
},
});

Expand All @@ -78,7 +76,7 @@ const CreditCardInput = (props: Props) => {
style,
labelStyle,
inputStyle,
placeholderColor,
placeholderColor = 'darkgray',
labels = {
number: 'CARD NUMBER',
expiry: 'EXPIRY',
Expand Down
5 changes: 2 additions & 3 deletions src/LiteCreditCardInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface Props {
autoFocus?: boolean;
style?: ViewStyle;
inputStyle?: TextStyle;
placeholderColor: string;
placeholderColor?: string;
placeholders?: {
number: string;
expiry: string;
Expand Down Expand Up @@ -76,7 +76,6 @@ const s = StyleSheet.create({
input: {
height: 40,
fontSize: 16,
color: 'black',
// @ts-expect-error outlineWidth is used to hide the text-input outline on react-native-web
outlineWidth: 0,
},
Expand All @@ -87,7 +86,7 @@ const LiteCreditCardInput = (props: Props) => {
autoFocus = false,
style,
inputStyle,
placeholderColor,
placeholderColor = 'darkgray',
placeholders = {
number: '1234 5678 1234 5678',
expiry: 'MM/YY',
Expand Down

0 comments on commit 6d17474

Please sign in to comment.