@particle-network/ui-react 0.5.1-beta.2 → 0.5.1-beta.21

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 (90) hide show
  1. package/dist/components/ProgressWrapper/index.d.ts +2 -2
  2. package/dist/components/ProgressWrapper/index.js +2 -3
  3. package/dist/components/UXAutocomplete/index.js +1 -2
  4. package/dist/components/UXButton/button-theme.js +2 -2
  5. package/dist/components/UXButton/button.js +1 -1
  6. package/dist/components/UXCheckbox/checkbox.extend.js +16 -13
  7. package/dist/components/UXChip/chip.extend.d.ts +2 -1
  8. package/dist/components/UXChip/index.d.ts +1 -1
  9. package/dist/components/UXColorPicker/color-input.js +1 -1
  10. package/dist/components/UXColorPicker/color-picker.js +51 -33
  11. package/dist/components/UXColorPicker/types.d.ts +15 -0
  12. package/dist/components/UXCopy/index.js +1 -1
  13. package/dist/components/UXEmpty/index.js +1 -1
  14. package/dist/components/UXHint/index.js +1 -1
  15. package/dist/components/UXInput/index.d.ts +6 -6
  16. package/dist/components/UXInput/input.extend.d.ts +6 -6
  17. package/dist/components/UXModal/index.d.ts +1 -1
  18. package/dist/components/UXRadio/radio.extend.js +3 -3
  19. package/dist/components/UXSlider/use-slider.js +1 -1
  20. package/dist/components/UXSpinner/spinner.d.ts +1 -5
  21. package/dist/components/UXSpinner/spinner.js +3 -4
  22. package/dist/components/UXSwitch/index.d.ts +2 -2
  23. package/dist/components/UXSwitch/switch.extend.d.ts +2 -2
  24. package/dist/components/UXSwitch/switch.extend.js +6 -6
  25. package/dist/components/UXTabs/tabs.classes.js +4 -4
  26. package/dist/components/UXThemeSwitch/constants.d.ts +9 -0
  27. package/dist/components/UXThemeSwitch/constants.js +3 -0
  28. package/dist/components/UXThemeSwitch/custom-theme-config.d.ts +5 -0
  29. package/dist/components/UXThemeSwitch/custom-theme-config.js +172 -0
  30. package/dist/components/UXThemeSwitch/index.d.ts +2 -2
  31. package/dist/components/UXThemeSwitch/index.js +2 -2
  32. package/dist/components/UXThemeSwitch/theme-item.js +93 -15
  33. package/dist/components/UXThemeSwitch/theme-switch.d.ts +8 -1
  34. package/dist/components/UXThemeSwitch/theme-switch.js +20 -5
  35. package/dist/components/UXThemeSwitch/use-theme.d.ts +4 -1
  36. package/dist/components/UXThemeSwitch/use-theme.js +9 -57
  37. package/dist/components/UXThemeSwitch/utils.d.ts +28 -0
  38. package/dist/components/UXThemeSwitch/utils.js +260 -0
  39. package/dist/components/UXToast/index.d.ts +1 -1
  40. package/dist/components/UXToast/index.js +23 -11
  41. package/dist/components/UXTooltip/index.js +4 -12
  42. package/dist/components/WrapText/index.d.ts +6 -0
  43. package/dist/components/WrapText/index.js +15 -0
  44. package/dist/components/index.d.ts +1 -0
  45. package/dist/components/index.js +1 -0
  46. package/dist/components/layout/Box/box-theme.d.ts +2213 -0
  47. package/dist/components/layout/Box/box-theme.js +344 -0
  48. package/dist/components/layout/Box/box.d.ts +14 -0
  49. package/dist/components/layout/Box/box.js +99 -0
  50. package/dist/components/layout/Circle.js +2 -3
  51. package/dist/components/layout/Flex.d.ts +3 -27
  52. package/dist/components/layout/Flex.js +6 -19
  53. package/dist/components/layout/HStack.d.ts +1 -1
  54. package/dist/components/layout/Square.js +3 -3
  55. package/dist/components/layout/VStack.d.ts +1 -1
  56. package/dist/components/layout/VStack.js +2 -2
  57. package/dist/components/layout/index.d.ts +1 -0
  58. package/dist/components/layout/index.js +1 -0
  59. package/dist/components/typography/Text.js +35 -10
  60. package/dist/components/typography/Text.type.d.ts +4 -26
  61. package/dist/components/typography/Text.type.js +0 -47
  62. package/dist/components/typography/text-theme.d.ts +178 -0
  63. package/dist/components/typography/text-theme.js +79 -0
  64. package/dist/heroui/constants.d.ts +18 -0
  65. package/dist/heroui/constants.js +98 -0
  66. package/dist/heroui/types.d.ts +91 -0
  67. package/dist/heroui/types.js +0 -0
  68. package/dist/heroui/utils/colors.d.ts +34 -0
  69. package/dist/heroui/utils/colors.js +121 -0
  70. package/dist/heroui/utils/object.d.ts +1 -0
  71. package/dist/heroui/utils/object.js +17 -0
  72. package/dist/hooks/useI18n.d.ts +133 -25
  73. package/dist/hooks/useI18n.js +84 -2
  74. package/dist/hooks/useLang.d.ts +5 -1
  75. package/dist/hooks/useLang.js +13 -1
  76. package/dist/utils/cn.d.ts +2 -0
  77. package/dist/utils/cn.js +250 -0
  78. package/dist/utils/common.d.ts +1 -0
  79. package/dist/utils/common.js +4 -0
  80. package/dist/utils/index.d.ts +2 -0
  81. package/dist/utils/index.js +3 -1
  82. package/dist/utils/input-classes.js +2 -2
  83. package/package.json +7 -5
  84. package/tailwind-preset.js +84 -160
  85. package/dist/components/UXThemeSwitch/use-color-scheme.d.ts +0 -5
  86. package/dist/components/UXThemeSwitch/use-color-scheme.js +0 -11
  87. package/dist/components/UXThemeSwitch/use-theme-color.d.ts +0 -22
  88. package/dist/components/UXThemeSwitch/use-theme-color.js +0 -10
  89. package/dist/components/UXThemeSwitch/use-theme-store.d.ts +0 -41
  90. package/dist/components/UXThemeSwitch/use-theme-store.js +0 -31
@@ -0,0 +1,28 @@
1
+ import { type ThemeItemType } from '@particle-network/ui-shared';
2
+ /**
3
+ * 初始化并预加载字体 CSS(仅执行一次)
4
+ */
5
+ export declare const preloadFonts: () => void;
6
+ export declare const setCSSProperty: (property: string, value: string) => void;
7
+ /**
8
+ * 应用自定义主题的颜色到 CSS 变量
9
+ */
10
+ export declare const applyCustomThemeColors: (theme: ThemeItemType) => void;
11
+ /**
12
+ * 清除自定义主题的 CSS 变量(切换到其他主题时)
13
+ */
14
+ export declare const clearCustomThemeColors: () => void;
15
+ /**
16
+ * 应用主题到文档根元素
17
+ */
18
+ export declare const applyTheme: (theme: ThemeItemType) => void;
19
+ /**
20
+ * 从 Google Fonts 链接中提取字体名称
21
+ * 例如: https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap
22
+ * 提取: Roboto
23
+ */
24
+ export declare const extractFontFamilyFromLink: (link: string) => string | null;
25
+ /**
26
+ * 应用字体到 DOM
27
+ */
28
+ export declare const applyFont: (fontName: string | undefined) => void;
@@ -0,0 +1,260 @@
1
+ import { hexColorToHSLValue, themeData, themeKeys } from "@particle-network/ui-shared";
2
+ import { readableColor } from "color2k";
3
+ import { generateThemeColor } from "../../heroui/utils/colors.js";
4
+ import { objectEntries } from "../../utils/index.js";
5
+ import { DEFAULT_FONT_FAMILY, PRELOAD_FONTS_URL } from "./constants.js";
6
+ const getCSSProperties = (theme)=>{
7
+ const { colorVariables } = theme;
8
+ return {
9
+ foreground: [
10
+ [
11
+ '--heroui-foreground',
12
+ colorVariables.foreground
13
+ ]
14
+ ],
15
+ secondary: [
16
+ [
17
+ '--heroui-secondary',
18
+ colorVariables.secondary
19
+ ],
20
+ [
21
+ '--heroui-foreground-300',
22
+ colorVariables.secondary
23
+ ],
24
+ [
25
+ '--heroui-secondary-foreground',
26
+ readableColor(colorVariables.secondary)
27
+ ]
28
+ ],
29
+ tertiary: [
30
+ [
31
+ '--heroui-tertiary',
32
+ colorVariables.tertiary
33
+ ],
34
+ [
35
+ '--heroui-foreground-100',
36
+ colorVariables.tertiary
37
+ ],
38
+ [
39
+ '--heroui-tertiary-foreground',
40
+ readableColor(colorVariables.tertiary)
41
+ ]
42
+ ],
43
+ primary: generateThemeColor(colorVariables.primary, 'primary', theme.colorScheme).cssVariables,
44
+ success: [
45
+ [
46
+ '--heroui-success',
47
+ colorVariables.success
48
+ ],
49
+ [
50
+ '--heroui-success-foreground',
51
+ readableColor(colorVariables.success)
52
+ ]
53
+ ],
54
+ danger: [
55
+ [
56
+ '--heroui-danger',
57
+ colorVariables.danger
58
+ ],
59
+ [
60
+ '--heroui-danger-foreground',
61
+ readableColor(colorVariables.danger)
62
+ ]
63
+ ],
64
+ alert: [
65
+ [
66
+ '--heroui-alert',
67
+ colorVariables.alert
68
+ ],
69
+ [
70
+ '--heroui-alert-foreground',
71
+ readableColor(colorVariables.alert)
72
+ ]
73
+ ],
74
+ warning: [
75
+ [
76
+ '--heroui-warning',
77
+ colorVariables.warning
78
+ ],
79
+ [
80
+ '--heroui-warning-foreground',
81
+ readableColor(colorVariables.warning)
82
+ ]
83
+ ],
84
+ blue: [
85
+ [
86
+ '--heroui-blue',
87
+ colorVariables.blue
88
+ ],
89
+ [
90
+ '--heroui-blue-foreground',
91
+ readableColor(colorVariables.blue)
92
+ ]
93
+ ],
94
+ bgDefault: [
95
+ [
96
+ '--heroui-background',
97
+ colorVariables.bgDefault
98
+ ],
99
+ [
100
+ '--heroui-background-500',
101
+ colorVariables.bgDefault
102
+ ]
103
+ ],
104
+ bg200: [
105
+ [
106
+ '--heroui-background-200',
107
+ colorVariables.bg200
108
+ ]
109
+ ],
110
+ bg300: [
111
+ [
112
+ '--heroui-background-300',
113
+ colorVariables.bg300
114
+ ]
115
+ ],
116
+ bg400: [
117
+ [
118
+ '--heroui-background-400',
119
+ colorVariables.bg400
120
+ ]
121
+ ],
122
+ cursor: [
123
+ [
124
+ '--heroui-cursor',
125
+ colorVariables.cursor
126
+ ],
127
+ [
128
+ '--heroui-cursor-foreground',
129
+ readableColor(colorVariables.cursor)
130
+ ]
131
+ ],
132
+ overlay: [
133
+ [
134
+ '--heroui-overlay',
135
+ colorVariables.overlay
136
+ ],
137
+ [
138
+ '--heroui-content1',
139
+ colorVariables.overlay
140
+ ],
141
+ [
142
+ '--heroui-overlay-foreground',
143
+ readableColor(colorVariables.overlay)
144
+ ],
145
+ [
146
+ '--heroui-content1-foreground',
147
+ readableColor(colorVariables.overlay)
148
+ ]
149
+ ],
150
+ divider: [
151
+ [
152
+ '--heroui-divider',
153
+ colorVariables.divider
154
+ ],
155
+ [
156
+ '--heroui-divider-foreground',
157
+ readableColor(colorVariables.divider)
158
+ ]
159
+ ],
160
+ bullish: [
161
+ [
162
+ '--heroui-bullish',
163
+ colorVariables.bullish
164
+ ],
165
+ [
166
+ '--heroui-bullish-foreground',
167
+ readableColor(colorVariables.bullish)
168
+ ]
169
+ ],
170
+ bearish: [
171
+ [
172
+ '--heroui-bearish',
173
+ colorVariables.bearish
174
+ ],
175
+ [
176
+ '--heroui-bearish-foreground',
177
+ readableColor(colorVariables.bearish)
178
+ ]
179
+ ]
180
+ };
181
+ };
182
+ const preloadFonts = ()=>{
183
+ if ('undefined' == typeof window) return;
184
+ const existingLink = document.getElementById('ux-preload-fonts-link');
185
+ if (existingLink) return;
186
+ const linkElement = document.createElement('link');
187
+ linkElement.id = 'ux-preload-fonts-link';
188
+ linkElement.rel = 'stylesheet';
189
+ linkElement.href = PRELOAD_FONTS_URL;
190
+ document.head.appendChild(linkElement);
191
+ };
192
+ const setCSSProperty = (property, value)=>{
193
+ if ('undefined' == typeof window) return;
194
+ const root = document.documentElement;
195
+ root.style.setProperty(property, hexColorToHSLValue(value));
196
+ };
197
+ const applyCustomThemeColors = (theme)=>{
198
+ if ('undefined' == typeof window) return;
199
+ const baseThemeColors = themeData.find((t)=>t.id === theme.baseThemeId).colorVariables;
200
+ const customThemeColors = theme.colorVariables;
201
+ const cssProperties = getCSSProperties(theme);
202
+ objectEntries(cssProperties).forEach(([colorKey, value])=>{
203
+ if (baseThemeColors[colorKey] === customThemeColors[colorKey]) return;
204
+ value.forEach(([variable, value])=>{
205
+ setCSSProperty(variable, value);
206
+ });
207
+ });
208
+ };
209
+ const clearCustomThemeColors = ()=>{
210
+ if ('undefined' == typeof window) return;
211
+ const rootStyles = getComputedStyle(document.documentElement);
212
+ Array.from(rootStyles).filter((prop)=>prop.startsWith('--heroui')).forEach((prop)=>{
213
+ document.documentElement.style.removeProperty(prop);
214
+ });
215
+ };
216
+ const applyTheme = (theme)=>{
217
+ if ('undefined' == typeof window) return;
218
+ const root = document.documentElement;
219
+ const isClassListCorrect = root.classList.contains(theme.id);
220
+ const isDataThemeCorrect = root.getAttribute('data-theme') === theme.colorScheme;
221
+ const isDataPrefersColorCorrect = root.getAttribute('data-prefers-color') === theme.colorScheme;
222
+ if ('custom' === theme.id) {
223
+ clearCustomThemeColors();
224
+ applyCustomThemeColors(theme);
225
+ } else clearCustomThemeColors();
226
+ if (isClassListCorrect && isDataThemeCorrect && isDataPrefersColorCorrect && 'custom' !== theme.id) return;
227
+ if (!isDataThemeCorrect) root.setAttribute('data-theme', theme.colorScheme);
228
+ if (!isDataPrefersColorCorrect) root.setAttribute('data-prefers-color', theme.colorScheme);
229
+ root.classList.remove('dark');
230
+ root.classList.remove('light');
231
+ if (!isClassListCorrect) {
232
+ themeKeys.forEach((key)=>{
233
+ root.classList.remove(key);
234
+ });
235
+ root.classList.add('custom' === theme.id ? theme.baseThemeId : theme.id);
236
+ }
237
+ };
238
+ const extractFontFamilyFromLink = (link)=>{
239
+ if (!link) return null;
240
+ try {
241
+ const url = new URL(link);
242
+ const familyParam = url.searchParams.get('family');
243
+ if (!familyParam) return null;
244
+ const firstFamily = familyParam.split('&family=')[0].split(':')[0].replace(/\+/g, ' ');
245
+ return firstFamily;
246
+ } catch {
247
+ return null;
248
+ }
249
+ };
250
+ const applyFont = (fontName)=>{
251
+ if ('undefined' == typeof window) return;
252
+ if (fontName) {
253
+ document.documentElement.style.setProperty('--ux-font-family', `"${fontName}", ${DEFAULT_FONT_FAMILY}`);
254
+ document.body.style.fontFamily = `"${fontName}", ${DEFAULT_FONT_FAMILY}`;
255
+ } else {
256
+ document.documentElement.style.setProperty('--ux-font-family', DEFAULT_FONT_FAMILY);
257
+ document.body.style.fontFamily = DEFAULT_FONT_FAMILY;
258
+ }
259
+ };
260
+ export { applyCustomThemeColors, applyFont, applyTheme, clearCustomThemeColors, extractFontFamilyFromLink, preloadFonts, setCSSProperty };
@@ -12,7 +12,7 @@ export declare const toast: {
12
12
  error: (message: ReactNode, props?: Partial<ToastProps>) => string | null;
13
13
  loading: (message: ReactNode, props?: Partial<ToastProps>) => string | null;
14
14
  show: (props?: Partial<ToastProps> & {
15
- type: UXToastType;
15
+ type?: UXToastType;
16
16
  }) => string | null;
17
17
  closeAll: () => void;
18
18
  close: (key: string) => void;
@@ -5,6 +5,7 @@ import CircleCloseIcon from "@particle-network/icons/web/CircleCloseIcon";
5
5
  import CloseIcon from "@particle-network/icons/web/CloseIcon";
6
6
  import { hasLongWord } from "../../utils/index.js";
7
7
  import { UXSpinner } from "../UXSpinner/index.js";
8
+ import { WrapText } from "../WrapText/index.js";
8
9
  const UXToastProvider = ()=>/*#__PURE__*/ jsx(ToastProvider, {
9
10
  disableAnimation: true,
10
11
  placement: "top-center",
@@ -13,7 +14,7 @@ const UXToastProvider = ()=>/*#__PURE__*/ jsx(ToastProvider, {
13
14
  timeout: 4000
14
15
  },
15
16
  regionProps: {
16
- className: 'items-center mt-12 p-0 gap-2'
17
+ className: 'items-center mt-12 p-0 gap-2 z-[9999999999]'
17
18
  }
18
19
  });
19
20
  const getIcon = (type)=>{
@@ -32,19 +33,25 @@ const getIcon = (type)=>{
32
33
  return null;
33
34
  };
34
35
  const show = (props)=>{
35
- const { type, hideCloseButton, icon, variant, classNames, description, ...toastProps } = props ?? {};
36
- const { base, description: descriptionClassName, icon: iconClassName, loadingComponent, content, closeButton, ...restClassNames } = classNames ?? {};
36
+ const { type = 'info', hideCloseButton, icon, variant, classNames, title, description, ...toastProps } = props ?? {};
37
+ const { base, title: titleClassName, description: descriptionClassName, icon: iconClassName, loadingComponent, content, closeButton, ...restClassNames } = classNames ?? {};
37
38
  return addToast({
38
39
  classNames: {
39
40
  base: [
40
- 'bg-tertiary rounded-xl px-3.5 py-3 shadow-none border-none !w-fit max-w-[90vw] md:max-w-[400px] m-0',
41
+ 'bg-cursor rounded-xl px-3.5 shadow-none min-h-11 border-none !w-fit max-w-[90vw] md:max-w-[400px] m-0',
41
42
  !hideCloseButton && 'pr-12',
42
43
  'flat' === variant && 'success' === type && 'bg-[#0E3728]',
43
44
  'flat' === variant && 'error' === type && 'bg-[#501D1D]',
44
45
  base
45
46
  ],
47
+ title: [
48
+ 'text-cursor-foreground text-xs font-medium leading-4 !whitespace-normal me-0 line-clamp-2',
49
+ hasLongWord(title) && 'break-all',
50
+ 'flat' === variant && 'text-white',
51
+ titleClassName
52
+ ],
46
53
  description: [
47
- 'text-tertiary-foreground text-xs font-medium me-0 leading-4 line-clamp-4',
54
+ 'text-secondary !text-body3 me-0 leading-4',
48
55
  'flat' === variant && 'text-white',
49
56
  hasLongWord(description) && 'break-all',
50
57
  descriptionClassName
@@ -68,11 +75,16 @@ const show = (props)=>{
68
75
  ],
69
76
  ...restClassNames
70
77
  },
71
- description,
78
+ title: /*#__PURE__*/ jsx(WrapText, {
79
+ children: title
80
+ }),
81
+ description: /*#__PURE__*/ jsx(WrapText, {
82
+ children: description
83
+ }),
72
84
  icon: icon ?? getIcon(type),
73
85
  hideIcon: !icon && !getIcon(type),
74
86
  closeIcon: /*#__PURE__*/ jsx(CloseIcon, {
75
- className: 'flat' === variant ? 'text-white' : 'text-tertiary-foreground'
87
+ className: 'flat' === variant ? 'text-white' : 'text-cursor-foreground'
76
88
  }),
77
89
  loadingComponent: /*#__PURE__*/ jsx(UXSpinner, {
78
90
  size: 18
@@ -84,22 +96,22 @@ const show = (props)=>{
84
96
  const toast = {
85
97
  info: (message, props)=>show({
86
98
  type: 'info',
87
- description: message,
99
+ title: message,
88
100
  ...props
89
101
  }),
90
102
  success: (message, props)=>show({
91
103
  type: 'success',
92
- description: message,
104
+ title: message,
93
105
  ...props
94
106
  }),
95
107
  error: (message, props)=>show({
96
108
  type: 'error',
97
- description: message,
109
+ title: message,
98
110
  ...props
99
111
  }),
100
112
  loading: (message, props)=>show({
101
113
  type: 'loading',
102
- description: message,
114
+ title: message,
103
115
  ...props
104
116
  }),
105
117
  show,
@@ -1,23 +1,15 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import "react";
3
3
  import { hasLongWord } from "../../utils/index.js";
4
+ import { WrapText } from "../WrapText/index.js";
4
5
  import tooltip_extend from "./tooltip.extend.js";
5
- const renderContent = (content)=>{
6
- if (!content) return null;
7
- if ('string' != typeof content) return content;
8
- if (!content.includes('\n')) return content;
9
- return content.split('\n').flatMap((x, i, arr)=>i < arr.length - 1 ? [
10
- x,
11
- /*#__PURE__*/ jsx("br", {}, i)
12
- ] : [
13
- x
14
- ]);
15
- };
16
6
  const UXTooltip = (props)=>{
17
7
  const { content, classNames, ...restProps } = props;
18
8
  const { content: contentClassName, ...restClassNames } = classNames ?? {};
19
9
  return /*#__PURE__*/ jsx(tooltip_extend, {
20
- content: renderContent(content),
10
+ content: /*#__PURE__*/ jsx(WrapText, {
11
+ children: content
12
+ }),
21
13
  classNames: {
22
14
  content: [
23
15
  hasLongWord(content) && 'break-all',
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface WarpTextProps {
3
+ children: React.ReactNode;
4
+ }
5
+ export declare const WrapText: (props: WarpTextProps) => string | number | bigint | true | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | (string | import("react/jsx-runtime").JSX.Element)[] | null;
6
+ export {};
@@ -0,0 +1,15 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ const WrapText = (props)=>{
4
+ const { children } = props;
5
+ if (!children) return null;
6
+ if ('string' != typeof children) return children;
7
+ if (!children.includes('\n')) return children;
8
+ return children.split('\n').flatMap((x, i, arr)=>i < arr.length - 1 ? [
9
+ x,
10
+ /*#__PURE__*/ jsx("br", {}, i)
11
+ ] : [
12
+ x
13
+ ]);
14
+ };
15
+ export { WrapText };
@@ -32,3 +32,4 @@ export * from './UXTextarea';
32
32
  export * from './UXThemeSwitch';
33
33
  export * from './UXToast';
34
34
  export * from './UXTooltip';
35
+ export * from './WrapText';
@@ -32,3 +32,4 @@ export * from "./UXTextarea/index.js";
32
32
  export * from "./UXThemeSwitch/index.js";
33
33
  export * from "./UXToast/index.js";
34
34
  export * from "./UXTooltip/index.js";
35
+ export * from "./WrapText/index.js";