@blocklet/payment-react 1.20.16 → 1.20.18
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 +7 -1
- package/.aigne/doc-smith/upload-cache.yaml +441 -0
- package/docs/components-business-auto-topup.ja.md +187 -0
- package/docs/components-business-auto-topup.zh-TW.md +187 -0
- package/docs/components-business-auto-topup.zh.md +187 -0
- package/docs/components-business-overdue-invoice-payment.ja.md +196 -0
- package/docs/components-business-overdue-invoice-payment.zh-TW.md +197 -0
- package/docs/components-business-overdue-invoice-payment.zh.md +197 -0
- package/docs/components-business-resume-subscription.ja.md +190 -0
- package/docs/components-business-resume-subscription.zh-TW.md +190 -0
- package/docs/components-business-resume-subscription.zh.md +190 -0
- package/docs/components-business.ja.md +21 -0
- package/docs/components-business.zh-TW.md +21 -0
- package/docs/components-business.zh.md +21 -0
- package/docs/components-checkout-checkout-donate.ja.md +259 -0
- package/docs/components-checkout-checkout-donate.zh-TW.md +259 -0
- package/docs/components-checkout-checkout-donate.zh.md +259 -0
- package/docs/components-checkout-checkout-form.ja.md +163 -0
- package/docs/components-checkout-checkout-form.zh-TW.md +163 -0
- package/docs/components-checkout-checkout-form.zh.md +163 -0
- package/docs/components-checkout-checkout-table.ja.md +148 -0
- package/docs/components-checkout-checkout-table.zh-TW.md +148 -0
- package/docs/components-checkout-checkout-table.zh.md +149 -0
- package/docs/components-checkout.ja.md +65 -0
- package/docs/components-checkout.zh-TW.md +65 -0
- package/docs/components-checkout.zh.md +65 -0
- package/docs/components-history-credit-grants-list.ja.md +73 -0
- package/docs/components-history-credit-grants-list.zh-TW.md +73 -0
- package/docs/components-history-credit-grants-list.zh.md +73 -0
- package/docs/components-history-credit-transactions-list.ja.md +106 -0
- package/docs/components-history-credit-transactions-list.zh-TW.md +106 -0
- package/docs/components-history-credit-transactions-list.zh.md +106 -0
- package/docs/components-history-invoice-list.ja.md +110 -0
- package/docs/components-history-invoice-list.zh-TW.md +110 -0
- package/docs/components-history-invoice-list.zh.md +110 -0
- package/docs/components-history-payment-list.ja.md +44 -0
- package/docs/components-history-payment-list.zh-TW.md +44 -0
- package/docs/components-history-payment-list.zh.md +44 -0
- package/docs/components-history.ja.md +67 -0
- package/docs/components-history.zh-TW.md +67 -0
- package/docs/components-history.zh.md +67 -0
- package/docs/components-ui-form-elements-address-form.ja.md +121 -0
- package/docs/components-ui-form-elements-address-form.zh-TW.md +121 -0
- package/docs/components-ui-form-elements-address-form.zh.md +121 -0
- package/docs/components-ui-form-elements-country-select.ja.md +126 -0
- package/docs/components-ui-form-elements-country-select.zh-TW.md +126 -0
- package/docs/components-ui-form-elements-country-select.zh.md +126 -0
- package/docs/components-ui-form-elements-currency-selector.ja.md +108 -0
- package/docs/components-ui-form-elements-currency-selector.zh-TW.md +108 -0
- package/docs/components-ui-form-elements-currency-selector.zh.md +108 -0
- package/docs/components-ui-form-elements-phone-input.ja.md +138 -0
- package/docs/components-ui-form-elements-phone-input.zh-TW.md +138 -0
- package/docs/components-ui-form-elements-phone-input.zh.md +139 -0
- package/docs/components-ui-form-elements.ja.md +91 -0
- package/docs/components-ui-form-elements.zh-TW.md +91 -0
- package/docs/components-ui-form-elements.zh.md +91 -0
- package/docs/components-ui-payment-summary.ja.md +109 -0
- package/docs/components-ui-payment-summary.zh-TW.md +109 -0
- package/docs/components-ui-payment-summary.zh.md +109 -0
- package/docs/components-ui-pricing-table.ja.md +140 -0
- package/docs/components-ui-pricing-table.zh-TW.md +140 -0
- package/docs/components-ui-pricing-table.zh.md +140 -0
- package/docs/components-ui.ja.md +71 -0
- package/docs/components-ui.zh-TW.md +71 -0
- package/docs/components-ui.zh.md +71 -0
- package/docs/components.ja.md +122 -0
- package/docs/components.zh-TW.md +122 -0
- package/docs/components.zh.md +122 -0
- package/docs/getting-started.ja.md +84 -0
- package/docs/getting-started.zh-TW.md +84 -0
- package/docs/getting-started.zh.md +84 -0
- package/docs/guides-theming.ja.md +213 -0
- package/docs/guides-theming.zh-TW.md +213 -0
- package/docs/guides-theming.zh.md +213 -0
- package/docs/guides-utilities.ja.md +197 -0
- package/docs/guides-utilities.zh-TW.md +197 -0
- package/docs/guides-utilities.zh.md +197 -0
- package/docs/guides.ja.md +18 -0
- package/docs/guides.zh-TW.md +18 -0
- package/docs/guides.zh.md +18 -0
- package/docs/hooks-use-mobile.ja.md +84 -0
- package/docs/hooks-use-mobile.zh-TW.md +84 -0
- package/docs/hooks-use-mobile.zh.md +84 -0
- package/docs/hooks-use-subscription.ja.md +111 -0
- package/docs/hooks-use-subscription.zh-TW.md +111 -0
- package/docs/hooks-use-subscription.zh.md +110 -0
- package/docs/hooks.ja.md +14 -0
- package/docs/hooks.zh-TW.md +14 -0
- package/docs/hooks.zh.md +14 -0
- package/docs/overview.ja.md +80 -0
- package/docs/overview.zh-TW.md +80 -0
- package/docs/overview.zh.md +80 -0
- package/docs/providers-donate-provider.ja.md +153 -0
- package/docs/providers-donate-provider.zh-TW.md +153 -0
- package/docs/providers-donate-provider.zh.md +153 -0
- package/docs/providers-payment-provider.ja.md +191 -0
- package/docs/providers-payment-provider.zh-TW.md +191 -0
- package/docs/providers-payment-provider.zh.md +191 -0
- package/docs/providers.ja.md +42 -0
- package/docs/providers.zh-TW.md +42 -0
- package/docs/providers.zh.md +42 -0
- package/package.json +3 -3
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# テーマ設定
|
|
2
|
+
|
|
3
|
+
組み込みのテーマプロバイダーとMaterial-UIのテーマオプションを使用して、支払いコンポーネントの外観をカスタマイズする方法を学びます。`@blocklet/payment-react`ライブラリはMaterial-UIを基盤に構築されており、支払いフローのルックアンドフィールを広範囲にわたって制御できます。
|
|
4
|
+
|
|
5
|
+
## `PaymentThemeProvider`の概要
|
|
6
|
+
|
|
7
|
+
このライブラリには、すべての支払いコンポーネントをラップする専用の`PaymentThemeProvider`が含まれています。このプロバイダーは、ArcBlock UXテーマ(`@arcblock/ux/lib/Theme`)から継承したデフォルトテーマを確立し、ArcBlockエコシステム内での視覚的な一貫性を保証します。また、特別な`chip`カラーパレットやさまざまなMUIコンポーネントのスタイルオーバーライドなど、独自のカスタマイズも追加します。
|
|
8
|
+
|
|
9
|
+
`PaymentThemeProvider`の構造を簡略化したものを以下に示します:
|
|
10
|
+
|
|
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';
|
|
14
|
+
|
|
15
|
+
export function PaymentThemeProvider({ children, theme: customTheme = {} }) {
|
|
16
|
+
const parentTheme = useTheme();
|
|
17
|
+
|
|
18
|
+
const mergeTheme = useMemo(() => {
|
|
19
|
+
// Start with the base blocklet theme
|
|
20
|
+
const blockletTheme = parentTheme.themeName === 'ArcBlock' ? parentTheme : createBlockletTheme();
|
|
21
|
+
|
|
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
|
+
});
|
|
35
|
+
|
|
36
|
+
// Merge any user-provided custom theme
|
|
37
|
+
paymentThemeOptions = deepmerge(paymentThemeOptions, customTheme);
|
|
38
|
+
|
|
39
|
+
return createTheme(paymentThemeOptions);
|
|
40
|
+
}, [parentTheme, customTheme]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<ThemeProvider theme={mergeTheme}>
|
|
44
|
+
<CssBaseline />
|
|
45
|
+
{children}
|
|
46
|
+
</ThemeProvider>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## コンポーネントスタイルのカスタマイズ
|
|
52
|
+
|
|
53
|
+
バージョン1.14.22以降、`theme`プロパティを渡すことで、個々の支払いコンポーネントのテーマを簡単にカスタマイズできます。このプロパティはMaterial-UIの`ThemeOptions`オブジェクトを受け入れ、カスタムスタイルを適用するための2つの主要な方法を提供します。
|
|
54
|
+
|
|
55
|
+
### 1. `styleOverrides`の使用
|
|
56
|
+
|
|
57
|
+
詳細な構造的変更を行うには、支払いコンポーネントのスコープ内で特定のMaterial-UIコンポーネントのスタイルをオーバーライドできます。これは、テーマ設定の標準的なMUIの方法です。
|
|
58
|
+
|
|
59
|
+
```tsx プライマリーボタンのカスタマイズ icon=logos:react
|
|
60
|
+
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
61
|
+
import { useSessionContext } from '@/hooks/session-context'; // Assuming session context is defined here
|
|
62
|
+
|
|
63
|
+
function CustomStyledCheckout() {
|
|
64
|
+
const { session, connectApi } = useSessionContext();
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<PaymentProvider session={session} connect={connectApi}>
|
|
68
|
+
<CheckoutForm
|
|
69
|
+
id="plink_xxx"
|
|
70
|
+
onChange={console.info}
|
|
71
|
+
theme={{
|
|
72
|
+
components: {
|
|
73
|
+
MuiButton: {
|
|
74
|
+
styleOverrides: {
|
|
75
|
+
containedPrimary: {
|
|
76
|
+
backgroundColor: '#1DC1C7',
|
|
77
|
+
color: '#fff',
|
|
78
|
+
'&:hover': {
|
|
79
|
+
backgroundColor: 'rgb(20, 135, 139)',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
</PaymentProvider>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
この例では、プライマリーのcontainedボタン(`MuiButton.styleOverrides.containedPrimary`)をターゲットにし、その背景色とテキスト色を変更しています。
|
|
93
|
+
|
|
94
|
+
### 2. `sx`プロパティの使用
|
|
95
|
+
|
|
96
|
+
手早く、特定のCSS変更を行うには、`theme`プロパティ内に`sx`オブジェクトを渡すことができます。これにより、CSSセレクターを使用してコンポーネント内の特定の要素をターゲットにできます。
|
|
97
|
+
|
|
98
|
+
```tsx sxプロパティでのカスタマイズ icon=logos:react
|
|
99
|
+
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
100
|
+
import { useSessionContext } from '@/hooks/session-context';
|
|
101
|
+
|
|
102
|
+
function SxStyledCheckout() {
|
|
103
|
+
const { session, connectApi } = useSessionContext();
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<PaymentProvider session={session} connect={connectApi}>
|
|
107
|
+
<CheckoutForm
|
|
108
|
+
id="plink_xxx"
|
|
109
|
+
showCheckoutSummary={false}
|
|
110
|
+
onChange={console.info}
|
|
111
|
+
theme={{
|
|
112
|
+
sx: {
|
|
113
|
+
// Target the submit button by its specific class name
|
|
114
|
+
'.cko-submit-button': {
|
|
115
|
+
backgroundColor: '#1DC1C7',
|
|
116
|
+
color: '#fff',
|
|
117
|
+
'&:hover': {
|
|
118
|
+
backgroundColor: 'rgb(20, 135, 139)',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
</PaymentProvider>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
この方法は、標準のコンポーネントスタイルオーバーライドでは簡単にアクセスできないスタイルをオーバーライドする必要がある場合に便利です。
|
|
131
|
+
|
|
132
|
+
## デフォルトテーマの理解
|
|
133
|
+
|
|
134
|
+
デフォルトテーマは、色、スペーシング、タイポグラフィのためのCSS変数(デザイントークン)のシステム上に構築されており、ライトモードとダークモードで一貫したスタイリングを可能にします。
|
|
135
|
+
|
|
136
|
+
### カラーパレット
|
|
137
|
+
|
|
138
|
+
このテーマは、標準のMaterial-UIパレットをカスタム`chip`オブジェクトで拡張し、ステータスインジケーターのスタイルを設定します。これらの色はカスタムテーマでオーバーライドできます。
|
|
139
|
+
|
|
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
|
+
```
|
|
155
|
+
|
|
156
|
+
### デザイントークン(CSS変数)
|
|
157
|
+
|
|
158
|
+
高度なグローバルカスタマイズを行うには、テーマを定義するCSS変数をオーバーライドできます。これらの変数は、ライト(`:root`)モードとダーク(`[data-theme='dark']`)モードの両方で定義されています。
|
|
159
|
+
|
|
160
|
+
以下に、ターゲットにできる主要な変数をいくつか示します:
|
|
161
|
+
|
|
162
|
+
```css src/theme/index.css icon=logos:css-3
|
|
163
|
+
:root {
|
|
164
|
+
/* ライトテーマ */
|
|
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
|
+
}
|
|
172
|
+
|
|
173
|
+
[data-theme='dark'] {
|
|
174
|
+
/* ダークテーマ */
|
|
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
|
+
```
|
|
183
|
+
|
|
184
|
+
グローバルスタイルシートでこれらの変数をオーバーライドすると、すべての`@blocklet/payment-react`コンポーネントに変更が適用されます。
|
|
185
|
+
|
|
186
|
+
### タイポグラフィ
|
|
187
|
+
|
|
188
|
+
デフォルトのタイポグラフィ設定は`src/theme/typography.ts`にあります。アプリケーションのタイポグラフィに合わせて、これらの設定をカスタムテーマでオーバーライドできます。
|
|
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
|
+
```
|
|
204
|
+
|
|
205
|
+
これらのカスタマイズのレイヤーを理解することで、支払いコンポーネントをアプリケーションに一貫性のある洗練されたデザインでシームレスに統合できます。
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
次に、データキャッシングや日付フォーマットなどのタスクに役立つさまざまなユーティリティ関数について見ていきましょう。
|
|
210
|
+
|
|
211
|
+
<x-card data-title="次へ: ユーティリティ" data-icon="lucide:wrench" data-href="/guides/utilities" data-cta="続きを読む">
|
|
212
|
+
ライブラリが提供するユーティリティ関数のリファレンス。キャッシュされたリクエストや日付フォーマットなどが含まれます。
|
|
213
|
+
</x-card>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# 主題化
|
|
2
|
+
|
|
3
|
+
了解如何使用內建的主題提供者和 Material-UI 主題選項來自訂支付元件的外觀。`@blocklet/payment-react` 函式庫建立在 Material-UI 之上,讓您對支付流程的外觀和風格有廣泛的控制權。
|
|
4
|
+
|
|
5
|
+
## `PaymentThemeProvider` 概覽
|
|
6
|
+
|
|
7
|
+
該函式庫包含一個專用的 `PaymentThemeProvider`,它包裝了所有支付元件。此提供者建立了一個預設主題,該主題繼承自 ArcBlock UX 主題 (`@arcblock/ux/lib/Theme`),確保在 ArcBlock 生態系統中的視覺一致性。它還添加了自己的自訂功能,例如特殊的 `chip` 調色盤和對各種 MUI 元件的樣式覆寫。
|
|
8
|
+
|
|
9
|
+
以下是 `PaymentThemeProvider` 結構的簡化視圖:
|
|
10
|
+
|
|
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';
|
|
14
|
+
|
|
15
|
+
export function PaymentThemeProvider({ children, theme: customTheme = {} }) {
|
|
16
|
+
const parentTheme = useTheme();
|
|
17
|
+
|
|
18
|
+
const mergeTheme = useMemo(() => {
|
|
19
|
+
// Start with the base blocklet theme
|
|
20
|
+
const blockletTheme = parentTheme.themeName === 'ArcBlock' ? parentTheme : createBlockletTheme();
|
|
21
|
+
|
|
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
|
+
});
|
|
35
|
+
|
|
36
|
+
// Merge any user-provided custom theme
|
|
37
|
+
paymentThemeOptions = deepmerge(paymentThemeOptions, customTheme);
|
|
38
|
+
|
|
39
|
+
return createTheme(paymentThemeOptions);
|
|
40
|
+
}, [parentTheme, customTheme]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<ThemeProvider theme={mergeTheme}>
|
|
44
|
+
<CssBaseline />
|
|
45
|
+
{children}
|
|
46
|
+
</ThemeProvider>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 自訂元件樣式
|
|
52
|
+
|
|
53
|
+
自 1.14.22 版本起,您可以透過傳遞 `theme` 屬性輕鬆地為單個支付元件自訂主題。此屬性接受一個 Material-UI `ThemeOptions` 物件,為您提供了兩種主要方式來應用自訂樣式。
|
|
54
|
+
|
|
55
|
+
### 1. 使用 `styleOverrides`
|
|
56
|
+
|
|
57
|
+
對於深層的、結構性的變更,您可以在支付元件的範圍內覆寫特定 Material-UI 元件的樣式。這是標準的 MUI 主題化方式。
|
|
58
|
+
|
|
59
|
+
```tsx Customizing the Primary Button icon=logos:react
|
|
60
|
+
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
61
|
+
import { useSessionContext } from '@/hooks/session-context'; // 假設 session context 在此定義
|
|
62
|
+
|
|
63
|
+
function CustomStyledCheckout() {
|
|
64
|
+
const { session, connectApi } = useSessionContext();
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<PaymentProvider session={session} connect={connectApi}>
|
|
68
|
+
<CheckoutForm
|
|
69
|
+
id="plink_xxx"
|
|
70
|
+
onChange={console.info}
|
|
71
|
+
theme={{
|
|
72
|
+
components: {
|
|
73
|
+
MuiButton: {
|
|
74
|
+
styleOverrides: {
|
|
75
|
+
containedPrimary: {
|
|
76
|
+
backgroundColor: '#1DC1C7',
|
|
77
|
+
color: '#fff',
|
|
78
|
+
'&:hover': {
|
|
79
|
+
backgroundColor: 'rgb(20, 135, 139)',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
</PaymentProvider>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
在此範例中,我們鎖定主要包含按鈕 (`MuiButton.styleOverrides.containedPrimary`) 並更改其背景和文字顏色。
|
|
93
|
+
|
|
94
|
+
### 2. 使用 `sx` 屬性
|
|
95
|
+
|
|
96
|
+
對於快速、有針對性的 CSS 變更,您可以在 `theme` 屬性中傳遞一個 `sx` 物件。這允許您使用 CSS 選擇器來鎖定元件內的特定元素。
|
|
97
|
+
|
|
98
|
+
```tsx Customizing with the sx Prop icon=logos:react
|
|
99
|
+
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
100
|
+
import { useSessionContext } from '@/hooks/session-context';
|
|
101
|
+
|
|
102
|
+
function SxStyledCheckout() {
|
|
103
|
+
const { session, connectApi } = useSessionContext();
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<PaymentProvider session={session} connect={connectApi}>
|
|
107
|
+
<CheckoutForm
|
|
108
|
+
id="plink_xxx"
|
|
109
|
+
showCheckoutSummary={false}
|
|
110
|
+
onChange={console.info}
|
|
111
|
+
theme={{
|
|
112
|
+
sx: {
|
|
113
|
+
// Target the submit button by its specific class name
|
|
114
|
+
'.cko-submit-button': {
|
|
115
|
+
backgroundColor: '#1DC1C7',
|
|
116
|
+
color: '#fff',
|
|
117
|
+
'&:hover': {
|
|
118
|
+
backgroundColor: 'rgb(20, 135, 139)',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
</PaymentProvider>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
當您需要覆寫一個透過標準元件樣式覆寫不易存取的樣式時,此方法非常有用。
|
|
131
|
+
|
|
132
|
+
## 理解預設主題
|
|
133
|
+
|
|
134
|
+
預設主題建立在一套用於顏色、間距和排版的 CSS 變數(設計權杖)系統之上,允許在淺色和深色模式下實現一致的樣式。
|
|
135
|
+
|
|
136
|
+
### 調色盤
|
|
137
|
+
|
|
138
|
+
該主題擴展了標準的 Material-UI 調色盤,增加了一個自訂的 `chip` 物件來為狀態指示器設定樣式。您可以在您的自訂主題中覆寫這些顏色。
|
|
139
|
+
|
|
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
|
+
```
|
|
155
|
+
|
|
156
|
+
### 設計權杖(CSS 變數)
|
|
157
|
+
|
|
158
|
+
對於進階的全域自訂,您可以覆寫定義主題的 CSS 變數。這些變數為淺色(`:root`)和深色(`[data-theme='dark']`)模式都進行了定義。
|
|
159
|
+
|
|
160
|
+
以下是您可以鎖定的一些關鍵變數:
|
|
161
|
+
|
|
162
|
+
```css src/theme/index.css icon=logos:css-3
|
|
163
|
+
:root {
|
|
164
|
+
/* 淺色主題 */
|
|
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
|
+
}
|
|
172
|
+
|
|
173
|
+
[data-theme='dark'] {
|
|
174
|
+
/* 深色主題 */
|
|
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
|
+
```
|
|
183
|
+
|
|
184
|
+
在您的全域樣式表中覆寫這些變數,將會對所有 `@blocklet/payment-react` 元件應用變更。
|
|
185
|
+
|
|
186
|
+
### 排版
|
|
187
|
+
|
|
188
|
+
預設的排版設定可以在 `src/theme/typography.ts` 中找到。您可以在您的自訂主題中覆寫任何這些設定,以匹配您應用程式的排版。
|
|
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
|
+
```
|
|
204
|
+
|
|
205
|
+
透過理解這些自訂層次,您可以將支付元件無縫整合到您的應用程式中,並實現一致且精緻的設計。
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
接下來,探索各種實用工具函式,這些函式可以幫助您處理資料快取和日期格式化等任務。
|
|
210
|
+
|
|
211
|
+
<x-card data-title="下一步:實用工具" data-icon="lucide:wrench" data-href="/guides/utilities" data-cta="閱讀更多">
|
|
212
|
+
該函式庫提供的實用工具函式參考,包括快取請求和日期格式化。
|
|
213
|
+
</x-card>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# 主题化
|
|
2
|
+
|
|
3
|
+
了解如何使用内置的主题提供器和 Material-UI 主题选项来自定义支付组件的外观。`@blocklet/payment-react` 库基于 Material-UI 构建,让您能够广泛地控制支付流程的观感。
|
|
4
|
+
|
|
5
|
+
## `PaymentThemeProvider` 概览
|
|
6
|
+
|
|
7
|
+
该库包含一个专用的 `PaymentThemeProvider`,它包裹了所有支付组件。此提供器建立了一个默认主题,该主题继承自 ArcBlock UX 主题 (`@arcblock/ux/lib/Theme`),以确保在 ArcBlock 生态系统内的视觉一致性。它还添加了自己的自定义项,例如一个特殊的 `chip` 调色板和对各种 MUI 组件的样式覆盖。
|
|
8
|
+
|
|
9
|
+
以下是 `PaymentThemeProvider` 结构的简化示例:
|
|
10
|
+
|
|
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';
|
|
14
|
+
|
|
15
|
+
export function PaymentThemeProvider({ children, theme: customTheme = {} }) {
|
|
16
|
+
const parentTheme = useTheme();
|
|
17
|
+
|
|
18
|
+
const mergeTheme = useMemo(() => {
|
|
19
|
+
// 从基础 blocklet 主题开始
|
|
20
|
+
const blockletTheme = parentTheme.themeName === 'ArcBlock' ? parentTheme : createBlockletTheme();
|
|
21
|
+
|
|
22
|
+
// 合并我们的自定义支付主题选项
|
|
23
|
+
let paymentThemeOptions = deepmerge(blockletTheme, {
|
|
24
|
+
// 自定义调色板扩展,例如,用于 chip
|
|
25
|
+
palette: {
|
|
26
|
+
chip: { /* ... */ },
|
|
27
|
+
},
|
|
28
|
+
// 自定义组件样式覆盖
|
|
29
|
+
components: {
|
|
30
|
+
MuiButton: { /* ... */ },
|
|
31
|
+
MuiOutlinedInput: { /* ... */ },
|
|
32
|
+
// ... 其他组件
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 合并任何用户提供的自定义主题
|
|
37
|
+
paymentThemeOptions = deepmerge(paymentThemeOptions, customTheme);
|
|
38
|
+
|
|
39
|
+
return createTheme(paymentThemeOptions);
|
|
40
|
+
}, [parentTheme, customTheme]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<ThemeProvider theme={mergeTheme}>
|
|
44
|
+
<CssBaseline />
|
|
45
|
+
{children}
|
|
46
|
+
</ThemeProvider>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 自定义组件样式
|
|
52
|
+
|
|
53
|
+
从 1.14.22 版本开始,您可以通过传递 `theme` 属性轻松地为单个支付组件自定义主题。该属性接受一个 Material-UI `ThemeOptions` 对象,为您提供了两种应用自定义样式的主要方法。
|
|
54
|
+
|
|
55
|
+
### 1. 使用 `styleOverrides`
|
|
56
|
+
|
|
57
|
+
对于深度的结构性更改,您可以在支付组件的作用域内覆盖特定 Material-UI 组件的样式。这是标准的 MUI 主题化方法。
|
|
58
|
+
|
|
59
|
+
```tsx Customizing the Primary Button icon=logos:react
|
|
60
|
+
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
61
|
+
import { useSessionContext } from '@/hooks/session-context'; // 假设 session 上下文在此处定义
|
|
62
|
+
|
|
63
|
+
function CustomStyledCheckout() {
|
|
64
|
+
const { session, connectApi } = useSessionContext();
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<PaymentProvider session={session} connect={connectApi}>
|
|
68
|
+
<CheckoutForm
|
|
69
|
+
id="plink_xxx"
|
|
70
|
+
onChange={console.info}
|
|
71
|
+
theme={{
|
|
72
|
+
components: {
|
|
73
|
+
MuiButton: {
|
|
74
|
+
styleOverrides: {
|
|
75
|
+
containedPrimary: {
|
|
76
|
+
backgroundColor: '#1DC1C7',
|
|
77
|
+
color: '#fff',
|
|
78
|
+
'&:hover': {
|
|
79
|
+
backgroundColor: 'rgb(20, 135, 139)',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
</PaymentProvider>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
在此示例中,我们针对主 contained 按钮 (`MuiButton.styleOverrides.containedPrimary`) 并更改其背景和文本颜色。
|
|
93
|
+
|
|
94
|
+
### 2. 使用 `sx` 属性
|
|
95
|
+
|
|
96
|
+
对于快速、有针对性的 CSS 更改,您可以在 `theme` 属性中传递一个 `sx` 对象。这允许您使用 CSS 选择器来定位组件内的特定元素。
|
|
97
|
+
|
|
98
|
+
```tsx Customizing with the sx Prop icon=logos:react
|
|
99
|
+
import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
|
|
100
|
+
import { useSessionContext } from '@/hooks/session-context';
|
|
101
|
+
|
|
102
|
+
function SxStyledCheckout() {
|
|
103
|
+
const { session, connectApi } = useSessionContext();
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<PaymentProvider session={session} connect={connectApi}>
|
|
107
|
+
<CheckoutForm
|
|
108
|
+
id="plink_xxx"
|
|
109
|
+
showCheckoutSummary={false}
|
|
110
|
+
onChange={console.info}
|
|
111
|
+
theme={{
|
|
112
|
+
sx: {
|
|
113
|
+
// 通过其特定的类名来定位提交按钮
|
|
114
|
+
'.cko-submit-button': {
|
|
115
|
+
backgroundColor: '#1DC1C7',
|
|
116
|
+
color: '#fff',
|
|
117
|
+
'&:hover': {
|
|
118
|
+
backgroundColor: 'rgb(20, 135, 139)',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
</PaymentProvider>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
当您需要覆盖一个通过标准组件样式覆盖不易访问的样式时,此方法非常有用。
|
|
131
|
+
|
|
132
|
+
## 理解默认主题
|
|
133
|
+
|
|
134
|
+
默认主题建立在颜色、间距和排版的 CSS 变量(设计令牌)系统之上,从而在亮色和暗色模式下实现一致的样式。
|
|
135
|
+
|
|
136
|
+
### 调色板
|
|
137
|
+
|
|
138
|
+
该主题通过一个自定义的 `chip` 对象扩展了标准的 Material-UI 调色板,用于设置状态指示器的样式。您可以在您的自定义主题中覆盖这些颜色。
|
|
139
|
+
|
|
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 定义
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 设计令牌(CSS 变量)
|
|
157
|
+
|
|
158
|
+
对于高级的全局自定义,您可以覆盖定义主题的 CSS 变量。这些变量为亮色模式 (`:root`) 和暗色模式 (`[data-theme='dark']`) 都进行了定义。
|
|
159
|
+
|
|
160
|
+
以下是您可以作为目标的一些关键变量:
|
|
161
|
+
|
|
162
|
+
```css src/theme/index.css icon=logos:css-3
|
|
163
|
+
:root {
|
|
164
|
+
/* 亮色主题 */
|
|
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
|
+
}
|
|
172
|
+
|
|
173
|
+
[data-theme='dark'] {
|
|
174
|
+
/* 暗色主题 */
|
|
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
|
+
```
|
|
183
|
+
|
|
184
|
+
在您的全局样式表中覆盖这些变量,将会把更改应用到所有 `@blocklet/payment-react` 组件。
|
|
185
|
+
|
|
186
|
+
### 排版
|
|
187
|
+
|
|
188
|
+
默认的排版设置可以在 `src/theme/typography.ts` 中找到。您可以在您的自定义主题中覆盖任何这些设置,以匹配您应用程序的排版。
|
|
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
|
+
// ... 其他排版设置
|
|
202
|
+
};
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
通过理解这些自定义层次,您可以将支付组件无缝集成到您的应用程序中,并实现一致且精致的设计。
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
接下来,探索各种可以帮助您完成数据缓存和日期格式化等任务的实用工具函数。
|
|
210
|
+
|
|
211
|
+
<x-card data-title="下一步:实用工具" data-icon="lucide:wrench" data-href="/guides/utilities" data-cta="阅读更多">
|
|
212
|
+
该库提供的实用工具函数参考,包括缓存请求和日期格式化。
|
|
213
|
+
</x-card>
|