@xyo-network/react-form-credit-card 7.5.7 → 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/react-form-credit-card",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.11",
|
|
4
4
|
"description": "Common React library for all XYO projects that use React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xyo",
|
|
@@ -36,52 +36,138 @@
|
|
|
36
36
|
},
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
|
-
"module": "dist/browser/index.mjs",
|
|
40
|
-
"types": "dist/browser/index.d.ts",
|
|
41
39
|
"files": [
|
|
42
40
|
"dist",
|
|
43
|
-
"
|
|
41
|
+
"README.md"
|
|
44
42
|
],
|
|
45
43
|
"dependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@xylabs/react-promise": "~7.1.17",
|
|
49
|
-
"@xylabs/react-shared": "~7.1.17",
|
|
50
|
-
"@xylabs/sdk-js": "~5.0.90",
|
|
51
|
-
"@xyo-network/archivist-storage": "~5.3.17",
|
|
52
|
-
"@xyo-network/payload-model": "~5.3.17",
|
|
53
|
-
"@xyo-network/react-form-group": "7.5.7",
|
|
54
|
-
"@xyo-network/react-shared": "7.5.7",
|
|
55
|
-
"card-validator": "~10.0.4"
|
|
44
|
+
"@xyo-network/react-shared": "~7.5.11",
|
|
45
|
+
"@xyo-network/react-form-group": "~7.5.11"
|
|
56
46
|
},
|
|
57
47
|
"devDependencies": {
|
|
58
|
-
"@
|
|
59
|
-
"@mui/material": "
|
|
60
|
-
"@
|
|
48
|
+
"@bitauth/libauth": "~3.0.0",
|
|
49
|
+
"@mui/icons-material": "^7.3.10",
|
|
50
|
+
"@mui/material": "^7.3.10",
|
|
51
|
+
"@opentelemetry/api": "^1.9.1",
|
|
52
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
53
|
+
"@scure/base": "~2.2.0",
|
|
54
|
+
"@storybook/react-vite": "~10.3.5",
|
|
55
|
+
"@types/node": "~25.6.0",
|
|
61
56
|
"@types/react": "^19.2.14",
|
|
62
|
-
"@xylabs/
|
|
63
|
-
"@xylabs/
|
|
64
|
-
"@xylabs/
|
|
65
|
-
"@xylabs/
|
|
66
|
-
"@xylabs/
|
|
67
|
-
"react": "
|
|
68
|
-
"react-
|
|
69
|
-
"react-
|
|
70
|
-
"
|
|
57
|
+
"@xylabs/react-async-effect": "~7.1.20",
|
|
58
|
+
"@xylabs/react-button": "~7.1.20",
|
|
59
|
+
"@xylabs/react-dialogs": "~7.1.20",
|
|
60
|
+
"@xylabs/react-error": "~7.1.20",
|
|
61
|
+
"@xylabs/react-flexbox": "~7.1.20",
|
|
62
|
+
"@xylabs/react-hooks": "~7.1.20",
|
|
63
|
+
"@xylabs/react-link": "~7.1.20",
|
|
64
|
+
"@xylabs/react-promise": "~7.1.20",
|
|
65
|
+
"@xylabs/react-quick-tip-button": "~7.1.20",
|
|
66
|
+
"@xylabs/react-shared": "~7.1.20",
|
|
67
|
+
"@xylabs/react-theme": "~7.1.20",
|
|
68
|
+
"@xylabs/sdk-js": "^5.0.100",
|
|
69
|
+
"@xylabs/threads": "~5.0.100",
|
|
70
|
+
"@xylabs/toolchain": "~7.11.9",
|
|
71
|
+
"@xylabs/tsconfig": "^7.11.9",
|
|
72
|
+
"@xylabs/tsconfig-dom": "^7.11.9",
|
|
73
|
+
"@xylabs/tsconfig-react": "~7.11.9",
|
|
74
|
+
"@xylabs/zod": "~5.0.100",
|
|
75
|
+
"@xyo-network/account": "~5.5.1",
|
|
76
|
+
"@xyo-network/account-model": "^5.5.1",
|
|
77
|
+
"@xyo-network/archivist-model": "^5.5.5",
|
|
78
|
+
"@xyo-network/archivist-storage": "~5.5.5",
|
|
79
|
+
"@xyo-network/boundwitness-builder": "^5.5.1",
|
|
80
|
+
"@xyo-network/boundwitness-model": "^5.5.1",
|
|
81
|
+
"@xyo-network/boundwitness-validator": "^5.5.1",
|
|
82
|
+
"@xyo-network/boundwitness-wrapper": "~5.5.1",
|
|
83
|
+
"@xyo-network/config-payload-plugin": "~5.5.1",
|
|
84
|
+
"@xyo-network/manifest-model": "~5.5.1",
|
|
85
|
+
"@xyo-network/module-event-emitter": "~5.5.5",
|
|
86
|
+
"@xyo-network/payload-builder": "^5.5.1",
|
|
87
|
+
"@xyo-network/payload-model": "^5.5.1",
|
|
88
|
+
"@xyo-network/query-payload-plugin": "~5.5.1",
|
|
89
|
+
"@xyo-network/wallet-model": "^5.5.1",
|
|
90
|
+
"async-mutex": "^0.5.0",
|
|
91
|
+
"axios": "^1.15.2",
|
|
92
|
+
"bn.js": "^5.2.3",
|
|
93
|
+
"bowser": "^2.14.1",
|
|
94
|
+
"buffer": "^6.0.3",
|
|
95
|
+
"card-validator": "~10.0.4",
|
|
96
|
+
"chalk": "^5.6.2",
|
|
97
|
+
"debug": "~4.4.3",
|
|
98
|
+
"esbuild": "~0.28.0",
|
|
99
|
+
"eslint": "^10.2.1",
|
|
100
|
+
"ethers": "^6.16.0",
|
|
101
|
+
"fast-deep-equal": "~3.1.3",
|
|
102
|
+
"hash-wasm": "~4.12.0",
|
|
103
|
+
"js-cookie": "~3.0.5",
|
|
104
|
+
"lru-cache": "^11.3.5",
|
|
105
|
+
"observable-fns": "~0.6.1",
|
|
106
|
+
"pako": "^2.1.0",
|
|
107
|
+
"react": "^19.2.5",
|
|
108
|
+
"react-dom": "^19.2.5",
|
|
109
|
+
"react-router-dom": "^7.14.2",
|
|
110
|
+
"spark-md5": "~3.0.2",
|
|
111
|
+
"store2": "~2.14.4",
|
|
112
|
+
"storybook": "^10.3.5",
|
|
71
113
|
"typescript": "^5.9.3",
|
|
72
|
-
"vite": "
|
|
114
|
+
"vite": "^8.0.10",
|
|
115
|
+
"wasm-feature-detect": "~1.8.0",
|
|
73
116
|
"zod": "^4.3.6"
|
|
74
117
|
},
|
|
75
118
|
"peerDependencies": {
|
|
76
|
-
"@mui/icons-material": "
|
|
77
|
-
"@mui/material": "
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
119
|
+
"@mui/icons-material": "^7.3.10",
|
|
120
|
+
"@mui/material": "^7.3.10",
|
|
121
|
+
"@opentelemetry/api": "^1.9.1",
|
|
122
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
123
|
+
"@scure/base": "~2.2.0",
|
|
124
|
+
"@xylabs/react-async-effect": "~7.1.20",
|
|
125
|
+
"@xylabs/react-button": "~7.1.20",
|
|
126
|
+
"@xylabs/react-error": "~7.1.20",
|
|
127
|
+
"@xylabs/react-flexbox": "~7.1.20",
|
|
128
|
+
"@xylabs/react-hooks": "~7.1.20",
|
|
129
|
+
"@xylabs/react-link": "~7.1.20",
|
|
130
|
+
"@xylabs/react-promise": "~7.1.20",
|
|
131
|
+
"@xylabs/react-quick-tip-button": "~7.1.20",
|
|
132
|
+
"@xylabs/react-shared": "~7.1.20",
|
|
133
|
+
"@xylabs/react-theme": "~7.1.20",
|
|
134
|
+
"@xylabs/sdk-js": "^5.0.100",
|
|
135
|
+
"@xylabs/zod": "~5.0.100",
|
|
136
|
+
"@xyo-network/account": "~5.5.1",
|
|
137
|
+
"@xyo-network/account-model": "^5.5.1",
|
|
138
|
+
"@xyo-network/archivist-model": "^5.5.5",
|
|
139
|
+
"@xyo-network/archivist-storage": "~5.5.5",
|
|
140
|
+
"@xyo-network/boundwitness-builder": "^5.5.1",
|
|
141
|
+
"@xyo-network/boundwitness-model": "^5.5.1",
|
|
142
|
+
"@xyo-network/boundwitness-validator": "^5.5.1",
|
|
143
|
+
"@xyo-network/boundwitness-wrapper": "~5.5.1",
|
|
144
|
+
"@xyo-network/config-payload-plugin": "~5.5.1",
|
|
145
|
+
"@xyo-network/manifest-model": "~5.5.1",
|
|
146
|
+
"@xyo-network/module-event-emitter": "~5.5.5",
|
|
147
|
+
"@xyo-network/payload-builder": "^5.5.1",
|
|
148
|
+
"@xyo-network/payload-model": "^5.5.1",
|
|
149
|
+
"@xyo-network/query-payload-plugin": "~5.5.1",
|
|
150
|
+
"@xyo-network/wallet-model": "^5.5.1",
|
|
151
|
+
"async-mutex": "^0.5.0",
|
|
152
|
+
"bn.js": "^5.2.3",
|
|
153
|
+
"bowser": "^2.14.1",
|
|
154
|
+
"buffer": "^6.0.3",
|
|
155
|
+
"card-validator": "~10.0.4",
|
|
156
|
+
"chalk": "^5.6.2",
|
|
157
|
+
"ethers": "^6.16.0",
|
|
158
|
+
"fast-deep-equal": "~3.1.3",
|
|
159
|
+
"js-cookie": "~3.0.5",
|
|
160
|
+
"lru-cache": "^11.3.5",
|
|
161
|
+
"pako": "^2.1.0",
|
|
162
|
+
"react": "^19.2.5",
|
|
163
|
+
"react-dom": "^19.2.5",
|
|
164
|
+
"react-router-dom": "^7.14.2",
|
|
165
|
+
"spark-md5": "~3.0.2",
|
|
166
|
+
"store2": "~2.14.4",
|
|
167
|
+
"zod": "^4.3.6"
|
|
82
168
|
},
|
|
83
169
|
"publishConfig": {
|
|
84
170
|
"access": "public"
|
|
85
171
|
},
|
|
86
172
|
"docs": "dist/docs.json"
|
|
87
|
-
}
|
|
173
|
+
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
import { CreditCardEmailFormControl } from '../../../controls/index.ts'
|
|
4
|
-
import type { WithFormControlProps } from '../WithFormControlProps.ts'
|
|
5
|
-
import { FormControlTextField } from './FormControlTextField.tsx'
|
|
6
|
-
import { useCreditCardFormControl } from './useCreditCardFormControl.tsx'
|
|
7
|
-
|
|
8
|
-
export const CreditCardEmailWithFormControl: React.FC<WithFormControlProps> = ({
|
|
9
|
-
formControlName = 'emailAddress',
|
|
10
|
-
fieldLabel = 'Email',
|
|
11
|
-
...props
|
|
12
|
-
}) => {
|
|
13
|
-
const {
|
|
14
|
-
creditCardFormControl, error, inputRef, value,
|
|
15
|
-
} = useCreditCardFormControl(formControlName, CreditCardEmailFormControl)
|
|
16
|
-
const {
|
|
17
|
-
autoComplete, autoCorrect, id, inputMode, name, spellCheck, ...cvcProps
|
|
18
|
-
} = creditCardFormControl?.props ?? {}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<FormControlTextField
|
|
22
|
-
fieldLabel={fieldLabel}
|
|
23
|
-
formControl={creditCardFormControl}
|
|
24
|
-
formControlError={error}
|
|
25
|
-
inputMode={inputMode}
|
|
26
|
-
slotProps={{
|
|
27
|
-
htmlInput: {
|
|
28
|
-
'aria-label': `${fieldLabel} for your purchase`, autoComplete, autoCorrect, id, name, spellCheck,
|
|
29
|
-
},
|
|
30
|
-
}}
|
|
31
|
-
inputRef={inputRef}
|
|
32
|
-
value={value}
|
|
33
|
-
{...cvcProps}
|
|
34
|
-
{...props}
|
|
35
|
-
/>
|
|
36
|
-
)
|
|
37
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
import { CreditCardExpirationFormControl } from '../../../controls/index.ts'
|
|
4
|
-
import type { WithFormControlProps } from '../WithFormControlProps.ts'
|
|
5
|
-
import { FormControlTextField } from './FormControlTextField.tsx'
|
|
6
|
-
import { useCreditCardFormControl } from './useCreditCardFormControl.tsx'
|
|
7
|
-
|
|
8
|
-
export const CreditCardExpirationWithFormControl: React.FC<WithFormControlProps> = ({
|
|
9
|
-
formControlName = 'expiration',
|
|
10
|
-
fieldLabel = 'Expiration',
|
|
11
|
-
...props
|
|
12
|
-
}) => {
|
|
13
|
-
const {
|
|
14
|
-
creditCardFormControl, error, inputRef, value,
|
|
15
|
-
} = useCreditCardFormControl(formControlName, CreditCardExpirationFormControl)
|
|
16
|
-
const {
|
|
17
|
-
autoComplete, autoCorrect, id, inputMode, name, spellCheck, ...expirationProps
|
|
18
|
-
} = creditCardFormControl?.props ?? {}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<FormControlTextField
|
|
22
|
-
inputRef={inputRef}
|
|
23
|
-
formControl={creditCardFormControl}
|
|
24
|
-
fieldLabel={fieldLabel}
|
|
25
|
-
formControlError={error}
|
|
26
|
-
inputMode={inputMode}
|
|
27
|
-
slotProps={{
|
|
28
|
-
htmlInput: {
|
|
29
|
-
'aria-label': `${fieldLabel} of the card`, autoComplete, autoCorrect, id, name, spellCheck,
|
|
30
|
-
},
|
|
31
|
-
}}
|
|
32
|
-
value={value}
|
|
33
|
-
{...expirationProps}
|
|
34
|
-
{...props}
|
|
35
|
-
/>
|
|
36
|
-
)
|
|
37
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { StandardTextFieldProps } from '@mui/material'
|
|
2
|
-
import { FormControl as MuiFormControl, TextField } from '@mui/material'
|
|
3
|
-
import type { FormControl } from '@xyo-network/react-form-group'
|
|
4
|
-
import { LabeledTextFieldWrapper } from '@xyo-network/react-shared'
|
|
5
|
-
import type {
|
|
6
|
-
ChangeEventHandler, FocusEventHandler, KeyboardEvent,
|
|
7
|
-
} from 'react'
|
|
8
|
-
import React from 'react'
|
|
9
|
-
|
|
10
|
-
export interface FormControlTextFieldProps extends StandardTextFieldProps {
|
|
11
|
-
fieldLabel: string
|
|
12
|
-
formControl?: FormControl<StandardTextFieldProps>
|
|
13
|
-
formControlError?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const FormControlTextField = ({
|
|
17
|
-
ref, formControl, formControlError, fieldLabel = '', ...props
|
|
18
|
-
}: FormControlTextFieldProps) => {
|
|
19
|
-
const { name } = formControl?.props ?? {}
|
|
20
|
-
|
|
21
|
-
const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {
|
|
22
|
-
formControl?.setValue(event.target.value)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const handleBlur: FocusEventHandler<HTMLInputElement> = (event) => {
|
|
26
|
-
formControl?.blurError?.(event.target.value)
|
|
27
|
-
formControl?.setTouched(true)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<MuiFormControl fullWidth>
|
|
32
|
-
<LabeledTextFieldWrapper label={fieldLabel}>
|
|
33
|
-
<label htmlFor={name}>
|
|
34
|
-
<TextField
|
|
35
|
-
error={!!formControlError}
|
|
36
|
-
helperText={formControlError || ' '}
|
|
37
|
-
fullWidth
|
|
38
|
-
hiddenLabel
|
|
39
|
-
name={name}
|
|
40
|
-
onBlur={handleBlur}
|
|
41
|
-
onChange={handleChange}
|
|
42
|
-
onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
|
|
43
|
-
// See - https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11508#issuecomment-256045682
|
|
44
|
-
// .currentTarget is the div in mui that emits the event, .target is the input element
|
|
45
|
-
// Unfortunately, the type definitions do not let you pass a generic specifically for target, only currentTarget
|
|
46
|
-
const selectionEnd = (event.target as HTMLInputElement).selectionEnd
|
|
47
|
-
if (selectionEnd && formControl) {
|
|
48
|
-
formControl.cursorPosition.previous = selectionEnd
|
|
49
|
-
}
|
|
50
|
-
}}
|
|
51
|
-
ref={ref}
|
|
52
|
-
required={formControl?.required}
|
|
53
|
-
size="small"
|
|
54
|
-
variant="filled"
|
|
55
|
-
{...props}
|
|
56
|
-
/>
|
|
57
|
-
</label>
|
|
58
|
-
</LabeledTextFieldWrapper>
|
|
59
|
-
</MuiFormControl>
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
FormControlTextField.displayName = 'FormControlTextField'
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from 'react'
|
|
2
|
-
|
|
3
|
-
import { NameFormControl } from '../../../controls/index.ts'
|
|
4
|
-
import type { WithFormControlProps } from '../WithFormControlProps.ts'
|
|
5
|
-
import { FormControlTextField } from './FormControlTextField.tsx'
|
|
6
|
-
import { useCreditCardFormControl } from './useCreditCardFormControl.tsx'
|
|
7
|
-
|
|
8
|
-
export interface NameWithFormControlProps extends WithFormControlProps {
|
|
9
|
-
autoCompleteLabel: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const NameWithFormControl: React.FC<NameWithFormControlProps> = ({
|
|
13
|
-
autoCompleteLabel,
|
|
14
|
-
fieldLabel = 'Name',
|
|
15
|
-
formControlName,
|
|
16
|
-
placeholder,
|
|
17
|
-
tabIndex,
|
|
18
|
-
...props
|
|
19
|
-
}) => {
|
|
20
|
-
const args = useMemo(() => [fieldLabel, autoCompleteLabel, placeholder ?? ''], [autoCompleteLabel, fieldLabel, placeholder])
|
|
21
|
-
const {
|
|
22
|
-
creditCardFormControl, error, inputRef, value,
|
|
23
|
-
} = useCreditCardFormControl(formControlName, NameFormControl, args)
|
|
24
|
-
const {
|
|
25
|
-
autoComplete, autoCorrect, id, inputMode, name, spellCheck, ...cvcProps
|
|
26
|
-
} = creditCardFormControl?.props ?? {}
|
|
27
|
-
return (
|
|
28
|
-
<FormControlTextField
|
|
29
|
-
fieldLabel={fieldLabel}
|
|
30
|
-
formControl={creditCardFormControl}
|
|
31
|
-
formControlError={error}
|
|
32
|
-
inputMode={inputMode}
|
|
33
|
-
slotProps={{
|
|
34
|
-
htmlInput: {
|
|
35
|
-
'aria-label': `${fieldLabel} name on your card`, autoComplete, autoCorrect, id, name, spellCheck, tabIndex,
|
|
36
|
-
},
|
|
37
|
-
}}
|
|
38
|
-
inputRef={inputRef}
|
|
39
|
-
value={value}
|
|
40
|
-
{...cvcProps}
|
|
41
|
-
{...props}
|
|
42
|
-
/>
|
|
43
|
-
)
|
|
44
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AmexIcon, DiscoverIcon, MastercardIcon, VisaIcon,
|
|
3
|
-
} from '../../img/index.ts'
|
|
4
|
-
|
|
5
|
-
export interface CreditCardInfo {
|
|
6
|
-
icon: string
|
|
7
|
-
name: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface CreditCardOptions {
|
|
11
|
-
amex: CreditCardInfo
|
|
12
|
-
discover: CreditCardInfo
|
|
13
|
-
mastercard: CreditCardInfo
|
|
14
|
-
visa: CreditCardInfo
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const CreditCardData: CreditCardOptions = {
|
|
18
|
-
amex: { icon: AmexIcon, name: 'American Express' },
|
|
19
|
-
discover: { icon: DiscoverIcon, name: 'Discover' },
|
|
20
|
-
mastercard: { icon: MastercardIcon, name: 'Mastercard' },
|
|
21
|
-
visa: { icon: VisaIcon, name: 'Visa' },
|
|
22
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
import { CreditCardZipFormControl } from '../../../controls/index.ts'
|
|
4
|
-
import type { WithFormControlProps } from '../WithFormControlProps.ts'
|
|
5
|
-
import { FormControlTextField } from './FormControlTextField.tsx'
|
|
6
|
-
import { useCreditCardFormControl } from './useCreditCardFormControl.tsx'
|
|
7
|
-
|
|
8
|
-
export const CreditCardZipWithFormControl: React.FC<WithFormControlProps> = ({
|
|
9
|
-
formControlName = 'zip', fieldLabel = 'Zip', ...props
|
|
10
|
-
}) => {
|
|
11
|
-
const {
|
|
12
|
-
creditCardFormControl, error, inputRef, value,
|
|
13
|
-
} = useCreditCardFormControl(formControlName, CreditCardZipFormControl)
|
|
14
|
-
const {
|
|
15
|
-
autoComplete, autoCorrect, id, inputMode, name, spellCheck, ...cvcProps
|
|
16
|
-
} = creditCardFormControl?.props ?? {}
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<FormControlTextField
|
|
20
|
-
fieldLabel={fieldLabel}
|
|
21
|
-
formControl={creditCardFormControl}
|
|
22
|
-
formControlError={error}
|
|
23
|
-
inputMode={inputMode}
|
|
24
|
-
inputProps={{
|
|
25
|
-
'aria-label': `${fieldLabel} code for your card`, autoComplete, autoCorrect, id, name, spellCheck,
|
|
26
|
-
}}
|
|
27
|
-
inputRef={inputRef}
|
|
28
|
-
value={value}
|
|
29
|
-
{...cvcProps}
|
|
30
|
-
{...props}
|
|
31
|
-
/>
|
|
32
|
-
)
|
|
33
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
import { CreditCardCvvFormControl } from '../../../../controls/index.ts'
|
|
4
|
-
import type { WithFormControlProps } from '../../WithFormControlProps.ts'
|
|
5
|
-
import { FormControlTextField } from '../FormControlTextField.tsx'
|
|
6
|
-
import { useCreditCardCvvFormControl } from './use.ts'
|
|
7
|
-
|
|
8
|
-
export const CreditCardCvvWithFormControl: React.FC<WithFormControlProps> = ({
|
|
9
|
-
formControlName = 'cvc', fieldLabel = 'CVC', ...props
|
|
10
|
-
}) => {
|
|
11
|
-
const {
|
|
12
|
-
creditCardFormControl, error, inputRef, value,
|
|
13
|
-
} = useCreditCardCvvFormControl(formControlName, undefined, CreditCardCvvFormControl)
|
|
14
|
-
const {
|
|
15
|
-
autoComplete, autoCorrect, id, inputMode, name, spellCheck, ...cvcProps
|
|
16
|
-
} = creditCardFormControl?.props ?? {}
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<FormControlTextField
|
|
20
|
-
fieldLabel={fieldLabel}
|
|
21
|
-
formControl={creditCardFormControl}
|
|
22
|
-
formControlError={error}
|
|
23
|
-
inputMode={inputMode}
|
|
24
|
-
slotProps={{
|
|
25
|
-
htmlInput: {
|
|
26
|
-
'aria-label': `${fieldLabel} number on the back of your card`, autoComplete, autoCorrect, id, name, spellCheck,
|
|
27
|
-
},
|
|
28
|
-
}}
|
|
29
|
-
inputRef={inputRef}
|
|
30
|
-
value={value}
|
|
31
|
-
{...cvcProps}
|
|
32
|
-
{...props}
|
|
33
|
-
/>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { StandardTextFieldProps } from '@mui/material'
|
|
2
|
-
import type { FormControlBase } from '@xyo-network/react-form-group'
|
|
3
|
-
import { useEffect } from 'react'
|
|
4
|
-
|
|
5
|
-
import { useFormGroupWithCreditCardInput } from '../../../../context/index.ts'
|
|
6
|
-
import type { CreditCardCvvFormControl } from '../../../../controls/index.ts'
|
|
7
|
-
import { useCreditCardFormControl } from '../useCreditCardFormControl.tsx'
|
|
8
|
-
|
|
9
|
-
export const useCreditCardCvvFormControl = (
|
|
10
|
-
formControlName?: string,
|
|
11
|
-
cardNumberControlName = 'cardNumber',
|
|
12
|
-
control?: new () => FormControlBase<StandardTextFieldProps>,
|
|
13
|
-
) => {
|
|
14
|
-
const {
|
|
15
|
-
creditCardFormControl, error, value, inputRef,
|
|
16
|
-
} = useCreditCardFormControl(formControlName, control)
|
|
17
|
-
|
|
18
|
-
// only use FormGroupContext when name is passed
|
|
19
|
-
const { formGroup } = useFormGroupWithCreditCardInput(!!formControlName)
|
|
20
|
-
|
|
21
|
-
const creditCardNumberFormControl = formGroup?.getControl?.(cardNumberControlName)
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (creditCardNumberFormControl) {
|
|
25
|
-
const castControl = creditCardFormControl as CreditCardCvvFormControl
|
|
26
|
-
if (!castControl.setCardNumberFormControl) {
|
|
27
|
-
console.error('cannot setCardNumberFormControl on control because it is not a CreditCardCvvFormControl')
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
castControl.setCardNumberFormControl(creditCardNumberFormControl)
|
|
31
|
-
}
|
|
32
|
-
}, [creditCardFormControl, creditCardNumberFormControl])
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
creditCardFormControl, error, inputRef, value,
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './cvv/index.ts'
|
|
2
|
-
export * from './Email.tsx'
|
|
3
|
-
export * from './Expiration.tsx'
|
|
4
|
-
export * from './FormControlTextField.tsx'
|
|
5
|
-
export * from './Name.tsx'
|
|
6
|
-
export * from './number/index.ts'
|
|
7
|
-
export * from './Options.ts'
|
|
8
|
-
export * from './useCreditCardFormControl.tsx'
|
|
9
|
-
export * from './Zip.tsx'
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { InputAdornment } from '@mui/material'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { CreditCardNumberFormControl } from '../../../../controls/index.ts'
|
|
5
|
-
import type { WithFormControlProps } from '../../WithFormControlProps.ts'
|
|
6
|
-
import { FormControlTextField } from '../FormControlTextField.tsx'
|
|
7
|
-
import { CreditCardData } from '../Options.ts'
|
|
8
|
-
import { useCreditCardNumberFormControl } from './use.ts'
|
|
9
|
-
|
|
10
|
-
export const CreditCardNumberWithFormControl: React.FC<WithFormControlProps> = ({
|
|
11
|
-
fieldLabel = 'Card Number',
|
|
12
|
-
formControlName = 'cardNumber',
|
|
13
|
-
...props
|
|
14
|
-
}) => {
|
|
15
|
-
const {
|
|
16
|
-
creditCardFormControl, error, inputRef, type, value,
|
|
17
|
-
} = useCreditCardNumberFormControl(formControlName, CreditCardNumberFormControl)
|
|
18
|
-
const {
|
|
19
|
-
autoComplete, autoCorrect, id, inputMode, name, spellCheck, ...cardProps
|
|
20
|
-
} = creditCardFormControl?.props ?? {}
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<FormControlTextField
|
|
24
|
-
fieldLabel={fieldLabel}
|
|
25
|
-
formControl={creditCardFormControl}
|
|
26
|
-
formControlError={error}
|
|
27
|
-
inputRef={inputRef}
|
|
28
|
-
inputMode={inputMode}
|
|
29
|
-
slotProps={{
|
|
30
|
-
htmlInput: {
|
|
31
|
-
'aria-label': fieldLabel, autoComplete, autoCorrect, id, inputMode, name, spellCheck,
|
|
32
|
-
},
|
|
33
|
-
input: {
|
|
34
|
-
startAdornment:
|
|
35
|
-
type.length > 0
|
|
36
|
-
? (
|
|
37
|
-
<InputAdornment position="start">
|
|
38
|
-
<img height="30px" width="40px" src={CreditCardData[type].icon} />
|
|
39
|
-
</InputAdornment>
|
|
40
|
-
)
|
|
41
|
-
: null,
|
|
42
|
-
},
|
|
43
|
-
}}
|
|
44
|
-
value={value}
|
|
45
|
-
{...cardProps}
|
|
46
|
-
{...props}
|
|
47
|
-
/>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { StandardTextFieldProps } from '@mui/material'
|
|
2
|
-
import type { FormControlBase } from '@xyo-network/react-form-group'
|
|
3
|
-
import { useEffect, useState } from 'react'
|
|
4
|
-
|
|
5
|
-
import type { CreditCardNumberFormControl } from '../../../../controls/index.ts'
|
|
6
|
-
import type { CreditCardOptions } from '../Options.ts'
|
|
7
|
-
import { useCreditCardFormControl } from '../useCreditCardFormControl.tsx'
|
|
8
|
-
|
|
9
|
-
export const useCreditCardNumberFormControl = (formControlName?: string, control?: new () => FormControlBase<StandardTextFieldProps>) => {
|
|
10
|
-
const {
|
|
11
|
-
creditCardFormControl, error, inputRef, value,
|
|
12
|
-
} = useCreditCardFormControl(formControlName, control)
|
|
13
|
-
const [type, setType] = useState('' as keyof CreditCardOptions)
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (creditCardFormControl) {
|
|
17
|
-
const castControl = creditCardFormControl as CreditCardNumberFormControl<StandardTextFieldProps>
|
|
18
|
-
if (!castControl.onCreditCardTypeChange) {
|
|
19
|
-
console.error('cannot set onCreditCardTypeChange on control because it is not a CreditCardNumberFormControl')
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
castControl.onCreditCardTypeChange = (type: string) => setType(type as keyof CreditCardOptions)
|
|
23
|
-
castControl.onCursorChange = (cursor: number | undefined) => {
|
|
24
|
-
if (inputRef.current && cursor) {
|
|
25
|
-
inputRef.current.setSelectionRange(cursor, cursor)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}, [creditCardFormControl, inputRef])
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
creditCardFormControl, error, inputRef, type, value,
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { StandardTextFieldProps } from '@mui/material'
|
|
2
|
-
import type { FormControlBase, ValidControlValue } from '@xyo-network/react-form-group'
|
|
3
|
-
import {
|
|
4
|
-
useMemo, useRef, useState,
|
|
5
|
-
} from 'react'
|
|
6
|
-
|
|
7
|
-
import { useFormGroupWithCreditCardInput } from '../../../context/index.ts'
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
const STABLE_DEFAULT_ARGS: any[] = [] as const
|
|
11
|
-
|
|
12
|
-
export const useCreditCardFormControl = (
|
|
13
|
-
formControlName?: string,
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
Control?: new (...args: any[]) => FormControlBase<StandardTextFieldProps>,
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
args: any[] = STABLE_DEFAULT_ARGS,
|
|
18
|
-
) => {
|
|
19
|
-
const [error, setError] = useState('')
|
|
20
|
-
const [value, setValue] = useState<ValidControlValue>('')
|
|
21
|
-
const inputRef = useRef<HTMLInputElement>(null)
|
|
22
|
-
|
|
23
|
-
// only use FormGroupContext when name is passed
|
|
24
|
-
const { formGroup } = useFormGroupWithCreditCardInput(!!formControlName)
|
|
25
|
-
|
|
26
|
-
const creditCardFormControl = useMemo(() => {
|
|
27
|
-
if (Control) {
|
|
28
|
-
const control = new Control(...args)
|
|
29
|
-
control.registerOnErrorChange((newError: string) => setError(newError))
|
|
30
|
-
control.registerOnChange((value: ValidControlValue) => setValue(value))
|
|
31
|
-
|
|
32
|
-
if (formControlName) formGroup?.registerControl(formControlName, control)
|
|
33
|
-
return control
|
|
34
|
-
}
|
|
35
|
-
}, [Control, args, formControlName, formGroup])
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
creditCardFormControl, error, inputRef, value,
|
|
39
|
-
}
|
|
40
|
-
}
|