@xyo-network/react-form-credit-card 7.5.8 → 7.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/components/controls/card/FormControlTextField.d.ts.map +1 -1
- package/dist/browser/components/controls/card/number/use.d.ts.map +1 -1
- package/dist/browser/components/support/InputError.d.ts +2 -2
- package/dist/browser/components/support/InputError.d.ts.map +1 -1
- package/dist/browser/controls/CreditCardNumber.d.ts.map +1 -1
- package/dist/browser/index.mjs +474 -425
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/models/CreditCardInput.d.ts +2 -2
- package/dist/browser/models/CreditCardInput.d.ts.map +1 -1
- package/package.json +120 -34
- package/src/components/controls/WithFormControlProps.ts +0 -6
- package/src/components/controls/card/Email.tsx +0 -37
- package/src/components/controls/card/Expiration.tsx +0 -37
- package/src/components/controls/card/FormControlTextField.tsx +0 -63
- package/src/components/controls/card/Name.tsx +0 -44
- package/src/components/controls/card/Options.ts +0 -22
- package/src/components/controls/card/Zip.tsx +0 -33
- package/src/components/controls/card/cvv/Cvv.tsx +0 -35
- package/src/components/controls/card/cvv/index.ts +0 -2
- package/src/components/controls/card/cvv/use.ts +0 -37
- package/src/components/controls/card/index.ts +0 -9
- package/src/components/controls/card/number/Number.tsx +0 -49
- package/src/components/controls/card/number/index.ts +0 -2
- package/src/components/controls/card/number/use.ts +0 -34
- package/src/components/controls/card/useCreditCardFormControl.tsx +0 -40
- package/src/components/controls/index.ts +0 -2
- package/src/components/form/Form.tsx +0 -83
- package/src/components/form/InputFieldsStack.tsx +0 -69
- package/src/components/form/Props.ts +0 -15
- package/src/components/form/index.ts +0 -4
- package/src/components/form/useFormStorage.tsx +0 -40
- package/src/components/img/american-express.svg +0 -69
- package/src/components/img/discover.svg +0 -13
- package/src/components/img/index.ts +0 -4
- package/src/components/img/mastercard.svg +0 -16
- package/src/components/img/visa.svg +0 -1
- package/src/components/index.ts +0 -3
- package/src/components/support/Fields.ts +0 -3
- package/src/components/support/InputError.ts +0 -4
- package/src/components/support/index.ts +0 -3
- package/src/components/support/validateCreditCardInputs.ts +0 -18
- package/src/context/FormGroupCreditCardContext.ts +0 -6
- package/src/context/FormGroupCreditCardProvider.tsx +0 -33
- package/src/context/index.ts +0 -3
- package/src/context/useFormGroupWithCreditCard.tsx +0 -7
- package/src/controls/CreditCardCvv.ts +0 -85
- package/src/controls/CreditCardExpiry.ts +0 -94
- package/src/controls/CreditCardNumber.ts +0 -138
- package/src/controls/Email.ts +0 -47
- package/src/controls/Name.ts +0 -40
- package/src/controls/Zip.ts +0 -54
- package/src/controls/index.ts +0 -6
- package/src/index.ts +0 -5
- package/src/models/CreditCardInput.ts +0 -20
- package/src/models/index.ts +0 -1
- package/src/stories/form.stories.tsx +0 -26
- package/src/types/images.d.ts +0 -29
- package/src/utils/index.ts +0 -1
- package/src/utils/umask.ts +0 -3
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject } from '@xylabs/sdk-js'
|
|
2
|
-
import type { SetOptions, ValidControlValue } from '@xyo-network/react-form-group'
|
|
3
|
-
import { FormControlBase } from '@xyo-network/react-form-group'
|
|
4
|
-
import valid from 'card-validator'
|
|
5
|
-
|
|
6
|
-
import { unmask } from '../utils/index.ts'
|
|
7
|
-
|
|
8
|
-
const CONTROL_NAME = 'cardNumber2'
|
|
9
|
-
|
|
10
|
-
export class CreditCardNumberFormControl<TProps extends EmptyObject = EmptyObject> extends FormControlBase<TProps> {
|
|
11
|
-
creditCardType: string = ''
|
|
12
|
-
|
|
13
|
-
override invalidMessage = 'Card Number is invalid'
|
|
14
|
-
|
|
15
|
-
override pattern = /^(\d+)?$/
|
|
16
|
-
override patternStrict = /^\d+$/
|
|
17
|
-
|
|
18
|
-
override props = {
|
|
19
|
-
autoComplete: 'cc-number',
|
|
20
|
-
autoCorrect: 'off',
|
|
21
|
-
id: CONTROL_NAME,
|
|
22
|
-
inputMode: 'numeric',
|
|
23
|
-
name: CONTROL_NAME,
|
|
24
|
-
placeholder: '1234 1234 1234 1234',
|
|
25
|
-
spellCheck: false,
|
|
26
|
-
} as TProps
|
|
27
|
-
|
|
28
|
-
override required = true
|
|
29
|
-
|
|
30
|
-
override unmask = unmask
|
|
31
|
-
|
|
32
|
-
constructor() {
|
|
33
|
-
super()
|
|
34
|
-
super.setName(CONTROL_NAME)
|
|
35
|
-
this.setSerializeSettings({ sensitive: true, serializable: true })
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
override blurError(value: string) {
|
|
39
|
-
const unmasked = unmask(value)
|
|
40
|
-
const numberValidation = valid.number(unmasked)
|
|
41
|
-
if (!numberValidation.isValid) {
|
|
42
|
-
this.setErrorAndValidity(this.invalidMessage, 'INVALID')
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
this.setErrorAndValidity('', 'VALID')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
override changeError(value: string) {
|
|
49
|
-
const unmasked = unmask(value)
|
|
50
|
-
const match = RegExp(this.patternStrict).exec(unmasked)
|
|
51
|
-
if (match) {
|
|
52
|
-
const numberValidation = valid.number(unmasked)
|
|
53
|
-
if (!numberValidation.isPotentiallyValid) {
|
|
54
|
-
this.setErrorAndValidity(this.invalidMessage, 'INVALID')
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
this.setErrorAndValidity('', 'VALID')
|
|
58
|
-
} else {
|
|
59
|
-
this.setErrorAndValidity(this.invalidMessage, 'INVALID')
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
earlyNumberCheck(number: string) {
|
|
64
|
-
switch (number) {
|
|
65
|
-
case '4': {
|
|
66
|
-
this.setCreditCardType('visa')
|
|
67
|
-
break
|
|
68
|
-
}
|
|
69
|
-
case '5': {
|
|
70
|
-
this.setCreditCardType('mastercard')
|
|
71
|
-
break
|
|
72
|
-
}
|
|
73
|
-
case '3': {
|
|
74
|
-
this.setCreditCardType('amex')
|
|
75
|
-
break
|
|
76
|
-
}
|
|
77
|
-
case '6': {
|
|
78
|
-
this.setCreditCardType('discover')
|
|
79
|
-
break
|
|
80
|
-
}
|
|
81
|
-
default: {
|
|
82
|
-
this.setCreditCardType('')
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
override getCursorPosition() {
|
|
88
|
-
if (this.value) {
|
|
89
|
-
const previousValue = this.previousValue ?? ''
|
|
90
|
-
const unmasked = unmask(this.value)
|
|
91
|
-
const numberValidation = valid.number(unmasked)
|
|
92
|
-
const card = numberValidation.card
|
|
93
|
-
const lengthChange = this.value.length - (previousValue?.length ?? 0)
|
|
94
|
-
const unmaskedChange = unmask(this.value).length - unmask(previousValue).length
|
|
95
|
-
|
|
96
|
-
if (card) {
|
|
97
|
-
const gaps = card.gaps
|
|
98
|
-
const oldCursor = this.cursorPosition.previous ?? 0
|
|
99
|
-
const oldSeparation = gaps.filter((gap, i) => gap + i < oldCursor).length
|
|
100
|
-
const newSeparation = gaps.filter((gap, i) => gap + i < oldCursor + lengthChange).length
|
|
101
|
-
const newCursor = oldCursor - oldSeparation + newSeparation + unmaskedChange
|
|
102
|
-
return newCursor
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
override mask(value: ValidControlValue = '') {
|
|
108
|
-
const unmasked = unmask(value)
|
|
109
|
-
const numberValidation = valid.number(unmasked)
|
|
110
|
-
const card = numberValidation.card
|
|
111
|
-
|
|
112
|
-
if (card) {
|
|
113
|
-
const max = card.lengths.includes(16) ? 16 : card.lengths[0]
|
|
114
|
-
const gaps = [...card.gaps, max]
|
|
115
|
-
const newVal = gaps
|
|
116
|
-
.map((gap, i) => unmasked.slice(gaps[i - 1] || 0, gap))
|
|
117
|
-
.filter(Boolean)
|
|
118
|
-
.join(' ')
|
|
119
|
-
|
|
120
|
-
return newVal
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return value
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
onCreditCardTypeChange: (type: string) => void = () => {}
|
|
127
|
-
|
|
128
|
-
setCreditCardType(type: string) {
|
|
129
|
-
this.creditCardType = type
|
|
130
|
-
this.onCreditCardTypeChange(type)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
override setValue(value = '', options: SetOptions) {
|
|
134
|
-
const umMasked = this.unmask(value)
|
|
135
|
-
super.setValue(umMasked, options)
|
|
136
|
-
this.earlyNumberCheck(umMasked.charAt(0))
|
|
137
|
-
}
|
|
138
|
-
}
|
package/src/controls/Email.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject } from '@xylabs/sdk-js'
|
|
2
|
-
import { FormControlBase } from '@xyo-network/react-form-group'
|
|
3
|
-
|
|
4
|
-
const CONTROL_NAME = 'Email'
|
|
5
|
-
|
|
6
|
-
export class CreditCardEmailFormControl<TProps extends EmptyObject = EmptyObject> extends FormControlBase<TProps> {
|
|
7
|
-
override invalidMessage = 'Your email is invalid.'
|
|
8
|
-
|
|
9
|
-
override pattern = /^.*$/
|
|
10
|
-
override patternStrict = /^([\w+.\-])+@(([\dA-Za-z-])+\.)+([\dA-Za-z]{2,4})+$/
|
|
11
|
-
|
|
12
|
-
override props = {
|
|
13
|
-
autoComplete: 'email',
|
|
14
|
-
autoCorrect: 'off',
|
|
15
|
-
id: CONTROL_NAME.toLocaleLowerCase(),
|
|
16
|
-
name: CONTROL_NAME.toLocaleLowerCase(),
|
|
17
|
-
placeholder: 'jerry.smith@email.com',
|
|
18
|
-
spellCheck: false,
|
|
19
|
-
} as TProps
|
|
20
|
-
|
|
21
|
-
override required = true
|
|
22
|
-
|
|
23
|
-
constructor() {
|
|
24
|
-
super()
|
|
25
|
-
super.setName(CONTROL_NAME)
|
|
26
|
-
this.setSerializeSettings({ sensitive: false, serializable: true })
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
override blurError(value: string) {
|
|
30
|
-
const match = RegExp(this.patternStrict).exec(value)
|
|
31
|
-
this.updateValidation(match)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
override changeError(value: string) {
|
|
35
|
-
if (this.error) {
|
|
36
|
-
this.blurError(value)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private updateValidation(match: RegExpMatchArray | null) {
|
|
41
|
-
if (match) {
|
|
42
|
-
this.setErrorAndValidity('', 'VALID')
|
|
43
|
-
} else {
|
|
44
|
-
this.setErrorAndValidity(this.invalidMessage, 'INVALID')
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/controls/Name.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject } from '@xylabs/sdk-js'
|
|
2
|
-
import { FormControlBase } from '@xyo-network/react-form-group'
|
|
3
|
-
|
|
4
|
-
export class NameFormControl<TProps extends EmptyObject = EmptyObject> extends FormControlBase<TProps> {
|
|
5
|
-
override required = true
|
|
6
|
-
|
|
7
|
-
private nameLabel: string
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
nameLabel: string,
|
|
11
|
-
autoCompleteLabel: string,
|
|
12
|
-
placeHolder: string,
|
|
13
|
-
) {
|
|
14
|
-
super()
|
|
15
|
-
this.nameLabel = nameLabel
|
|
16
|
-
super.setName(nameLabel)
|
|
17
|
-
this.setSerializeSettings({ sensitive: false, serializable: true })
|
|
18
|
-
this.invalidMessage = `${nameLabel} name is missing.`
|
|
19
|
-
this.props = {
|
|
20
|
-
autoComplete: autoCompleteLabel,
|
|
21
|
-
autoCorrect: 'off',
|
|
22
|
-
id: this.nameLabel,
|
|
23
|
-
name: this.nameLabel,
|
|
24
|
-
placeholder: placeHolder,
|
|
25
|
-
spellCheck: false,
|
|
26
|
-
} as TProps
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
override blurError(value: string) {
|
|
30
|
-
if (value) {
|
|
31
|
-
this.setErrorAndValidity('', 'VALID')
|
|
32
|
-
} else {
|
|
33
|
-
this.setErrorAndValidity(this.invalidMessage, 'INVALID')
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
override changeError(value: string): void {
|
|
38
|
-
this.blurError(value)
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/controls/Zip.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject } from '@xylabs/sdk-js'
|
|
2
|
-
import { FormControlBase } from '@xyo-network/react-form-group'
|
|
3
|
-
import valid from 'card-validator'
|
|
4
|
-
|
|
5
|
-
import { unmask } from '../utils/index.ts'
|
|
6
|
-
|
|
7
|
-
const CONTROL_NAME = 'Zip'
|
|
8
|
-
|
|
9
|
-
export class CreditCardZipFormControl<TProps extends EmptyObject = EmptyObject> extends FormControlBase<TProps> {
|
|
10
|
-
override invalidMessage = 'Your zip code is invalid.'
|
|
11
|
-
|
|
12
|
-
override props = {
|
|
13
|
-
autoComplete: 'postal-code',
|
|
14
|
-
autoCorrect: 'off',
|
|
15
|
-
id: CONTROL_NAME.toLocaleLowerCase(),
|
|
16
|
-
name: CONTROL_NAME.toLocaleLowerCase(),
|
|
17
|
-
placeholder: '12345',
|
|
18
|
-
spellCheck: false,
|
|
19
|
-
} as TProps
|
|
20
|
-
|
|
21
|
-
override required = true
|
|
22
|
-
|
|
23
|
-
override unmask = unmask
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
super()
|
|
27
|
-
super.setName(CONTROL_NAME)
|
|
28
|
-
this.setSerializeSettings({ sensitive: true, serializable: true })
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
override blurError(value: string) {
|
|
32
|
-
const postalCodeValidation = valid.postalCode(value)
|
|
33
|
-
if (postalCodeValidation.isValid) {
|
|
34
|
-
this.setErrorAndValidity('', 'VALID')
|
|
35
|
-
} else {
|
|
36
|
-
this.setErrorAndValidity(this.invalidMessage, 'INVALID')
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
override changeError(value: string) {
|
|
41
|
-
const unmasked = this.unmask(value)
|
|
42
|
-
const match = RegExp(this.patternStrict).exec(unmasked)
|
|
43
|
-
if (match) {
|
|
44
|
-
const postalCodeValidation = valid.postalCode(value)
|
|
45
|
-
if (postalCodeValidation.isPotentiallyValid) {
|
|
46
|
-
this.setErrorAndValidity('', 'VALID')
|
|
47
|
-
} else {
|
|
48
|
-
this.setErrorAndValidity('Your zip code is invalid.', 'INVALID')
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
this.setErrorAndValidity(this.invalidMessage, 'INVALID')
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
package/src/controls/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
2
|
-
import { asSchema, isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
export const CreditCardInputSchema = asSchema('network.xyo.credit.card.input', true)
|
|
5
|
-
export type CreditCardInputSchema = typeof CreditCardInputSchema
|
|
6
|
-
|
|
7
|
-
export type CreditCardInputFields = {
|
|
8
|
-
cardNumber: string
|
|
9
|
-
cvc: string
|
|
10
|
-
emailAddress: string
|
|
11
|
-
expiration: string
|
|
12
|
-
firstName: string
|
|
13
|
-
lastName: string
|
|
14
|
-
timestamp: number
|
|
15
|
-
zip: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type CreditCardInput = Payload<CreditCardInputFields, CreditCardInputSchema>
|
|
19
|
-
|
|
20
|
-
export const isCreditCardInput = isPayloadOfSchemaType<CreditCardInput>(CreditCardInputSchema)
|
package/src/models/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './CreditCardInput.ts'
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Button } from '@mui/material'
|
|
2
|
-
import type { Meta, StoryFn } from '@storybook/react-vite'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
|
-
import { CreditCardFormFlexboxWithFormGroupProvider } from '../components/index.ts'
|
|
6
|
-
import type { CreditCardInput } from '../models/index.ts'
|
|
7
|
-
|
|
8
|
-
export default { title: 'form/CreditCardForm' } as Meta<typeof CreditCardFormFlexboxWithFormGroupProvider>
|
|
9
|
-
|
|
10
|
-
const Template: StoryFn<typeof CreditCardFormFlexboxWithFormGroupProvider> = (args) => {
|
|
11
|
-
return <CreditCardFormFlexboxWithFormGroupProvider ConfirmationButton={Button} {...args} />
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const Default = Template.bind({})
|
|
15
|
-
Default.args = {}
|
|
16
|
-
|
|
17
|
-
const WithCallbacks = Template.bind({})
|
|
18
|
-
WithCallbacks.args = {
|
|
19
|
-
displayErrors: true,
|
|
20
|
-
onErrorDuringSubmit: (error: Error) => console.log('onErrorDuringSubmit', error),
|
|
21
|
-
onInvalidSubmit: errorSummary => console.log('onInvalidSubmit', errorSummary),
|
|
22
|
-
onSuccessfulSubmit: () => console.log('onSuccessfulSubmit'),
|
|
23
|
-
onValidSubmit: (args: CreditCardInput) => Promise.resolve(console.log('onValidSubmit', args)),
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { Default, WithCallbacks }
|
package/src/types/images.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
declare module '*.svg' {
|
|
2
|
-
const content: string
|
|
3
|
-
export default content
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
declare module '*.png' {
|
|
7
|
-
const content: string
|
|
8
|
-
export default content
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare module '*.jpg' {
|
|
12
|
-
const content: string
|
|
13
|
-
export default content
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
declare module '*.jpeg' {
|
|
17
|
-
const content: string
|
|
18
|
-
export default content
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare module '*.gif' {
|
|
22
|
-
const content: string
|
|
23
|
-
export default content
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
declare module '*.webp' {
|
|
27
|
-
const content: string
|
|
28
|
-
export default content
|
|
29
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './umask.ts'
|
package/src/utils/umask.ts
DELETED