react-iro-gradient-picker 1.1.5 → 1.1.7

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/README.md CHANGED
@@ -59,12 +59,22 @@ yarn add react-iro-gradient-picker
59
59
  pnpm add react-iro-gradient-picker
60
60
  ```
61
61
 
62
+ ### ⚠️ **IMPORTANT: Import CSS Styles**
63
+
64
+ **You MUST import the CSS file for the component to work properly:**
65
+
66
+ ```tsx
67
+ import 'react-iro-gradient-picker/dist/index.css';
68
+ ```
69
+
70
+ Add this import at the top of your main App.js/App.tsx file or in your main CSS/SCSS file.
71
+
62
72
  ### Basic Usage
63
73
 
64
74
  ```tsx
65
75
  import React, { useState } from 'react';
66
76
  import ColorPicker from 'react-iro-gradient-picker';
67
- import 'react-iro-gradient-picker/dist/index.css'; // Import CSS styles
77
+ import 'react-iro-gradient-picker/dist/index.css'; // ⚠️ REQUIRED CSS import
68
78
 
69
79
  function App() {
70
80
  const [color, setColor] = useState('#3B82F6');
@@ -89,6 +99,7 @@ export default App;
89
99
  ```tsx
90
100
  import React, { useState } from 'react';
91
101
  import ColorPicker from 'react-iro-gradient-picker';
102
+ import 'react-iro-gradient-picker/dist/index.css'; // ⚠️ REQUIRED CSS import
92
103
 
93
104
  function App() {
94
105
  const [color, setColor] = useState('#3B82F6');
package/dist/index.es.js CHANGED
@@ -7632,39 +7632,22 @@ var useDebounce = (function (value, delay) {
7632
7632
  });
7633
7633
 
7634
7634
  var IroGradient = function (_a) {
7635
- var _b;
7636
- var _c = _a.value, value = _c === void 0 ? 'linear-gradient(90deg, #ffffff 0%, #000000 100%)' : _c, _d = _a.onChange, onChange = _d === void 0 ? function () { return ({}); } : _d, _e = _a.format, format = _e === void 0 ? 'rgb' : _e, _f = _a.debounceMS, debounceMS = _f === void 0 ? 300 : _f, _g = _a.debounce, debounce = _g === void 0 ? true : _g, _h = _a.showAlpha, showAlpha = _h === void 0 ? true : _h, _j = _a.showInputs, showInputs = _j === void 0 ? true : _j, _k = _a.showGradientResult, showGradientResult = _k === void 0 ? true : _k, _l = _a.showGradientStops, showGradientStops = _l === void 0 ? true : _l, _m = _a.showGradientMode, showGradientMode = _m === void 0 ? true : _m, _o = _a.showGradientAngle, showGradientAngle = _o === void 0 ? true : _o, _p = _a.showGradientPosition, showGradientPosition = _p === void 0 ? true : _p, _q = _a.allowAddGradientStops, allowAddGradientStops = _q === void 0 ? true : _q, _r = _a.colorBoardHeight, colorBoardHeight = _r === void 0 ? 120 : _r, defaultColors = _a.defaultColors, _s = _a.showReset, showReset = _s === void 0 ? false : _s, onReset = _a.onReset;
7635
+ var _b = _a.value, value = _b === void 0 ? 'linear-gradient(90deg, #ffffff 0%, #000000 100%)' : _b, _c = _a.onChange, onChange = _c === void 0 ? function () { return ({}); } : _c, _d = _a.format, format = _d === void 0 ? 'rgb' : _d, _e = _a.debounceMS, debounceMS = _e === void 0 ? 300 : _e, _f = _a.debounce, debounce = _f === void 0 ? true : _f, _g = _a.showAlpha, showAlpha = _g === void 0 ? true : _g, _h = _a.showInputs, showInputs = _h === void 0 ? true : _h, _j = _a.showGradientResult, showGradientResult = _j === void 0 ? true : _j, _k = _a.showGradientStops, showGradientStops = _k === void 0 ? true : _k, _l = _a.showGradientMode, showGradientMode = _l === void 0 ? true : _l, _m = _a.showGradientAngle, showGradientAngle = _m === void 0 ? true : _m, _o = _a.showGradientPosition, showGradientPosition = _o === void 0 ? true : _o, _p = _a.allowAddGradientStops, allowAddGradientStops = _p === void 0 ? true : _p, _q = _a.colorBoardHeight, colorBoardHeight = _q === void 0 ? 120 : _q, defaultColors = _a.defaultColors, _r = _a.showReset, showReset = _r === void 0 ? false : _r, onReset = _a.onReset;
7637
7636
  // Store the initial value for reset functionality
7638
7637
  var initialValue = useRef(value);
7639
7638
  var parsedColors = useCallback(function () {
7640
7639
  return parseGradient(value);
7641
7640
  // eslint-disable-next-line react-hooks/exhaustive-deps
7642
7641
  }, [value]);
7643
- var _t = parsedColors(), stops = _t.stops, type = _t.type, modifier = _t.modifier;
7644
- // Safely extract active stop information with fallbacks
7645
- var safeStops = stops && stops.length > 0
7646
- ? stops
7647
- : [
7648
- ['rgba(255,255,255,1)', 0],
7649
- ['rgba(0,0,0,1)', 100]
7650
- ];
7651
- var activeStopIndex = safeStops.length - 1;
7652
- var activeStop = '#ffffff';
7653
- var activeAlpha = 100;
7654
- try {
7655
- var lastStop = rgbaToArray(safeStops[activeStopIndex][0]);
7656
- if (lastStop && lastStop.length >= 4) {
7657
- activeStop = rgbaToHex([lastStop[0], lastStop[1], lastStop[2]]);
7658
- activeAlpha = Math.round((lastStop[3] || 1) * 100);
7659
- }
7660
- }
7661
- catch (error) {
7662
- console.warn('⚠️ Error parsing gradient stops, using defaults:', error);
7663
- }
7642
+ var _s = parsedColors(), stops = _s.stops, type = _s.type, modifier = _s.modifier;
7643
+ var lastStop = rgbaToArray(stops[stops.length - 1][0]);
7644
+ var activeStopIndex = stops.length - 1;
7645
+ var activeStop = rgbaToHex([lastStop[0], lastStop[1], lastStop[2]]);
7646
+ var activeAlpha = Math.round(lastStop[3] * 100);
7664
7647
  var iroPickerRef = useRef(null);
7665
7648
  var containerRef = useRef(null);
7666
7649
  var isUpdatingFromGradientStop = useRef(false);
7667
- var _u = __read(useState(200), 2), pickerWidth = _u[0], setPickerWidth = _u[1];
7650
+ var _t = __read(useState(200), 2), pickerWidth = _t[0], setPickerWidth = _t[1];
7668
7651
  // Responsive width for IroColorPicker - match solid picker logic
7669
7652
  useEffect(function () {
7670
7653
  if (!containerRef.current)
@@ -7703,39 +7686,27 @@ var IroGradient = function (_a) {
7703
7686
  resizeObserver.observe(containerRef.current);
7704
7687
  return function () { return resizeObserver.disconnect(); };
7705
7688
  }, []);
7706
- var _v = __read(useState({
7689
+ var _u = __read(useState({
7707
7690
  gradient: value,
7708
7691
  type: type,
7709
7692
  modifier: modifier,
7710
- stops: safeStops
7711
- }), 2), color = _v[0], setColor = _v[1];
7712
- var _w = __read(useState({
7713
- hex: activeStop || '#ffffff',
7714
- alpha: activeAlpha !== null && activeAlpha !== void 0 ? activeAlpha : 100,
7715
- loc: ((_b = safeStops[activeStopIndex]) === null || _b === void 0 ? void 0 : _b[1]) || 0,
7716
- index: activeStopIndex || 0
7717
- }), 2), activeColor = _w[0], setActiveColor = _w[1];
7693
+ stops: stops
7694
+ }), 2), color = _u[0], setColor = _u[1];
7695
+ var _v = __read(useState({
7696
+ hex: activeStop,
7697
+ alpha: activeAlpha,
7698
+ loc: stops[activeStopIndex][1],
7699
+ index: activeStopIndex
7700
+ }), 2), activeColor = _v[0], setActiveColor = _v[1];
7718
7701
  var debounceColor = useDebounce(color, debounceMS);
7719
7702
  // Update iro picker color
7720
7703
  var updateIroPickerColor = useCallback(function (colorData, retryCount) {
7721
7704
  if (retryCount === void 0) { retryCount = 0; }
7722
7705
  var maxRetries = 5;
7723
- // Validate input data before proceeding
7724
- if (!colorData || !colorData.hex || colorData.alpha == null) {
7725
- console.warn('❌ Invalid color data provided to updateIroPickerColor:', colorData);
7726
- return;
7727
- }
7728
- // Ensure hex is valid (starts with # and has proper length)
7729
- if (!/^#[0-9A-Fa-f]{6}$/i.test(colorData.hex)) {
7730
- console.warn('❌ Invalid hex format provided:', colorData.hex);
7731
- return;
7732
- }
7733
- // Ensure alpha is a valid number between 0 and 100
7734
- if (isNaN(colorData.alpha) ||
7735
- colorData.alpha < 0 ||
7736
- colorData.alpha > 100) {
7737
- console.warn('❌ Invalid alpha value provided:', colorData.alpha);
7738
- return;
7706
+ // Validate input data
7707
+ if (!colorData || !colorData.hex || typeof colorData.alpha !== 'number') {
7708
+ console.log('❌ Invalid color data provided to updateIroPickerColor:', colorData);
7709
+ return; // Early return if invalid data
7739
7710
  }
7740
7711
  var updateColor = function () {
7741
7712
  var _a, _b, _c, _d, _e, _f;
@@ -7813,7 +7784,9 @@ var IroGradient = function (_a) {
7813
7784
  useEffect(function () {
7814
7785
  var initializeIroPicker = function () {
7815
7786
  var _a, _b;
7816
- if (((_b = (_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) === null || _b === void 0 ? void 0 : _b.color) && activeColor.hex) {
7787
+ if (((_b = (_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) === null || _b === void 0 ? void 0 : _b.color) &&
7788
+ activeColor.hex &&
7789
+ typeof activeColor.alpha === 'number') {
7817
7790
  console.log('🚀 Initializing iro picker with activeColor:', activeColor);
7818
7791
  // Wait a bit for the picker to be fully ready, then update
7819
7792
  setTimeout(function () {
@@ -7834,13 +7807,19 @@ var IroGradient = function (_a) {
7834
7807
  var handleSetActiveColor = useCallback(function (newActiveColor) {
7835
7808
  console.log('🎯 Gradient stop clicked, setting active color:', newActiveColor);
7836
7809
  setActiveColor(newActiveColor);
7837
- // Force immediate update of iro picker with longer delay for first-time reliability
7838
- setTimeout(function () {
7839
- updateIroPickerColor({
7840
- hex: newActiveColor.hex,
7841
- alpha: newActiveColor.alpha
7842
- });
7843
- }, 50); // Increased from 5ms to 50ms for better first-time success
7810
+ // Validate before updating iro picker
7811
+ if (newActiveColor.hex && typeof newActiveColor.alpha === 'number') {
7812
+ // Force immediate update of iro picker with longer delay for first-time reliability
7813
+ setTimeout(function () {
7814
+ updateIroPickerColor({
7815
+ hex: newActiveColor.hex,
7816
+ alpha: newActiveColor.alpha
7817
+ });
7818
+ }, 50); // Increased from 5ms to 50ms for better first-time success
7819
+ }
7820
+ else {
7821
+ console.log('⚠️ Skipping iro picker update in handleSetActiveColor - invalid data:', newActiveColor);
7822
+ }
7844
7823
  }, [updateIroPickerColor]);
7845
7824
  // Update iro picker when activeColor changes (e.g., clicking gradient stops)
7846
7825
  useEffect(function () {
@@ -7850,18 +7829,14 @@ var IroGradient = function (_a) {
7850
7829
  index: activeColor.index,
7851
7830
  loc: activeColor.loc
7852
7831
  });
7832
+ // Validate activeColor before proceeding
7833
+ if (!activeColor.hex || typeof activeColor.alpha !== 'number') {
7834
+ console.log('⚠️ Skipping iro picker update - invalid activeColor:', activeColor);
7835
+ return;
7836
+ }
7853
7837
  // Add a small delay to ensure the activeColor state has fully updated
7854
7838
  var timeoutId = setTimeout(function () {
7855
- // Only call updateIroPickerColor if we have valid hex and alpha values
7856
- if (activeColor.hex && activeColor.alpha != null) {
7857
- updateIroPickerColor({
7858
- hex: activeColor.hex,
7859
- alpha: activeColor.alpha
7860
- });
7861
- }
7862
- else {
7863
- console.warn('⚠️ Skipping iro picker update due to invalid activeColor:', activeColor);
7864
- }
7839
+ updateIroPickerColor({ hex: activeColor.hex, alpha: activeColor.alpha });
7865
7840
  }, 10);
7866
7841
  return function () { return clearTimeout(timeoutId); };
7867
7842
  }, [activeColor, updateIroPickerColor]);
@@ -7939,7 +7914,10 @@ var IroGradient = function (_a) {
7939
7914
  setActiveColor(newActiveColor);
7940
7915
  // Update iro picker if available
7941
7916
  if ((_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) {
7942
- updateIroPickerColor(newActiveColor);
7917
+ updateIroPickerColor({
7918
+ hex: newActiveColor.hex,
7919
+ alpha: newActiveColor.alpha
7920
+ });
7943
7921
  }
7944
7922
  // Call onChange with initial value
7945
7923
  onChange(initialValue.current);
@@ -7950,17 +7928,20 @@ var IroGradient = function (_a) {
7950
7928
  var handleColorFromPanel = function (newColor) {
7951
7929
  setColor(newColor);
7952
7930
  if (newColor === null || newColor === void 0 ? void 0 : newColor.stops) {
7953
- var lastStop = rgbaToArray(newColor.stops[newColor.stops.length - 1][0]);
7954
- var activeStop_1 = rgbaToHex([lastStop[0], lastStop[1], lastStop[2]]);
7931
+ var lastStop_1 = rgbaToArray(newColor.stops[newColor.stops.length - 1][0]);
7932
+ var activeStop_1 = rgbaToHex([lastStop_1[0], lastStop_1[1], lastStop_1[2]]);
7955
7933
  var newActiveColor = {
7956
7934
  hex: activeStop_1,
7957
- alpha: Math.round(lastStop[3] * 100),
7935
+ alpha: Math.round(lastStop_1[3] * 100),
7958
7936
  loc: newColor.stops[newColor.stops.length - 1][1],
7959
7937
  index: newColor.stops.length - 1
7960
7938
  };
7961
7939
  setActiveColor(newActiveColor);
7962
7940
  // Update the iro color picker
7963
- updateIroPickerColor(newActiveColor);
7941
+ updateIroPickerColor({
7942
+ hex: newActiveColor.hex,
7943
+ alpha: newActiveColor.alpha
7944
+ });
7964
7945
  }
7965
7946
  };
7966
7947
  var handleIroColorChange = function (iroColor) {