@blocklet/payment-react 1.20.16 → 1.20.17

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 (102) hide show
  1. package/.aigne/doc-smith/config.yaml +7 -1
  2. package/.aigne/doc-smith/upload-cache.yaml +441 -0
  3. package/docs/components-business-auto-topup.ja.md +187 -0
  4. package/docs/components-business-auto-topup.zh-TW.md +187 -0
  5. package/docs/components-business-auto-topup.zh.md +187 -0
  6. package/docs/components-business-overdue-invoice-payment.ja.md +196 -0
  7. package/docs/components-business-overdue-invoice-payment.zh-TW.md +197 -0
  8. package/docs/components-business-overdue-invoice-payment.zh.md +197 -0
  9. package/docs/components-business-resume-subscription.ja.md +190 -0
  10. package/docs/components-business-resume-subscription.zh-TW.md +190 -0
  11. package/docs/components-business-resume-subscription.zh.md +190 -0
  12. package/docs/components-business.ja.md +21 -0
  13. package/docs/components-business.zh-TW.md +21 -0
  14. package/docs/components-business.zh.md +21 -0
  15. package/docs/components-checkout-checkout-donate.ja.md +259 -0
  16. package/docs/components-checkout-checkout-donate.zh-TW.md +259 -0
  17. package/docs/components-checkout-checkout-donate.zh.md +259 -0
  18. package/docs/components-checkout-checkout-form.ja.md +163 -0
  19. package/docs/components-checkout-checkout-form.zh-TW.md +163 -0
  20. package/docs/components-checkout-checkout-form.zh.md +163 -0
  21. package/docs/components-checkout-checkout-table.ja.md +148 -0
  22. package/docs/components-checkout-checkout-table.zh-TW.md +148 -0
  23. package/docs/components-checkout-checkout-table.zh.md +149 -0
  24. package/docs/components-checkout.ja.md +65 -0
  25. package/docs/components-checkout.zh-TW.md +65 -0
  26. package/docs/components-checkout.zh.md +65 -0
  27. package/docs/components-history-credit-grants-list.ja.md +73 -0
  28. package/docs/components-history-credit-grants-list.zh-TW.md +73 -0
  29. package/docs/components-history-credit-grants-list.zh.md +73 -0
  30. package/docs/components-history-credit-transactions-list.ja.md +106 -0
  31. package/docs/components-history-credit-transactions-list.zh-TW.md +106 -0
  32. package/docs/components-history-credit-transactions-list.zh.md +106 -0
  33. package/docs/components-history-invoice-list.ja.md +110 -0
  34. package/docs/components-history-invoice-list.zh-TW.md +110 -0
  35. package/docs/components-history-invoice-list.zh.md +110 -0
  36. package/docs/components-history-payment-list.ja.md +44 -0
  37. package/docs/components-history-payment-list.zh-TW.md +44 -0
  38. package/docs/components-history-payment-list.zh.md +44 -0
  39. package/docs/components-history.ja.md +67 -0
  40. package/docs/components-history.zh-TW.md +67 -0
  41. package/docs/components-history.zh.md +67 -0
  42. package/docs/components-ui-form-elements-address-form.ja.md +121 -0
  43. package/docs/components-ui-form-elements-address-form.zh-TW.md +121 -0
  44. package/docs/components-ui-form-elements-address-form.zh.md +121 -0
  45. package/docs/components-ui-form-elements-country-select.ja.md +126 -0
  46. package/docs/components-ui-form-elements-country-select.zh-TW.md +126 -0
  47. package/docs/components-ui-form-elements-country-select.zh.md +126 -0
  48. package/docs/components-ui-form-elements-currency-selector.ja.md +108 -0
  49. package/docs/components-ui-form-elements-currency-selector.zh-TW.md +108 -0
  50. package/docs/components-ui-form-elements-currency-selector.zh.md +108 -0
  51. package/docs/components-ui-form-elements-phone-input.ja.md +138 -0
  52. package/docs/components-ui-form-elements-phone-input.zh-TW.md +138 -0
  53. package/docs/components-ui-form-elements-phone-input.zh.md +139 -0
  54. package/docs/components-ui-form-elements.ja.md +91 -0
  55. package/docs/components-ui-form-elements.zh-TW.md +91 -0
  56. package/docs/components-ui-form-elements.zh.md +91 -0
  57. package/docs/components-ui-payment-summary.ja.md +109 -0
  58. package/docs/components-ui-payment-summary.zh-TW.md +109 -0
  59. package/docs/components-ui-payment-summary.zh.md +109 -0
  60. package/docs/components-ui-pricing-table.ja.md +140 -0
  61. package/docs/components-ui-pricing-table.zh-TW.md +140 -0
  62. package/docs/components-ui-pricing-table.zh.md +140 -0
  63. package/docs/components-ui.ja.md +71 -0
  64. package/docs/components-ui.zh-TW.md +71 -0
  65. package/docs/components-ui.zh.md +71 -0
  66. package/docs/components.ja.md +122 -0
  67. package/docs/components.zh-TW.md +122 -0
  68. package/docs/components.zh.md +122 -0
  69. package/docs/getting-started.ja.md +84 -0
  70. package/docs/getting-started.zh-TW.md +84 -0
  71. package/docs/getting-started.zh.md +84 -0
  72. package/docs/guides-theming.ja.md +213 -0
  73. package/docs/guides-theming.zh-TW.md +213 -0
  74. package/docs/guides-theming.zh.md +213 -0
  75. package/docs/guides-utilities.ja.md +197 -0
  76. package/docs/guides-utilities.zh-TW.md +197 -0
  77. package/docs/guides-utilities.zh.md +197 -0
  78. package/docs/guides.ja.md +18 -0
  79. package/docs/guides.zh-TW.md +18 -0
  80. package/docs/guides.zh.md +18 -0
  81. package/docs/hooks-use-mobile.ja.md +84 -0
  82. package/docs/hooks-use-mobile.zh-TW.md +84 -0
  83. package/docs/hooks-use-mobile.zh.md +84 -0
  84. package/docs/hooks-use-subscription.ja.md +111 -0
  85. package/docs/hooks-use-subscription.zh-TW.md +111 -0
  86. package/docs/hooks-use-subscription.zh.md +110 -0
  87. package/docs/hooks.ja.md +14 -0
  88. package/docs/hooks.zh-TW.md +14 -0
  89. package/docs/hooks.zh.md +14 -0
  90. package/docs/overview.ja.md +80 -0
  91. package/docs/overview.zh-TW.md +80 -0
  92. package/docs/overview.zh.md +80 -0
  93. package/docs/providers-donate-provider.ja.md +153 -0
  94. package/docs/providers-donate-provider.zh-TW.md +153 -0
  95. package/docs/providers-donate-provider.zh.md +153 -0
  96. package/docs/providers-payment-provider.ja.md +191 -0
  97. package/docs/providers-payment-provider.zh-TW.md +191 -0
  98. package/docs/providers-payment-provider.zh.md +191 -0
  99. package/docs/providers.ja.md +42 -0
  100. package/docs/providers.zh-TW.md +42 -0
  101. package/docs/providers.zh.md +42 -0
  102. package/package.json +3 -3
@@ -0,0 +1,126 @@
1
+ # CountrySelect
2
+
3
+ `CountrySelect` 元件提供了一個方便使用者選擇國家的下拉式選單。它具有可搜尋的列表、顯示國旗,並提供響應式設計,能適應桌面和行動裝置的視窗。它設計用於在 `react-hook-form` 管理的表單中使用。
4
+
5
+ ## Props
6
+
7
+ | Prop | Type | Description | Required | Default |
8
+ |--------------|----------------------------------|---------------------------------------------------------------------------------------------|----------|---------|
9
+ | `value` | `CountryIso2` | 所選國家的 ISO2 代碼(例如 'us')。 | Yes | |
10
+ | `onChange` | `(value: CountryIso2) => void` | 選擇國家時叫用的回呼函式。 | Yes | |
11
+ | `name` | `string` | 輸入框的 name 屬性,用於與 `react-hook-form` 整合。 | Yes | |
12
+ | `sx` | `SxProps` | 應用於根元素的自訂樣式。 | No | `{}` |
13
+ | `showDialCode` | `boolean` | 如果為 `true`,國家的撥號代碼將與其名稱一起顯示在列表中。 | No | `false` |
14
+
15
+ ## 基本用法
16
+
17
+ 要使用 `CountrySelect` 元件,您必須將其包裝在 `react-hook-form` 的 `FormProvider` 中。元件的狀態應透過表單上下文進行管理。
18
+
19
+ ```tsx Basic CountrySelect Example icon=logos:react
20
+ import { FormProvider, useForm } from 'react-hook-form';
21
+ import { Box, Button, Typography } from '@mui/material';
22
+ import CountrySelect from '@blocklet/payment-react/src/components/country-select'; // 根據需要調整路徑
23
+ import type { CountryIso2 } from 'react-international-phone';
24
+
25
+ export default function BasicCountrySelect() {
26
+ const methods = useForm<{ country: CountryIso2 }>({
27
+ defaultValues: {
28
+ country: 'us',
29
+ },
30
+ });
31
+
32
+ const { handleSubmit, watch, setValue } = methods;
33
+ const countryValue = watch('country'); // 監聽變更以更新受控元件
34
+
35
+ const onSubmit = (data: { country: CountryIso2 }) => {
36
+ alert(`表單已提交,國家:${data.country}`);
37
+ };
38
+
39
+ return (
40
+ <FormProvider {...methods}>
41
+ <form onSubmit={handleSubmit(onSubmit)}>
42
+ <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, maxWidth: 400 }}>
43
+ <Typography variant="h6">選擇您的國家</Typography>
44
+ <CountrySelect
45
+ name="country"
46
+ value={countryValue}
47
+ onChange={(newCountry) => {
48
+ setValue('country', newCountry, { shouldValidate: true });
49
+ }}
50
+ />
51
+ <Button type="submit" variant="contained">
52
+ 提交
53
+ </Button>
54
+ <Typography>
55
+ 目前表單值:{countryValue}
56
+ </Typography>
57
+ </Box>
58
+ </form>
59
+ </FormProvider>
60
+ );
61
+ }
62
+ ```
63
+
64
+ ## 功能
65
+
66
+ ### 搜尋與篩選
67
+ 元件在下拉列表頂部包含一個搜尋欄,讓使用者可以透過國家名稱、ISO2 代碼或撥號代碼快速找到國家。例如,搜尋「+1」將會顯示美國和加拿大。
68
+
69
+ ### 響應式 UI
70
+ 在桌面裝置上,`CountrySelect` 會渲染為標準的下拉式選單。在行動裝置上,它會轉換成一個從螢幕底部滑出的全寬對話方塊,為小型裝置提供最佳化的使用者體驗。
71
+
72
+ ### 鍵盤可及性
73
+ `CountrySelect` 支援完整的鍵盤導覽。使用者可以使用 `ArrowUp` 和 `ArrowDown` 鍵在列表中導覽,`Enter` 鍵選擇國家,`Escape` 鍵關閉下拉選單。`Tab` 和 `Shift+Tab` 也可以在列表項目之間循環。
74
+
75
+ ### 表單整合
76
+ 設計用於與 `react-hook-form` 無縫協作。當做出選擇時,它會自動更新表單狀態,因此需要將其包裝在 `FormProvider` 內。
77
+
78
+ ## 進階用法
79
+
80
+ ### 顯示撥號代碼
81
+
82
+ 您可以透過將 `showDialCode` 屬性設定為 `true`,在列表中顯示每個國家的電話撥號代碼。
83
+
84
+ ```tsx CountrySelect with Dial Code icon=logos:react
85
+ import { FormProvider, useForm } from 'react-hook-form';
86
+ import { Box, Button } from '@mui/material';
87
+ import CountrySelect from '@blocklet/payment-react/src/components/country-select'; // 根據需要調整路徑
88
+ import type { CountryIso2 } from 'react-international-phone';
89
+
90
+ export default function CountrySelectWithDialCode() {
91
+ const methods = useForm<{ country: CountryIso2 }>({
92
+ defaultValues: {
93
+ country: 'gb',
94
+ },
95
+ });
96
+
97
+ const { handleSubmit, watch, setValue } = methods;
98
+ const countryValue = watch('country');
99
+
100
+ const onSubmit = (data: { country: CountryIso2 }) => {
101
+ alert(`表單已提交,國家:${data.country}`);
102
+ };
103
+
104
+ return (
105
+ <FormProvider {...methods}>
106
+ <form onSubmit={handleSubmit(onSubmit)}>
107
+ <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, maxWidth: 400 }}>
108
+ <CountrySelect
109
+ name="country"
110
+ value={countryValue}
111
+ onChange={(newCountry) => setValue('country', newCountry)}
112
+ showDialCode={true}
113
+ />
114
+ <Button type="submit" variant="contained">
115
+ 提交
116
+ </Button>
117
+ </Box>
118
+ </form>
119
+ </FormProvider>
120
+ );
121
+ }
122
+ ```
123
+
124
+ ## 後續步驟
125
+
126
+ 此元件是建構更複雜表單元素的基礎。查看它如何整合到 [PhoneInput](./components-ui-form-elements-phone-input.md) 元件中,以建立一個完整的國際電話號碼欄位。
@@ -0,0 +1,126 @@
1
+ # CountrySelect
2
+
3
+ `CountrySelect` 组件提供了一个用户友好的国家选择下拉菜单。它具有可搜索列表、显示国旗,并提供响应式设计,可适应桌面和移动设备。该组件设计用于在 `react-hook-form` 管理的表单中使用。
4
+
5
+ ## Props
6
+
7
+ | Prop | Type | Description | Required | Default |
8
+ |---|---|---|---|---|
9
+ | `value` | `CountryIso2` | 所选国家的 ISO2 代码(例如,'us')。 | 是 | |
10
+ | `onChange` | `(value: CountryIso2) => void` | 选择国家时调用的回调函数。 | 是 | |
11
+ | `name` | `string` | 输入的 name 属性,用于与 `react-hook-form` 集成。 | 是 | |
12
+ | `sx` | `SxProps` | 应用于根元素的自定义样式。 | 否 | `{}` |
13
+ | `showDialCode` | `boolean` | 如果为 `true`,国家的电话区号将与其名称一起显示在列表中。 | 否 | `false` |
14
+
15
+ ## 基本用法
16
+
17
+ 要使用 `CountrySelect` 组件,您必须将其包装在 `react-hook-form` 的 `FormProvider` 中。组件的状态应通过表单上下文进行管理。
18
+
19
+ ```tsx Basic CountrySelect Example icon=logos:react
20
+ import { FormProvider, useForm } from 'react-hook-form';
21
+ import { Box, Button, Typography } from '@mui/material';
22
+ import CountrySelect from '@blocklet/payment-react/src/components/country-select'; // Adjust path as needed
23
+ import type { CountryIso2 } from 'react-international-phone';
24
+
25
+ export default function BasicCountrySelect() {
26
+ const methods = useForm<{ country: CountryIso2 }>({
27
+ defaultValues: {
28
+ country: 'us',
29
+ },
30
+ });
31
+
32
+ const { handleSubmit, watch, setValue } = methods;
33
+ const countryValue = watch('country'); // Watch for changes to update the controlled component
34
+
35
+ const onSubmit = (data: { country: CountryIso2 }) => {
36
+ alert(`Form submitted with country: ${data.country}`);
37
+ };
38
+
39
+ return (
40
+ <FormProvider {...methods}>
41
+ <form onSubmit={handleSubmit(onSubmit)}>
42
+ <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, maxWidth: 400 }}>
43
+ <Typography variant="h6">Select Your Country</Typography>
44
+ <CountrySelect
45
+ name="country"
46
+ value={countryValue}
47
+ onChange={(newCountry) => {
48
+ setValue('country', newCountry, { shouldValidate: true });
49
+ }}
50
+ />
51
+ <Button type="submit" variant="contained">
52
+ Submit
53
+ </Button>
54
+ <Typography>
55
+ Current form value: {countryValue}
56
+ </Typography>
57
+ </Box>
58
+ </form>
59
+ </FormProvider>
60
+ );
61
+ }
62
+ ```
63
+
64
+ ## 功能
65
+
66
+ ### 搜索和筛选
67
+ 组件在下拉列表顶部包含一个搜索栏,允许用户通过国家名称、ISO2 代码或电话区号快速查找国家。例如,搜索“+1”将显示美国和加拿大。
68
+
69
+ ### 响应式 UI
70
+ 在桌面设备上,`CountrySelect` 渲染为标准下拉菜单。在移动设备上,它会转变为一个从屏幕底部滑出的全宽对话框,为小型设备提供优化的用户体验。
71
+
72
+ ### 键盘可访问性
73
+ `CountrySelect` 支持完整的键盘导航。用户可以使用 `ArrowUp` 和 `ArrowDown` 键在列表中导航,使用 `Enter` 键选择国家,使用 `Escape` 键关闭下拉列表。`Tab` 和 `Shift+Tab` 也可以在列表项之间循环切换。
74
+
75
+ ### 表单集成
76
+ 设计用于与 `react-hook-form` 无缝协作。当做出选择时,它会自动更新表单状态,因此需要将其包装在 `FormProvider` 中。
77
+
78
+ ## 高级用法
79
+
80
+ ### 显示电话区号
81
+
82
+ 您可以通过将 `showDialCode` 属性设置为 `true` 来在列表中显示每个国家的电话区号。
83
+
84
+ ```tsx CountrySelect with Dial Code icon=logos:react
85
+ import { FormProvider, useForm } from 'react-hook-form';
86
+ import { Box, Button } from '@mui/material';
87
+ import CountrySelect from '@blocklet/payment-react/src/components/country-select'; // Adjust path as needed
88
+ import type { CountryIso2 } from 'react-international-phone';
89
+
90
+ export default function CountrySelectWithDialCode() {
91
+ const methods = useForm<{ country: CountryIso2 }>({
92
+ defaultValues: {
93
+ country: 'gb',
94
+ },
95
+ });
96
+
97
+ const { handleSubmit, watch, setValue } = methods;
98
+ const countryValue = watch('country');
99
+
100
+ const onSubmit = (data: { country: CountryIso2 }) => {
101
+ alert(`Form submitted with country: ${data.country}`);
102
+ };
103
+
104
+ return (
105
+ <FormProvider {...methods}>
106
+ <form onSubmit={handleSubmit(onSubmit)}>
107
+ <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, maxWidth: 400 }}>
108
+ <CountrySelect
109
+ name="country"
110
+ value={countryValue}
111
+ onChange={(newCountry) => setValue('country', newCountry)}
112
+ showDialCode={true}
113
+ />
114
+ <Button type="submit" variant="contained">
115
+ Submit
116
+ </Button>
117
+ </Box>
118
+ </form>
119
+ </FormProvider>
120
+ );
121
+ }
122
+ ```
123
+
124
+ ## 后续步骤
125
+
126
+ 该组件是构建更复杂表单元素的基础。请参阅它如何集成到 [PhoneInput](./components-ui-form-elements-phone-input.md) 组件中,以创建一个完整的国际电话号码字段。
@@ -0,0 +1,108 @@
1
+ # CurrencySelector
2
+
3
+ `CurrencySelector`コンポーネントは、利用可能なオプションのリストから支払い通貨を選択するための、使いやすいインターフェースを提供します。各通貨をロゴ、シンボル、関連する支払い方法とともに表示し、ユーザーが簡単に選択できるようにします。このコンポーネントは通常、より大きな支払いフォームやチェックアウトフォーム内で使用されます。
4
+
5
+ ## Props
6
+
7
+ | Prop | Type | Description | Required |
8
+ | :----------- | :------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------- | :------- |
9
+ | `value` | `string` | 現在選択されている通貨のIDです。親コンポーネントのstateで管理する必要があります。 | Yes |
10
+ | `currencies` | `TPaymentCurrency[]` | 選択可能なオプションとして表示される、利用可能な通貨オブジェクトの配列です。 | Yes |
11
+ | `onChange` | `(currencyId: string, methodId?: string) => void` | ユーザーが通貨を選択したときに実行されるコールバック関数です。新しい通貨IDと、オプションで関連する支払い方法のIDを受け取ります。 | Yes |
12
+
13
+ ### TPaymentCurrency 型
14
+
15
+ `currencies` propは、以下の構造を持つオブジェクトの配列を想定しています:
16
+
17
+ ```typescript TPaymentCurrency icon=mdi:code-json
18
+ export type TPaymentCurrency = {
19
+ id: string; // 通貨オプションの一意の識別子
20
+ logo: string; // 通貨/メソッドのロゴのURL
21
+ name: string; // 通貨の表示名
22
+ symbol: string; // 通貨記号(例:'$'、'€')
23
+ method: { // 関連する支払い方法
24
+ id: string;
25
+ name: string;
26
+ };
27
+ };
28
+ ```
29
+
30
+ ## 使用例
31
+
32
+ 以下は`CurrencySelector`コンポーネントを実装する基本的な例です。親コンポーネントで選択された通貨のstateを管理し、利用可能な通貨のリストを提供する必要があります。
33
+
34
+ `@blocklet/payment-react`コンポーネントは`PaymentProvider`内で動作するように設計されており、`PaymentProvider`が必要なテーマとコンテキストを提供します。コンポーネントが適切にラップされていることを確認してください。
35
+
36
+ ```jsx MyCurrencySelectorComponent.tsx icon=logos:react
37
+ import React, { useState } from 'react';
38
+ import { PaymentProvider } from '@blocklet/payment-react';
39
+ import { CurrencySelector } from '@blocklet/payment-react/components';
40
+ import type { TPaymentCurrency } from '@blocklet/payment-types';
41
+ import { useSessionContext } from '@/hooks/session-context'; // このインポートパスをあなたのプロジェクト構造に合わせて調整してください
42
+
43
+ // デモンストレーション用のモックデータ
44
+ const mockCurrencies: TPaymentCurrency[] = [
45
+ {
46
+ id: 'usd_xxxxxx',
47
+ logo: 'https://path-to-your/usd-logo.png',
48
+ name: 'US Dollar',
49
+ symbol: 'USD',
50
+ method: {
51
+ id: 'stripe_yyyyy',
52
+ name: 'Stripe',
53
+ },
54
+ },
55
+ {
56
+ id: 'eth_zzzzzz',
57
+ logo: 'https://path-to-your/eth-logo.png',
58
+ name: 'Ethereum',
59
+ symbol: 'ETH',
60
+ method: {
61
+ id: 'crypto_aaaaa',
62
+ name: 'Crypto Payment',
63
+ },
64
+ },
65
+ ];
66
+
67
+ function MyCurrencySelectorComponent() {
68
+ const [selectedCurrency, setSelectedCurrency] = useState<string>(mockCurrencies[0].id);
69
+
70
+ const handleCurrencyChange = (currencyId: string, methodId?: string) => {
71
+ console.log(`選択された通貨: ${currencyId}, メソッド: ${methodId}`);
72
+ setSelectedCurrency(currencyId);
73
+ };
74
+
75
+ return (
76
+ <div>
77
+ <h3>通貨を選択</h3>
78
+ <CurrencySelector
79
+ value={selectedCurrency}
80
+ currencies={mockCurrencies}
81
+ onChange={handleCurrencyChange}
82
+ />
83
+ </div>
84
+ );
85
+ }
86
+
87
+ // あなたのアプリのエントリーポイント
88
+ export default function App() {
89
+ const { session, connectApi } = useSessionContext();
90
+
91
+ if (!session || !connectApi) {
92
+ return <div>読み込み中...</div>;
93
+ }
94
+
95
+ return (
96
+ <PaymentProvider session={session} connectApi={connectApi}>
97
+ <MyCurrencySelectorComponent />
98
+ </PaymentProvider>
99
+ );
100
+ }
101
+ ```
102
+
103
+ この例では:
104
+ 1. `TPaymentCurrency`構造に従う`mockCurrencies`配列を定義します。
105
+ 2. `MyCurrencySelectorComponent`は`useState`フックを使用して`selectedCurrency`を追跡します。
106
+ 3. `handleCurrencyChange`関数は、新しい通貨が選択されたときにstateを更新し、新しい値をログに出力します。
107
+ 4. `CurrencySelector`は制御されたコンポーネントであり、その`value`と`onChange` propsは親のstateによって管理されます。
108
+ 5. コンポーネント全体が`PaymentProvider`でラップされ、適切なレンダリングとスタイリングに使用されるMaterial-UIテーマへのアクセスを確保します。
@@ -0,0 +1,108 @@
1
+ # CurrencySelector
2
+
3
+ `CurrencySelector` 組件提供了一個使用者友善的介面,讓使用者能從可用選項清單中選擇支付貨幣。它會顯示每種貨幣的標誌、符號及相關的支付方式,方便使用者進行選擇。此組件通常用於較大的支付或結帳表單中。
4
+
5
+ ## 屬性
6
+
7
+ | Prop | 類型 | 描述 | 必填 |
8
+ | :----------- | :------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------- | :------- |
9
+ | `value` | `string` | 當前所選貨幣的 ID。此 ID 應由父組件的狀態管理。 | 是 |
10
+ | `currencies` | `TPaymentCurrency[]` | 一個可用貨幣物件的陣列,用以顯示為可選選項。 | 是 |
11
+ | `onChange` | `(currencyId: string, methodId?: string) => void` | 當使用者選擇貨幣時執行的回呼函式。它會接收新的貨幣 ID 和可選的相關支付方式 ID。 | 是 |
12
+
13
+ ### TPaymentCurrency 類型
14
+
15
+ `currencies` 屬性需要一個具有以下結構的物件陣列:
16
+
17
+ ```typescript TPaymentCurrency icon=mdi:code-json
18
+ export type TPaymentCurrency = {
19
+ id: string; // 貨幣選項的唯一識別碼
20
+ logo: string; // 貨幣/方式標誌的 URL
21
+ name: string; // 貨幣的顯示名稱
22
+ symbol: string; // 貨幣符號(例如:'$'、'€')
23
+ method: { // 相關的支付方式
24
+ id: string;
25
+ name: string;
26
+ };
27
+ };
28
+ ```
29
+
30
+ ## 使用範例
31
+
32
+ 這是一個如何實現 `CurrencySelector` 組件的基本範例。您需要在父組件中管理所選貨幣的狀態,並提供一個可用貨幣的清單。
33
+
34
+ 請注意,`@blocklet/payment-react` 組件設計為在 `PaymentProvider` 內運作,`PaymentProvider` 提供了必要的主題和上下文。請確保您的組件被適當地包裹。
35
+
36
+ ```jsx MyCurrencySelectorComponent.tsx icon=logos:react
37
+ import React, { useState } from 'react';
38
+ import { PaymentProvider } from '@blocklet/payment-react';
39
+ import { CurrencySelector } from '@blocklet/payment-react/components';
40
+ import type { TPaymentCurrency } from '@blocklet/payment-types';
41
+ import { useSessionContext } from '@/hooks/session-context'; // 根據您的專案結構調整此匯入路徑
42
+
43
+ // 用於示範的模擬資料
44
+ const mockCurrencies: TPaymentCurrency[] = [
45
+ {
46
+ id: 'usd_xxxxxx',
47
+ logo: 'https://path-to-your/usd-logo.png',
48
+ name: 'US Dollar',
49
+ symbol: 'USD',
50
+ method: {
51
+ id: 'stripe_yyyyy',
52
+ name: 'Stripe',
53
+ },
54
+ },
55
+ {
56
+ id: 'eth_zzzzzz',
57
+ logo: 'https://path-to-your/eth-logo.png',
58
+ name: 'Ethereum',
59
+ symbol: 'ETH',
60
+ method: {
61
+ id: 'crypto_aaaaa',
62
+ name: 'Crypto Payment',
63
+ },
64
+ },
65
+ ];
66
+
67
+ function MyCurrencySelectorComponent() {
68
+ const [selectedCurrency, setSelectedCurrency] = useState<string>(mockCurrencies[0].id);
69
+
70
+ const handleCurrencyChange = (currencyId: string, methodId?: string) => {
71
+ console.log(`選擇的貨幣:${currencyId},方式:${methodId}`);
72
+ setSelectedCurrency(currencyId);
73
+ };
74
+
75
+ return (
76
+ <div>
77
+ <h3>選擇貨幣</h3>
78
+ <CurrencySelector
79
+ value={selectedCurrency}
80
+ currencies={mockCurrencies}
81
+ onChange={handleCurrencyChange}
82
+ />
83
+ </div>
84
+ );
85
+ }
86
+
87
+ // 您的應用程式進入點
88
+ export default function App() {
89
+ const { session, connectApi } = useSessionContext();
90
+
91
+ if (!session || !connectApi) {
92
+ return <div>載入中...</div>;
93
+ }
94
+
95
+ return (
96
+ <PaymentProvider session={session} connectApi={connectApi}>
97
+ <MyCurrencySelectorComponent />
98
+ </PaymentProvider>
99
+ );
100
+ }
101
+ ```
102
+
103
+ 在此範例中:
104
+ 1. 我們定義了一個遵循 `TPaymentCurrency` 結構的 `mockCurrencies` 陣列。
105
+ 2. `MyCurrencySelectorComponent` 使用 `useState` hook 來追蹤 `selectedCurrency`。
106
+ 3. `handleCurrencyChange` 函式在選擇新貨幣時更新狀態,並記錄新值。
107
+ 4. `CurrencySelector` 是一個受控組件,其 `value` 和 `onChange` 屬性由父組件的狀態管理。
108
+ 5. 整個組件被包裹在 `PaymentProvider` 中,以確保正確的渲染和存取用於樣式設定的 Material-UI 主題。
@@ -0,0 +1,108 @@
1
+ # CurrencySelector
2
+
3
+ `CurrencySelector` 组件提供了一个用户友好的界面,用于从可用选项列表中选择支付货币。它会显示每种货币的徽标、符号和关联的支付方式,方便用户做出选择。该组件通常在较大的支付或结账表单中使用。
4
+
5
+ ## Props
6
+
7
+ | Prop | Type | Description | Required |
8
+ | :----------- | :------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------- | :------- |
9
+ | `value` | `string` | 当前所选货币的 ID。该值应由父组件的状态管理。 | 是 |
10
+ | `currencies` | `TPaymentCurrency[]` | 一个包含可用货币对象的数组,用作可选项进行显示。 | 是 |
11
+ | `onChange` | `(currencyId: string, methodId?: string) => void` | 当用户选择一种货币时执行的回调函数。它会接收新的货币 ID 和可选的关联支付方式 ID。 | 是 |
12
+
13
+ ### TPaymentCurrency 类型
14
+
15
+ `currencies` prop 需要一个具有以下结构的对象数组:
16
+
17
+ ```typescript TPaymentCurrency icon=mdi:code-json
18
+ export type TPaymentCurrency = {
19
+ id: string; // 货币选项的唯一标识符
20
+ logo: string; // 货币/方式的徽标 URL
21
+ name: string; // 货币的显示名称
22
+ symbol: string; // 货币符号(例如 '$', '€')
23
+ method: { // 关联的支付方式
24
+ id: string;
25
+ name: string;
26
+ };
27
+ };
28
+ ```
29
+
30
+ ## 用法示例
31
+
32
+ 这是一个如何实现 `CurrencySelector` 组件的基本示例。您需要在父组件中管理所选货币的状态,并提供一个可用货币列表。
33
+
34
+ 请注意,`@blocklet/payment-react` 组件设计为在 `PaymentProvider` 内部工作,`PaymentProvider` 提供了必要的主题和上下文。请确保您的组件被正确包裹。
35
+
36
+ ```jsx MyCurrencySelectorComponent.tsx icon=logos:react
37
+ import React, { useState } from 'react';
38
+ import { PaymentProvider } from '@blocklet/payment-react';
39
+ import { CurrencySelector } from '@blocklet/payment-react/components';
40
+ import type { TPaymentCurrency } from '@blocklet/payment-types';
41
+ import { useSessionContext } from '@/hooks/session-context'; // 根据您的项目结构调整此导入路径
42
+
43
+ // 用于演示的模拟数据
44
+ const mockCurrencies: TPaymentCurrency[] = [
45
+ {
46
+ id: 'usd_xxxxxx',
47
+ logo: 'https://path-to-your/usd-logo.png',
48
+ name: 'US Dollar',
49
+ symbol: 'USD',
50
+ method: {
51
+ id: 'stripe_yyyyy',
52
+ name: 'Stripe',
53
+ },
54
+ },
55
+ {
56
+ id: 'eth_zzzzzz',
57
+ logo: 'https://path-to-your/eth-logo.png',
58
+ name: 'Ethereum',
59
+ symbol: 'ETH',
60
+ method: {
61
+ id: 'crypto_aaaaa',
62
+ name: 'Crypto Payment',
63
+ },
64
+ },
65
+ ];
66
+
67
+ function MyCurrencySelectorComponent() {
68
+ const [selectedCurrency, setSelectedCurrency] = useState<string>(mockCurrencies[0].id);
69
+
70
+ const handleCurrencyChange = (currencyId: string, methodId?: string) => {
71
+ console.log(`Selected currency: ${currencyId}, Method: ${methodId}`);
72
+ setSelectedCurrency(currencyId);
73
+ };
74
+
75
+ return (
76
+ <div>
77
+ <h3>Select a Currency</h3>
78
+ <CurrencySelector
79
+ value={selectedCurrency}
80
+ currencies={mockCurrencies}
81
+ onChange={handleCurrencyChange}
82
+ />
83
+ </div>
84
+ );
85
+ }
86
+
87
+ // 您的应用的入口点
88
+ export default function App() {
89
+ const { session, connectApi } = useSessionContext();
90
+
91
+ if (!session || !connectApi) {
92
+ return <div>Loading...</div>;
93
+ }
94
+
95
+ return (
96
+ <PaymentProvider session={session} connectApi={connectApi}>
97
+ <MyCurrencySelectorComponent />
98
+ </PaymentProvider>
99
+ );
100
+ }
101
+ ```
102
+
103
+ 在此示例中:
104
+ 1. 我们定义了一个遵循 `TPaymentCurrency` 结构的 `mockCurrencies` 数组。
105
+ 2. `MyCurrencySelectorComponent` 使用 `useState` 钩子来跟踪 `selectedCurrency`。
106
+ 3. `handleCurrencyChange` 函数在选择新货币时更新状态,并记录新值。
107
+ 4. `CurrencySelector` 是一个受控组件,其 `value` 和 `onChange` props 由父组件的状态管理。
108
+ 5. 整个组件被包裹在 `PaymentProvider` 中,以确保正确渲染并访问用于样式的 Material-UI 主题。