Skip to content

Commit f55c494

Browse files
Update v6 jsx namespace with the available list of web components (#786)
* update jsx namespace with the available list of web components * update interface extensions * chore: add changeset * dry up sdk web components * update bcdc and paypal messsages ref property * remove usage of react.ref and import ref directly
1 parent 0212046 commit f55c494

File tree

3 files changed

+84
-21
lines changed

3 files changed

+84
-21
lines changed

.changeset/smart-carrots-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@paypal/react-paypal-js": patch
3+
---
4+
5+
Update v6 jsx namespace.

packages/react-paypal-js/src/v6/index.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import type {
2-
IntrinsicButtonProps,
3-
IntrinsicPayLaterButtonProps,
4-
} from "./types/sdkWebComponents";
1+
import type { SDKWebComponents } from "./types/sdkWebComponents";
52

63
export * from "./types";
7-
export type { ButtonProps } from "./types/sdkWebComponents";
4+
export type {
5+
ButtonProps,
6+
InternalButtonProps,
7+
PayLaterButtonProps,
8+
PayPalBasicCardButtonProps,
9+
PayPalCreditButtonProps,
10+
PayPalMessagesElement,
11+
} from "./types/sdkWebComponents";
812
export {
913
PayPalCardFieldsProvider,
1014
type CardFieldsSessionType,
@@ -37,22 +41,14 @@ export { usePayPalCreditSavePaymentSession } from "./hooks/usePayPalCreditSavePa
3741
declare global {
3842
// eslint-disable-next-line @typescript-eslint/no-namespace
3943
namespace JSX {
40-
interface IntrinsicElements {
41-
"paypal-button": IntrinsicButtonProps;
42-
"venmo-button": IntrinsicButtonProps;
43-
"paypal-pay-later-button": IntrinsicPayLaterButtonProps;
44-
}
44+
interface IntrinsicElements extends SDKWebComponents {}
4545
}
4646
}
4747

4848
// React 17/18 JSX SDK Web Components type declaration (for backwards compatibility)
4949
declare module "react" {
5050
// eslint-disable-next-line @typescript-eslint/no-namespace
5151
namespace JSX {
52-
interface IntrinsicElements {
53-
"paypal-button": IntrinsicButtonProps;
54-
"venmo-button": IntrinsicButtonProps;
55-
"paypal-pay-later-button": IntrinsicPayLaterButtonProps;
56-
}
52+
interface IntrinsicElements extends SDKWebComponents {}
5753
}
5854
}
Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,83 @@
1-
import type { HTMLAttributes } from "react";
1+
import type { HTMLAttributes, Ref } from "react";
22

3-
export interface ButtonProps {
3+
export interface InternalButtonProps {
44
type?: "buynow" | "checkout" | "donate" | "pay" | "subscribe";
55
disabled?: boolean;
66
}
77

8-
export interface IntrinsicButtonProps
8+
export interface ButtonProps
99
extends HTMLAttributes<HTMLButtonElement>,
10-
ButtonProps {}
10+
InternalButtonProps {}
1111

1212
/**
1313
* Internal interface for the PayLater web component.
1414
* Includes countryCode and productCode which are populated internally by the React component.
1515
*/
16-
export interface IntrinsicPayLaterButtonProps
17-
extends HTMLAttributes<HTMLButtonElement> {
16+
export interface PayLaterButtonProps extends HTMLAttributes<HTMLButtonElement> {
1817
countryCode?: string;
1918
productCode?: string;
2019
disabled?: boolean;
2120
}
21+
22+
export interface PayPalBasicCardButtonProps
23+
extends HTMLAttributes<HTMLButtonElement> {
24+
buyerCountry: string;
25+
ref?: Ref<HTMLElement>;
26+
}
27+
28+
export interface PayPalCreditButtonProps
29+
extends HTMLAttributes<HTMLButtonElement> {
30+
countryCode?: string;
31+
}
32+
33+
export interface PayPalMessagesElement extends HTMLAttributes<HTMLElement> {
34+
amount?: string;
35+
"auto-bootstrap"?: boolean;
36+
"buyer-country"?: string;
37+
"currency-code"?: string;
38+
"logo-position"?: "INLINE" | "LEFT" | "RIGHT" | "TOP";
39+
"logo-type"?: "MONOGRAM" | "WORDMARK";
40+
"offer-types"?: string;
41+
"presentation-mode"?: "AUTO" | "MODAL" | "POPUP" | "REDIRECT";
42+
ref?: Ref<PayPalMessagesElement>;
43+
"text-color"?: "BLACK" | "MONOCHROME" | "WHITE";
44+
45+
// Event handlers for custom events
46+
onPaypalMessageClick?: (
47+
event: CustomEvent<{
48+
config: {
49+
amount?: string;
50+
buyerCountry?: string;
51+
clickUrl?: string;
52+
offerType?: string;
53+
};
54+
}>,
55+
) => void;
56+
57+
onPaypalMessageAttributeChange?: (
58+
event: CustomEvent<{
59+
changedProperties: string[];
60+
config: {
61+
amount?: string;
62+
buyerCountry?: string;
63+
currencyCode?: string;
64+
logoPosition?: string;
65+
logoType?: string;
66+
offerTypes?: string;
67+
textColor?: string;
68+
};
69+
}>,
70+
) => void;
71+
72+
setContent?: (content: Record<string, unknown>) => void;
73+
}
74+
75+
export type SDKWebComponents = {
76+
"paypal-button": ButtonProps;
77+
"venmo-button": ButtonProps;
78+
"paypal-pay-later-button": PayLaterButtonProps;
79+
"paypal-credit-button": PayPalCreditButtonProps;
80+
"paypal-basic-card-button": PayPalBasicCardButtonProps;
81+
"paypal-basic-card-container": HTMLAttributes<HTMLElement>;
82+
"paypal-message": PayPalMessagesElement;
83+
};

0 commit comments

Comments
 (0)