best-unit 1.2.13 → 1.2.14

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.
@@ -1,7 +1,9 @@
1
1
  import type { ComponentChildren } from "preact";
2
2
  import { useState } from "preact/hooks";
3
3
  import { getModalTheme } from "./theme";
4
-
4
+ import { getInitParams } from "@/utils/business";
5
+ import { Size } from "@/types";
6
+ const size = getInitParams<Size>("size");
5
7
  interface ModalProps {
6
8
  visible: boolean;
7
9
  onClose: () => void;
@@ -18,8 +20,8 @@ export function Modal({
18
20
  onClose,
19
21
  title,
20
22
  children,
21
- width = 400,
22
- maxWidth = 400,
23
+ width = size === Size.SMALL ? 300 : 400,
24
+ maxWidth = size === Size.SMALL ? 300 : 400,
23
25
  showClose = true,
24
26
  maskClosable = true,
25
27
  }: ModalProps) {
@@ -64,8 +66,8 @@ export function Modal({
64
66
  <div
65
67
  style={{
66
68
  background: theme.modalBg,
67
- padding: 32,
68
- borderRadius: 12,
69
+ padding: size === Size.SMALL ? 24 : 32,
70
+ borderRadius: size === Size.SMALL ? 8 : 12,
69
71
  minWidth: width,
70
72
  maxWidth: maxWidth,
71
73
  color: theme.modalColor,
@@ -1,6 +1,6 @@
1
- import { Theme } from "@/types";
1
+ import { Size, Theme } from "@/types";
2
2
  import { getInitParams } from "@/utils/business";
3
-
3
+ const size = getInitParams<Size>("size");
4
4
  export const modalThemes = {
5
5
  white: {
6
6
  mask: "rgba(0, 0, 0, 0.45)",
@@ -13,31 +13,31 @@ export const modalThemes = {
13
13
  right: "16px",
14
14
  background: "none",
15
15
  border: "none",
16
- fontSize: "24px",
16
+ fontSize: size === Size.SMALL ? 16 : 24,
17
17
  cursor: "pointer",
18
18
  color: "#999",
19
19
  padding: "0",
20
- width: "24px",
21
- height: "24px",
20
+ width: size === Size.SMALL ? 16 : 24,
21
+ height: size === Size.SMALL ? 16 : 24,
22
22
  display: "flex",
23
23
  alignItems: "center",
24
24
  justifyContent: "center",
25
25
  },
26
26
  title: {
27
- fontSize: "18px",
27
+ fontSize: size === Size.SMALL ? 16 : 18,
28
28
  fontWeight: "600",
29
- marginBottom: "24px",
29
+ marginBottom: size === Size.SMALL ? 16 : 24,
30
30
  color: "#222",
31
31
  },
32
32
  tabBtn: (active: boolean, isFirst: boolean) => ({
33
33
  flex: 1,
34
- padding: "12px 16px",
34
+ padding: size === Size.SMALL ? "8px 10px" : "12px 16px",
35
35
  background: active ? "#1890ff" : "transparent",
36
36
  color: active ? "#fff" : "#666",
37
37
  border: "1px solid #d9d9d9",
38
38
  borderRight: isFirst ? "none" : "1px solid #d9d9d9",
39
39
  cursor: "pointer",
40
- fontSize: "14px",
40
+ fontSize: size === Size.SMALL ? 12 : 14,
41
41
  fontWeight: active ? "600" : "400",
42
42
  borderRadius: isFirst ? "6px 0 0 6px" : "0 6px 6px 0",
43
43
  }),
@@ -49,35 +49,35 @@ export const modalThemes = {
49
49
  modalBoxShadow: "0 6px 16px rgba(0,0,0,0.32)",
50
50
  closeBtn: {
51
51
  position: "absolute",
52
- top: "16px",
53
- right: "16px",
52
+ top: size === Size.SMALL ? "12px" : "16px",
53
+ right: size === Size.SMALL ? "12px" : "16px",
54
54
  background: "none",
55
55
  border: "none",
56
- fontSize: "24px",
56
+ fontSize: size === Size.SMALL ? 16 : 24,
57
57
  cursor: "pointer",
58
58
  color: "#B5B8BE",
59
59
  padding: "0",
60
- width: "24px",
61
- height: "24px",
60
+ width: size === Size.SMALL ? 16 : 24,
61
+ height: size === Size.SMALL ? 16 : 24,
62
62
  display: "flex",
63
63
  alignItems: "center",
64
64
  justifyContent: "center",
65
65
  },
66
66
  title: {
67
- fontSize: "18px",
67
+ fontSize: size === Size.SMALL ? 16 : 18,
68
68
  fontWeight: "600",
69
- marginBottom: "24px",
69
+ marginBottom: size === Size.SMALL ? 16 : 24,
70
70
  color: "#F5F6FA",
71
71
  },
72
72
  tabBtn: (active: boolean, isFirst: boolean) => ({
73
73
  flex: 1,
74
- padding: "12px 16px",
74
+ padding: size === Size.SMALL ? "8px 10px" : "12px 16px",
75
75
  background: active ? "#00E8C6" : "transparent",
76
76
  color: active ? "#fff" : "#B5B8BE",
77
77
  border: "1px solid #444C5C",
78
78
  borderRight: isFirst ? "none" : "1px solid #444C5C",
79
79
  cursor: "pointer",
80
- fontSize: "14px",
80
+ fontSize: size === Size.SMALL ? 12 : 14,
81
81
  fontWeight: active ? "600" : "400",
82
82
  borderRadius: isFirst ? "6px 0 0 6px" : "0 6px 6px 0",
83
83
  }),
@@ -2,7 +2,9 @@ import type { FunctionalComponent, JSX } from "preact";
2
2
  import { useState, useRef, useEffect } from "preact/hooks";
3
3
  import { t } from "@/local";
4
4
  import { getSelectTheme } from "./theme";
5
-
5
+ import { getInitParams } from "@/utils/business";
6
+ import { Size } from "@/types";
7
+ const size = getInitParams<Size>("size");
6
8
  interface Option {
7
9
  value: string;
8
10
  label: string;
@@ -73,7 +75,7 @@ export const Select: FunctionalComponent<SelectProps> = ({
73
75
  scrollbar-color: ${theme.scrollbarThumb} ${theme.scrollbarTrack};
74
76
  }
75
77
  .custom-select-dropdown::-webkit-scrollbar {
76
- width: 8px;
78
+ width: ${size === Size.SMALL ? 6 : 8}px;
77
79
  }
78
80
  .custom-select-dropdown::-webkit-scrollbar-thumb {
79
81
  border-radius: 4px;
@@ -86,12 +88,12 @@ export const Select: FunctionalComponent<SelectProps> = ({
86
88
  <div
87
89
  onClick={() => !disabled && setOpen((o) => !o)}
88
90
  style={{
89
- minHeight: 40,
91
+ minHeight: size === Size.SMALL ? 32 : 40,
90
92
  borderRadius: 6,
91
93
  display: "flex",
92
94
  alignItems: "center",
93
- padding: "0 12px",
94
- fontSize: 15,
95
+ padding: size === Size.SMALL ? "0 10px" : "0 12px",
96
+ fontSize: size === Size.SMALL ? 12 : 15,
95
97
  cursor: disabled ? "not-allowed" : "pointer",
96
98
  boxSizing: "border-box",
97
99
  transition: "border 0.2s",
@@ -111,8 +113,8 @@ export const Select: FunctionalComponent<SelectProps> = ({
111
113
  </span>
112
114
  <span style={{ marginLeft: 8, display: "flex", alignItems: "center" }}>
113
115
  <svg
114
- width="20"
115
- height="20"
116
+ width={size === Size.SMALL ? 16 : 20}
117
+ height={size === Size.SMALL ? 16 : 20}
116
118
  viewBox="0 0 20 20"
117
119
  fill="none"
118
120
  xmlns="http://www.w3.org/2000/svg"
@@ -136,11 +138,11 @@ export const Select: FunctionalComponent<SelectProps> = ({
136
138
  position: "absolute",
137
139
  left: 0,
138
140
  right: 0,
139
- top: 44,
141
+ top: size === Size.SMALL ? 32 : 44,
140
142
  zIndex: 10,
141
143
  borderRadius: 6,
142
144
  boxShadow: theme.boxShadow,
143
- maxHeight: 220,
145
+ maxHeight: size === Size.SMALL ? 160 : 220,
144
146
  overflowY: "auto",
145
147
  ...theme.dropdown,
146
148
  ...dropdownStyle,
@@ -153,14 +155,14 @@ export const Select: FunctionalComponent<SelectProps> = ({
153
155
  flexDirection: "column",
154
156
  alignItems: "center",
155
157
  justifyContent: "center",
156
- minHeight: 120,
158
+ minHeight: size === Size.SMALL ? 80 : 120,
157
159
  width: "100%",
158
160
  userSelect: "none",
159
161
  }}
160
162
  >
161
163
  <svg
162
- width="64"
163
- height="41"
164
+ width={size === Size.SMALL ? 48 : 64}
165
+ height={size === Size.SMALL ? 32 : 41}
164
166
  viewBox="0 0 64 41"
165
167
  xmlns="http://www.w3.org/2000/svg"
166
168
  >
@@ -182,7 +184,13 @@ export const Select: FunctionalComponent<SelectProps> = ({
182
184
  </g>
183
185
  </g>
184
186
  </svg>
185
- <div style={{ marginTop: 8, color: "#bfbfbf", fontSize: 15 }}>
187
+ <div
188
+ style={{
189
+ marginTop: 8,
190
+ color: "#bfbfbf",
191
+ fontSize: size === Size.SMALL ? 12 : 15,
192
+ }}
193
+ >
186
194
  {t("暂无数据")}
187
195
  </div>
188
196
  </div>
@@ -198,7 +206,8 @@ export const Select: FunctionalComponent<SelectProps> = ({
198
206
  onMouseEnter={() => setHoveredIndex(idx)}
199
207
  onMouseLeave={() => setHoveredIndex(null)}
200
208
  style={{
201
- padding: "10px 16px",
209
+ padding: size === Size.SMALL ? "6px 10px" : "10px 16px",
210
+ fontSize: size === Size.SMALL ? 12 : 15,
202
211
  cursor: opt.disabled ? "not-allowed" : "pointer",
203
212
  fontWeight: value === opt.value ? 600 : 400,
204
213
  opacity: opt.disabled ? 0.6 : 1,
@@ -3,7 +3,9 @@ import { useState, useRef } from "preact/hooks";
3
3
  import { uploadFile } from "@/api";
4
4
  import { t } from "@/local";
5
5
  import { getUploadTheme } from "./theme";
6
-
6
+ import { getInitParams } from "@/utils/business";
7
+ import { Size } from "@/types";
8
+ const size = getInitParams<Size>("size");
7
9
  interface UploadProps {
8
10
  value?: string[];
9
11
  onChange?: (urls: string[]) => void;
@@ -68,11 +70,24 @@ export const Upload: FunctionalComponent<UploadProps> = ({
68
70
  }}
69
71
  onClick={() => !disabled && fileInputRef.current?.click()}
70
72
  >
71
- <div style={{ fontSize: 48, marginBottom: 12 }}>📁</div>
72
- <div style={{ color: "#222", fontSize: 15, marginBottom: 4 }}>
73
+ <div
74
+ style={{
75
+ fontSize: size === Size.SMALL ? 32 : 48,
76
+ marginBottom: size === Size.SMALL ? 8 : 12,
77
+ }}
78
+ >
79
+ 📁
80
+ </div>
81
+ <div
82
+ style={{
83
+ color: "#222",
84
+ fontSize: size === Size.SMALL ? 12 : 15,
85
+ marginBottom: size === Size.SMALL ? 4 : 8,
86
+ }}
87
+ >
73
88
  {t("点击或拖拽文件到此处上传")}
74
89
  </div>
75
- <div style={{ color: "#999", fontSize: 13 }}>
90
+ <div style={{ color: "#999", fontSize: size === Size.SMALL ? 12 : 13 }}>
76
91
  {t("支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传")}{" "}
77
92
  {maxCount} {t("个文件")}
78
93
  </div>
@@ -86,22 +101,24 @@ export const Upload: FunctionalComponent<UploadProps> = ({
86
101
  disabled={disabled}
87
102
  />
88
103
  {uploading && (
89
- <div style={{ marginTop: 12, color: "#1677ff" }}>
104
+ <div
105
+ style={{
106
+ marginTop: size === Size.SMALL ? 8 : 12,
107
+ color: "#1677ff",
108
+ }}
109
+ >
90
110
  {t("正在上传...")} {progress}%
91
111
  </div>
92
112
  )}
93
113
  </div>
94
114
  {value && value.length > 0 && (
95
- <div style={{ marginTop: 12 }}>
115
+ <div style={{ marginTop: size === Size.SMALL ? 8 : 12 }}>
96
116
  {value.map((url, idx) => (
97
117
  <div key={url} style={theme.fileItem}>
98
118
  <div style={{ display: "flex", alignItems: "center", flex: 1 }}>
99
119
  <span style={{ fontWeight: 500, wordBreak: "break-all" }}>
100
120
  {url.split("/").pop()}
101
121
  </span>
102
- <span style={{ color: "#8C8F93", fontSize: 13, marginLeft: 8 }}>
103
- [{t("已上传")}]
104
- </span>
105
122
  </div>
106
123
  <button
107
124
  type="button"
@@ -1,5 +1,7 @@
1
- import { Theme } from "@/types";
1
+ import { Size, Theme } from "@/types";
2
2
  import { getInitParams } from "@/utils/business";
3
+ const size = getInitParams<Size>("size");
4
+
3
5
 
4
6
  export const uploadThemes = {
5
7
  white: {
@@ -7,25 +9,25 @@ export const uploadThemes = {
7
9
  border: "1px dashed #E5E6EB",
8
10
  borderRadius: 8,
9
11
  background: "#FCFCFD",
10
- padding: 24,
12
+ padding: size === Size.SMALL ? 16 : 24,
11
13
  textAlign: "center",
12
14
  cursor: "pointer",
13
- minHeight: 120,
15
+ minHeight: size === Size.SMALL ? 80 : 120,
14
16
  display: "flex",
15
17
  flexDirection: "column",
16
18
  alignItems: "center",
17
19
  justifyContent: "center",
18
20
  color: "#999",
19
- fontSize: 15,
21
+ fontSize: size === Size.SMALL ? 12 : 15,
20
22
  },
21
23
  fileItem: {
22
24
  display: "flex",
23
25
  alignItems: "center",
24
26
  background: "#F7F8FA",
25
27
  borderRadius: 8,
26
- padding: "12px 16px",
28
+ padding: size === Size.SMALL ? "8px 10px" : "12px 16px",
27
29
  marginBottom: 8,
28
- fontSize: 15,
30
+ fontSize: size === Size.SMALL ? 12 : 15,
29
31
  color: "#222",
30
32
  justifyContent: "space-between",
31
33
  },
@@ -34,9 +36,9 @@ export const uploadThemes = {
34
36
  color: "#fff",
35
37
  border: "none",
36
38
  borderRadius: 6,
37
- padding: "4px 14px",
38
- fontSize: 15,
39
- marginLeft: 16,
39
+ padding: size === Size.SMALL ? "6px 10px" : "4px 14px",
40
+ fontSize: size === Size.SMALL ? 12 : 15,
41
+ marginLeft: size === Size.SMALL ? 8 : 16,
40
42
  cursor: "pointer",
41
43
  },
42
44
  },
@@ -45,25 +47,25 @@ export const uploadThemes = {
45
47
  border: "1.5px dashed #444C5C",
46
48
  borderRadius: 8,
47
49
  background: "#181A20",
48
- padding: 24,
50
+ padding: size === Size.SMALL ? 16 : 24,
49
51
  textAlign: "center",
50
52
  cursor: "pointer",
51
- minHeight: 120,
53
+ minHeight: size === Size.SMALL ? 80 : 120,
52
54
  display: "flex",
53
55
  flexDirection: "column",
54
56
  alignItems: "center",
55
57
  justifyContent: "center",
56
58
  color: "#999",
57
- fontSize: 15,
59
+ fontSize: size === Size.SMALL ? 12 : 15,
58
60
  },
59
61
  fileItem: {
60
62
  display: "flex",
61
63
  alignItems: "center",
62
64
  background: "#23262F",
63
65
  borderRadius: 8,
64
- padding: "12px 16px",
66
+ padding: size === Size.SMALL ? "8px 10px" : "12px 16px",
65
67
  marginBottom: 8,
66
- fontSize: 15,
68
+ fontSize: size === Size.SMALL ? 12 : 15,
67
69
  color: "#fff",
68
70
  justifyContent: "space-between",
69
71
  },
@@ -72,9 +74,9 @@ export const uploadThemes = {
72
74
  color: "#fff",
73
75
  border: "none",
74
76
  borderRadius: 6,
75
- padding: "4px 14px",
76
- fontSize: 15,
77
- marginLeft: 16,
77
+ padding: size === Size.SMALL ? "6px 10px" : "4px 14px",
78
+ fontSize: size === Size.SMALL ? 12 : 15,
79
+ marginLeft: size === Size.SMALL ? 8 : 16,
78
80
  cursor: "pointer",
79
81
  },
80
82
  },
package/src/demo/App.tsx CHANGED
@@ -5,7 +5,7 @@ import { initFundUnit, refreshBalance } from "@/main";
5
5
  import StatisticalBalance from "@/components/business/statistical-balance";
6
6
  import RefreshButton from "@/components/business/refresh-button";
7
7
  import { t } from "@/local";
8
- import { Env, Locale, Theme } from "@/types";
8
+ import { Env, Locale, Size, Theme } from "@/types";
9
9
  import TestBalanceData from "./testBalanceData";
10
10
 
11
11
  export default function DemoApp() {
@@ -43,14 +43,15 @@ 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
+ size: Size.SMALL,
47
+ // themeConfig: {
48
+ // white: {
49
+ // color: "red",
50
+ // },
51
+ // dark: {
52
+ // color: "pink",
53
+ // },
54
+ // },
54
55
  });
55
56
  };
56
57
 
@@ -17,6 +17,11 @@ export enum Env {
17
17
  PRODUCTION = "production",
18
18
  }
19
19
 
20
+ export enum Size {
21
+ SMALL = "small",
22
+ MEDIUM = "medium",
23
+ }
24
+
20
25
  // 类型定义
21
26
  export interface BalanceData {
22
27
  fundBalanceId: string;
@@ -43,15 +48,22 @@ export interface InitParams {
43
48
  theme?: Theme;
44
49
  locale?: Locale;
45
50
  env: Env;
51
+ size?: Size;
46
52
  themeConfig?: ThemeConfig;
47
53
  }
48
54
 
49
55
  export interface ThemeConfig {
50
56
  white?: {
51
57
  color?: string;
58
+ fontSize?: number;
52
59
  };
53
60
  dark?: {
54
61
  color?: string;
62
+ fontSize?: number;
63
+ };
64
+ global?: {
65
+ size?: Size;
66
+ fontSize?: number;
55
67
  };
56
68
  }
57
69
 
@@ -68,6 +80,7 @@ export declare function initFundUnit(params: {
68
80
  theme?: Theme;
69
81
  locale?: Locale;
70
82
  env: Env;
83
+ size?: Size;
71
84
  themeConfig?: ThemeConfig;
72
85
  }): {
73
86
  token: string;
@@ -77,6 +90,7 @@ export declare function initFundUnit(params: {
77
90
  theme?: Theme;
78
91
  locale: Locale;
79
92
  env: Env;
93
+ size?: Size;
80
94
  themeConfig?: ThemeConfig;
81
95
  };
82
96
 
@@ -16,6 +16,10 @@ export enum Env {
16
16
  PRODUCTION = "production",
17
17
  }
18
18
 
19
+ export enum Size {
20
+ SMALL = "small",
21
+ MEDIUM = "medium",
22
+ }
19
23
 
20
24
  export interface ThemeConfig {
21
25
  white?: {
@@ -1,6 +1,6 @@
1
1
  import { getAllDicts, getBalance } from "@/api";
2
2
  import { resetHttpInstance } from "@/api/axiosInstance";
3
- import { Locale, Theme, type Env } from "@/types";
3
+ import { Locale, Size, Theme, type Env } from "@/types";
4
4
 
5
5
  // 余额数据结构接口
6
6
  export interface BalanceData {
@@ -37,6 +37,7 @@ export interface InitParams {
37
37
  theme?: Theme;
38
38
  locale?: Locale;
39
39
  env: Env;
40
+ size?: Size;
40
41
  themeConfig?: ThemeConfig;
41
42
  }
42
43
 
@@ -59,6 +60,7 @@ export function initFundUnit(params: InitParams) {
59
60
  theme = Theme.WHITE,
60
61
  locale = Locale.ZH,
61
62
  env,
63
+ size,
62
64
  themeConfig,
63
65
  } = params;
64
66
  const token = "Bearer " + params.token;
@@ -73,6 +75,7 @@ export function initFundUnit(params: InitParams) {
73
75
  theme,
74
76
  locale,
75
77
  env,
78
+ size,
76
79
  themeConfig,
77
80
  })
78
81
  );
@@ -89,6 +92,7 @@ export function initFundUnit(params: InitParams) {
89
92
  theme,
90
93
  locale,
91
94
  env,
95
+ size,
92
96
  };
93
97
  }
94
98