@easyv/react-components 0.4.7 → 0.4.8

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.
@@ -34,44 +34,61 @@ export default function Panel(_ref) {
34
34
  _useState2 = _slicedToArray(_useState, 2),
35
35
  color = _useState2[0],
36
36
  setColor = _useState2[1];
37
+ var _useState3 = useState(function () {
38
+ return color.hsv.h;
39
+ }),
40
+ _useState4 = _slicedToArray(_useState3, 2),
41
+ hue = _useState4[0],
42
+ setHue = _useState4[1];
37
43
  useEffect(function () {
38
44
  if (propsColor) {
45
+ var hsv = tinycolor(propsColor).toHsv();
39
46
  setColor({
40
- hsv: tinycolor(propsColor).toHsv(),
47
+ hsv: hsv,
41
48
  alpha: tinycolor(propsColor).getAlpha()
42
49
  });
50
+ // 只有当饱和度和亮度都不为 0 时,才从 props 更新 hue
51
+ // 否则保留当前内存中的 hue,避免边缘跳动
52
+ if (hsv.s !== 0 && hsv.v !== 0) {
53
+ setHue(hsv.h);
54
+ }
43
55
  }
44
56
  }, [propsColor]);
45
57
  var _color$hsv = color.hsv,
46
- h = _color$hsv.h,
47
58
  s = _color$hsv.s,
48
59
  v = _color$hsv.v;
49
- var _tinycolor$toRgb = tinycolor(color.hsv).toRgb(),
60
+ var h = hue;
61
+ var colorHsv = {
62
+ h: h,
63
+ s: s,
64
+ v: v
65
+ };
66
+ var _tinycolor$toRgb = tinycolor(colorHsv).toRgb(),
50
67
  r = _tinycolor$toRgb.r,
51
68
  g = _tinycolor$toRgb.g,
52
69
  b = _tinycolor$toRgb.b;
53
- var colorString = tinycolor(color.hsv).setAlpha(color.alpha).toRgbString();
54
- var hexString = tinycolor(color.hsv).toHexString();
70
+ var colorString = tinycolor(colorHsv).setAlpha(color.alpha).toRgbString();
71
+ var hexString = tinycolor(colorHsv).toHexString();
55
72
  var hexRef = useRef(null);
56
73
  var handleHsvChange = function handleHsvChange(hsv, complete) {
74
+ setHue(hsv.h);
57
75
  setColor(_objectSpread(_objectSpread({}, color), {}, {
58
76
  hsv: hsv
59
77
  }));
78
+ var colorStr = tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
79
+ a: color.alpha
80
+ })).toRgbString();
60
81
  if (complete) {
61
- onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
62
- a: color.alpha
63
- })).toRgbString());
82
+ onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(colorStr);
64
83
  } else {
65
- onChange === null || onChange === void 0 ? void 0 : onChange(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
66
- a: color.alpha
67
- })).toRgbString());
84
+ onChange === null || onChange === void 0 ? void 0 : onChange(colorStr);
68
85
  }
69
86
  };
70
87
  var handleAlphaChange = function handleAlphaChange(alpha, complete) {
71
88
  setColor(_objectSpread(_objectSpread({}, color), {}, {
72
89
  alpha: alpha
73
90
  }));
74
- var value = tinycolor(_objectSpread(_objectSpread({}, color.hsv), {}, {
91
+ var value = tinycolor(_objectSpread(_objectSpread({}, colorHsv), {}, {
75
92
  a: alpha
76
93
  })).toRgbString();
77
94
  if (complete === 'all') {
@@ -85,9 +102,11 @@ export default function Panel(_ref) {
85
102
  };
86
103
  var handleHexChange = function handleHexChange(val) {
87
104
  var hexVal = getHexValue(val);
88
- var hsv = tinycolor(hexVal).toHsv();
89
- var hexString = tinycolor(hsv).toHexString();
105
+ var tc = tinycolor(hexVal);
106
+ var hsv = tc.toHsv();
107
+ var hexString = tc.toHexString();
90
108
  hexRef.current.forceUpdate(hexString.slice(1).toUpperCase());
109
+ setHue(hsv.h);
91
110
  setColor(_objectSpread(_objectSpread({}, color), {}, {
92
111
  hsv: hsv
93
112
  }));
@@ -96,11 +115,13 @@ export default function Panel(_ref) {
96
115
  })).toRgbString());
97
116
  };
98
117
  var handleRgbChange = function handleRgbChange(rgb) {
99
- var hsv = tinycolor(_objectSpread({
118
+ var tc = tinycolor(_objectSpread({
100
119
  r: r,
101
120
  g: g,
102
121
  b: b
103
- }, rgb)).toHsv();
122
+ }, rgb));
123
+ var hsv = tc.toHsv();
124
+ setHue(hsv.h);
104
125
  setColor(_objectSpread(_objectSpread({}, color), {}, {
105
126
  hsv: hsv
106
127
  }));
@@ -108,21 +129,26 @@ export default function Panel(_ref) {
108
129
  a: color.alpha
109
130
  })).toRgbString());
110
131
  };
111
- var handleColorChange = function handleColorChange(color) {
132
+ var handleColorChange = function handleColorChange(colorStr) {
133
+ var tc = tinycolor(colorStr);
134
+ var hsv = tc.toHsv();
135
+ setHue(hsv.h);
112
136
  setColor({
113
- hsv: tinycolor(color).toHsv(),
137
+ hsv: hsv,
114
138
  alpha: 1
115
139
  });
116
- onChangeWithComplete(color);
140
+ onChangeWithComplete(colorStr);
117
141
  };
118
- var onChangeWithComplete = function onChangeWithComplete(color) {
119
- onChange === null || onChange === void 0 ? void 0 : onChange(color);
120
- onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(color);
142
+ var onChangeWithComplete = function onChangeWithComplete(colorStr) {
143
+ onChange === null || onChange === void 0 ? void 0 : onChange(colorStr);
144
+ onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(colorStr);
121
145
  };
122
146
  return /*#__PURE__*/_jsxs("div", {
123
147
  className: "colors-picker-panel",
124
148
  children: [/*#__PURE__*/_jsx(Palette, {
125
- color: color,
149
+ color: _objectSpread(_objectSpread({}, color), {}, {
150
+ hsv: colorHsv
151
+ }),
126
152
  onChange: function onChange(newS, newV) {
127
153
  return handleHsvChange({
128
154
  h: h,
@@ -153,7 +179,9 @@ export default function Panel(_ref) {
153
179
  className: "colors-picker-control-bars",
154
180
  children: [/*#__PURE__*/_jsx(ControlBar, {
155
181
  type: "hue",
156
- color: color,
182
+ color: _objectSpread(_objectSpread({}, color), {}, {
183
+ hsv: colorHsv
184
+ }),
157
185
  onChange: function onChange(newH) {
158
186
  return handleHsvChange({
159
187
  h: newH,
@@ -170,7 +198,9 @@ export default function Panel(_ref) {
170
198
  }
171
199
  }), !disabledAlpha && /*#__PURE__*/_jsx(ControlBar, {
172
200
  type: "alpha",
173
- color: color,
201
+ color: _objectSpread(_objectSpread({}, color), {}, {
202
+ hsv: colorHsv
203
+ }),
174
204
  onChange: handleAlphaChange,
175
205
  onChangeComplete: function onChangeComplete(val) {
176
206
  return handleAlphaChange(val, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/react-components",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "a react component library base on arco design",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
@@ -101,7 +101,7 @@
101
101
  },
102
102
  "packageManager": "pnpm@8.12.1",
103
103
  "engines": {
104
- "node": ">=14.17.0"
104
+ "node": ">=14.17.0 <24.0.0"
105
105
  },
106
106
  "publishConfig": {
107
107
  "access": "public",