@akinon/pz-one-click-checkout 1.89.0 → 1.90.0
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/CHANGELOG.md +6 -0
- package/README.md +37 -1
- package/package.json +1 -1
- package/src/types/index.ts +8 -0
- package/src/views/providers/provider-button.tsx +14 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -25,7 +25,43 @@ npx @akinon/projectzero@latest --plugins
|
|
|
25
25
|
| content | `React.ReactNode` | It is used to create custom content. |
|
|
26
26
|
| openMiniBasket | `boolean` | Manages the opening status of the minibasket. |
|
|
27
27
|
| translations.buttonText | `string` | The text of the button. |
|
|
28
|
+
| customUIRender | `React.ReactNode` | Optional function to fully customize the button rendering. Receives onClick, disabled, loading, provider, productError and content props. |
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
### Customizing Checkout Button
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
import PluginModule, { Component } from '@akinon/next/components/plugin-module';
|
|
34
|
+
|
|
35
|
+
<PluginModule
|
|
36
|
+
component={Component.OneClickCheckoutButtons}
|
|
37
|
+
props={{
|
|
38
|
+
customUIRender: ({
|
|
39
|
+
onClick,
|
|
40
|
+
disabled,
|
|
41
|
+
loading,
|
|
42
|
+
provider,
|
|
43
|
+
productError,
|
|
44
|
+
content
|
|
45
|
+
}) => (
|
|
46
|
+
<>
|
|
47
|
+
<button
|
|
48
|
+
onClick={onClick}
|
|
49
|
+
disabled={disabled}
|
|
50
|
+
className="relative w-full py-3 bg-[#ff2000] text-black hover:bg-[#547ee7] text-sm font-semibold flex items-center justify-center"
|
|
51
|
+
>
|
|
52
|
+
{loading && (
|
|
53
|
+
<span className="absolute left-3 w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" />
|
|
54
|
+
)}
|
|
55
|
+
{loading ? 'Please wait...' : content ?? `Buy with ${provider.name}`}
|
|
56
|
+
</button>
|
|
30
57
|
|
|
58
|
+
{productError && (
|
|
59
|
+
<div className="mt-4 text-xs text-center text-[#d72b01]">
|
|
60
|
+
{productError}
|
|
61
|
+
</div>
|
|
62
|
+
)}
|
|
63
|
+
</>
|
|
64
|
+
)
|
|
65
|
+
}}
|
|
66
|
+
/>;
|
|
31
67
|
```
|
package/package.json
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -19,6 +19,14 @@ export interface OneClickCheckoutProps {
|
|
|
19
19
|
buttonText?: string;
|
|
20
20
|
};
|
|
21
21
|
content?: React.ReactNode;
|
|
22
|
+
customUIRender?: (props: {
|
|
23
|
+
onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
24
|
+
disabled: boolean;
|
|
25
|
+
loading: boolean;
|
|
26
|
+
provider: OneClickCheckoutButtonProps['provider'];
|
|
27
|
+
productError?: string | null;
|
|
28
|
+
content?: React.ReactNode;
|
|
29
|
+
}) => React.ReactNode;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export interface OneClickCheckoutButtonProps extends OneClickCheckoutProps {
|
|
@@ -27,7 +27,8 @@ export const OneClickCheckoutButton = (props: OneClickCheckoutButtonProps) => {
|
|
|
27
27
|
onError,
|
|
28
28
|
provider,
|
|
29
29
|
translations,
|
|
30
|
-
content
|
|
30
|
+
content,
|
|
31
|
+
customUIRender
|
|
31
32
|
} = props;
|
|
32
33
|
|
|
33
34
|
const [disabled, setDisabled] = useState(isDisabled);
|
|
@@ -101,6 +102,17 @@ export const OneClickCheckoutButton = (props: OneClickCheckoutButtonProps) => {
|
|
|
101
102
|
setDisabled(false);
|
|
102
103
|
};
|
|
103
104
|
|
|
105
|
+
if (customUIRender) {
|
|
106
|
+
return customUIRender({
|
|
107
|
+
onClick: (e) => handleOnClick(e, provider?.pk),
|
|
108
|
+
disabled,
|
|
109
|
+
loading: disabled,
|
|
110
|
+
provider,
|
|
111
|
+
content,
|
|
112
|
+
productError
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
104
116
|
return (
|
|
105
117
|
<>
|
|
106
118
|
<Button
|
|
@@ -120,7 +132,7 @@ export const OneClickCheckoutButton = (props: OneClickCheckoutButtonProps) => {
|
|
|
120
132
|
>
|
|
121
133
|
{content
|
|
122
134
|
? content
|
|
123
|
-
: translations?.buttonText ?? `${provider
|
|
135
|
+
: translations?.buttonText ?? `${provider?.name} Checkout`}
|
|
124
136
|
|
|
125
137
|
{disabled && (
|
|
126
138
|
<div className="absolute flex justify-center items-center bg-[#000000] opacity-50 w-full h-full">
|