react-iro-gradient-picker 1.1.5 → 1.1.6

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;
@@ -7852,19 +7823,16 @@ var IroGradient = function (_a) {
7852
7823
  });
7853
7824
  // Add a small delay to ensure the activeColor state has fully updated
7854
7825
  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
- }
7826
+ updateIroPickerColor({ hex: activeColor.hex, alpha: activeColor.alpha });
7865
7827
  }, 10);
7866
7828
  return function () { return clearTimeout(timeoutId); };
7867
- }, [activeColor, updateIroPickerColor]);
7829
+ }, [
7830
+ activeColor.hex,
7831
+ activeColor.alpha,
7832
+ activeColor.index,
7833
+ activeColor.loc,
7834
+ updateIroPickerColor
7835
+ ]);
7868
7836
  var updateGradient = useCallback(function (newColor) {
7869
7837
  if (Array.isArray(newColor)) {
7870
7838
  // Handle the case where it's called with stops array
@@ -7939,7 +7907,10 @@ var IroGradient = function (_a) {
7939
7907
  setActiveColor(newActiveColor);
7940
7908
  // Update iro picker if available
7941
7909
  if ((_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) {
7942
- updateIroPickerColor(newActiveColor);
7910
+ updateIroPickerColor({
7911
+ hex: newActiveColor.hex,
7912
+ alpha: newActiveColor.alpha
7913
+ });
7943
7914
  }
7944
7915
  // Call onChange with initial value
7945
7916
  onChange(initialValue.current);
@@ -7950,17 +7921,20 @@ var IroGradient = function (_a) {
7950
7921
  var handleColorFromPanel = function (newColor) {
7951
7922
  setColor(newColor);
7952
7923
  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]]);
7924
+ var lastStop_1 = rgbaToArray(newColor.stops[newColor.stops.length - 1][0]);
7925
+ var activeStop_1 = rgbaToHex([lastStop_1[0], lastStop_1[1], lastStop_1[2]]);
7955
7926
  var newActiveColor = {
7956
7927
  hex: activeStop_1,
7957
- alpha: Math.round(lastStop[3] * 100),
7928
+ alpha: Math.round(lastStop_1[3] * 100),
7958
7929
  loc: newColor.stops[newColor.stops.length - 1][1],
7959
7930
  index: newColor.stops.length - 1
7960
7931
  };
7961
7932
  setActiveColor(newActiveColor);
7962
7933
  // Update the iro color picker
7963
- updateIroPickerColor(newActiveColor);
7934
+ updateIroPickerColor({
7935
+ hex: newActiveColor.hex,
7936
+ alpha: newActiveColor.alpha
7937
+ });
7964
7938
  }
7965
7939
  };
7966
7940
  var handleIroColorChange = function (iroColor) {