@blocklet/payment-react 1.20.5 → 1.20.6
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/.aigne/doc-smith/config.yaml +2 -2
- package/.aigne/doc-smith/upload-cache.yaml +381 -0
- package/docs/components-business-auto-topup.md +128 -179
- package/docs/components-business-overdue-invoice-payment.md +108 -143
- package/docs/components-business-resume-subscription.md +117 -104
- package/docs/components-business.md +12 -36
- package/docs/components-checkout-checkout-donate.md +209 -149
- package/docs/components-checkout-checkout-form.md +115 -136
- package/docs/components-checkout-checkout-table.md +92 -172
- package/docs/components-checkout.md +43 -109
- package/docs/components-history-credit-grants-list.md +45 -70
- package/docs/components-history-credit-transactions-list.md +57 -67
- package/docs/components-history-invoice-list.md +58 -52
- package/docs/components-history-payment-list.md +19 -40
- package/docs/components-history.md +42 -67
- package/docs/components-ui-form-elements-address-form.md +37 -65
- package/docs/components-ui-form-elements-country-select.md +80 -59
- package/docs/components-ui-form-elements-currency-selector.md +57 -73
- package/docs/components-ui-form-elements-phone-input.md +90 -112
- package/docs/components-ui-form-elements.md +46 -80
- package/docs/components-ui-payment-summary.md +71 -119
- package/docs/components-ui-pricing-table.md +117 -204
- package/docs/components-ui.md +59 -32
- package/docs/components.md +89 -62
- package/docs/getting-started.md +36 -63
- package/docs/guides-theming.md +122 -84
- package/docs/guides-utilities.md +107 -145
- package/docs/guides.md +7 -84
- package/docs/hooks-use-mobile.md +50 -36
- package/docs/hooks-use-subscription.md +72 -89
- package/docs/hooks.md +12 -82
- package/docs/overview.md +45 -52
- package/docs/providers-donate-provider.md +73 -95
- package/docs/providers-payment-provider.md +115 -169
- package/docs/providers.md +27 -86
- package/es/locales/en.js +7 -0
- package/es/locales/zh.js +8 -1
- package/es/payment/index.js +3 -0
- package/es/payment/progress-item.d.ts +12 -0
- package/es/payment/progress-item.js +78 -0
- package/es/payment/success.d.ts +4 -1
- package/es/payment/success.js +55 -3
- package/lib/locales/en.js +7 -0
- package/lib/locales/zh.js +8 -1
- package/lib/payment/index.js +3 -0
- package/lib/payment/progress-item.d.ts +12 -0
- package/lib/payment/progress-item.js +107 -0
- package/lib/payment/success.d.ts +4 -1
- package/lib/payment/success.js +59 -3
- package/package.json +3 -3
- package/src/locales/en.tsx +7 -0
- package/src/locales/zh.tsx +8 -1
- package/src/payment/index.tsx +6 -0
- package/src/payment/progress-item.tsx +107 -0
- package/src/payment/success.tsx +88 -3
package/docs/components.md
CHANGED
|
@@ -1,95 +1,122 @@
|
|
|
1
1
|
# Components
|
|
2
2
|
|
|
3
|
-
The `@blocklet/payment-react` library
|
|
3
|
+
The `@blocklet/payment-react` library offers a comprehensive suite of pre-built React components designed to accelerate the development of payment, subscription, and donation features. These components are categorized to help you find the right tool for the job, whether you need a complete drop-in solution or fine-grained UI elements to build a custom experience.
|
|
4
4
|
|
|
5
|
-
All components are designed to
|
|
5
|
+
All components are designed to work seamlessly within the `PaymentProvider` context, which handles state management and API communication.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Component Architecture
|
|
8
8
|
|
|
9
|
-
The
|
|
9
|
+
The following diagram illustrates how the high-level components typically interact. User-facing components like `CheckoutTable` or `CheckoutDonate` act as entry points, which then utilize the core `CheckoutForm` to handle the final payment processing.
|
|
10
10
|
|
|
11
11
|
```d2
|
|
12
12
|
direction: down
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
shape:
|
|
16
|
-
|
|
17
|
-
"Checkout Components": {
|
|
18
|
-
tooltip: "High-level components for complete payment flows"
|
|
19
|
-
"CheckoutForm": {}
|
|
20
|
-
"CheckoutTable": {}
|
|
21
|
-
"CheckoutDonate": {}
|
|
22
|
-
}
|
|
14
|
+
User: {
|
|
15
|
+
shape: c4-person
|
|
16
|
+
}
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
18
|
+
PaymentProvider-Context: {
|
|
19
|
+
label: "PaymentProvider Context"
|
|
20
|
+
shape: rectangle
|
|
21
|
+
style: {
|
|
22
|
+
stroke: "#888"
|
|
23
|
+
stroke-width: 2
|
|
24
|
+
stroke-dash: 4
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
Entry-Points: {
|
|
28
|
+
label: "High-Level Components"
|
|
29
|
+
shape: rectangle
|
|
30
|
+
|
|
31
|
+
CheckoutTable: {
|
|
32
|
+
label: "CheckoutTable"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
CheckoutDonate: {
|
|
36
|
+
label: "CheckoutDonate"
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
Core-Processor: {
|
|
41
|
+
label: "Core Payment Processor"
|
|
42
|
+
shape: rectangle
|
|
43
|
+
|
|
44
|
+
CheckoutForm: {
|
|
45
|
+
label: "CheckoutForm"
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
48
|
}
|
|
49
|
+
|
|
50
|
+
User -> PaymentProvider-Context.Entry-Points.CheckoutTable: "Selects a plan"
|
|
51
|
+
User -> PaymentProvider-Context.Entry-Points.CheckoutDonate: "Makes a donation"
|
|
52
|
+
PaymentProvider-Context.Entry-Points.CheckoutTable -> PaymentProvider-Context.Core-Processor.CheckoutForm: "Initiates checkout"
|
|
53
|
+
PaymentProvider-Context.Entry-Points.CheckoutDonate -> PaymentProvider-Context.Core-Processor.CheckoutForm: "Initiates checkout"
|
|
45
54
|
```
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
## Component Categories
|
|
48
57
|
|
|
49
|
-
|
|
58
|
+
Explore our component categories to find the building blocks you need.
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
### Checkout Components
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
55
|
-
// This is your application's custom hook for session management
|
|
56
|
-
import { useSessionContext } from '../hooks/session';
|
|
62
|
+
These are high-level components that provide complete, out-of-the-box payment experiences. Use them as the primary entry points for your payment flows.
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
<x-cards>
|
|
65
|
+
<x-card data-title="CheckoutForm" data-icon="lucide:credit-card" data-href="/components/checkout/checkout-form">
|
|
66
|
+
The primary component for handling payment links and checkout sessions.
|
|
67
|
+
</x-card>
|
|
68
|
+
<x-card data-title="CheckoutTable" data-icon="lucide:table" data-href="/components/checkout/checkout-table">
|
|
69
|
+
Renders a complete pricing table and handles the checkout flow.
|
|
70
|
+
</x-card>
|
|
71
|
+
<x-card data-title="CheckoutDonate" data-icon="lucide:heart-handshake" data-href="/components/checkout/checkout-donate">
|
|
72
|
+
Implement donation functionality with this flexible component.
|
|
73
|
+
</x-card>
|
|
74
|
+
</x-cards>
|
|
61
75
|
|
|
62
|
-
|
|
63
|
-
// The PaymentProvider wraps all components that need payment context
|
|
64
|
-
<PaymentProvider session={session} connect={connectApi}>
|
|
65
|
-
{/* Now, components like CheckoutForm can be used */}
|
|
66
|
-
<CheckoutForm id="plink_xxx" mode="inline" />
|
|
67
|
-
</PaymentProvider>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
```
|
|
76
|
+
### UI Components
|
|
71
77
|
|
|
72
|
-
|
|
78
|
+
A collection of granular components for building custom payment forms and displays. Combine these blocks to create a user interface that perfectly matches your application's design.
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
<x-cards>
|
|
81
|
+
<x-card data-title="PricingTable" data-icon="lucide:layout-list" data-href="/components/ui/pricing-table">
|
|
82
|
+
Display subscription plans and pricing options in a structured table.
|
|
83
|
+
</x-card>
|
|
84
|
+
<x-card data-title="PaymentSummary" data-icon="lucide:receipt" data-href="/components/ui/payment-summary">
|
|
85
|
+
Show a detailed summary of an order, including line items and totals.
|
|
86
|
+
</x-card>
|
|
87
|
+
<x-card data-title="Form Elements" data-icon="lucide:pencil-ruler" data-href="/components/ui/form-elements">
|
|
88
|
+
A collection of inputs for building custom payment and contact forms.
|
|
89
|
+
</x-card>
|
|
90
|
+
</x-cards>
|
|
75
91
|
|
|
76
|
-
|
|
92
|
+
### Business Logic Components
|
|
77
93
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Granular building blocks for creating custom interfaces, including forms, selectors, and display elements like `PricingTable` and `PaymentSummary`.
|
|
94
|
+
Specialized components designed to handle complex business workflows, such as managing overdue invoices, resuming subscriptions, and configuring automatic credit top-ups.
|
|
95
|
+
|
|
96
|
+
<x-cards>
|
|
97
|
+
<x-card data-title="OverdueInvoicePayment" data-icon="lucide:file-warning" data-href="/components/business/overdue-invoice-payment">
|
|
98
|
+
Handle the payment of overdue invoices for a customer or subscription.
|
|
84
99
|
</x-card>
|
|
85
|
-
<x-card data-title="
|
|
86
|
-
|
|
100
|
+
<x-card data-title="ResumeSubscription" data-icon="lucide:play-circle" data-href="/components/business/resume-subscription">
|
|
101
|
+
Allow users to resume a canceled subscription with ease.
|
|
87
102
|
</x-card>
|
|
88
|
-
<x-card data-title="
|
|
89
|
-
|
|
103
|
+
<x-card data-title="Auto-Topup Components" data-icon="lucide:battery-charging" data-href="/components/business/auto-topup">
|
|
104
|
+
Manage and configure automatic credit top-up functionality.
|
|
90
105
|
</x-card>
|
|
91
106
|
</x-cards>
|
|
92
107
|
|
|
93
|
-
|
|
108
|
+
### History Components
|
|
109
|
+
|
|
110
|
+
Display historical payment and credit data to your users. These components make it easy to render lists of invoices, payments, and credit transactions.
|
|
94
111
|
|
|
95
|
-
|
|
112
|
+
<x-cards>
|
|
113
|
+
<x-card data-title="CustomerInvoiceList" data-icon="lucide:history" data-href="/components/history/invoice-list">
|
|
114
|
+
Render a list of a customer's invoices with details and status.
|
|
115
|
+
</x-card>
|
|
116
|
+
<x-card data-title="CustomerPaymentList" data-icon="lucide:landmark" data-href="/components/history/payment-list">
|
|
117
|
+
Display a customer's payment history, including transaction details.
|
|
118
|
+
</x-card>
|
|
119
|
+
<x-card data-title="CreditGrantsList" data-icon="lucide:award" data-href="/components/history/credit-grants-list">
|
|
120
|
+
Show a list of credit grants, including status and remaining amounts.
|
|
121
|
+
</x-card>
|
|
122
|
+
</x-cards>
|
package/docs/getting-started.md
CHANGED
|
@@ -1,111 +1,84 @@
|
|
|
1
1
|
# Getting Started
|
|
2
2
|
|
|
3
|
-
This guide
|
|
3
|
+
This guide will walk you through the essential steps to install `@blocklet/payment-react` and integrate a basic, functional payment form into your application. In just a few minutes, you'll have a working checkout experience.
|
|
4
4
|
|
|
5
|
-
## 1
|
|
5
|
+
## Step 1: Installation
|
|
6
6
|
|
|
7
7
|
First, add the library to your project using npm or your preferred package manager.
|
|
8
8
|
|
|
9
|
-
```bash
|
|
9
|
+
```bash Installation Command icon=lucide:terminal
|
|
10
10
|
npm install @blocklet/payment-react
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
## 2
|
|
13
|
+
## Step 2: Set Up the PaymentProvider
|
|
14
14
|
|
|
15
|
-
Most components in
|
|
15
|
+
Most components in this library require access to a shared payment context. The `PaymentProvider` component provides this context and must be placed at the root of your application or component tree where payments will be handled.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
It requires a `session` object and a `connect` API function from your application's authentication context to work correctly.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Once your context is set up, you can use it like this:
|
|
22
|
-
|
|
23
|
-
```tsx
|
|
19
|
+
```tsx App.tsx icon=logos:react
|
|
24
20
|
import { PaymentProvider } from '@blocklet/payment-react';
|
|
25
|
-
|
|
21
|
+
// This is a placeholder for your app's authentication context hook.
|
|
22
|
+
// It should return the current user session and an API connector.
|
|
23
|
+
import { useSessionContext } from './contexts/session';
|
|
26
24
|
|
|
27
|
-
function App() {
|
|
25
|
+
function App({ children }) {
|
|
28
26
|
const { session, connectApi } = useSessionContext();
|
|
29
27
|
|
|
30
28
|
return (
|
|
31
29
|
<PaymentProvider session={session} connect={connectApi}>
|
|
32
30
|
{/* Your payment components will go here */}
|
|
31
|
+
{children}
|
|
33
32
|
</PaymentProvider>
|
|
34
33
|
);
|
|
35
34
|
}
|
|
36
35
|
```
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```d2
|
|
41
|
-
direction: down
|
|
42
|
-
|
|
43
|
-
"Your App": {
|
|
44
|
-
"PaymentProvider": {
|
|
45
|
-
style: { fill: "#dbeafe" }
|
|
46
|
-
"CheckoutForm": {
|
|
47
|
-
label: "Renders the payment UI"
|
|
48
|
-
style: { fill: "#ede9fe" }
|
|
49
|
-
}
|
|
50
|
-
"Other Components": {
|
|
51
|
-
label: "e.g., CustomerInvoiceList"
|
|
52
|
-
style: { fill: "#ede9fe" }
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
37
|
+
> For detailed information on setting up your session context and for advanced `PaymentProvider` configurations, please see the [PaymentProvider documentation](./providers-payment-provider.md).
|
|
56
38
|
|
|
57
|
-
|
|
58
|
-
"Your App.PaymentProvider" -> "Your App.PaymentProvider.Other Components": "Provides context (session, API)"
|
|
59
|
-
```
|
|
39
|
+
## Step 3: Add a CheckoutForm
|
|
60
40
|
|
|
61
|
-
|
|
41
|
+
The `CheckoutForm` is the primary component for rendering a payment flow. It can handle both one-time payments and subscriptions initiated from a Payment Link.
|
|
62
42
|
|
|
63
|
-
|
|
43
|
+
To use it, simply place it inside the `PaymentProvider` and pass the required `id` of a Payment Link (`plink_...`) or a Checkout Session (`cs_...`).
|
|
64
44
|
|
|
65
|
-
##
|
|
45
|
+
## Complete Example
|
|
66
46
|
|
|
67
|
-
|
|
47
|
+
Here is a complete, minimal example that combines the steps above. You can use this code as a starting point for your integration.
|
|
68
48
|
|
|
69
|
-
```tsx
|
|
70
|
-
import React from 'react';
|
|
49
|
+
```tsx PaymentPage.tsx icon=logos:react
|
|
71
50
|
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
51
|
+
// This is a placeholder for your app's authentication context hook.
|
|
52
|
+
import { useSessionContext } from './contexts/session';
|
|
72
53
|
|
|
73
|
-
|
|
74
|
-
// For setup details, see the PaymentProvider documentation.
|
|
75
|
-
import { useSessionContext } from '../path/to/your/session-context';
|
|
76
|
-
|
|
77
|
-
function MyPaymentPage() {
|
|
54
|
+
function PaymentPage() {
|
|
78
55
|
const { session, connectApi } = useSessionContext();
|
|
79
56
|
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
return <div>Loading user session...</div>;
|
|
83
|
-
}
|
|
57
|
+
// A Payment Link ID is generated from your Payment Kit dashboard.
|
|
58
|
+
const paymentLinkId = 'plink_xxx';
|
|
84
59
|
|
|
85
60
|
return (
|
|
86
61
|
<PaymentProvider session={session} connect={connectApi}>
|
|
87
62
|
<CheckoutForm
|
|
88
|
-
id=
|
|
89
|
-
mode="inline"
|
|
63
|
+
id={paymentLinkId}
|
|
64
|
+
mode="inline" // Embeds the form directly into your page
|
|
90
65
|
showCheckoutSummary={true}
|
|
91
|
-
onChange={(state) => console.log('Checkout State:', state)}
|
|
92
|
-
onPaid={() =>
|
|
93
|
-
onError={(err) => alert(`Payment Failed: ${err.message}`)}
|
|
66
|
+
onChange={(state) => console.log('Checkout State Changed:', state)}
|
|
67
|
+
onPaid={(result) => console.log('Payment Successful:', result)}
|
|
94
68
|
/>
|
|
95
69
|
</PaymentProvider>
|
|
96
70
|
);
|
|
97
71
|
}
|
|
98
72
|
|
|
99
|
-
export default
|
|
73
|
+
export default PaymentPage;
|
|
100
74
|
```
|
|
101
75
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
- `mode="inline"` renders the form within the current page flow.
|
|
106
|
-
- `showCheckoutSummary={true}` displays a summary of what the user is paying for.
|
|
107
|
-
- The `onChange`, `onPaid`, and `onError` callbacks allow you to monitor and react to the state of the checkout process.
|
|
76
|
+
With this setup, the `CheckoutForm` will render a complete payment UI, handle user input, and process the transaction seamlessly.
|
|
77
|
+
|
|
78
|
+
## Next Steps
|
|
108
79
|
|
|
109
|
-
|
|
80
|
+
Congratulations! You've successfully integrated your first payment form. Now you're ready to explore more advanced features and components.
|
|
110
81
|
|
|
111
|
-
|
|
82
|
+
- **[CheckoutForm](./components-checkout-checkout-form.md)**: Dive deeper into the `CheckoutForm` props and customization options.
|
|
83
|
+
- **[Providers](./providers.md)**: Learn more about the context providers that power the library.
|
|
84
|
+
- **[Components](./components.md)**: Discover the full range of UI and business logic components available.
|
package/docs/guides-theming.md
CHANGED
|
@@ -1,80 +1,73 @@
|
|
|
1
1
|
# Theming
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Learn how to customize the appearance of payment components using the built-in theme provider and Material-UI theme options. The `@blocklet/payment-react` library is built on top of Material-UI, giving you extensive control over the look and feel of your payment flows.
|
|
4
4
|
|
|
5
|
-
## `PaymentThemeProvider`
|
|
5
|
+
## Overview of `PaymentThemeProvider`
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The library includes a dedicated `PaymentThemeProvider` that wraps all payment components. This provider establishes a default theme that inherits from the ArcBlock UX theme (`@arcblock/ux/lib/Theme`), ensuring visual consistency within the ArcBlock ecosystem. It also adds its own customizations, such as a special `chip` color palette and style overrides for various MUI components.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Here is a simplified look at how `PaymentThemeProvider` is structured:
|
|
10
10
|
|
|
11
|
-
```
|
|
12
|
-
|
|
11
|
+
```tsx src/theme/index.tsx icon=logos:react
|
|
12
|
+
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
|
13
|
+
import { create as createBlockletTheme, deepmerge } from '@arcblock/ux/lib/Theme';
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
export function PaymentThemeProvider({ children, theme: customTheme = {} }) {
|
|
16
|
+
const parentTheme = useTheme();
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"Parent MUI Theme" -> is_ab_theme
|
|
18
|
+
const mergeTheme = useMemo(() => {
|
|
19
|
+
// Start with the base blocklet theme
|
|
20
|
+
const blockletTheme = parentTheme.themeName === 'ArcBlock' ? parentTheme : createBlockletTheme();
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// Merge our custom payment theme options
|
|
23
|
+
let paymentThemeOptions = deepmerge(blockletTheme, {
|
|
24
|
+
// Custom palette extensions, e.g., for chips
|
|
25
|
+
palette: {
|
|
26
|
+
chip: { /* ... */ },
|
|
27
|
+
},
|
|
28
|
+
// Custom component style overrides
|
|
29
|
+
components: {
|
|
30
|
+
MuiButton: { /* ... */ },
|
|
31
|
+
MuiOutlinedInput: { /* ... */ },
|
|
32
|
+
// ... other components
|
|
33
|
+
},
|
|
34
|
+
});
|
|
24
35
|
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
// Merge any user-provided custom theme
|
|
37
|
+
paymentThemeOptions = deepmerge(paymentThemeOptions, customTheme);
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
create_new -> base_theme
|
|
39
|
+
return createTheme(paymentThemeOptions);
|
|
40
|
+
}, [parentTheme, customTheme]);
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
return (
|
|
43
|
+
<ThemeProvider theme={mergeTheme}>
|
|
44
|
+
<CssBaseline />
|
|
45
|
+
{children}
|
|
46
|
+
</ThemeProvider>
|
|
47
|
+
);
|
|
36
48
|
}
|
|
37
|
-
|
|
38
|
-
base_theme -> merge1
|
|
39
|
-
default_payment_styles -> merge1
|
|
40
|
-
|
|
41
|
-
user_customizations: "User's Customizations (from 'theme' prop)"
|
|
42
|
-
|
|
43
|
-
final_theme: "Final Merged Theme"
|
|
44
|
-
|
|
45
|
-
merge1 -> final_theme
|
|
46
|
-
user_customizations -> final_theme
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
##
|
|
50
|
-
|
|
51
|
-
You can customize the theme by passing a `theme` prop to payment components like `CheckoutForm`. This prop accepts a `PaymentThemeOptions` object, offering two primary methods for customization.
|
|
52
|
-
|
|
53
|
-
In the following examples, `useSessionContext` is a hook from your local session management setup. For more details on setting up the required context, please refer to the [PaymentProvider documentation](./providers-payment-provider.md).
|
|
51
|
+
## Customizing Component Styles
|
|
54
52
|
|
|
55
|
-
|
|
53
|
+
Since version 1.14.22, you can easily customize the theme for individual payment components by passing a `theme` prop. This prop accepts a Material-UI `ThemeOptions` object, giving you two primary ways to apply custom styles.
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
### 1. Using `styleOverrides`
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
For deep, structural changes, you can override the styles for specific Material-UI components within the payment component's scope. This is the standard MUI way of theming.
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
```tsx
|
|
59
|
+
```tsx Customizing the Primary Button icon=logos:react
|
|
64
60
|
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
65
|
-
import { useSessionContext } from '/
|
|
61
|
+
import { useSessionContext } from '@/hooks/session-context'; // Assuming session context is defined here
|
|
66
62
|
|
|
67
|
-
function
|
|
63
|
+
function CustomStyledCheckout() {
|
|
68
64
|
const { session, connectApi } = useSessionContext();
|
|
69
65
|
|
|
70
|
-
if (!session) {
|
|
71
|
-
return <div>Loading session...</div>;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
66
|
return (
|
|
75
67
|
<PaymentProvider session={session} connect={connectApi}>
|
|
76
68
|
<CheckoutForm
|
|
77
69
|
id="plink_xxx"
|
|
70
|
+
onChange={console.info}
|
|
78
71
|
theme={{
|
|
79
72
|
components: {
|
|
80
73
|
MuiButton: {
|
|
@@ -96,34 +89,28 @@ function CustomStyledForm() {
|
|
|
96
89
|
}
|
|
97
90
|
```
|
|
98
91
|
|
|
99
|
-
|
|
92
|
+
In this example, we target the primary contained button (`MuiButton.styleOverrides.containedPrimary`) and change its background and text color.
|
|
100
93
|
|
|
101
|
-
|
|
94
|
+
### 2. Using the `sx` Prop
|
|
102
95
|
|
|
103
|
-
|
|
96
|
+
For quick, targeted CSS changes, you can pass an `sx` object within the `theme` prop. This allows you to use CSS selectors to target specific elements within the component.
|
|
104
97
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
```tsx
|
|
98
|
+
```tsx Customizing with the sx Prop icon=logos:react
|
|
108
99
|
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
109
|
-
import { useSessionContext } from '/
|
|
100
|
+
import { useSessionContext } from '@/hooks/session-context';
|
|
110
101
|
|
|
111
|
-
function
|
|
102
|
+
function SxStyledCheckout() {
|
|
112
103
|
const { session, connectApi } = useSessionContext();
|
|
113
104
|
|
|
114
|
-
if (!session) {
|
|
115
|
-
return <div>Loading session...</div>;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
105
|
return (
|
|
119
106
|
<PaymentProvider session={session} connect={connectApi}>
|
|
120
107
|
<CheckoutForm
|
|
121
108
|
id="plink_xxx"
|
|
122
109
|
showCheckoutSummary={false}
|
|
110
|
+
onChange={console.info}
|
|
123
111
|
theme={{
|
|
124
112
|
sx: {
|
|
125
|
-
//
|
|
126
|
-
// Inspect the element in your browser to find the correct selector.
|
|
113
|
+
// Target the submit button by its specific class name
|
|
127
114
|
'.cko-submit-button': {
|
|
128
115
|
backgroundColor: '#1DC1C7',
|
|
129
116
|
color: '#fff',
|
|
@@ -137,39 +124,90 @@ function TargetedStyleForm() {
|
|
|
137
124
|
</PaymentProvider>
|
|
138
125
|
);
|
|
139
126
|
}
|
|
127
|
+
|
|
140
128
|
```
|
|
141
129
|
|
|
130
|
+
This method is useful when you need to override a style that isn't easily accessible through the standard component style overrides.
|
|
131
|
+
|
|
142
132
|
## Understanding the Default Theme
|
|
143
133
|
|
|
144
|
-
|
|
134
|
+
The default theme is built upon a system of CSS variables (Design Tokens) for colors, spacing, and typography, allowing for consistent styling across light and dark modes.
|
|
135
|
+
|
|
136
|
+
### Color Palette
|
|
145
137
|
|
|
146
|
-
|
|
138
|
+
The theme extends the standard Material-UI palette with a custom `chip` object to style status indicators. You can override these colors in your custom theme.
|
|
147
139
|
|
|
148
|
-
|
|
140
|
+
```ts src/theme/types.ts icon=mdi:language-typescript
|
|
141
|
+
declare module '@mui/material/styles' {
|
|
142
|
+
interface Palette {
|
|
143
|
+
chip: {
|
|
144
|
+
success: { text: string; background: string; border: string; };
|
|
145
|
+
default: { text: string; background: string; border: string; };
|
|
146
|
+
secondary: { text: string; background: string; border: string; };
|
|
147
|
+
error: { text: string; background: string; border: string; };
|
|
148
|
+
warning: { text: string; background: string; border: string; };
|
|
149
|
+
info: { text: string; background: string; border: string; };
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// ... PaletteOptions definition
|
|
153
|
+
}
|
|
154
|
+
```
|
|
149
155
|
|
|
150
|
-
|
|
151
|
-
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
152
|
-
| `palette.chip` | An object containing `text`, `background`, and `border` colors for different chip statuses: `success`, `default`, `secondary`, `error`, `warning`, and `info`. |
|
|
153
|
-
| `palette.text.lighter` | A lighter text color, typically mapped to `grey[400]`. |
|
|
154
|
-
| `palette.text.link` | The color for hyperlink text, mapped to `secondary.main`. |
|
|
156
|
+
### Design Tokens (CSS Variables)
|
|
155
157
|
|
|
156
|
-
|
|
158
|
+
For advanced, global customization, you can override the CSS variables that define the theme. These variables are defined for both light (`:root`) and dark (`[data-theme='dark']`) modes.
|
|
157
159
|
|
|
158
|
-
|
|
160
|
+
Here are some of the key variables you can target:
|
|
159
161
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
```css src/theme/index.css icon=logos:css-3
|
|
163
|
+
:root {
|
|
164
|
+
/* Light Theme */
|
|
165
|
+
--backgrounds-bg-base: #ffffff;
|
|
166
|
+
--backgrounds-bg-interactive: #3b82f6;
|
|
167
|
+
--foregrounds-fg-base: #030712;
|
|
168
|
+
--foregrounds-fg-interactive: #3b82f6;
|
|
169
|
+
--stroke-border-base: #eff1f5;
|
|
170
|
+
--radius-m: 0.5rem; /* 8px */
|
|
171
|
+
}
|
|
162
172
|
|
|
163
|
-
|
|
173
|
+
[data-theme='dark'] {
|
|
174
|
+
/* Dark Theme */
|
|
175
|
+
--backgrounds-bg-base: #1b1b1f;
|
|
176
|
+
--backgrounds-bg-interactive: #60a5fa;
|
|
177
|
+
--foregrounds-fg-base: #edeef0;
|
|
178
|
+
--foregrounds-fg-interactive: #60a5fa;
|
|
179
|
+
--stroke-border-base: #2e3035;
|
|
180
|
+
--radius-m: 0.5rem;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
164
183
|
|
|
165
|
-
|
|
184
|
+
Overriding these variables in your global stylesheet will apply changes across all `@blocklet/payment-react` components.
|
|
185
|
+
|
|
186
|
+
### Typography
|
|
187
|
+
|
|
188
|
+
The default typography settings can be found in `src/theme/typography.ts`. You can override any of these settings in your custom theme to match your application's typography.
|
|
189
|
+
|
|
190
|
+
```ts src/theme/typography.ts icon=mdi:language-typescript
|
|
191
|
+
export const typography = {
|
|
192
|
+
h1: {
|
|
193
|
+
fontSize: '1.5rem',
|
|
194
|
+
lineHeight: 1.2,
|
|
195
|
+
fontWeight: 800,
|
|
196
|
+
},
|
|
197
|
+
body1: {
|
|
198
|
+
fontSize: '0.875rem',
|
|
199
|
+
lineHeight: 1.75,
|
|
200
|
+
},
|
|
201
|
+
// ... other typography settings
|
|
202
|
+
};
|
|
203
|
+
```
|
|
166
204
|
|
|
167
|
-
|
|
168
|
-
| ------------------------ | ---------------- | --------------- |
|
|
169
|
-
| `--backgrounds-bg-base` | `#ffffff` | `#1b1b1f` |
|
|
170
|
-
| `--foregrounds-fg-base` | `#030712` | `#edeef0` |
|
|
171
|
-
| `--stroke-border-base` | `#eff1f5` | `#2e3035` |
|
|
205
|
+
By understanding these layers of customization, you can seamlessly integrate the payment components into your application with a consistent and polished design.
|
|
172
206
|
|
|
173
207
|
---
|
|
174
208
|
|
|
175
|
-
|
|
209
|
+
Next, explore the various utility functions that can help you with tasks like data caching and date formatting.
|
|
210
|
+
|
|
211
|
+
<x-card data-title="Next: Utilities" data-icon="lucide:wrench" data-href="/guides/utilities" data-cta="Read More">
|
|
212
|
+
A reference for utility functions provided by the library, including cached requests, and date formatting.
|
|
213
|
+
</x-card>
|