ar-design 0.4.7 → 0.4.9

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.
@@ -1,5 +1,6 @@
1
1
  import { IBorder, IColors, IIcon, IVariant } from "../../../libs/types/IGlobalProps";
2
2
  interface IProps extends IVariant, IColors, IBorder, IIcon {
3
3
  text: string;
4
+ customColor?: string;
4
5
  }
5
6
  export default IProps;
@@ -2,10 +2,15 @@
2
2
  import React from "react";
3
3
  import "../../../assets/css/components/data-display/chip/chip.css";
4
4
  import Utils from "../../../libs/infrastructure/shared/Utils";
5
- const Chip = ({ variant = "outlined", color = "light", border = { radius: "sm" }, text, icon }) => {
5
+ const Chip = ({ variant = "outlined", color = "light", customColor, border = { radius: "sm" }, text, icon, }) => {
6
6
  let _chipClassName = ["ar-chip"];
7
7
  _chipClassName.push(...Utils.GetClassName(variant, undefined, color, border, undefined, undefined, undefined));
8
- return (React.createElement("div", { className: _chipClassName.map((c) => c).join(" ") },
8
+ return (React.createElement("div", { className: _chipClassName.map((c) => c).join(" "), ...(customColor && {
9
+ style: {
10
+ backgroundColor: customColor,
11
+ color: "var(--black)",
12
+ },
13
+ }) },
9
14
  icon?.element && React.createElement("span", null, icon?.element),
10
15
  React.createElement("span", null, text)));
11
16
  };
@@ -44,6 +44,9 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
44
44
  const _searchTimeOut = useRef(null);
45
45
  // refs -> Filter
46
46
  const _filterButton = useRef([]);
47
+ // refs -> Selection
48
+ const _selectionItems = useRef([]);
49
+ const lastSentRef = useRef([]);
47
50
  // variables
48
51
  const _subrowOpenAutomatically = config.subrow?.openAutomatically ?? false;
49
52
  const _subrowSelector = config.subrow?.selector ?? "subitems";
@@ -52,7 +55,6 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
52
55
  const _tableClassName = ["ar-table", "scroll"];
53
56
  // states
54
57
  const [selectAll, setSelectAll] = useState(false);
55
- const [selectionItems, setSelectionItems] = useState([]);
56
58
  const [showSubitems, setShowSubitems] = useState({});
57
59
  const [rowHeights, setRowHeights] = useState([]);
58
60
  // states -> File
@@ -76,6 +78,8 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
76
78
  const [totalRecords, setTotalRecords] = useState(0);
77
79
  const [currentPage, setCurrentPage] = useState(1);
78
80
  const [selectedPerPage, setSelectedPerPage] = useState(pagination?.perPage ?? 10);
81
+ // states -> Selection
82
+ const [_, setTriggerForRender] = useState(false);
79
83
  // states -> Mobil
80
84
  const [isMobile, setIsMobile] = useState(false);
81
85
  // hooks
@@ -371,11 +375,18 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
371
375
  _tBodyTR.current[index] = element;
372
376
  }, style: { ..._rowColor }, ...(onDnD && data.length > 1 ? { className: "draggable", draggable: true } : {}) },
373
377
  selections && (React.createElement("td", { className: "flex justify-content-center sticky-left", "data-sticky-position": "left" },
374
- React.createElement(Checkbox, { ref: (element) => (_checkboxItems.current[index] = element), variant: "filled", color: "green", checked: selectionItems.some((selectionItem) => trackBy?.(selectionItem) === trackBy?.(item)), onChange: (event) => {
375
- if (event.target.checked)
376
- setSelectionItems((prev) => [...prev, item]);
377
- else
378
- setSelectionItems((prev) => prev.filter((_item) => trackBy?.(_item) !== trackBy?.(item)));
378
+ React.createElement(Checkbox, { key: Date.now(), ref: (element) => (_checkboxItems.current[index] = element), variant: "filled", color: "green", checked: _selectionItems.current.some((selectionItem) => trackBy?.(selectionItem) === trackBy?.(item)), onChange: (event) => {
379
+ const key = trackBy?.(item);
380
+ if (event.target.checked) {
381
+ if (!_selectionItems.current.some((_item) => trackBy?.(_item) === key)) {
382
+ _selectionItems.current = [..._selectionItems.current, item];
383
+ }
384
+ }
385
+ else {
386
+ _selectionItems.current = _selectionItems.current.filter((_item) => trackBy?.(_item) !== key);
387
+ }
388
+ selections(_selectionItems.current);
389
+ setTriggerForRender((prev) => !prev);
379
390
  } }))),
380
391
  isHasSubitems && _subrowButton ? (React.createElement("td", null, item[_subrowSelector] && (React.createElement("div", { className: "subitem-open-button-wrapper" },
381
392
  React.createElement("span", { className: `subitem-open-button ${(showSubitems[index] && "opened") ?? ""}`, onClick: () => {
@@ -464,17 +475,16 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
464
475
  }, [getData, columns, showSubitems, rowHeights]);
465
476
  // useEffects
466
477
  useEffect(() => {
467
- if (Utils.DeepEqual(previousSelections, selectionItems))
468
- return;
469
- if (previousSelections && previousSelections.length > 0) {
470
- const validSelections = data.filter((item) => previousSelections.some((selected) => trackBy?.(selected) === trackBy?.(item)));
471
- setSelectionItems(validSelections);
478
+ if (!previousSelections || previousSelections.length === 0) {
479
+ _selectionItems.current = [];
472
480
  return;
473
481
  }
474
- else {
475
- setSelectionItems([]);
482
+ const validSelections = data.filter((item) => previousSelections.some((selected) => trackBy?.(selected) === trackBy?.(item)));
483
+ // Gereksiz overwrite’i engelle
484
+ if (!Utils.DeepEqual(_selectionItems.current, validSelections)) {
485
+ _selectionItems.current = validSelections;
476
486
  }
477
- }, [previousSelections, data]);
487
+ }, [previousSelections, data, trackBy]);
478
488
  useEffect(() => {
479
489
  if (config?.isServerSide && searchedParams) {
480
490
  const searchRecord = {};
@@ -517,14 +527,17 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
517
527
  pagination.onChange?.(1, selectedPerPage);
518
528
  }, [checkboxSelectedParams]);
519
529
  useEffect(() => {
520
- if (typeof selections === "function" && Array.isArray(selectionItems)) {
521
- selections(selectionItems.map((selectionItem) => ({ ...selectionItem, trackByValue: trackBy?.(selectionItem) })));
522
- }
523
- if (Array.isArray(_checkboxItems.current) && _checkboxItems.current.length > 0) {
524
- const allChecked = _checkboxItems.current.every((item) => item?.checked === true);
525
- setSelectAll(allChecked);
530
+ if (typeof selections !== "function")
531
+ return;
532
+ const payload = _selectionItems.current.map((item) => ({
533
+ ...item,
534
+ trackByValue: trackBy?.(item),
535
+ }));
536
+ if (!Utils.DeepEqual(payload, lastSentRef.current)) {
537
+ lastSentRef.current = payload;
538
+ selections(payload);
526
539
  }
527
- }, [selectionItems, currentPage, selectedPerPage]);
540
+ }, [selections, trackBy]);
528
541
  useEffect(() => {
529
542
  // Filter Content alanı re-render işlemi.
530
543
  if (filterCurrentColumn && filterCurrentDataType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",