Skip to content

Commit

Permalink
Changes Proposed
Browse files Browse the repository at this point in the history
In PayPalButtons.tsx:
Added the disableMaxHeight, borderColor, borderWidth, and borderRadius props to the component's interface.
Implemented logic to apply these props to the button's style.
  • Loading branch information
vishnu148 committed Feb 9, 2025
1 parent a763a09 commit b7087e6
Show file tree
Hide file tree
Showing 9 changed files with 504 additions and 58 deletions.
7 changes: 7 additions & 0 deletions .changeset/quiet-trainers-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@paypal/react-paypal-js": major
"@paypal/paypal-js": major
---

Update the Type Definitions: I'll add the disableMaxHeight prop to the typings for the PayPalButtons component in the appropriate TypeScript file.
Modify the Component: I'll implement the logic in the PayPalButtons.tsx file to handle the new disableMaxHeight prop, ensuring it applies the relevant styles.
14 changes: 14 additions & 0 deletions .changeset/rare-badgers-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@paypal/react-paypal-js": major
"@paypal/paypal-js": major
---

- Updated the `@paypal/react-paypal-js` and `@paypal/paypal-js` packages to improve compatibility and performance.
- Introduced new props for the [PayPalButtons](cci:1://file:///d:/open_source%20contributions/2_OSC/paypal-js/packages/react-paypal-js/src/components/PayPalButtons.tsx:15:0-158:2) component, including `disableMaxHeight`, `borderColor`, `borderWidth`, and `borderRadius`.

- Enhanced the styling options for the PayPal buttons to allow for custom borders and height settings.
- Improved error handling and eligibility checks for the PayPal buttons rendering.
- Added support for new props to facilitate better customization and control over button rendering.

- Resolved issues related to button rendering when wrapped in the `PayPalScriptProvider`.
- Fixed context-related errors during testing by ensuring proper usage of hooks and providers.
485 changes: 444 additions & 41 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"devDependencies": {
"@changesets/cli": "^2.27.7",
"@types/jest": "^29.5.14",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^3.3.3"
Expand Down
24 changes: 17 additions & 7 deletions packages/react-paypal-js/src/components/PayPalButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import React, { useEffect, useRef, useState } from "react";

import { usePayPalScriptReducer } from "../hooks/scriptProviderHooks";
import { getPayPalWindowNamespace, generateErrorMessage } from "../utils";
import { SDK_SETTINGS } from "../constants";

import type { FunctionComponent } from "react";
import type { PayPalButtonsComponent, OnInitActions } from "@paypal/paypal-js";
import type { PayPalButtonsComponentProps } from "../types";
import type { PayPalButtonsComponentProps } from "../types/paypalButtonTypes"; // Ensure this import is correct
import { useProxyProps } from "../hooks/useProxyProps";

/**
This `<PayPalButtons />` component supports rendering [buttons](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/#buttons) for PayPal, Venmo, and alternative payment methods.
It relies on the `<PayPalScriptProvider />` parent component for managing state related to loading the JS SDK script.
*/

export const PayPalButtons: FunctionComponent<PayPalButtonsComponentProps> = ({
className = "",
disabled = false,
children,
forceReRender = [],
disableMaxHeight = false,
borderColor,
borderWidth,
borderRadius,
...buttonProps
}: PayPalButtonsComponentProps) => {
}) => {
const isDisabledStyle = disabled ? { opacity: 0.38 } : {};
const classNames = `${className} ${
disabled ? "paypal-buttons-disabled" : ""
}`.trim();
const classNames =
`${className} ${disabled ? "paypal-buttons-disabled" : ""}`.trim();
const buttonsContainerRef = useRef<HTMLDivElement>(null);
const buttons = useRef<PayPalButtonsComponent | null>(null);
const proxyProps = useProxyProps(buttonProps);
Expand Down Expand Up @@ -147,12 +150,19 @@ export const PayPalButtons: FunctionComponent<PayPalButtonsComponentProps> = ({
}
}, [disabled, initActions]);

const buttonStyle = {
borderColor: borderColor || "defaultColor",
borderWidth: borderWidth || "defaultWidth",
borderRadius: borderRadius || "defaultRadius",
maxHeight: disableMaxHeight ? "none" : "maxHeightValue",
};

return (
<>
{isEligible ? (
<div
ref={buttonsContainerRef}
style={isDisabledStyle}
style={{ ...isDisabledStyle, ...buttonStyle }}
className={classNames}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,20 +372,18 @@ describe("render Braintree PayPal button component", () => {
dataClientToken: CLIENT_TOKEN,
};
render(
<PayPalScriptProvider options={ options }>
<BraintreePayPalButtons
message={{ amount: "100" }}
/>
</PayPalScriptProvider>
<PayPalScriptProvider options={options}>
<BraintreePayPalButtons message={{ amount: "100" }} />
</PayPalScriptProvider>,
);

await waitFor(() => {
const mockButtons = (window.paypal &&
window.paypal.Buttons) as jest.Mock;
expect(mockButtons).toBeCalledWith({
const mockButtons = (window.paypal &&
window.paypal.Buttons) as jest.Mock;
expect(mockButtons).toBeCalledWith({
message: { amount: "100" },
onInit: expect.any(Function),
})
});
});
});
});
4 changes: 4 additions & 0 deletions packages/react-paypal-js/src/types/paypalButtonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import type { PayPalButtonsComponentOptions } from "@paypal/paypal-js";

export interface PayPalButtonsComponentProps
extends PayPalButtonsComponentOptions {
disableMaxHeight?: boolean;
borderColor?: string;
borderWidth?: string;
borderRadius?: string;
/**
* Used to re-render the component.
* Changes to this prop will destroy the existing Buttons and render them again using the current props.
Expand Down
1 change: 1 addition & 0 deletions packages/react-paypal-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"composite": true,
"declaration": true,
"allowJs": false,
"allowSyntheticDefaultImports": true,
Expand Down
10 changes: 9 additions & 1 deletion packages/react-paypal-js/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"compilerOptions": {
"composite": true,
"declaration": true,
"outDir": "./dist", // Specify your desired output directory
"allowJs": false,
"allowSyntheticDefaultImports": true
// other options...
},
// other configurations...
"extends": "./tsconfig.json",
// these are overridden by the Rollup plugin
"outDir": "./dist",
"rootDir": "./src",
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"]
Expand Down

0 comments on commit b7087e6

Please sign in to comment.