@bigbinary/neetoui 5.1.16 → 5.1.17

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/index.js CHANGED
@@ -19839,6 +19839,7 @@ var ColorPicker = function ColorPicker(_ref) {
19839
19839
  _useState2 = _slicedToArray$2(_useState, 2),
19840
19840
  colorInternal = _useState2[0],
19841
19841
  setColorInternal = _useState2[1];
19842
+ var isInputChanged = useRef(false);
19842
19843
  var _useEyeDropper = useEyeDropper({
19843
19844
  pickRadius: 3
19844
19845
  // cursorActive: CSS Cursors,
@@ -19852,15 +19853,31 @@ var ColorPicker = function ColorPicker(_ref) {
19852
19853
  var PickerComponent = showTransparencyControl ? ne : Z;
19853
19854
  var colorValue = (_ref2 = color !== null && color !== void 0 ? color : colorInternal) !== null && _ref2 !== void 0 ? _ref2 : "";
19854
19855
  var onChangeInternal = onChange || setColorInternal;
19855
- var onColorChange = function onColorChange(hex) {
19856
+ var getColor = function getColor(colorValue) {
19857
+ var color = tinycolor(colorValue);
19858
+ return {
19859
+ hex: showTransparencyControl ? color.toHex8String() : color.toHexString(),
19860
+ rgb: color.toRgb()
19861
+ };
19862
+ };
19863
+ var onColorInputChange = function onColorInputChange(hex) {
19856
19864
  var color = tinycolor(hex);
19857
19865
  var rgb = color.toRgb();
19858
- var hexValue = showTransparencyControl ? color.toHex8String() : color.toHexString();
19866
+ isInputChanged.current = true;
19859
19867
  onChangeInternal({
19860
- hex: hexValue,
19868
+ hex: hex,
19861
19869
  rgb: rgb
19862
19870
  });
19863
19871
  };
19872
+ var onPickerChange = function onPickerChange(hex) {
19873
+ return onChangeInternal(getColor(hex));
19874
+ };
19875
+ var onBlur = function onBlur() {
19876
+ // If input is not changed, don't call onChange on blur
19877
+ if (!isInputChanged.current) return;
19878
+ isInputChanged.current = false;
19879
+ onChangeInternal(getColor(colorValue));
19880
+ };
19864
19881
  var pickColor = /*#__PURE__*/function () {
19865
19882
  var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
19866
19883
  var colorResponse, colorHex;
@@ -19873,7 +19890,7 @@ var ColorPicker = function ColorPicker(_ref) {
19873
19890
  case 3:
19874
19891
  colorResponse = _context.sent;
19875
19892
  colorHex = tinycolor(colorResponse.sRGBHex).toHexString();
19876
- onColorChange(colorHex);
19893
+ onPickerChange(colorHex);
19877
19894
  _context.next = 10;
19878
19895
  break;
19879
19896
  case 8:
@@ -19929,7 +19946,7 @@ var ColorPicker = function ColorPicker(_ref) {
19929
19946
  className: "neeto-ui-colorpicker__pointer"
19930
19947
  }, /*#__PURE__*/React__default.createElement(PickerComponent, {
19931
19948
  color: colorValue,
19932
- onChange: onColorChange
19949
+ onChange: onPickerChange
19933
19950
  })), /*#__PURE__*/React__default.createElement("div", {
19934
19951
  className: "neeto-ui-flex neeto-ui-items-center neeto-ui-justify-center neeto-ui-mt-2 neeto-ui-gap-2"
19935
19952
  }, showEyeDropper && isSupported() && /*#__PURE__*/React__default.createElement(Button, {
@@ -19947,7 +19964,8 @@ var ColorPicker = function ColorPicker(_ref) {
19947
19964
  }, /*#__PURE__*/React__default.createElement(Oe, {
19948
19965
  alpha: !!showTransparencyControl,
19949
19966
  color: colorValue,
19950
- onChange: onColorChange
19967
+ onBlur: onBlur,
19968
+ onChange: onColorInputChange
19951
19969
  })))), colorPaletteProps && /*#__PURE__*/React__default.createElement("div", {
19952
19970
  className: "neeto-ui-colorpicker__palette-wrapper",
19953
19971
  "data-testid": "color-palette"