@rovula/ui 0.0.56 → 0.0.58

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,6 +1,7 @@
1
1
  import React from "react";
2
2
  import "./Tabs.css";
3
3
  type Tab = {
4
+ id?: string;
4
5
  label: string;
5
6
  startTabContent?: React.ReactElement;
6
7
  endTabContent?: React.ReactElement;
@@ -3,6 +3,7 @@ declare const meta: {
3
3
  title: string;
4
4
  component: React.FC<{
5
5
  tabs: {
6
+ id?: string | undefined;
6
7
  label: string;
7
8
  startTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
8
9
  endTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
@@ -38,6 +39,7 @@ declare const meta: {
38
39
  };
39
40
  decorators: ((Story: import("@storybook/types").PartialStoryFn<import("@storybook/react").ReactRenderer, {
40
41
  tabs: {
42
+ id?: string | undefined;
41
43
  label: string;
42
44
  startTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
43
45
  endTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
@@ -83,7 +83,7 @@ export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRig
83
83
  checkedId?: string[];
84
84
  loadingId?: string[];
85
85
  onExpandChange?: (id: string, expanded: boolean) => void;
86
- onCheckedChange?: (checkedState: Record<string, boolean>) => void;
86
+ onCheckedChange?: (checkedState: Record<string, boolean>, id?: string) => void;
87
87
  onClickItem?: (id: string) => void;
88
88
  onCheckedItem?: (id: string, checked: boolean) => void;
89
89
  defaultExpandAll?: boolean;
@@ -91,6 +91,6 @@ export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRig
91
91
  hierarchicalCheck?: boolean;
92
92
  checkable?: boolean;
93
93
  maxLevel?: number;
94
- mode: "checkbox" | "radio";
94
+ mode?: "checkbox" | "radio";
95
95
  autoDisabled?: boolean;
96
96
  }
@@ -77,6 +77,6 @@ const Tabs = ({ tabs = [], value, initialTab = 0, tabBarSize = 38, enableBorderL
77
77
  onTabChange === null || onTabChange === void 0 ? void 0 : onTabChange(index);
78
78
  }, children: [(keepIconSpace || tab.startTabContent) && (_jsx("div", { className: "h-full w-3 flex items-center justify-center", children: tab.isLoading ? _jsx(Loading, {}) : tab.startTabContent })), tab.label, (keepIconSpace || tab.endTabContent) && (_jsx("div", { className: "h-full w-3 flex items-center justify-center", children: tab.endTabContent }))] }, index))), _jsx("div", { className: cn(`absolute left-0 bottom-0 h-[2px] rounded-full bg-foreground transition-all duration-300 ease-in-out`, {
79
79
  "bg-state-disable-solid": disabled,
80
- }, borderSliderClassName), style: sliderStyle })] }) }), enableAddTabButton && (_jsx("div", { className: cn("sticky right-0 flex content-center items-center mx-4", addTabButtonWrapperClassName), children: _jsx(ActionButton, { variant: "outline", size: "sm", onClick: () => onAddTab === null || onAddTab === void 0 ? void 0 : onAddTab(), disabled: disabled, children: _jsx(Icon, { name: "plus" }) }) })), rightAction] }), _jsx("div", { className: cn("mt-4 text-foreground", tabContentClassName), role: "tabpanel", id: `tab-content-${activeTab}`, "aria-labelledby": `tab-${activeTab}`, children: (_a = tabs[activeTab]) === null || _a === void 0 ? void 0 : _a.content })] }));
80
+ }, borderSliderClassName), style: sliderStyle })] }) }), enableAddTabButton && (_jsx("div", { className: cn("sticky right-0 flex content-center items-center mx-4", addTabButtonWrapperClassName), children: _jsx(ActionButton, { variant: "outline", size: "sm", onClick: () => onAddTab === null || onAddTab === void 0 ? void 0 : onAddTab(), disabled: disabled, children: _jsx(Icon, { name: "plus" }) }) })), rightAction] }), _jsx("div", { className: cn("mt-4 text-foreground", tabContentClassName), role: "tabpanel", id: `tab-content-${activeTab}`, "aria-labelledby": `tab-${activeTab}`, children: _jsx("div", { children: (_a = tabs[activeTab]) === null || _a === void 0 ? void 0 : _a.content }, tabs[activeTab].label + tabs[activeTab].id) })] }));
81
81
  };
82
82
  export default Tabs;
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useState } from "react";
3
3
  import TreeItem from "./TreeItem";
4
4
  import { cn } from "@/utils/cn";
5
- const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, loadingId, lineSize, horizontalLineWidth, expandButtonSize, spacing, renderIcon, renderRightSection, renderElement, renderTitle, onExpandChange, onCheckedChange, onClickItem, onCheckedItem, defaultExpandAll = false, defaultCheckAll = false, hierarchicalCheck = false, showIcon = true, disabled, enableSeparatorLine = true, checkable = true, maxLevel, mode, autoDisabled = false, }) => {
5
+ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, loadingId, lineSize, horizontalLineWidth, expandButtonSize, spacing, renderIcon, renderRightSection, renderElement, renderTitle, onExpandChange, onCheckedChange, onClickItem, onCheckedItem, defaultExpandAll = false, defaultCheckAll = false, hierarchicalCheck = false, showIcon = true, disabled, enableSeparatorLine = true, checkable = true, maxLevel, mode = "checkbox", autoDisabled = false, }) => {
6
6
  const [checkedState, setCheckedState] = useState({});
7
7
  const [expandedState, setExpandedState] = useState({});
8
8
  const traverseTree = (nodes, callback) => {
@@ -52,6 +52,30 @@ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, l
52
52
  setCheckedState(checkedId.reduce((prev, cur) => (Object.assign(Object.assign({}, prev), { [cur]: true })), {}));
53
53
  }
54
54
  }, [checkedId]);
55
+ useEffect(() => {
56
+ if (!hierarchicalCheck) {
57
+ return;
58
+ }
59
+ const state = {};
60
+ const updateChildren = (parentId, isChecked) => {
61
+ traverseTree(data, (node) => {
62
+ if (node.id === parentId && node.children) {
63
+ node.children.forEach((child) => {
64
+ state[child.id] = isChecked;
65
+ updateChildren(child.id, isChecked);
66
+ });
67
+ }
68
+ });
69
+ };
70
+ setCheckedState((prev) => {
71
+ Object.keys(prev)
72
+ .filter((key) => prev[key])
73
+ .map((id) => {
74
+ updateChildren(id, true);
75
+ });
76
+ return Object.assign(Object.assign({}, prev), state);
77
+ });
78
+ }, [data, hierarchicalCheck]);
55
79
  const handleExpandChange = useCallback((id, expanded) => {
56
80
  onExpandChange === null || onExpandChange === void 0 ? void 0 : onExpandChange(id, expanded);
57
81
  setExpandedState((prev) => (Object.assign(Object.assign({}, prev), { [id]: expanded })));
@@ -61,7 +85,7 @@ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, l
61
85
  let newState = { [id]: checked };
62
86
  onCheckedItem === null || onCheckedItem === void 0 ? void 0 : onCheckedItem(id, checked);
63
87
  setCheckedState(newState);
64
- onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(newState);
88
+ onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(newState, id);
65
89
  return;
66
90
  }
67
91
  onCheckedItem === null || onCheckedItem === void 0 ? void 0 : onCheckedItem(id, checked);
@@ -99,7 +123,7 @@ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, l
99
123
  }
100
124
  setCheckedState(newState);
101
125
  if (onCheckedChange) {
102
- onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(newState);
126
+ onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(newState, id);
103
127
  }
104
128
  }, [
105
129
  checkedState,
@@ -168,7 +168,7 @@ export const ExpandLoadData = {
168
168
  }, 1500);
169
169
  }
170
170
  };
171
- return (_jsx("div", { className: "flex flex-row gap-4 w-full", children: _jsx(Tree, Object.assign({}, args, { data: data, loadingId: loadingId, onExpandChange: handleOnExpandChange })) }));
171
+ return (_jsx("div", { className: "flex flex-row gap-4 w-full", children: _jsx(Tree, Object.assign({}, args, { data: data, loadingId: loadingId, hierarchicalCheck: true, onExpandChange: handleOnExpandChange })) }));
172
172
  },
173
173
  };
174
174
  export const MaximumLevel = {
@@ -85,6 +85,6 @@ const TreeItem = ({ id, title, classes, children, isFirstLevel = false, isLeaf =
85
85
  !isLastItem &&
86
86
  ((isExpanded && (hasChildren || isLoading)) || !isExpanded) && (_jsx("div", { className: cn("flex w-[2px] h-1/2 bg-grey-150", classes === null || classes === void 0 ? void 0 : classes.branch), style: styles.branch }))] }), _jsxs("div", { className: cn("flex flex-1 items-center py-2 min-h-10", classes === null || classes === void 0 ? void 0 : classes.itemContainer), children: [!isFirstLevel && (_jsx("div", { className: cn("bg-grey-150", classes === null || classes === void 0 ? void 0 : classes.horizontalLine), style: styles.horizontalLine })), isFirstLevel && !shouldExpandButton && (_jsx("div", { className: cn("flex mr-[2px]", classes === null || classes === void 0 ? void 0 : classes.expandButton), style: styles.expandButton })), shouldExpandButton && (_jsx("div", { className: cn("flex mr-[2px]", classes === null || classes === void 0 ? void 0 : classes.expandButton), style: styles.expandButton, onClick: !isLoading && handleExpandToggle, children: _jsx(ActionButton, { variant: "icon", size: "sm", children: isLoading ? (_jsx(Loading, {})) : (_jsx(Icon, { name: isExpanded ? "chevron-down" : "chevron-right" })) }) })), shouldShowCheckbox ? (_jsx(Checkbox, { id: id, className: cn("size-[16px]", classes === null || classes === void 0 ? void 0 : classes.checkbox), checked: isChecked, disabled: disabled, onCheckedChange: (newChecked) => onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(id, newChecked) })) : (_jsx("div", { className: isFirstLevel && checkable
87
87
  ? cn("size-[16px]", classes === null || classes === void 0 ? void 0 : classes.checkbox)
88
- : "" })), _jsxs("div", { className: cn("ml-2 gap-1 flex flex-1 items-center text-foreground", classes === null || classes === void 0 ? void 0 : classes.item), onClick: handleOnClickItem, children: [showIcon ? customIcon || defaultIcon : null, _jsx("div", { className: cn("flex flex-1 cursor-pointer text-subtitle5 text-ellipsis", classes === null || classes === void 0 ? void 0 : classes.title), children: titleContent })] }), rightIcon] })] }), isExpanded && hasChildren && currentLevel < (maxLevel || Infinity) && (_jsxs("div", { className: cn("flex flex-row overflow-hidden max-h-screen", classes === null || classes === void 0 ? void 0 : classes.expandedChildrenWrapper), children: [!isFirstLevel && !isLastItem && (_jsx("div", { className: cn("flex w-[2px] h-full bg-grey-150", classes === null || classes === void 0 ? void 0 : classes.branch), style: styles.branch })), _jsx("div", { className: cn("flex flex-col overflow-hidden max-h-screen", classes === null || classes === void 0 ? void 0 : classes.expandedChildrenWrapperInner), style: styles.childPadding, children: children === null || children === void 0 ? void 0 : children.map((child, idx) => (_jsx(TreeItem, Object.assign({ classes: classes, isLastItem: idx === children.length - 1, checkIsExpanded: checkIsExpanded, checkIsChecked: checkIsChecked, checkAutoDisabled: checkAutoDisabled, checkIsLoading: checkIsLoading, onExpandChange: onExpandChange, onCheckedChange: onCheckedChange, renderIcon: renderIcon, renderElement: renderElement, renderTitle: renderTitle, disabled: checkAutoDisabled(child.id), showIcon: showIcon, lineSize: lineSize, horizontalLineWidth: horizontalLineWidth, expandButtonSize: expandButtonSize, spacing: spacing, notifyClickItem: notifyClickItem, maxLevel: maxLevel, currentLevel: currentLevel + 1, checkable: checkable }, child), child.id))) })] })), enableSeparatorLine && isFirstLevel && !isLastItem && (_jsx("div", { className: cn("bg-grey-150 w-full h-[2px] rounded", classes === null || classes === void 0 ? void 0 : classes.separatorLine) }))] }) }));
88
+ : "" })), _jsxs("div", { className: cn("ml-2 gap-1 flex flex-1 items-center text-foreground", classes === null || classes === void 0 ? void 0 : classes.item), onClick: handleOnClickItem, children: [showIcon ? customIcon || defaultIcon : null, _jsx("div", { className: cn("flex flex-1 cursor-pointer text-subtitle5 text-ellipsis", classes === null || classes === void 0 ? void 0 : classes.title), children: titleContent })] }), rightIcon] })] }), isExpanded && hasChildren && currentLevel < (maxLevel || Infinity) && (_jsxs("div", { className: cn("flex flex-row overflow-hidden", classes === null || classes === void 0 ? void 0 : classes.expandedChildrenWrapper), children: [!isFirstLevel && !isLastItem && (_jsx("div", { className: cn("flex w-[2px] h-full bg-grey-150", classes === null || classes === void 0 ? void 0 : classes.branch), style: styles.branch })), _jsx("div", { className: cn("flex flex-col overflow-hidden", classes === null || classes === void 0 ? void 0 : classes.expandedChildrenWrapperInner), style: styles.childPadding, children: children === null || children === void 0 ? void 0 : children.map((child, idx) => (_jsx(TreeItem, Object.assign({ classes: classes, isLastItem: idx === children.length - 1, checkIsExpanded: checkIsExpanded, checkIsChecked: checkIsChecked, checkAutoDisabled: checkAutoDisabled, checkIsLoading: checkIsLoading, onExpandChange: onExpandChange, onCheckedChange: onCheckedChange, renderIcon: renderIcon, renderElement: renderElement, renderTitle: renderTitle, disabled: checkAutoDisabled(child.id), showIcon: showIcon, lineSize: lineSize, horizontalLineWidth: horizontalLineWidth, expandButtonSize: expandButtonSize, spacing: spacing, notifyClickItem: notifyClickItem, maxLevel: maxLevel, currentLevel: currentLevel + 1, checkable: checkable }, child), child.id))) })] })), enableSeparatorLine && isFirstLevel && !isLastItem && (_jsx("div", { className: cn("bg-grey-150 w-full h-[2px] rounded", classes === null || classes === void 0 ? void 0 : classes.separatorLine) }))] }) }));
89
89
  };
90
90
  export default TreeItem;