@particle-network/ui-react 0.5.1-beta.11 → 0.5.1-beta.12

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.
@@ -162,8 +162,7 @@ const ThemeItem = ({ id, zhName, enName, isSelected, onClick })=>{
162
162
  'custom' === id ? /*#__PURE__*/ jsxs(Fragment, {
163
163
  children: [
164
164
  /*#__PURE__*/ jsx("g", {
165
- "clip-path": "url(#paint0_angular_48986_280686_clip_path)",
166
- "data-figma-skip-parse": "true",
165
+ clipPath: "url(#paint0_angular_48986_280686_clip_path)",
167
166
  children: /*#__PURE__*/ jsx("g", {
168
167
  transform: "matrix(0 0.011 -0.011 0 39 51)",
169
168
  children: /*#__PURE__*/ jsx("foreignObject", {
@@ -188,7 +187,7 @@ const ThemeItem = ({ id, zhName, enName, isSelected, onClick })=>{
188
187
  r: "10.7583",
189
188
  "data-figma-gradient-fill": '{"type":"GRADIENT_ANGULAR","stops":[{"color":{"r":1.0,"g":0.0,"b":0.0,"a":1.0},"position":0.0},{"color":{"r":1.0,"g":0.52295231819152832,"b":0.0,"a":1.0},"position":0.15000000596046448},{"color":{"r":0.74555355310440063,"g":1.0,"b":0.0,"a":1.0},"position":0.32499998807907104},{"color":{"r":0.029410807415843010,"g":0.88352936506271362,"b":1.0,"a":1.0},"position":0.55500000715255737},{"color":{"r":0.14000000059604645,"g":0.0,"b":1.0,"a":1.0},"position":0.78500002622604370},{"color":{"r":0.67999994754791260,"g":0.0,"b":1.0,"a":1.0},"position":1.0}],"stopsVar":[{"color":{"r":1.0,"g":0.0,"b":0.0,"a":1.0},"position":0.0},{"color":{"r":1.0,"g":0.52295231819152832,"b":0.0,"a":1.0},"position":0.15000000596046448},{"color":{"r":0.74555355310440063,"g":1.0,"b":0.0,"a":1.0},"position":0.32499998807907104},{"color":{"r":0.029410807415843010,"g":0.88352936506271362,"b":1.0,"a":1.0},"position":0.55500000715255737},{"color":{"r":0.14000000059604645,"g":0.0,"b":1.0,"a":1.0},"position":0.78500002622604370},{"color":{"r":0.67999994754791260,"g":0.0,"b":1.0,"a":1.0},"position":1.0}],"transform":{"m00":1.3471115643134642e-15,"m01":-22.0,"m02":50.0,"m10":22.0,"m11":1.3471115643134642e-15,"m12":40.0},"opacity":1.0,"blendMode":"NORMAL","visible":true}',
190
189
  stroke: "#8B8EA1",
191
- "stroke-width": "0.483303"
190
+ strokeWidth: "0.483303"
192
191
  }),
193
192
  /*#__PURE__*/ jsx("defs", {
194
193
  children: /*#__PURE__*/ jsx("clipPath", {
@@ -197,7 +196,7 @@ const ThemeItem = ({ id, zhName, enName, isSelected, onClick })=>{
197
196
  cx: "39",
198
197
  cy: "51",
199
198
  r: "10.7583",
200
- "stroke-width": "0.483303"
199
+ strokeWidth: "0.483303"
201
200
  })
202
201
  })
203
202
  })
@@ -1,8 +1,8 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useMemo, useState } from "react";
2
+ import { useEffect, useMemo, useState } from "react";
3
3
  import { useDisclosure } from "@heroui/use-disclosure";
4
4
  import { ChartColorSwitchIcon, CopyIcon } from "@particle-network/icons/web";
5
- import { DEFAULT_THEME_ID, themeData } from "@particle-network/ui-shared";
5
+ import { themeData } from "@particle-network/ui-shared";
6
6
  import { useI18n } from "../../hooks/index.js";
7
7
  import { cn } from "../../utils/index.js";
8
8
  import { HStack, VStack } from "../layout/index.js";
@@ -34,25 +34,17 @@ const FONT_EXAMPLES = [
34
34
  ];
35
35
  const UXThemeSwitchModal = ({ as = 'modal', omitThemes = [], backdrop, isOpen, onClose, onOpenChange })=>{
36
36
  const i18n = useI18n();
37
- const { theme: selectedTheme, customTheme: savedCustomTheme, setTheme, fontUrl, setFontUrl, fontName, fontLoadStatus, clearFontUrl } = useTheme();
37
+ const { theme: selectedTheme, customTheme: savedCustomTheme, setTheme, initTheme, fontUrl, setFontUrl, fontName, fontLoadStatus, clearFontUrl } = useTheme();
38
38
  const [isFontExampleOpen, setIsFontExampleOpen] = useState(false);
39
+ useEffect(()=>{
40
+ initTheme();
41
+ }, []);
39
42
  const Component = 'modal' === as ? UXModal : UXDrawer;
40
43
  const themes = useMemo(()=>themeData.filter((theme)=>!omitThemes.includes(theme.id)), [
41
44
  omitThemes
42
45
  ]);
43
46
  const handleThemeSelect = (theme)=>{
44
- if ('custom' === theme.id) if (savedCustomTheme) setTheme(savedCustomTheme);
45
- else {
46
- const baseTheme = themeData.find((t)=>t.id === DEFAULT_THEME_ID) || themeData["0"];
47
- const customTheme = {
48
- ...theme,
49
- baseThemeId: DEFAULT_THEME_ID,
50
- colorScheme: baseTheme.colorScheme,
51
- colorVariables: baseTheme.colorVariables
52
- };
53
- setTheme(customTheme);
54
- }
55
- else setTheme(theme);
47
+ 'custom' === theme.id ? setTheme(savedCustomTheme) : setTheme(theme);
56
48
  };
57
49
  return /*#__PURE__*/ jsx(Component, {
58
50
  isOpen: isOpen,
@@ -6,6 +6,7 @@ export declare const useTheme: () => {
6
6
  theme: ThemeItemType;
7
7
  customTheme: ThemeItemType;
8
8
  setTheme: (theme: ThemeItemType) => void;
9
+ initTheme: () => void;
9
10
  setCustomTheme: (customTheme: ThemeItemType) => void;
10
11
  fontUrl: string;
11
12
  setFontUrl: (link: string) => void;
@@ -1,4 +1,3 @@
1
- import { useEffect } from "react";
2
1
  import { useDebounceFn } from "ahooks";
3
2
  import { useThemeStore } from "./use-theme-store.js";
4
3
  import { applyFont, applyTheme, extractFontFamilyFromLink, preloadFonts } from "./utils.js";
@@ -42,16 +41,11 @@ const useTheme = ()=>{
42
41
  const { run: debouncedApplyFont } = useDebounceFn((customFontLink, themeFontName)=>applyFontWithStatus(customFontLink, themeFontName), {
43
42
  wait: 300
44
43
  });
45
- useEffect(()=>{
44
+ const initTheme = ()=>{
46
45
  preloadFonts();
47
46
  applyTheme(theme);
48
47
  debouncedApplyFont(fontUrl, theme.fontName);
49
- }, []);
50
- useEffect(()=>{
51
- applyTheme(theme);
52
- }, [
53
- theme
54
- ]);
48
+ };
55
49
  const setTheme = (theme)=>{
56
50
  storeSetTheme(theme);
57
51
  applyTheme(theme);
@@ -71,6 +65,7 @@ const useTheme = ()=>{
71
65
  theme,
72
66
  customTheme,
73
67
  setTheme,
68
+ initTheme,
74
69
  setCustomTheme: storeSetCustomTheme,
75
70
  fontUrl,
76
71
  setFontUrl,
@@ -1,6 +1,7 @@
1
- import { hexColorToHSLValue, themeKeys } from "@particle-network/ui-shared";
1
+ import { hexColorToHSLValue, themeData, themeKeys } from "@particle-network/ui-shared";
2
2
  import { readableColor } from "color2k";
3
3
  import { generateThemeColor } from "../../heroui/utils/colors.js";
4
+ import { objectEntries } from "../../utils/index.js";
4
5
  import { DEFAULT_FONT_FAMILY, PRELOAD_FONTS_URL } from "./constants.js";
5
6
  const getCSSProperties = (theme)=>{
6
7
  const { colorVariables } = theme;
@@ -12,10 +13,17 @@ const getCSSProperties = (theme)=>{
12
13
  ]
13
14
  ],
14
15
  secondary: [
15
- ...generateThemeColor(colorVariables.secondary, 'secondary', theme.colorScheme).cssVariables,
16
+ [
17
+ '--heroui-secondary',
18
+ colorVariables.secondary
19
+ ],
16
20
  [
17
21
  '--heroui-foreground-300',
18
22
  colorVariables.secondary
23
+ ],
24
+ [
25
+ '--heroui-secondary-foreground',
26
+ readableColor(colorVariables.secondary)
19
27
  ]
20
28
  ],
21
29
  tertiary: [
@@ -33,8 +41,26 @@ const getCSSProperties = (theme)=>{
33
41
  ]
34
42
  ],
35
43
  primary: generateThemeColor(colorVariables.primary, 'primary', theme.colorScheme).cssVariables,
36
- success: generateThemeColor(colorVariables.success, 'success', theme.colorScheme).cssVariables,
37
- danger: generateThemeColor(colorVariables.danger, 'danger', 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
+ ],
38
64
  alert: [
39
65
  [
40
66
  '--heroui-alert',
@@ -45,7 +71,16 @@ const getCSSProperties = (theme)=>{
45
71
  readableColor(colorVariables.alert)
46
72
  ]
47
73
  ],
48
- warning: generateThemeColor(colorVariables.warning, 'warning', theme.colorScheme).cssVariables,
74
+ warning: [
75
+ [
76
+ '--heroui-warning',
77
+ colorVariables.warning
78
+ ],
79
+ [
80
+ '--heroui-warning-foreground',
81
+ readableColor(colorVariables.warning)
82
+ ]
83
+ ],
49
84
  blue: [
50
85
  [
51
86
  '--heroui-blue',
@@ -161,8 +196,11 @@ const setCSSProperty = (property, value)=>{
161
196
  };
162
197
  const applyCustomThemeColors = (theme)=>{
163
198
  if ('undefined' == typeof window) return;
199
+ const baseThemeColors = themeData.find((t)=>t.id === theme.baseThemeId).colorVariables;
200
+ const customThemeColors = theme.colorVariables;
164
201
  const cssProperties = getCSSProperties(theme);
165
- Object.entries(cssProperties).forEach(([, value])=>{
202
+ objectEntries(cssProperties).forEach(([colorKey, value])=>{
203
+ if (baseThemeColors[colorKey] === customThemeColors[colorKey]) return;
166
204
  value.forEach(([variable, value])=>{
167
205
  setCSSProperty(variable, value);
168
206
  });
package/dist/utils/cn.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { clsx } from "clsx";
2
- import { extendTailwindMerge, twMerge } from "tailwind-merge";
2
+ import { extendTailwindMerge } from "tailwind-merge";
3
3
  const COMMON_UNITS = [
4
4
  'small',
5
5
  'medium',
@@ -27,7 +27,7 @@ const OPACITY = [
27
27
  'disabled',
28
28
  'hover'
29
29
  ];
30
- const cn_twMerge = extendTailwindMerge({
30
+ const twMerge = extendTailwindMerge({
31
31
  extend: {
32
32
  classGroups: {
33
33
  'font-size': [
@@ -245,14 +245,6 @@ const cn_twMerge = extendTailwindMerge({
245
245
  }
246
246
  });
247
247
  function cn(...inputs) {
248
- return cn_twMerge(clsx(inputs));
248
+ return twMerge(clsx(inputs));
249
249
  }
250
- console.log(cn('text-red-500 text-brand text-h1'), '|', twMerge('text-red-500 text-brand text-h1'));
251
- console.log(cn('text-red-500 text-sm text-h1'), '|', twMerge('text-red-500 text-sm text-h1'));
252
- console.log(cn('px-2 px-md'), '|', twMerge('px-2 px-md'));
253
- console.log(cn('gap-2 gap-md'), '|', twMerge('gap-2 gap-md'));
254
- console.log(cn('rounded-sm rounded-small'), '|', twMerge('rounded-sm rounded-small'));
255
- console.log(cn('top-1 top-md'), '|', twMerge('top-1 top-md'));
256
- console.log(cn('opacity-0 opacity-disabled opacity-hover'), '|', twMerge('opacity-0 opacity-disabled opacity-hover'));
257
- console.log(cn('border-1 border-large'), '|', twMerge('border-1 border-large'));
258
250
  export { cn };
@@ -0,0 +1 @@
1
+ export declare function objectEntries<T extends object>(obj: T): [keyof T & string, T[keyof T & string]][];
@@ -0,0 +1,4 @@
1
+ function objectEntries(obj) {
2
+ return Object.entries(obj);
3
+ }
4
+ export { objectEntries };
@@ -1,5 +1,6 @@
1
1
  export { absoluteFullClasses, baseStyles, collapseAdjacentVariantBorders, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, ringClasses, translateCenterClasses, } from './classes';
2
2
  export { cn } from './cn';
3
+ export { objectEntries } from './common';
3
4
  export * from './detect';
4
5
  export * from './input-classes';
5
6
  export { colorVariants } from './variants';
@@ -1,6 +1,7 @@
1
1
  import { absoluteFullClasses, baseStyles, collapseAdjacentVariantBorders, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, ringClasses, translateCenterClasses } from "./classes.js";
2
2
  import { cn } from "./cn.js";
3
+ import { objectEntries } from "./common.js";
3
4
  import { colorVariants } from "./variants.js";
4
5
  export * from "./detect.js";
5
6
  export * from "./input-classes.js";
6
- export { absoluteFullClasses, baseStyles, cn, collapseAdjacentVariantBorders, colorVariants, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, ringClasses, translateCenterClasses };
7
+ export { absoluteFullClasses, baseStyles, cn, collapseAdjacentVariantBorders, colorVariants, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, objectEntries, ringClasses, translateCenterClasses };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-react",
3
- "version": "0.5.1-beta.11",
3
+ "version": "0.5.1-beta.12",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -38,8 +38,8 @@
38
38
  "@rslib/core": "^0.12.3",
39
39
  "@types/react": "^19.1.10",
40
40
  "react": "^19.1.0",
41
- "@particle-network/lintstaged-config": "0.1.0",
42
- "@particle-network/eslint-config": "0.3.0"
41
+ "@particle-network/eslint-config": "0.3.0",
42
+ "@particle-network/lintstaged-config": "0.1.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "react": ">=16.9.0",
@@ -52,8 +52,8 @@
52
52
  "react-aria-components": "^1.14.0",
53
53
  "values.js": "^2.1.1",
54
54
  "zustand": "^5.0.8",
55
- "@particle-network/icons": "0.5.1-beta.5",
56
- "@particle-network/ui-shared": "0.4.1-beta.4"
55
+ "@particle-network/icons": "0.5.1-beta.6",
56
+ "@particle-network/ui-shared": "0.4.1-beta.5"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "rslib build",