@amos.com/react-amos-js 0.9.11 → 0.9.13
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/README.md +27 -12
- package/dist/index.d.ts +23 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +56 -27
- package/package.json +2 -2
- package/src/index.tsx +83 -10
package/README.md
CHANGED
|
@@ -143,10 +143,12 @@ Radio groups (e.g. account type) always use an above-style group label regardles
|
|
|
143
143
|
| `--input-border-width` | Input field border width | `1px` |
|
|
144
144
|
| `--input-shadow` | Input field box shadow | `0 1px 2px 0 rgb(0 0 0 / 0.05)` |
|
|
145
145
|
| `--floating-input-height` | Height of inputs when labels are floating | `3.25rem` |
|
|
146
|
-
| `--floating-label-font-size`
|
|
147
|
-
| `--floating-label-font-
|
|
148
|
-
| `--floating-label-
|
|
149
|
-
| `--floating-label-
|
|
146
|
+
| `--floating-label-font-size` | Font size of floating labels when focused or filled | `0.75rem` |
|
|
147
|
+
| `--floating-label-empty-font-size` | Font size of floating labels when empty (unfocused) | `var(--input-font-size)` |
|
|
148
|
+
| `--floating-label-font-weight` | Font weight of floating labels | `500` |
|
|
149
|
+
| `--floating-label-color` | Color of floating labels when empty (unfocused) | `var(--muted-foreground)` |
|
|
150
|
+
| `--floating-label-floated-color` | Color of floating labels when focused or filled | `var(--floating-label-color)` |
|
|
151
|
+
| `--floating-label-offset` | Top offset of the shrunk floating label | `0.625rem` |
|
|
150
152
|
| `--label-font-size` | Font size of above-style field labels | `0.875rem` |
|
|
151
153
|
| `--label-font-weight` | Font weight of above-style field labels | `500` |
|
|
152
154
|
| `--field-gap` | Vertical gap between stacked form fields | `1rem` |
|
|
@@ -460,15 +462,27 @@ Renders the secure Google Pay iframe button (express checkout flow).
|
|
|
460
462
|
**Optional props:**
|
|
461
463
|
|
|
462
464
|
- `appearance` (`{ themeVariables?: Partial<Record<ThemeVariable, string>>; labels?: "above" | "floating" | "placeholder" }`)
|
|
465
|
+
- `fullWidth` (`boolean`, defaults to `false`) — fills the component's mount container
|
|
463
466
|
- `buttonType` (`"book" | "buy" | "checkout" | "donate" | "order" | "pay" | "plain" | "subscribe" | "short" | "long"`, defaults to `"short"`)
|
|
464
467
|
- `buttonColor` (`"default" | "black" | "white"`)
|
|
465
468
|
- `buttonRadius` (`number`, 0–20)
|
|
466
469
|
- `buttonSizeMode` (`"static" | "fill"`)
|
|
467
470
|
- `buttonLocale` (`string`)
|
|
468
471
|
- `buttonBorderType` (`"no_border" | "default_border"`)
|
|
469
|
-
- `
|
|
472
|
+
- `buttonStyle` — styles the Google Pay button **inside** the iframe, for example `buttonStyle={{ height: "48px" }}`
|
|
473
|
+
- `iframeStyle` — styles the host-page `<iframe>` element
|
|
474
|
+
- `style` — backward-compatible alias for `buttonStyle`; prefer the explicit name in new integrations
|
|
470
475
|
|
|
471
|
-
|
|
476
|
+
```tsx
|
|
477
|
+
<AmosGooglePayButton
|
|
478
|
+
fullWidth
|
|
479
|
+
buttonStyle={{ height: "48px" }}
|
|
480
|
+
iframeStyle={{ borderRadius: "6px" }}
|
|
481
|
+
// ...required props
|
|
482
|
+
/>
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
**Also accepts:** standard iframe props, minus `src`, `title`, `name`, `role`, `allow`, and `style`.
|
|
472
486
|
|
|
473
487
|
### `AmosApplePayButton`
|
|
474
488
|
|
|
@@ -476,21 +490,22 @@ Renders the secure Apple Pay iframe button (express checkout flow). Same require
|
|
|
476
490
|
|
|
477
491
|
**Optional visual props** use Apple's `<apple-pay-button>` attribute names:
|
|
478
492
|
|
|
493
|
+
- `fullWidth` (`boolean`, defaults to `false`) — fills the component's mount container
|
|
479
494
|
- `buttonstyle` (`"black" | "white" | "white-outline"`, defaults to `"black"`)
|
|
480
495
|
- `type` (`"plain" | "buy" | "set-up" | "donate" | "check-out" | "book" | "subscribe" | "reload" | "add-money" | "top-up" | "order" | "rent" | "support" | "contribute" | "tip"`, defaults to `"plain"`)
|
|
481
496
|
- `locale` (`string`, BCP 47, defaults to `"en-US"`)
|
|
482
|
-
- `
|
|
497
|
+
- `buttonStyle` — forwarded to the `<apple-pay-button>` inside the iframe. Apple maps a CSS `height` onto its required custom property.
|
|
498
|
+
- `iframeStyle` — styles the host-page `<iframe>` element
|
|
499
|
+
- `style` — backward-compatible alias for `buttonStyle`
|
|
483
500
|
|
|
484
501
|
```tsx
|
|
485
502
|
<AmosApplePayButton
|
|
503
|
+
fullWidth
|
|
486
504
|
buttonstyle="white-outline"
|
|
487
505
|
type="buy"
|
|
488
506
|
locale="en-GB"
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
"--apple-pay-button-width": "100%",
|
|
492
|
-
width: "100%",
|
|
493
|
-
}}
|
|
507
|
+
buttonStyle={{ height: "48px" }}
|
|
508
|
+
iframeStyle={{ borderRadius: "6px" }}
|
|
494
509
|
// ...required props
|
|
495
510
|
/>
|
|
496
511
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="googlepay" />
|
|
2
|
-
import { Appearance, ApplePayButtonElementProps, BillingAddressRequirement, ConfirmationResult, CreditCardAdditionalFields, GooglePayButtonElementProps } from '@amos.com/amos-js';
|
|
2
|
+
import { Appearance, ApplePayButtonElementProps, BillingAddressRequirement, ConfirmationResult, CreditCardAdditionalFields, GooglePayButtonElementProps, WalletButtonStyle } from '@amos.com/amos-js';
|
|
3
3
|
import { components } from '@amos.com/node';
|
|
4
4
|
import { ComponentProps, RefObject } from 'react';
|
|
5
5
|
export * from '@amos.com/amos-js';
|
|
@@ -41,6 +41,24 @@ export declare function resetForm({ iframeRef }: {
|
|
|
41
41
|
iframeRef: IframeRef;
|
|
42
42
|
}): void;
|
|
43
43
|
type IframePassthroughProps = Omit<ComponentProps<"iframe">, "src" | "title" | "name" | "role" | "allow">;
|
|
44
|
+
type WalletStyleProps = {
|
|
45
|
+
/**
|
|
46
|
+
* Stretch the wallet button to fill the iframe width.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
fullWidth?: boolean;
|
|
51
|
+
/** Styles applied to the wallet button inside the Amos iframe. */
|
|
52
|
+
buttonStyle?: WalletButtonStyle;
|
|
53
|
+
/** Styles applied to the host-page `<iframe>` element. */
|
|
54
|
+
iframeStyle?: ComponentProps<"iframe">["style"];
|
|
55
|
+
/**
|
|
56
|
+
* Styles applied to the wallet button inside the Amos iframe.
|
|
57
|
+
*
|
|
58
|
+
* @deprecated Use `buttonStyle` to distinguish it from `iframeStyle`.
|
|
59
|
+
*/
|
|
60
|
+
style?: WalletButtonStyle;
|
|
61
|
+
};
|
|
44
62
|
type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
|
|
45
63
|
renderToken: string;
|
|
46
64
|
appearance?: Appearance;
|
|
@@ -70,7 +88,7 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
|
|
|
70
88
|
billingAddressRequirement?: BillingAddressRequirement;
|
|
71
89
|
};
|
|
72
90
|
export declare function AmosBankAccountPaymentMethodForm({ ref, renderToken, appearance, onResult, onValidityChange, billingAddressRequirement, style, ...rest }: AmosBankAccountPaymentMethodFormProps): import("react").JSX.Element;
|
|
73
|
-
type AmosGooglePayButtonProps = Omit<IframePassthroughProps, "style"> & GooglePayButtonElementProps & {
|
|
91
|
+
type AmosGooglePayButtonProps = Omit<IframePassthroughProps, "style"> & Omit<GooglePayButtonElementProps, "style"> & WalletStyleProps & {
|
|
74
92
|
renderToken: string;
|
|
75
93
|
amount: string;
|
|
76
94
|
merchantName: string;
|
|
@@ -81,8 +99,8 @@ type AmosGooglePayButtonProps = Omit<IframePassthroughProps, "style"> & GooglePa
|
|
|
81
99
|
}) => Promise<components["schemas"]["EmbedToken"]["token"]>;
|
|
82
100
|
onResult: (result: ConfirmationResult) => void;
|
|
83
101
|
};
|
|
84
|
-
export declare function AmosGooglePayButton({ ref, renderToken, amount, merchantName, appearance, onInitiatePaymentIntentRequest, onResult, buttonType, buttonColor, buttonRadius, buttonSizeMode, buttonLocale, buttonBorderType, style, ...rest }: AmosGooglePayButtonProps): import("react").JSX.Element;
|
|
85
|
-
type AmosApplePayButtonProps = Omit<IframePassthroughProps, "style" | "type"> & ApplePayButtonElementProps & {
|
|
102
|
+
export declare function AmosGooglePayButton({ ref, renderToken, amount, merchantName, appearance, onInitiatePaymentIntentRequest, onResult, buttonType, buttonColor, buttonRadius, buttonSizeMode, buttonLocale, buttonBorderType, fullWidth, buttonStyle, iframeStyle, style, ...rest }: AmosGooglePayButtonProps): import("react").JSX.Element;
|
|
103
|
+
type AmosApplePayButtonProps = Omit<IframePassthroughProps, "style" | "type"> & Omit<ApplePayButtonElementProps, "style"> & WalletStyleProps & {
|
|
86
104
|
renderToken: string;
|
|
87
105
|
amount: string;
|
|
88
106
|
merchantName: string;
|
|
@@ -93,4 +111,4 @@ type AmosApplePayButtonProps = Omit<IframePassthroughProps, "style" | "type"> &
|
|
|
93
111
|
}) => Promise<components["schemas"]["EmbedToken"]["token"]>;
|
|
94
112
|
onResult: (result: ConfirmationResult) => void;
|
|
95
113
|
};
|
|
96
|
-
export declare function AmosApplePayButton({ ref, renderToken, amount, merchantName, appearance, onInitiatePaymentIntentRequest, onResult, buttonstyle, type, locale, style, ...rest }: AmosApplePayButtonProps): import("react").JSX.Element;
|
|
114
|
+
export declare function AmosApplePayButton({ ref, renderToken, amount, merchantName, appearance, onInitiatePaymentIntentRequest, onResult, buttonstyle, type, locale, fullWidth, buttonStyle, iframeStyle, style, ...rest }: AmosApplePayButtonProps): import("react").JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@amos.com/amos-js"),t=require("react"),n=require("react/jsx-runtime");function r(e){return e?e.current??null:null}function i({iframeRef:t}){return(0,e.validateForm)({iframe:r(t)})}function a({iframeRef:t,token:n}){(0,e.confirmPaymentIntent)({iframe:r(t),token:n})}function o({iframeRef:t,token:n}){(0,e.confirmSetupIntent)({iframe:r(t),token:n})}function s({iframeRef:t}){(0,e.resetForm)({iframe:r(t)})}function c(e,t){typeof e==`function`?e(t):e&&(e.current=t)}function l(e,{style:t,className:n,id:r,...i}){n!=null&&(e.className=n),r!=null&&(e.id=r),t!=null&&Object.assign(e.style,t);for(let[t,n]of Object.entries(i))n!=null&&(t in e?Reflect.set(e,t,n):e.setAttribute(t,String(n)))}function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@amos.com/amos-js"),t=require("react"),n=require("react/jsx-runtime");function r(e){return e?e.current??null:null}function i({iframeRef:t}){return(0,e.validateForm)({iframe:r(t)})}function a({iframeRef:t,token:n}){(0,e.confirmPaymentIntent)({iframe:r(t),token:n})}function o({iframeRef:t,token:n}){(0,e.confirmSetupIntent)({iframe:r(t),token:n})}function s({iframeRef:t}){(0,e.resetForm)({iframe:r(t)})}function c(e,t){typeof e==`function`?e(t):e&&(e.current=t)}function l({buttonSizeMode:e,style:t,fullWidth:n}){return{buttonSizeMode:e??(n?`fill`:void 0),style:n?{width:`100%`,...t}:t}}function u({style:e,fullWidth:t}){return t?{style:{"--apple-pay-button-width":`100%`,width:`100%`,...e}}:{style:e}}function d(e,{style:t,className:n,id:r,...i}){n!=null&&(e.className=n),r!=null&&(e.id=r),t!=null&&Object.assign(e.style,t);for(let[t,n]of Object.entries(i))n!=null&&(t in e?Reflect.set(e,t,n):e.setAttribute(t,String(n)))}function f({containerRef:e,iframeRef:n,mount:r,options:i,remountDeps:a,iframePassthrough:o,updateDeps:s}){let l=(0,t.useRef)(null);(0,t.useEffect)(()=>{let t=e.current;if(!t)return;let a=r(t,i);return l.current=a,c(n,a.iframe),d(a.iframe,o),()=>{a.destroy(),l.current=null,c(n,null)}},[...a]),(0,t.useEffect)(()=>{l.current?.update(i)},[...s]),(0,t.useEffect)(()=>{let e=l.current?.iframe;e&&d(e,o)})}function p({ref:r,renderToken:i,appearance:a,onResult:o,onValidityChange:s,additionalFields:c={cardholderName:!1},billingAddressRequirement:l=`country`,style:u,...d}){let p=(0,t.useRef)(null);return f({containerRef:p,iframeRef:r,mount:e.mountAmosCreditCardPaymentMethodForm,options:{renderToken:i,appearance:a,additionalFields:c,billingAddressRequirement:l,onResult:o,onValidityChange:s},remountDeps:[i,c.cardholderName,l],iframePassthrough:{style:u,...d},updateDeps:[a,c,l,o,s]}),(0,n.jsx)(`div`,{ref:p})}function m({ref:r,renderToken:i,appearance:a,onResult:o,onValidityChange:s,billingAddressRequirement:c=`country`,style:l,...u}){let d=(0,t.useRef)(null);return f({containerRef:d,iframeRef:r,mount:e.mountAmosBankAccountPaymentMethodForm,options:{renderToken:i,appearance:a,billingAddressRequirement:c,onResult:o,onValidityChange:s},remountDeps:[i,c],iframePassthrough:{style:l,...u},updateDeps:[a,c,o,s]}),(0,n.jsx)(`div`,{ref:d})}function h({ref:r,renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:u,buttonType:d,buttonColor:p,buttonRadius:m,buttonSizeMode:h,buttonLocale:g,buttonBorderType:_,fullWidth:v=!1,buttonStyle:y,iframeStyle:b,style:x,...S}){let C=(0,t.useRef)(null),w=l({buttonSizeMode:h,style:y??x,fullWidth:v});return f({containerRef:C,iframeRef:r,mount:e.mountAmosGooglePayButton,options:{renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:u,buttonType:d,buttonColor:p,buttonRadius:m,buttonSizeMode:w.buttonSizeMode,buttonLocale:g,buttonBorderType:_,style:w.style},remountDeps:[i],iframePassthrough:{style:b,...S},updateDeps:[a,o,s,c,u,d,p,m,w.buttonSizeMode,g,_,w.style]}),(0,n.jsx)(`div`,{ref:C})}function g({ref:r,renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonstyle:d,type:p,locale:m,fullWidth:h=!1,buttonStyle:g,iframeStyle:_,style:v,...y}){let b=(0,t.useRef)(null),x=u({style:g??v,fullWidth:h});return f({containerRef:b,iframeRef:r,mount:e.mountAmosApplePayButton,options:{renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonstyle:d,type:p,locale:m,style:x.style},remountDeps:[i],iframePassthrough:{style:_,...y},updateDeps:[a,o,s,c,l,d,p,m,x.style]}),(0,n.jsx)(`div`,{ref:b})}exports.AmosApplePayButton=g,exports.AmosBankAccountPaymentMethodForm=m,exports.AmosCreditCardPaymentMethodForm=p,exports.AmosGooglePayButton=h,exports.confirmPaymentIntent=a,exports.confirmSetupIntent=o,exports.resetForm=s,exports.validateForm=i,Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/index.mjs
CHANGED
|
@@ -27,29 +27,45 @@ function h({ iframeRef: e }) {
|
|
|
27
27
|
function g(e, t) {
|
|
28
28
|
typeof e == "function" ? e(t) : e && (e.current = t);
|
|
29
29
|
}
|
|
30
|
-
function _(e,
|
|
30
|
+
function _({ buttonSizeMode: e, style: t, fullWidth: n }) {
|
|
31
|
+
return {
|
|
32
|
+
buttonSizeMode: e ?? (n ? "fill" : void 0),
|
|
33
|
+
style: n ? {
|
|
34
|
+
width: "100%",
|
|
35
|
+
...t
|
|
36
|
+
} : t
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function v({ style: e, fullWidth: t }) {
|
|
40
|
+
return t ? { style: {
|
|
41
|
+
"--apple-pay-button-width": "100%",
|
|
42
|
+
width: "100%",
|
|
43
|
+
...e
|
|
44
|
+
} } : { style: e };
|
|
45
|
+
}
|
|
46
|
+
function y(e, { style: t, className: n, id: r, ...i }) {
|
|
31
47
|
n != null && (e.className = n), r != null && (e.id = r), t != null && Object.assign(e.style, t);
|
|
32
48
|
for (let [t, n] of Object.entries(i)) n != null && (t in e ? Reflect.set(e, t, n) : e.setAttribute(t, String(n)));
|
|
33
49
|
}
|
|
34
|
-
function
|
|
50
|
+
function b({ containerRef: e, iframeRef: t, mount: n, options: r, remountDeps: i, iframePassthrough: a, updateDeps: o }) {
|
|
35
51
|
let s = l(null);
|
|
36
52
|
c(() => {
|
|
37
53
|
let i = e.current;
|
|
38
54
|
if (!i) return;
|
|
39
55
|
let o = n(i, r);
|
|
40
|
-
return s.current = o, g(t, o.iframe),
|
|
56
|
+
return s.current = o, g(t, o.iframe), y(o.iframe, a), () => {
|
|
41
57
|
o.destroy(), s.current = null, g(t, null);
|
|
42
58
|
};
|
|
43
59
|
}, [...i]), c(() => {
|
|
44
60
|
s.current?.update(r);
|
|
45
61
|
}, [...o]), c(() => {
|
|
46
62
|
let e = s.current?.iframe;
|
|
47
|
-
e &&
|
|
63
|
+
e && y(e, a);
|
|
48
64
|
});
|
|
49
65
|
}
|
|
50
|
-
function
|
|
66
|
+
function x({ ref: e, renderToken: t, appearance: n, onResult: r, onValidityChange: a, additionalFields: o = { cardholderName: !1 }, billingAddressRequirement: s = "country", style: c, ...d }) {
|
|
51
67
|
let f = l(null);
|
|
52
|
-
return
|
|
68
|
+
return b({
|
|
53
69
|
containerRef: f,
|
|
54
70
|
iframeRef: e,
|
|
55
71
|
mount: i,
|
|
@@ -79,9 +95,9 @@ function y({ ref: e, renderToken: t, appearance: n, onResult: r, onValidityChang
|
|
|
79
95
|
]
|
|
80
96
|
}), /* @__PURE__ */ u("div", { ref: f });
|
|
81
97
|
}
|
|
82
|
-
function
|
|
98
|
+
function S({ ref: e, renderToken: t, appearance: n, onResult: i, onValidityChange: a, billingAddressRequirement: o = "country", style: s, ...c }) {
|
|
83
99
|
let d = l(null);
|
|
84
|
-
return
|
|
100
|
+
return b({
|
|
85
101
|
containerRef: d,
|
|
86
102
|
iframeRef: e,
|
|
87
103
|
mount: r,
|
|
@@ -105,10 +121,14 @@ function b({ ref: e, renderToken: t, appearance: n, onResult: i, onValidityChang
|
|
|
105
121
|
]
|
|
106
122
|
}), /* @__PURE__ */ u("div", { ref: d });
|
|
107
123
|
}
|
|
108
|
-
function
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
|
|
124
|
+
function C({ ref: e, renderToken: t, amount: n, merchantName: r, appearance: i, onInitiatePaymentIntentRequest: o, onResult: s, buttonType: c, buttonColor: d, buttonRadius: f, buttonSizeMode: p, buttonLocale: m, buttonBorderType: h, fullWidth: g = !1, buttonStyle: v, iframeStyle: y, style: x, ...S }) {
|
|
125
|
+
let C = l(null), w = _({
|
|
126
|
+
buttonSizeMode: p,
|
|
127
|
+
style: v ?? x,
|
|
128
|
+
fullWidth: g
|
|
129
|
+
});
|
|
130
|
+
return b({
|
|
131
|
+
containerRef: C,
|
|
112
132
|
iframeRef: e,
|
|
113
133
|
mount: a,
|
|
114
134
|
options: {
|
|
@@ -121,13 +141,16 @@ function x({ ref: e, renderToken: t, amount: n, merchantName: r, appearance: i,
|
|
|
121
141
|
buttonType: c,
|
|
122
142
|
buttonColor: d,
|
|
123
143
|
buttonRadius: f,
|
|
124
|
-
buttonSizeMode:
|
|
144
|
+
buttonSizeMode: w.buttonSizeMode,
|
|
125
145
|
buttonLocale: m,
|
|
126
146
|
buttonBorderType: h,
|
|
127
|
-
style:
|
|
147
|
+
style: w.style
|
|
128
148
|
},
|
|
129
149
|
remountDeps: [t],
|
|
130
|
-
iframePassthrough: {
|
|
150
|
+
iframePassthrough: {
|
|
151
|
+
style: y,
|
|
152
|
+
...S
|
|
153
|
+
},
|
|
131
154
|
updateDeps: [
|
|
132
155
|
n,
|
|
133
156
|
r,
|
|
@@ -137,17 +160,20 @@ function x({ ref: e, renderToken: t, amount: n, merchantName: r, appearance: i,
|
|
|
137
160
|
c,
|
|
138
161
|
d,
|
|
139
162
|
f,
|
|
140
|
-
|
|
163
|
+
w.buttonSizeMode,
|
|
141
164
|
m,
|
|
142
165
|
h,
|
|
143
|
-
|
|
166
|
+
w.style
|
|
144
167
|
]
|
|
145
|
-
}), /* @__PURE__ */ u("div", { ref:
|
|
168
|
+
}), /* @__PURE__ */ u("div", { ref: C });
|
|
146
169
|
}
|
|
147
|
-
function
|
|
148
|
-
let
|
|
149
|
-
|
|
150
|
-
|
|
170
|
+
function w({ ref: e, renderToken: t, amount: r, merchantName: i, appearance: a, onInitiatePaymentIntentRequest: o, onResult: s, buttonstyle: c, type: d, locale: f, fullWidth: p = !1, buttonStyle: m, iframeStyle: h, style: g, ..._ }) {
|
|
171
|
+
let y = l(null), x = v({
|
|
172
|
+
style: m ?? g,
|
|
173
|
+
fullWidth: p
|
|
174
|
+
});
|
|
175
|
+
return b({
|
|
176
|
+
containerRef: y,
|
|
151
177
|
iframeRef: e,
|
|
152
178
|
mount: n,
|
|
153
179
|
options: {
|
|
@@ -160,10 +186,13 @@ function S({ ref: e, renderToken: t, amount: r, merchantName: i, appearance: a,
|
|
|
160
186
|
buttonstyle: c,
|
|
161
187
|
type: d,
|
|
162
188
|
locale: f,
|
|
163
|
-
style:
|
|
189
|
+
style: x.style
|
|
164
190
|
},
|
|
165
191
|
remountDeps: [t],
|
|
166
|
-
iframePassthrough: {
|
|
192
|
+
iframePassthrough: {
|
|
193
|
+
style: h,
|
|
194
|
+
..._
|
|
195
|
+
},
|
|
167
196
|
updateDeps: [
|
|
168
197
|
r,
|
|
169
198
|
i,
|
|
@@ -173,9 +202,9 @@ function S({ ref: e, renderToken: t, amount: r, merchantName: i, appearance: a,
|
|
|
173
202
|
c,
|
|
174
203
|
d,
|
|
175
204
|
f,
|
|
176
|
-
|
|
205
|
+
x.style
|
|
177
206
|
]
|
|
178
|
-
}), /* @__PURE__ */ u("div", { ref:
|
|
207
|
+
}), /* @__PURE__ */ u("div", { ref: y });
|
|
179
208
|
}
|
|
180
209
|
//#endregion
|
|
181
|
-
export {
|
|
210
|
+
export { w as AmosApplePayButton, S as AmosBankAccountPaymentMethodForm, x as AmosCreditCardPaymentMethodForm, C as AmosGooglePayButton, p as confirmPaymentIntent, m as confirmSetupIntent, h as resetForm, f as validateForm };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amos.com/react-amos-js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.13",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"vite-plugin-dts": "5.0.3"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@amos.com/amos-js": "0.9.
|
|
51
|
+
"@amos.com/amos-js": "0.9.14",
|
|
52
52
|
"@types/googlepay": "0.7.11"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
package/src/index.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
mountAmosBankAccountPaymentMethodForm,
|
|
16
16
|
mountAmosCreditCardPaymentMethodForm,
|
|
17
17
|
mountAmosGooglePayButton,
|
|
18
|
+
type WalletButtonStyle,
|
|
18
19
|
} from "@amos.com/amos-js";
|
|
19
20
|
import type { components } from "@amos.com/node";
|
|
20
21
|
import {
|
|
@@ -108,6 +109,59 @@ type IframePassthroughProps = Omit<
|
|
|
108
109
|
"src" | "title" | "name" | "role" | "allow"
|
|
109
110
|
>;
|
|
110
111
|
|
|
112
|
+
type WalletStyleProps = {
|
|
113
|
+
/**
|
|
114
|
+
* Stretch the wallet button to fill the iframe width.
|
|
115
|
+
*
|
|
116
|
+
* @default false
|
|
117
|
+
*/
|
|
118
|
+
fullWidth?: boolean;
|
|
119
|
+
/** Styles applied to the wallet button inside the Amos iframe. */
|
|
120
|
+
buttonStyle?: WalletButtonStyle;
|
|
121
|
+
/** Styles applied to the host-page `<iframe>` element. */
|
|
122
|
+
iframeStyle?: ComponentProps<"iframe">["style"];
|
|
123
|
+
/**
|
|
124
|
+
* Styles applied to the wallet button inside the Amos iframe.
|
|
125
|
+
*
|
|
126
|
+
* @deprecated Use `buttonStyle` to distinguish it from `iframeStyle`.
|
|
127
|
+
*/
|
|
128
|
+
style?: WalletButtonStyle;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
function resolveGooglePayButtonLayout({
|
|
132
|
+
buttonSizeMode,
|
|
133
|
+
style,
|
|
134
|
+
fullWidth,
|
|
135
|
+
}: {
|
|
136
|
+
buttonSizeMode?: GooglePayButtonElementProps["buttonSizeMode"];
|
|
137
|
+
style?: WalletButtonStyle;
|
|
138
|
+
fullWidth: boolean;
|
|
139
|
+
}): Pick<GooglePayButtonElementProps, "buttonSizeMode" | "style"> {
|
|
140
|
+
return {
|
|
141
|
+
buttonSizeMode: buttonSizeMode ?? (fullWidth ? "fill" : undefined),
|
|
142
|
+
style: fullWidth ? { width: "100%", ...style } : style,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function resolveApplePayButtonLayout({
|
|
147
|
+
style,
|
|
148
|
+
fullWidth,
|
|
149
|
+
}: {
|
|
150
|
+
style?: WalletButtonStyle;
|
|
151
|
+
fullWidth: boolean;
|
|
152
|
+
}): Pick<ApplePayButtonElementProps, "style"> {
|
|
153
|
+
if (!fullWidth) {
|
|
154
|
+
return { style };
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
style: {
|
|
158
|
+
"--apple-pay-button-width": "100%",
|
|
159
|
+
width: "100%",
|
|
160
|
+
...style,
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
111
165
|
function applyIframePassthrough(
|
|
112
166
|
iframe: HTMLIFrameElement,
|
|
113
167
|
{ style, className, id, ...rest }: IframePassthroughProps,
|
|
@@ -295,7 +349,8 @@ export function AmosBankAccountPaymentMethodForm({
|
|
|
295
349
|
}
|
|
296
350
|
|
|
297
351
|
type AmosGooglePayButtonProps = Omit<IframePassthroughProps, "style"> &
|
|
298
|
-
GooglePayButtonElementProps &
|
|
352
|
+
Omit<GooglePayButtonElementProps, "style"> &
|
|
353
|
+
WalletStyleProps & {
|
|
299
354
|
renderToken: string;
|
|
300
355
|
amount: string;
|
|
301
356
|
merchantName: string;
|
|
@@ -324,10 +379,19 @@ export function AmosGooglePayButton({
|
|
|
324
379
|
buttonSizeMode,
|
|
325
380
|
buttonLocale,
|
|
326
381
|
buttonBorderType,
|
|
382
|
+
fullWidth = false,
|
|
383
|
+
buttonStyle,
|
|
384
|
+
iframeStyle,
|
|
327
385
|
style,
|
|
328
386
|
...rest
|
|
329
387
|
}: AmosGooglePayButtonProps) {
|
|
330
388
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
389
|
+
const resolvedStyle = buttonStyle ?? style;
|
|
390
|
+
const layout = resolveGooglePayButtonLayout({
|
|
391
|
+
buttonSizeMode,
|
|
392
|
+
style: resolvedStyle,
|
|
393
|
+
fullWidth,
|
|
394
|
+
});
|
|
331
395
|
|
|
332
396
|
useAmosEmbed({
|
|
333
397
|
containerRef,
|
|
@@ -343,13 +407,13 @@ export function AmosGooglePayButton({
|
|
|
343
407
|
buttonType,
|
|
344
408
|
buttonColor,
|
|
345
409
|
buttonRadius,
|
|
346
|
-
buttonSizeMode,
|
|
410
|
+
buttonSizeMode: layout.buttonSizeMode,
|
|
347
411
|
buttonLocale,
|
|
348
412
|
buttonBorderType,
|
|
349
|
-
style,
|
|
413
|
+
style: layout.style,
|
|
350
414
|
},
|
|
351
415
|
remountDeps: [renderToken],
|
|
352
|
-
iframePassthrough: { ...rest },
|
|
416
|
+
iframePassthrough: { style: iframeStyle, ...rest },
|
|
353
417
|
updateDeps: [
|
|
354
418
|
amount,
|
|
355
419
|
merchantName,
|
|
@@ -359,10 +423,10 @@ export function AmosGooglePayButton({
|
|
|
359
423
|
buttonType,
|
|
360
424
|
buttonColor,
|
|
361
425
|
buttonRadius,
|
|
362
|
-
buttonSizeMode,
|
|
426
|
+
layout.buttonSizeMode,
|
|
363
427
|
buttonLocale,
|
|
364
428
|
buttonBorderType,
|
|
365
|
-
style,
|
|
429
|
+
layout.style,
|
|
366
430
|
],
|
|
367
431
|
});
|
|
368
432
|
|
|
@@ -370,7 +434,8 @@ export function AmosGooglePayButton({
|
|
|
370
434
|
}
|
|
371
435
|
|
|
372
436
|
type AmosApplePayButtonProps = Omit<IframePassthroughProps, "style" | "type"> &
|
|
373
|
-
ApplePayButtonElementProps &
|
|
437
|
+
Omit<ApplePayButtonElementProps, "style"> &
|
|
438
|
+
WalletStyleProps & {
|
|
374
439
|
renderToken: string;
|
|
375
440
|
amount: string;
|
|
376
441
|
merchantName: string;
|
|
@@ -396,10 +461,18 @@ export function AmosApplePayButton({
|
|
|
396
461
|
buttonstyle,
|
|
397
462
|
type,
|
|
398
463
|
locale,
|
|
464
|
+
fullWidth = false,
|
|
465
|
+
buttonStyle,
|
|
466
|
+
iframeStyle,
|
|
399
467
|
style,
|
|
400
468
|
...rest
|
|
401
469
|
}: AmosApplePayButtonProps) {
|
|
402
470
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
471
|
+
const resolvedStyle = buttonStyle ?? style;
|
|
472
|
+
const layout = resolveApplePayButtonLayout({
|
|
473
|
+
style: resolvedStyle,
|
|
474
|
+
fullWidth,
|
|
475
|
+
});
|
|
403
476
|
|
|
404
477
|
useAmosEmbed({
|
|
405
478
|
containerRef,
|
|
@@ -415,10 +488,10 @@ export function AmosApplePayButton({
|
|
|
415
488
|
buttonstyle,
|
|
416
489
|
type,
|
|
417
490
|
locale,
|
|
418
|
-
style,
|
|
491
|
+
style: layout.style,
|
|
419
492
|
},
|
|
420
493
|
remountDeps: [renderToken],
|
|
421
|
-
iframePassthrough: { ...rest },
|
|
494
|
+
iframePassthrough: { style: iframeStyle, ...rest },
|
|
422
495
|
updateDeps: [
|
|
423
496
|
amount,
|
|
424
497
|
merchantName,
|
|
@@ -428,7 +501,7 @@ export function AmosApplePayButton({
|
|
|
428
501
|
buttonstyle,
|
|
429
502
|
type,
|
|
430
503
|
locale,
|
|
431
|
-
style,
|
|
504
|
+
layout.style,
|
|
432
505
|
],
|
|
433
506
|
});
|
|
434
507
|
|