pixel-react-excel-sheet 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pixel-react-excel-sheet",
3
3
  "description": "Great for pixel-perfect, design-focused components in React",
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
7
7
  "types": "lib/index.d.ts",
@@ -520,6 +520,23 @@ function applyUnderlineToCells(
520
520
  return updatedData;
521
521
  }
522
522
 
523
+ function isValidHexColor(color: string): boolean {
524
+ if (color.length !== 6) {
525
+ return false;
526
+ }
527
+
528
+ const hexChars = '0123456789ABCDEFabcdef';
529
+ for (let i = 1; i < color.length; i++) {
530
+ console.log(typeof color[i]);
531
+
532
+ if (!hexChars.includes(color[i] as string)) {
533
+ return false;
534
+ }
535
+ }
536
+
537
+ return true;
538
+ }
539
+
523
540
  function applyColorToCells(
524
541
  currentData: Matrix.Matrix<Types.CellBase<any>>,
525
542
  selectedRange: PointRange | null,
@@ -533,9 +550,9 @@ function applyColorToCells(
533
550
 
534
551
  let updatedData = currentData;
535
552
 
536
- const isHexColor = (color: string) => /^#[0-9A-Fa-f]{6}$/i.test(color);
553
+ const isHex = isValidHexColor(color);
537
554
 
538
- const applyColor = isHexColor(color) ? `#${color}` : color;
555
+ const applyColor = isHex ? `#${color}` : color;
539
556
 
540
557
  for (let row = start.row; row <= end.row; row++) {
541
558
  for (let col = start.column; col <= end.column; col++) {
@@ -570,6 +587,10 @@ function applyBackgroundColorToCells(
570
587
 
571
588
  let updatedData = currentData;
572
589
 
590
+ const isHex = isValidHexColor(backgroundColor);
591
+
592
+ const applyColor = isHex ? `#${backgroundColor}` : backgroundColor;
593
+
573
594
  for (let row = start.row; row <= end.row; row++) {
574
595
  for (let col = start.column; col <= end.column; col++) {
575
596
  const currentCell = Matrix.get({ row, column: col }, updatedData);
@@ -578,13 +599,11 @@ function applyBackgroundColorToCells(
578
599
  continue;
579
600
  }
580
601
 
581
- let HexCode = backgroundColor.length === 6;
582
-
583
602
  const updatedCell = {
584
603
  ...currentCell,
585
604
  style: {
586
605
  ...currentCell.style,
587
- backgroundColor: HexCode ? `#${backgroundColor}` : backgroundColor,
606
+ backgroundColor: applyColor,
588
607
  },
589
608
  };
590
609
 
@@ -67,7 +67,7 @@ const ExcelToolBar: React.FC<ExcelToolBarProps> = ({
67
67
  };
68
68
 
69
69
  const getTextColor = (color: string) => {
70
- setColorPicker((prev) => ({ ...prev, color }));
70
+ setColorPicker((prev) => ({ ...prev, color: color }));
71
71
  };
72
72
 
73
73
  const getBackgroundColor = (color: string) => {
@@ -76,6 +76,8 @@ const ExcelToolBar: React.FC<ExcelToolBarProps> = ({
76
76
 
77
77
  useEffect(() => {
78
78
  let timeGap = setTimeout(() => {
79
+ console.log(colorContainer.color);
80
+
79
81
  setColor(data, colorContainer.color);
80
82
  }, 0);
81
83
  return () => {