@blocklet/payment-react 1.20.4 → 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.
Files changed (55) hide show
  1. package/.aigne/doc-smith/config.yaml +2 -2
  2. package/.aigne/doc-smith/upload-cache.yaml +381 -0
  3. package/docs/components-business-auto-topup.md +128 -179
  4. package/docs/components-business-overdue-invoice-payment.md +108 -143
  5. package/docs/components-business-resume-subscription.md +117 -104
  6. package/docs/components-business.md +12 -36
  7. package/docs/components-checkout-checkout-donate.md +209 -149
  8. package/docs/components-checkout-checkout-form.md +115 -136
  9. package/docs/components-checkout-checkout-table.md +92 -172
  10. package/docs/components-checkout.md +43 -109
  11. package/docs/components-history-credit-grants-list.md +45 -70
  12. package/docs/components-history-credit-transactions-list.md +57 -67
  13. package/docs/components-history-invoice-list.md +58 -52
  14. package/docs/components-history-payment-list.md +19 -40
  15. package/docs/components-history.md +42 -67
  16. package/docs/components-ui-form-elements-address-form.md +37 -65
  17. package/docs/components-ui-form-elements-country-select.md +80 -59
  18. package/docs/components-ui-form-elements-currency-selector.md +57 -73
  19. package/docs/components-ui-form-elements-phone-input.md +90 -112
  20. package/docs/components-ui-form-elements.md +46 -80
  21. package/docs/components-ui-payment-summary.md +71 -119
  22. package/docs/components-ui-pricing-table.md +117 -204
  23. package/docs/components-ui.md +59 -32
  24. package/docs/components.md +89 -62
  25. package/docs/getting-started.md +36 -63
  26. package/docs/guides-theming.md +122 -84
  27. package/docs/guides-utilities.md +107 -145
  28. package/docs/guides.md +7 -84
  29. package/docs/hooks-use-mobile.md +50 -36
  30. package/docs/hooks-use-subscription.md +72 -89
  31. package/docs/hooks.md +12 -82
  32. package/docs/overview.md +45 -52
  33. package/docs/providers-donate-provider.md +73 -95
  34. package/docs/providers-payment-provider.md +115 -169
  35. package/docs/providers.md +27 -86
  36. package/es/locales/en.js +7 -0
  37. package/es/locales/zh.js +8 -1
  38. package/es/payment/index.js +3 -0
  39. package/es/payment/progress-item.d.ts +12 -0
  40. package/es/payment/progress-item.js +78 -0
  41. package/es/payment/success.d.ts +4 -1
  42. package/es/payment/success.js +55 -3
  43. package/lib/locales/en.js +7 -0
  44. package/lib/locales/zh.js +8 -1
  45. package/lib/payment/index.js +3 -0
  46. package/lib/payment/progress-item.d.ts +12 -0
  47. package/lib/payment/progress-item.js +107 -0
  48. package/lib/payment/success.d.ts +4 -1
  49. package/lib/payment/success.js +59 -3
  50. package/package.json +7 -7
  51. package/src/locales/en.tsx +7 -0
  52. package/src/locales/zh.tsx +8 -1
  53. package/src/payment/index.tsx +6 -0
  54. package/src/payment/progress-item.tsx +107 -0
  55. package/src/payment/success.tsx +88 -3
@@ -1,95 +1,122 @@
1
1
  # Components
2
2
 
3
- The `@blocklet/payment-react` library provides a comprehensive suite of pre-built React components designed to accelerate the development of payment, subscription, and donation features. These components are organized into logical categories to help you find the right tool for your specific use case, from high-level, all-in-one solutions to granular UI building blocks.
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 be composable and customizable, ensuring they can fit seamlessly into your application's design and logic.
5
+ All components are designed to work seamlessly within the `PaymentProvider` context, which handles state management and API communication.
6
6
 
7
- ### Component Architecture
7
+ ## Component Architecture
8
8
 
9
- The components are structured into distinct categories based on their functionality. This modular approach allows you to import only what you need and gives you a clear path for building your payment interfaces.
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
- "@blocklet/payment-react": {
15
- shape: package
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
- "UI Components": {
25
- tooltip: "Granular building blocks for custom UIs"
26
- "PricingTable": {}
27
- "AddressForm": {}
28
- "PaymentSummary": {}
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
- "Business Logic Components": {
32
- tooltip: "Components for specific business scenarios"
33
- "ResumeSubscription": {}
34
- "OverdueInvoicePayment": {}
35
- "AutoTopup": {}
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
- "History Components": {
39
- tooltip: "Components for displaying historical data"
40
- "CustomerInvoiceList": {}
41
- "CustomerPaymentList": {}
42
- "CreditGrantsList": {}
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
- ### Provider Requirements
56
+ ## Component Categories
48
57
 
49
- A critical concept to understand is that almost all components in this library must be wrapped within a `PaymentProvider` to function correctly. This provider supplies the necessary context, such as the user session and API connection details. Specific components, like `CheckoutDonate`, require an additional `DonateProvider`.
58
+ Explore our component categories to find the building blocks you need.
50
59
 
51
- Before using any components, ensure your application is set up with the required context providers.
60
+ ### Checkout Components
52
61
 
53
- ```tsx
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
- function App() {
59
- // Fetch session and connectApi from your application's context.
60
- const { session, connectApi } = useSessionContext();
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
- return (
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
- In the examples throughout this documentation, `useSessionContext` is a placeholder for your application's own hook for managing user sessions. For a complete guide on how to set up the `PaymentProvider` and create a session context, please refer to the [PaymentProvider](./providers-payment-provider.md) documentation.
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
- ## Component Categories
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
- Dive into the component categories to find the tools you need for your project. Each section provides detailed documentation and usage examples.
92
+ ### Business Logic Components
77
93
 
78
- <x-cards data-columns="2">
79
- <x-card data-title="Checkout Components" data-icon="lucide:shopping-cart" data-href="/components/checkout">
80
- High-level components that encapsulate entire payment flows. The fastest way to integrate standard checkouts, pricing plan selections, and donation widgets.
81
- </x-card>
82
- <x-card data-title="UI Components" data-icon="lucide:layout-template" data-href="/components/ui">
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="Business Logic Components" data-icon="lucide:briefcase" data-href="/components/business">
86
- Handle specific, complex business scenarios like resuming subscriptions, paying overdue invoices, or configuring automatic credit top-ups.
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="History Components" data-icon="lucide:history" data-href="/components/history">
89
- Display historical user data such as past invoices, payment lists, and credit grant histories for account management pages.
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
- ## Next Steps
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
- Now that you have an overview of the component categories, you can explore the specific documentation for the components that fit your needs. If you're looking for the fastest integration path, we recommend starting with the [Checkout Components](./components-checkout.md).
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>
@@ -1,111 +1,84 @@
1
1
  # Getting Started
2
2
 
3
- This guide provides a step-by-step walkthrough to get you up and running with `@blocklet/payment-react`. You will learn how to install the library, set up the essential `PaymentProvider`, and render your first payment form using the `CheckoutForm` component.
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. Installation
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. Set up PaymentProvider
13
+ ## Step 2: Set Up the PaymentProvider
14
14
 
15
- Most components in `@blocklet/payment-react` require access to payment context, such as user session information and API configuration. The `PaymentProvider` component provides this context to all its children. You should wrap it around the root of your application or at least the section that handles payments.
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
- To supply the necessary `session` and `connectApi` props, you should create a local session context using `@arcblock/did-connect-react`. This allows you to access authentication state throughout your app.
17
+ It requires a `session` object and a `connect` API function from your application's authentication context to work correctly.
18
18
 
19
- For a detailed guide on creating your `useSessionContext` hook, please refer to the [PaymentProvider documentation](./providers-payment-provider.md).
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
- import { useSessionContext } from '../path/to/your/session-context'; // Your local session context
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
- The relationship between the provider and the components it wraps can be visualized as follows:
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
- "Your App.PaymentProvider" -> "Your App.PaymentProvider.CheckoutForm": "Provides context (session, API)"
58
- "Your App.PaymentProvider" -> "Your App.PaymentProvider.Other Components": "Provides context (session, API)"
59
- ```
39
+ ## Step 3: Add a CheckoutForm
60
40
 
61
- ## 3. Add a Checkout Form
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
- The `CheckoutForm` is the primary component for building a payment flow. It renders a complete payment interface based on a `paymentLink` ID (prefixed with `plink_`) or a `checkoutSession` ID (prefixed with `cs_`) that you create in your payment service backend.
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
- ## 4. Complete Example
45
+ ## Complete Example
66
46
 
67
- This example combines the `PaymentProvider` and `CheckoutForm` to create a minimal, functional payment page. It uses the `useSessionContext` hook to provide the necessary authentication context.
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
- // This import points to your local session context implementation.
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
- // It's good practice to ensure the session is loaded before rendering payment components.
81
- if (!session || !session.user) {
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="plink_xxx" // IMPORTANT: Replace with your actual Payment Link ID
89
- mode="inline" // Embeds the form directly in your UI
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={() => alert('Payment Successful!')}
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 MyPaymentPage;
73
+ export default PaymentPage;
100
74
  ```
101
75
 
102
- In this example:
103
- - We wrap `CheckoutForm` with `PaymentProvider` to provide the necessary context, obtained from our `useSessionContext` hook.
104
- - The `id` prop is set to a Payment Link ID. This is **required**.
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
- ## 5. Next Steps
80
+ Congratulations! You've successfully integrated your first payment form. Now you're ready to explore more advanced features and components.
110
81
 
111
- You have now successfully integrated a basic payment form. To learn more about configuring the context for your payment components, see the [Providers](./providers.md) section. To explore the full range of available UI and business logic components, head over to the [Components](./components.md) documentation.
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.
@@ -1,80 +1,73 @@
1
1
  # Theming
2
2
 
3
- The `@blocklet/payment-react` library is built on Material-UI and includes a dedicated theme provider, `PaymentThemeProvider`, to ensure a consistent and polished look across all components. This guide explains how to customize the default theme to match your application's design system.
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
- Most components in the library, such as `CheckoutForm`, are internally wrapped with `PaymentThemeProvider`. This provider establishes a cohesive visual foundation by extending ArcBlock's base theme with styles tailored for payment UIs. It defines a specific color palette, typography scale, and default styles for various MUI components.
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
- The theme merging process follows a clear hierarchy to combine the base theme, default payment styles, and your custom overrides.
9
+ Here is a simplified look at how `PaymentThemeProvider` is structured:
10
10
 
11
- ```d2
12
- direction: down
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
- "Parent MUI Theme"
15
+ export function PaymentThemeProvider({ children, theme: customTheme = {} }) {
16
+ const parentTheme = useTheme();
15
17
 
16
- is_ab_theme: "Is it an ArcBlock Theme?" {
17
- shape: diamond
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
- use_parent: "Use Parent Theme as Base"
23
- create_new: "Create New BlockletTheme as Base"
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
- is_ab_theme -> use_parent: "Yes"
26
- is_ab_theme -> create_new: "No"
36
+ // Merge any user-provided custom theme
37
+ paymentThemeOptions = deepmerge(paymentThemeOptions, customTheme);
27
38
 
28
- base_theme: "Base Theme"
29
- use_parent -> base_theme
30
- create_new -> base_theme
39
+ return createTheme(paymentThemeOptions);
40
+ }, [parentTheme, customTheme]);
31
41
 
32
- default_payment_styles: "Default Payment Component Styles"
33
-
34
- merge1: "Merge with Base Theme" {
35
- shape: oval
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
- ## Customization Methods
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
- ### 1. Overriding Component Styles
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
- To modify the default styles of underlying Material-UI components, provide a `components` object in your theme configuration. This object follows the standard MUI `styleOverrides` structure and will be deeply merged with the default payment theme.
55
+ ### 1. Using `styleOverrides`
58
56
 
59
- This method is ideal for making consistent changes to components like buttons, inputs, and chips across the payment UI.
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
- **Example: Changing the Primary Button Color**
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 '/path/to/your/session/context'; // This path is specific to your project
61
+ import { useSessionContext } from '@/hooks/session-context'; // Assuming session context is defined here
66
62
 
67
- function CustomStyledForm() {
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
- ### 2. Using the `sx` Prop for Targeted Overrides
92
+ In this example, we target the primary contained button (`MuiButton.styleOverrides.containedPrimary`) and change its background and text color.
100
93
 
101
- For more specific, one-off style adjustments, you can use the `sx` property within the `theme` object. This applies CSS directly to the component's wrapper element, allowing you to use class selectors to target nested elements.
94
+ ### 2. Using the `sx` Prop
102
95
 
103
- This approach is useful when you need to style a specific element that doesn't have a direct `styleOverrides` entry or when you want to apply a quick fix without altering the global theme configuration.
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
- **Example: Customizing the Submit Button**
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 '/path/to/your/session/context'; // This path is specific to your project
100
+ import { useSessionContext } from '@/hooks/session-context';
110
101
 
111
- function TargetedStyleForm() {
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
- // Note: The specific class name may vary.
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
- To customize effectively, it's helpful to know what the default theme provides. The `PaymentThemeProvider` includes several key customizations.
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
- ### Custom Palette Extensions
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
- The theme extends the standard MUI palette with additional colors for specific UI elements.
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
- | Palette Key | Description |
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
- ### Global CSS Classes
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
- The theme injects several global utility classes via `MuiCssBaseline` that you can use for styling consistency.
160
+ Here are some of the key variables you can target:
159
161
 
160
- - **`.base-card`**: Applies standard padding, border-radius, background, border, and shadow for card-like containers.
161
- - **`.base-label`**: A standard style for form labels and other descriptive text.
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
- ### CSS Variables for Light & Dark Modes
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
- The entire color system is built upon a set of CSS variables that automatically adapt to light and dark modes. While you can override component styles directly, understanding this foundation helps explain the theme's adaptability.
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
- | Variable | Light Mode Value | Dark Mode Value |
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
- Now that you understand how to customize the visual appearance of components, you may want to explore the utility functions that can help with data formatting and API requests. For more information, see the [Utilities](./guides-utilities.md) guide.
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>