@particle-network/ui-react 0.5.1-beta.14 → 0.5.1-beta.15
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.
- package/dist/components/UXColorPicker/color-picker.js +14 -6
- package/dist/components/UXThemeSwitch/custom-theme-config.d.ts +4 -1
- package/dist/components/UXThemeSwitch/custom-theme-config.js +4 -3
- package/dist/components/UXThemeSwitch/theme-switch.d.ts +8 -1
- package/dist/components/UXThemeSwitch/theme-switch.js +4 -2
- package/package.json +3 -3
|
@@ -17,6 +17,7 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
17
17
|
const isControlled = void 0 !== value;
|
|
18
18
|
const [pickerKey, setPickerKey] = useState(0);
|
|
19
19
|
const [isInputFocused, setIsInputFocused] = useState(false);
|
|
20
|
+
const [isInteracting, setIsInteracting] = useState(false);
|
|
20
21
|
const getInitialColor = ()=>{
|
|
21
22
|
if (isControlled && value) return normalizeColor(value);
|
|
22
23
|
if (defaultValue) return normalizeColor(defaultValue);
|
|
@@ -31,12 +32,13 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
31
32
|
return parseColor('#000000');
|
|
32
33
|
});
|
|
33
34
|
const currentColor = useMemo(()=>{
|
|
34
|
-
if (isControlled && value) return normalizeColor(value);
|
|
35
|
+
if (isControlled && value && !isInteracting) return normalizeColor(value);
|
|
35
36
|
return internalColor;
|
|
36
37
|
}, [
|
|
37
38
|
value,
|
|
38
39
|
internalColor,
|
|
39
|
-
isControlled
|
|
40
|
+
isControlled,
|
|
41
|
+
isInteracting
|
|
40
42
|
]);
|
|
41
43
|
useEffect(()=>{
|
|
42
44
|
const initialColor = getInitialColor();
|
|
@@ -62,7 +64,10 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
62
64
|
]);
|
|
63
65
|
const handleChange = useCallback((color)=>{
|
|
64
66
|
if (color) {
|
|
65
|
-
|
|
67
|
+
if (isControlled) {
|
|
68
|
+
setInternalColor(color);
|
|
69
|
+
setIsInteracting(true);
|
|
70
|
+
} else setInternalColor(color);
|
|
66
71
|
onChange?.(color);
|
|
67
72
|
onValueChange?.(color.toString('hex'));
|
|
68
73
|
}
|
|
@@ -86,6 +91,7 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
86
91
|
]);
|
|
87
92
|
const handleChangeEnd = useCallback((color)=>{
|
|
88
93
|
if (color) {
|
|
94
|
+
setIsInteracting(false);
|
|
89
95
|
onChangeEnd?.(color);
|
|
90
96
|
onValueChangeEnd?.(color.toString('hex'));
|
|
91
97
|
}
|
|
@@ -123,7 +129,7 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
123
129
|
handleChangeEnd
|
|
124
130
|
]);
|
|
125
131
|
return /*#__PURE__*/ jsx(ColorPicker, {
|
|
126
|
-
value:
|
|
132
|
+
value: currentColor,
|
|
127
133
|
defaultValue: !isControlled && pickerKey > 0 ? internalColor : defaultValue,
|
|
128
134
|
onChange: handleChange,
|
|
129
135
|
children: /*#__PURE__*/ jsxs(HStack, {
|
|
@@ -153,6 +159,7 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
153
159
|
xChannel: "saturation",
|
|
154
160
|
yChannel: "brightness",
|
|
155
161
|
className: "aspect-square w-full overflow-hidden rounded-lg",
|
|
162
|
+
onChange: handleChange,
|
|
156
163
|
onChangeEnd: handleChangeEnd,
|
|
157
164
|
children: /*#__PURE__*/ jsx(ColorThumb, {
|
|
158
165
|
className: "h-4 w-4 rounded-full border-2 border-white shadow-[0_2px_4px_rgba(0,0,0,0.2)]"
|
|
@@ -179,6 +186,7 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
179
186
|
className: "min-w-0 flex-1",
|
|
180
187
|
colorSpace: "hsl",
|
|
181
188
|
orientation: "horizontal",
|
|
189
|
+
onChange: handleChange,
|
|
182
190
|
onChangeEnd: handleChangeEnd,
|
|
183
191
|
children: /*#__PURE__*/ jsx(SliderTrack, {
|
|
184
192
|
className: "h-3 rounded-full",
|
|
@@ -191,7 +199,7 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
191
199
|
}),
|
|
192
200
|
/*#__PURE__*/ jsx(ColorFields, {
|
|
193
201
|
defaultValue: !isControlled && pickerKey > 0 ? internalColor : defaultValue,
|
|
194
|
-
value:
|
|
202
|
+
value: currentColor,
|
|
195
203
|
onChange: handleColorFieldsChange
|
|
196
204
|
})
|
|
197
205
|
]
|
|
@@ -202,7 +210,7 @@ const UXColorPicker = ({ className, isDisabled, placement = 'bottom-start', valu
|
|
|
202
210
|
/*#__PURE__*/ jsx(ColorInput, {
|
|
203
211
|
isDisabled: isDisabled,
|
|
204
212
|
inputClassName: "focus:ring-0 px-0 text-left flex-1 relative bg-transparent",
|
|
205
|
-
value:
|
|
213
|
+
value: currentColor,
|
|
206
214
|
defaultValue: !isControlled && pickerKey > 0 ? internalColor : defaultValue,
|
|
207
215
|
onChange: handleColorFieldsChange,
|
|
208
216
|
onFocus: ()=>setIsInputFocused(true),
|
|
@@ -46,7 +46,7 @@ const COLOR_CATEGORIES = {
|
|
|
46
46
|
'blue'
|
|
47
47
|
]
|
|
48
48
|
};
|
|
49
|
-
const CustomThemeConfig = ()=>{
|
|
49
|
+
const CustomThemeConfig = ({ colorChangeMode = 'dragEnd' })=>{
|
|
50
50
|
const { lang } = useLang();
|
|
51
51
|
const i18n = useI18n();
|
|
52
52
|
const { theme, setTheme, setCustomTheme } = useTheme();
|
|
@@ -102,9 +102,10 @@ const CustomThemeConfig = ()=>{
|
|
|
102
102
|
children: label
|
|
103
103
|
}),
|
|
104
104
|
/*#__PURE__*/ jsx(UXColorPicker, {
|
|
105
|
-
|
|
105
|
+
defaultValue: value,
|
|
106
106
|
isChanged: isCustomized,
|
|
107
|
-
onValueChange: (newValue)=>handleColorChange(color, newValue),
|
|
107
|
+
onValueChange: 'drag' === colorChangeMode ? (newValue)=>handleColorChange(color, newValue) : void 0,
|
|
108
|
+
onValueChangeEnd: 'dragEnd' === colorChangeMode ? (newValue)=>handleColorChange(color, newValue) : void 0,
|
|
108
109
|
onReset: ()=>handleColorChange(color, baseTheme.colorVariables[color])
|
|
109
110
|
})
|
|
110
111
|
]
|
|
@@ -4,9 +4,16 @@ import { type UXModalProps } from '../UXModal';
|
|
|
4
4
|
export interface UXThemeSwitchModalProps extends Pick<UXModalProps, 'isOpen' | 'onClose' | 'onOpenChange' | 'backdrop'> {
|
|
5
5
|
as?: 'modal' | 'drawer';
|
|
6
6
|
omitThemes?: ThemeId[];
|
|
7
|
+
/**
|
|
8
|
+
* 颜色改变模式
|
|
9
|
+
* - drag: 拖动时改变颜色
|
|
10
|
+
* - dragEnd: 拖动停止时改变颜色
|
|
11
|
+
* @default dragEnd
|
|
12
|
+
*/
|
|
13
|
+
colorChangeMode?: 'drag' | 'dragEnd';
|
|
7
14
|
}
|
|
8
15
|
export declare const UXThemeSwitchModal: React.FC<UXThemeSwitchModalProps>;
|
|
9
|
-
export interface UXThemeSwitchProps extends Pick<UXThemeSwitchModalProps, 'as' | 'omitThemes' | 'backdrop'> {
|
|
16
|
+
export interface UXThemeSwitchProps extends Pick<UXThemeSwitchModalProps, 'as' | 'omitThemes' | 'backdrop' | 'colorChangeMode'> {
|
|
10
17
|
children?: (onOpen: () => void) => React.ReactNode;
|
|
11
18
|
}
|
|
12
19
|
export declare const UXThemeSwitch: React.FC<UXThemeSwitchProps>;
|
|
@@ -32,7 +32,7 @@ const FONT_EXAMPLES = [
|
|
|
32
32
|
url: 'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap'
|
|
33
33
|
}
|
|
34
34
|
];
|
|
35
|
-
const UXThemeSwitchModal = ({ as = 'modal', omitThemes = [], backdrop, isOpen, onClose, onOpenChange })=>{
|
|
35
|
+
const UXThemeSwitchModal = ({ as = 'modal', omitThemes = [], backdrop, isOpen, onClose, onOpenChange, colorChangeMode })=>{
|
|
36
36
|
const i18n = useI18n();
|
|
37
37
|
const { theme: selectedTheme, customTheme: savedCustomTheme, setTheme, initTheme, fontUrl, setFontUrl, fontName, fontLoadStatus, clearFontUrl } = useTheme();
|
|
38
38
|
const [isFontExampleOpen, setIsFontExampleOpen] = useState(false);
|
|
@@ -75,7 +75,9 @@ const UXThemeSwitchModal = ({ as = 'modal', omitThemes = [], backdrop, isOpen, o
|
|
|
75
75
|
'custom' === selectedTheme.id && /*#__PURE__*/ jsxs(Fragment, {
|
|
76
76
|
children: [
|
|
77
77
|
/*#__PURE__*/ jsx(UXDivider, {}),
|
|
78
|
-
/*#__PURE__*/ jsx(CustomThemeConfig, {
|
|
78
|
+
/*#__PURE__*/ jsx(CustomThemeConfig, {
|
|
79
|
+
colorChangeMode: colorChangeMode
|
|
80
|
+
})
|
|
79
81
|
]
|
|
80
82
|
}),
|
|
81
83
|
/*#__PURE__*/ jsx(UXDivider, {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@particle-network/ui-react",
|
|
3
|
-
"version": "0.5.1-beta.
|
|
3
|
+
"version": "0.5.1-beta.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -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/
|
|
56
|
-
"@particle-network/
|
|
55
|
+
"@particle-network/ui-shared": "0.4.1-beta.5",
|
|
56
|
+
"@particle-network/icons": "0.5.1-beta.6"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "rslib build",
|