best-unit 1.2.2 → 1.2.4

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.
@@ -11,6 +11,7 @@ export declare function initFundUnit(params: {
11
11
  theme?: Theme;
12
12
  locale?: Locale;
13
13
  env: Env;
14
+ themeConfig?: ThemeConfig;
14
15
  }): {
15
16
  token: string;
16
17
  merchantId?: string;
@@ -19,6 +20,7 @@ export declare function initFundUnit(params: {
19
20
  theme?: Theme;
20
21
  locale: Locale;
21
22
  env: Env;
23
+ themeConfig?: ThemeConfig;
22
24
  };
23
25
 
24
26
  export declare function getBalanceData(): any;
@@ -15,3 +15,13 @@ export enum Env {
15
15
  PROD = "prod",
16
16
  PRODUCTION = "production",
17
17
  }
18
+
19
+
20
+ export interface ThemeConfig {
21
+ white?: {
22
+ color?: string;
23
+ };
24
+ dark?: {
25
+ color?: string;
26
+ };
27
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "1.2.2",
4
+ "version": "1.2.4",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
@@ -1,4 +1,4 @@
1
- import { Theme } from "@/types";
1
+ import { Theme, type ThemeConfig } from "@/types";
2
2
  import { getInitParams } from "@/utils/business";
3
3
 
4
4
  export const offlineTransferFormThemes = {
@@ -116,7 +116,7 @@ export const offlineTransferFormThemes = {
116
116
  padding: "10px 12px",
117
117
  borderRadius: 6,
118
118
  boxSizing: "border-box",
119
- border: "1px solid #23262F",
119
+ border: "1px solid #374151",
120
120
  background: "#23262F",
121
121
  color: "#fff",
122
122
  fontSize: 15,
@@ -130,7 +130,7 @@ export const offlineTransferFormThemes = {
130
130
  width: "100%",
131
131
  padding: "10px 12px",
132
132
  borderRadius: 6,
133
- border: "1px solid #23262F",
133
+ border: "1px solid #374151",
134
134
  background: "#23262F",
135
135
  color: "#fff",
136
136
  fontSize: 15,
@@ -140,7 +140,7 @@ export const offlineTransferFormThemes = {
140
140
  border: "1px solid #ff4d4f",
141
141
  },
142
142
  upload: {
143
- border: "1px dashed #23262F",
143
+ border: "1px dashed #374151",
144
144
  borderRadius: 8,
145
145
  background: "#181A20",
146
146
  padding: 24,
@@ -208,8 +208,25 @@ export const offlineTransferFormThemes = {
208
208
 
209
209
  export function getOfflineTransferFormTheme() {
210
210
  const theme = getInitParams<Theme>("theme");
211
+ const themeConfig = getInitParams<ThemeConfig>("themeConfig");
211
212
  const whiteTheme = theme === Theme.WHITE;
212
- return whiteTheme
213
+ const baseTheme = whiteTheme
213
214
  ? offlineTransferFormThemes.white
214
215
  : offlineTransferFormThemes.dark;
216
+ console.log(themeConfig, "themeConfig");
217
+ // 如果初始化时传入了按钮配置,则覆盖默认配置
218
+ if (themeConfig) {
219
+ const config = whiteTheme ? themeConfig.white : themeConfig.dark;
220
+ if (config?.color) {
221
+ return {
222
+ ...baseTheme,
223
+ buttonSubmit: {
224
+ ...baseTheme.buttonSubmit,
225
+ background: config.color,
226
+ },
227
+ };
228
+ }
229
+ }
230
+
231
+ return baseTheme;
215
232
  }
@@ -1,4 +1,4 @@
1
- import { Theme } from "@/types";
1
+ import { Theme, type ThemeConfig } from "@/types";
2
2
  import { getInitParams } from "@/utils/business";
3
3
 
4
4
  export const onlineRechargeFormThemes = {
@@ -76,7 +76,7 @@ export const onlineRechargeFormThemes = {
76
76
  padding: "10px 12px",
77
77
  borderRadius: 6,
78
78
  boxSizing: "border-box",
79
- border: "1px solid #23262F",
79
+ border: "1px solid #374151",
80
80
  background: "#23262F",
81
81
  color: "#fff",
82
82
  fontSize: 15,
@@ -128,8 +128,24 @@ export const onlineRechargeFormThemes = {
128
128
 
129
129
  export function getOnlineRechargeFormTheme() {
130
130
  const theme = getInitParams<Theme>("theme");
131
+ const themeConfig = getInitParams<ThemeConfig>("themeConfig");
131
132
  const whiteTheme = theme === Theme.WHITE;
132
- return whiteTheme
133
+ const baseTheme = whiteTheme
133
134
  ? onlineRechargeFormThemes.white
134
135
  : onlineRechargeFormThemes.dark;
136
+ // 如果初始化时传入了按钮配置,则覆盖默认配置
137
+ if (themeConfig) {
138
+ const config = whiteTheme ? themeConfig.white : themeConfig.dark;
139
+ if (config?.color) {
140
+ return {
141
+ ...baseTheme,
142
+ buttonSubmit: {
143
+ ...baseTheme.buttonSubmit,
144
+ background: config.color,
145
+ },
146
+ };
147
+ }
148
+ }
149
+
150
+ return baseTheme;
135
151
  }
@@ -1,4 +1,4 @@
1
- import { Theme } from "@/types";
1
+ import { Theme, type ThemeConfig } from "@/types";
2
2
  import { getInitParams } from "@/utils/business";
3
3
 
4
4
  export const rechargeThemes = {
@@ -40,8 +40,26 @@ export const rechargeThemes = {
40
40
  },
41
41
  };
42
42
 
43
+
43
44
  export function getRechargeTheme() {
44
45
  const theme = getInitParams<Theme>("theme");
46
+ const themeConfig = getInitParams<ThemeConfig>("themeConfig");
45
47
  const whiteTheme = theme === Theme.WHITE;
46
- return whiteTheme ? rechargeThemes.white : rechargeThemes.dark;
48
+ const baseTheme = whiteTheme ? rechargeThemes.white : rechargeThemes.dark;
49
+
50
+ // 如果初始化时传入了主题配置,则覆盖默认配置
51
+ if (themeConfig) {
52
+ const config = whiteTheme ? themeConfig.white : themeConfig.dark;
53
+ if (config?.color) {
54
+ return {
55
+ ...baseTheme,
56
+ tabBtn: (active: boolean, left: boolean) => ({
57
+ ...baseTheme.tabBtn(active, left),
58
+ color: active ? config.color : baseTheme.tabBtn(active, left).color,
59
+ }),
60
+ };
61
+ }
62
+ }
63
+
64
+ return baseTheme;
47
65
  }
@@ -22,9 +22,7 @@ export function BestUnit() {
22
22
 
23
23
  return (
24
24
  <div>
25
- <Button onClick={() => setVisible(true)}>
26
- {t("充值/转账")}
27
- </Button>
25
+ <Button onClick={() => setVisible(true)}>{t("充值/转账")}</Button>
28
26
  <Recharge
29
27
  visible={visible}
30
28
  onClose={() => setVisible(false)}
@@ -42,7 +42,7 @@ function StatisticalBalance(props: { popoverPosition?: PopoverPosition }) {
42
42
  const details: DetailItem[] = [
43
43
  {
44
44
  label: "", // 翻译在渲染时处理
45
- value: balance.availableAmount,
45
+ value: balance.totalAmount,
46
46
  color: "#15b36b",
47
47
  dot: "#15b36b",
48
48
  },
@@ -70,7 +70,7 @@ function StatisticalBalance(props: { popoverPosition?: PopoverPosition }) {
70
70
  : []),
71
71
  {
72
72
  label: "",
73
- value: balance.totalAmount,
73
+ value: balance.availableAmount,
74
74
  color: "#1890ff",
75
75
  dot: "#15b36b",
76
76
  },
@@ -1,4 +1,4 @@
1
- import { Theme } from "@/types";
1
+ import { Theme, type ThemeConfig } from "@/types";
2
2
  import { getInitParams } from "@/utils/business";
3
3
 
4
4
  export const buttonThemes = {
@@ -26,14 +26,23 @@ export const buttonThemes = {
26
26
 
27
27
  export function getButtonTheme(color?: string) {
28
28
  const theme = getInitParams<Theme>("theme");
29
+ const themeConfig = getInitParams<ThemeConfig>("themeConfig");
29
30
  const whiteTheme = theme === Theme.WHITE;
31
+
32
+ // 优先使用传入的 color 参数,其次使用 themeConfig 中的配置
33
+ let buttonColor = color;
34
+ if (!buttonColor && themeConfig) {
35
+ const config = whiteTheme ? themeConfig.white : themeConfig.dark;
36
+ buttonColor = config?.color;
37
+ }
38
+
30
39
  return whiteTheme
31
40
  ? {
32
41
  ...buttonThemes.white,
33
- background: color || buttonThemes.white.background,
42
+ background: buttonColor || buttonThemes.white.background,
34
43
  }
35
44
  : {
36
45
  ...buttonThemes.dark,
37
- background: color || buttonThemes.dark.background,
46
+ background: buttonColor || buttonThemes.dark.background,
38
47
  };
39
48
  }
@@ -42,12 +42,12 @@ export const selectThemes = {
42
42
  trigger: {
43
43
  background: "#23262F",
44
44
  color: "#fff",
45
- border: "1px solid #23262F",
45
+ border: "1px solid #374151",
46
46
  },
47
47
  triggerDisabled: {
48
48
  background: "#23262F",
49
49
  color: "#666",
50
- border: "1px solid #23262F",
50
+ border: "1px solid #374151",
51
51
  },
52
52
  triggerError: {
53
53
  background: "#23262F",
@@ -56,7 +56,7 @@ export const selectThemes = {
56
56
  },
57
57
  dropdown: {
58
58
  background: "#23262F",
59
- border: "1px solid #23262F",
59
+ border: "1px solid #374151",
60
60
  color: "#fff",
61
61
  },
62
62
  option: (active: boolean, optDisabled: boolean, hovered: boolean) => ({
package/src/demo/App.tsx CHANGED
@@ -43,6 +43,14 @@ export default function DemoApp() {
43
43
  locale: locale as Locale,
44
44
  theme: theme ?? Theme.WHITE,
45
45
  env: env ?? currentEnv,
46
+ themeConfig: {
47
+ white: {
48
+ color: "red",
49
+ },
50
+ dark: {
51
+ color: "pink",
52
+ },
53
+ },
46
54
  });
47
55
  };
48
56
 
@@ -0,0 +1 @@
1
+
@@ -11,6 +11,7 @@ export declare function initFundUnit(params: {
11
11
  theme?: Theme;
12
12
  locale?: Locale;
13
13
  env: Env;
14
+ themeConfig?: ThemeConfig;
14
15
  }): {
15
16
  token: string;
16
17
  merchantId?: string;
@@ -19,6 +20,7 @@ export declare function initFundUnit(params: {
19
20
  theme?: Theme;
20
21
  locale: Locale;
21
22
  env: Env;
23
+ themeConfig?: ThemeConfig;
22
24
  };
23
25
 
24
26
  export declare function getBalanceData(): any;
@@ -15,3 +15,13 @@ export enum Env {
15
15
  PROD = "prod",
16
16
  PRODUCTION = "production",
17
17
  }
18
+
19
+
20
+ export interface ThemeConfig {
21
+ white?: {
22
+ color?: string;
23
+ };
24
+ dark?: {
25
+ color?: string;
26
+ };
27
+ }
@@ -16,6 +16,15 @@ export interface BalanceData {
16
16
  createdAt: string; // 创建时间
17
17
  }
18
18
 
19
+ interface ThemeConfig {
20
+ white?: {
21
+ color?: string;
22
+ };
23
+ dark?: {
24
+ color?: string;
25
+ };
26
+ }
27
+
19
28
  export interface InitParams {
20
29
  token: string;
21
30
  merchant_id?: string;
@@ -25,6 +34,7 @@ export interface InitParams {
25
34
  theme?: Theme;
26
35
  locale?: Locale;
27
36
  env: Env;
37
+ themeConfig?: ThemeConfig;
28
38
  }
29
39
 
30
40
  // 获取余额数据并暴露给外部系统
@@ -46,6 +56,7 @@ export function initFundUnit(params: InitParams) {
46
56
  theme = Theme.WHITE,
47
57
  locale = Locale.ZH,
48
58
  env,
59
+ themeConfig,
49
60
  } = params;
50
61
  const token = "Bearer " + params.token;
51
62
  sessionStorage.setItem(
@@ -59,6 +70,7 @@ export function initFundUnit(params: InitParams) {
59
70
  theme,
60
71
  locale,
61
72
  env,
73
+ themeConfig,
62
74
  })
63
75
  );
64
76
  // 重置 axios 实例,确保使用新的配置