react-asc 18.5.0 → 18.6.0

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.
@@ -7,7 +7,7 @@ export interface ITreeNodeProps {
7
7
  hasChildren: boolean;
8
8
  isExpanded: boolean;
9
9
  isSelected: boolean;
10
- onClick: (id: string) => void;
10
+ onToggleExpand: (id: string) => void;
11
11
  onClickSelect: (id: string) => void;
12
12
  }
13
13
  export declare const TreeNode: (props: ITreeNodeProps) => JSX.Element;
@@ -1,6 +1,13 @@
1
1
  /// <reference types="react" />
2
+ export interface ITreeNode {
3
+ id: string;
4
+ label: string;
5
+ children?: Array<ITreeNode>;
6
+ }
2
7
  export interface ITreeViewProps {
3
- data: Array<any>;
4
- onSelect: (selectedItems: Array<any>) => void;
8
+ data: Array<ITreeNode>;
9
+ onSelect?: (selectedItems: Array<any>) => void;
10
+ onExpand?: (id: string) => void;
11
+ onCollapse?: (id: string) => void;
5
12
  }
6
13
  export declare const TreeView: (props: ITreeViewProps) => JSX.Element;
package/index.es.js CHANGED
@@ -2440,16 +2440,16 @@ const TimeSelect = (props) => {
2440
2440
  };
2441
2441
 
2442
2442
  const TreeNode = (props) => {
2443
- const { id, label, level, hasChildren, isExpanded, isSelected, onClick, onClickSelect } = props;
2443
+ const { id, label, level, hasChildren, isExpanded, isSelected, onToggleExpand, onClickSelect } = props;
2444
2444
  return (React.createElement("li", { className: "tree-node", style: { paddingLeft: `${(48 * level) + (hasChildren ? 0 : 1) * 48}px` } },
2445
2445
  hasChildren &&
2446
- React.createElement(IconButton, { onClick: () => onClick(id), icon: !isExpanded ? React.createElement(ChevronRightSolidIcon, null) : React.createElement(ChevronDownSolidIcon, null) }),
2446
+ React.createElement(IconButton, { onClick: () => onToggleExpand(id), icon: !isExpanded ? React.createElement(ChevronRightSolidIcon, null) : React.createElement(ChevronDownSolidIcon, null) }),
2447
2447
  React.createElement(Checkbox, { checked: isSelected, onChange: () => onClickSelect(id) }),
2448
2448
  label));
2449
2449
  };
2450
2450
 
2451
2451
  const TreeView = (props) => {
2452
- const { data, onSelect } = props;
2452
+ const { data, onSelect, onExpand, onCollapse } = props;
2453
2453
  const [flattenData, setFlattenData] = useState([]);
2454
2454
  const [expandedItems, setExpandedItems] = useState([]);
2455
2455
  const [selectedItemIds, setSelectedItemIds] = useState([]);
@@ -2468,14 +2468,16 @@ const TreeView = (props) => {
2468
2468
  useEffect(() => {
2469
2469
  setFlattenData(flattenDeep(data));
2470
2470
  }, [data]);
2471
- const handleNodeClick = (item) => {
2471
+ const handleOnToggleExpand = (item) => {
2472
2472
  if (item.hasChildren) {
2473
2473
  let newExpandedItems = [...expandedItems];
2474
2474
  if (isExpanded(item.id)) {
2475
2475
  newExpandedItems = collapseRecursive(item, [...expandedItems]);
2476
+ onCollapse && onCollapse(item.id);
2476
2477
  }
2477
2478
  else {
2478
2479
  newExpandedItems.push(item);
2480
+ onExpand && onExpand(item.id);
2479
2481
  }
2480
2482
  setExpandedItems(newExpandedItems);
2481
2483
  }
@@ -2516,7 +2518,7 @@ const TreeView = (props) => {
2516
2518
  };
2517
2519
  return (React.createElement("ul", { className: "treeview" }, flattenData.map(item => {
2518
2520
  return isItemVisible(item) &&
2519
- React.createElement(TreeNode, { key: item.id, id: item.id, label: item.label, level: item.level, parentId: item.parentId, isExpanded: isExpanded(item.id), isSelected: isSelected(item.id), hasChildren: item.hasChildren, onClick: () => handleNodeClick(item), onClickSelect: () => handleNodeClickSelect(item) });
2521
+ React.createElement(TreeNode, { key: item.id, id: item.id, label: item.label, level: item.level, parentId: item.parentId, isExpanded: isExpanded(item.id), isSelected: isSelected(item.id), hasChildren: item.hasChildren, onToggleExpand: () => handleOnToggleExpand(item), onClickSelect: () => handleNodeClickSelect(item) });
2520
2522
  })));
2521
2523
  };
2522
2524